Advertisement
Guest User

Untitled

a guest
Oct 21st, 2016
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module test
  2. exports all
  3. definitions
  4.  
  5. state StateName of
  6. -- TODO Define state here
  7. end
  8.  
  9. types
  10. -- TODO Define types here
  11. SET_WALL:: ;
  12. NO_WALL::;
  13. UNKNOWN:: ;
  14.  
  15. WALL= SET_WALL | NO_WALL | UNKNOWN;
  16. ROW= seq of WALL;
  17. COL= seq of WALL;
  18. NUMBERS= seq of int;
  19. BOARD::
  20.     r: seq of ROW
  21.     c: seq of COL
  22.     n: seq of NUMBERS;
  23.  
  24. values
  25. -- TODO Define values here
  26.  
  27. functions
  28. -- TODO Define functions here
  29.  
  30. initB: NUMBERS * NUMBERS -> BOARD
  31. initB(n1,n2) == mk_BOARD([[mk_UNKNOWN(),mk_UNKNOWN(),mk_UNKNOWN()], --ROW
  32.                                                             [mk_UNKNOWN(),mk_UNKNOWN(),mk_UNKNOWN()],
  33.                                                             [mk_UNKNOWN(),mk_UNKNOWN(),mk_UNKNOWN()]],
  34.                                                     [
  35.                                                             [mk_UNKNOWN(),mk_UNKNOWN()], --COL
  36.                                                             [mk_UNKNOWN(),mk_UNKNOWN()],
  37.                                                             [mk_UNKNOWN(),mk_UNKNOWN()],
  38.                                                             [mk_UNKNOWN(),mk_UNKNOWN()]],
  39.                                                     [
  40.                                                             n1, --NUMBERS
  41.                                                             n2]
  42.                                                             );
  43.  
  44. setWall: seq of ROW * seq of COL * BOARD -> BOARD
  45. setWall(r, c, b) == mk_BOARD(r,c,b.n);-- b(0)[y][x]=w ;
  46.  
  47. isValid: BOARD -> bool
  48. isValid(b) ==
  49.  
  50.     --General varibles
  51.    
  52.     --Horizontal variables
  53.     let h11 = b.r(1)(1) in  -- Horizntal (1,1)
  54.     let h12 = b.r(1)(2) in  -- Horizntal (1,2)
  55.     let h13 = b.r(1)(3) in --Horizontal(1,3)
  56.     let h21 = b.r(2)(1) in --Horizontal(2,1)
  57.     let h22 = b.r(2)(2) in --Horizontal(2,2)
  58.     let h23 = b.r(2)(3) in --Horizontal(2,3)
  59.     let h31 = b.r(3)(1) in --Horizontal(3,1)
  60.     let h32 = b.r(3)(2) in --Horizontal(3,2)
  61.     let h33 = b.r(3)(3) in --Horizontal(3,3)
  62.     let h11s = (h11=mk_SET_WALL()) in  -- Horizntal  (1,1) SET_WALL
  63.     let h11u = (h11=mk_UNKNOWN()) in  -- Horizntal  (1,1) UNKNOWN
  64.     let h11n = (h11=mk_NO_WALL()) in  -- Horizntal  (1,1) NO_WALL
  65.     let h12s = (h12=mk_SET_WALL()) in  -- Horizntal  (1,2) SET_WALL
  66.     let h13s = (h13=mk_SET_WALL()) in  -- Horizntal  (1,3) SET_WALL
  67.     let h13u = (h13=mk_UNKNOWN()) in --Horizontal (1,3) UNKNOWN
  68.     let h13n = (h13=mk_NO_WALL()) in --Horizontal (1,3) NO_WALL
  69.     let h21s = (h21=mk_SET_WALL()) in  -- Horizntal  (2,1) SET_WALL
  70.     let h22s = (h22=mk_SET_WALL()) in  -- Horizntal  (2,2) SET_WALL
  71.     let h23s = (h23=mk_SET_WALL()) in  -- Horizntal  (2,3) SET_WALL
  72.     let h31s = (h31=mk_SET_WALL()) in  -- Horizntal  (3,1) SET_WALL
  73.     let h31u = (h31=mk_UNKNOWN()) in --Horizontal (3,1) UNKNOWN
  74.     let h31n = (h31=mk_NO_WALL()) in --Horizontal (3,1) NO_WALL
  75.     let h32s = (h32=mk_SET_WALL()) in  -- Horizntal  (3,2) SET_WALL
  76.     let h33s = (h33=mk_SET_WALL()) in  -- Horizntal  (3,3) SET_WALL
  77.     let h33u = (h33=mk_UNKNOWN()) in --Horizontal (3,3) UKNOWN
  78.     let h33n = (h33=mk_NO_WALL()) in --Horizontal (3,3) NO_WALL
  79.    
  80.     --Vertical variables
  81.     let v11 = b.c(1)(1) in  -- Vertical  (1,1)
  82.     let v12 = b.c(1)(2) in -- Vertical (1,2)
  83.     let v21 = b.c(2)(1) in  -- Vertical  (2,1)
  84.     let v22 = b.c(2)(2) in  -- Vertical  (2,2)
  85.     let v31 = b.c(3)(1) in --Vertical(3,1)
  86.     let v32 = b.c(3)(2) in --Vertical(3,2)
  87.     --let v12 = b.c(3)(3) in --vertical(3,3)
  88.     let v41 = b.c(4)(1) in --Vertical(4,1)
  89.     let v42 = b.c(4)(2) in --Vertical(4,2)
  90.     let v11s = (v11=mk_SET_WALL()) in  -- Vertical  (1,1) SET_WALL
  91.     let v11u = (v11=mk_UNKNOWN()) in  -- Vertical  (1,1) UNKNOWN
  92.     let v11n = (v11=mk_NO_WALL()) in  -- Vertical  (1,1) NO_WALL
  93.     let v12s = (v12=mk_SET_WALL()) in  -- Vertical  (1,2) SET_WALL
  94.     let v42u = (v42=mk_UNKNOWN()) in -- Vertical (1,3) UNKNOWN
  95.     let v42n = (v42=mk_NO_WALL()) in --Vertical (1,3) NO_WALL
  96.     let v21s = (v21=mk_SET_WALL()) in  -- Vertical  (2,1) SET_WALL
  97.     let v22s = (v22=mk_SET_WALL()) in  -- Vertical  (2,2) SET_WALL
  98.     let v31s = (v31=mk_SET_WALL()) in  -- Vertical  (3,1) SET_WALL
  99.     let v31u = (v31=mk_UNKNOWN()) in --Vertical (3,1) UNKNOWN
  100.     let v31n = (v31=mk_NO_WALL()) in --Vertical (3,1) NO_WALL
  101.     let v32s = (v32=mk_SET_WALL()) in  -- Vertical  (3,2) SET_WALL
  102.     let v12u = (v12=mk_UNKNOWN()) in -- Vertical (1,2) UNKNOWN
  103.     let v12n = (v12=mk_NO_WALL()) in --Vertical (1,2) NO_WALL
  104.     let v41s = (v41=mk_SET_WALL()) in  -- Vertical  (4,1) SET_WALL
  105.     let v42s = (v42=mk_SET_WALL()) in  -- Vertical  (4,2) SET_WALL
  106.    
  107.     --number values in a given square
  108.     let ulc_b_nr_1 = (b.n(1)(1) = 1) in --Upper left corner has number value 1
  109.     let urc_b_nr_1 = (b.n(1)(3) = 1) in --Upper right corner has number value 1
  110.     let llc_b_nr_1 = (b.n(2)(1) = 1) in --Lower left corner has number value 1
  111.     let lrc_b_nr_1 = (b.n(2)(3) = 1) in --Lower right corner has number value 1
  112.     --upper left corner
  113.     let ulc_ou = h11u or v11u in  -- Upper left corner One is UNKNOWN
  114.     let ulc_bu = h11u and v11u in  -- Upper left corner Both are UNKNOWN
  115.     let ulc_os = h11s or v11s in  -- Upper left corner One is SET_WALL
  116.     let ulc_bs = h11s and v11s in  -- Upper left corner Both are SET_WALL
  117.     (ulc_ou and ulc_os)
  118.     or
  119.     ulc_bs or ulc_bu and (
  120.    
  121.     --upper left corner containing value = 1
  122.     let one_ulc_bu = h11u and v11u in --both corner values unknown
  123.     let one_ulc_bn = h11n and v11n in --both corner values set to NO_WALL
  124.     let one_ulc_h11n = h11n and v11u in --horizontal corner value set to NO_WALL vertical corner value UNKNOWN
  125.     let one_ulc_v11n = h11u and v11n in -- horizontal corner value UNKNOWN vertical corner value set to NO_WALL
  126.     let one_ulc_num = ulc_b_nr_1 in --horizontal left corner square value is set to one.
  127.     (one_ulc_bu or one_ulc_bn or
  128.     one_ulc_h11n or one_ulc_v11n )and one_ulc_num) and (
  129.    
  130.     --upper right corner containing value = 1
  131.     let one_urc_bu = h13u and v31u in ----both corner values unknown
  132.     let one_urc_bn = h13n and v31n in --both corner values set to NO_WALL
  133.     let one_urc_h13n = h13n and v31u in --horizontal corner value set to NO_WALL vertical corner value UNKNOWN
  134.     let one_urc_v31n = h13u and v31n in --- horizontal corner value UNKNOWN vertical corner value set to NO_WALL
  135.     let one_urc_num = urc_b_nr_1 in   --horizontal right corner square value is set to one.
  136.     (one_urc_bu or one_urc_bn or
  137.     one_urc_h13n or one_urc_v31n) and one_urc_num) and (
  138.    
  139.     --lower right corner containing value = 1
  140.     let one_llc_bu = h31u and v42u in --both corner values unknown
  141.     let one_llc_bn = h31n and v42n in --both cornervalues set to NO_WALL
  142.     let one_llc_h31n = h31n and v42u in --horizontal corner value set to NO_WALL vertical corner value UNKNOWN
  143.     let one_llc_v42n = h31u and v42n in --horizontal corner value UNKNOWN vertical corner value set to NO_WALL
  144.     let one_llc_num = llc_b_nr_1 in --lower left corner value is set to one
  145.     (one_llc_bu or one_llc_bn or
  146.      one_llc_h31n or one_llc_v42n) and one_llc_num) and (
  147.      
  148.      --lower left corner containing value = 1
  149.      let one_lrc_bu = h33u and v12u in --both corner values unknown
  150.      let one_lrc_bn = h33n and v12n in --both corner values se to NO_WALL
  151.      let one_lrc_h33n = h33n and v12u in --horizontal lower right corner value set to NO_WALL, vertical corner UNKNOWN
  152.      let one_lrc_v12n = h33u and v12n in --horizontal lower right corner UNKNOWN, vertical corner set to NO_WALL
  153.      let one_lrc_num = lrc_b_nr_1 in --lower right corner value set to one
  154.      (one_lrc_bu or one_lrc_bn or one_lrc_h33n or one_lrc_v12n) and one_lrc_num) and (  
  155.      
  156.      --checking number of walls connected to joint 2
  157.      if h11s and h12s and v21s then false --all walls goint in to joint 2 is set, then false
  158.      else true --Less than three walls going into joint 2, true
  159.      ) and (
  160.      
  161.      --checking number of walls connected to joint 3
  162.      if h12s and h13s and v31s then false --all walls going in to joint 3 is set, then false
  163.      else true --Less than three walls going into joint 3, true
  164.      ) and (
  165.      
  166.      --checking number of walls connceted to joint 5
  167.      if v11s and v12s and h21s then false --all walls going in to joint 5 is set, then false
  168.      else true --Less than three walls going into joint 5, true
  169.      ) and (
  170.      
  171.      --checking number of walls connected to joint 6
  172.      if v21s and v22s and h21s and h22s then false --all walls going in to joint 6 is set, then false
  173.      elseif v21s and v22s and h21s then false --differen combos of three joints going in to joint 6 is set, then false.
  174.      elseif v21s and v22s and h22s then false
  175.      else if v21s and h21s and h22s then false
  176.      elseif v22s and h21s and h22s then false
  177.      else true --less than three walls going in to joint 6, true
  178.      ) and(
  179.      
  180.      --checking number of walls connected to joint 7
  181.       if v31s and v32s and h22s and h23s then false --all walls going in to joint 7 is set, then false
  182.      elseif v31s and v32s and h22s then false --differen combos of three joints going in to joint 7 is set, then false.
  183.      elseif v31s and v32s and h23s then false
  184.      else if v31s and h22s and h23s then false
  185.      elseif v32s and h22s and h23s then false
  186.      else true --less than three walls going in to joint 7, true
  187.      ) and(
  188.      
  189.      --checking number of walls connected to joint 8
  190.      if v41s and v42s and h23s then false --all walls going in to joint 8 is set, then false
  191.      else true --less than three walls going in to joint 8, true
  192.      ) and (
  193.      
  194.       --checking number of walls connected to joint 10
  195.      if h31s and h32s and v22s then false --all walls going in to joint 10 is set, then false
  196.      else true --less than three walls going in to joint 10, true
  197.      ) and (
  198.      
  199.       --checking number of walls connected to joint 11
  200.      if h32s and h33s and v32s then false --all walls going in to joint 11 is set, then false
  201.      else true --less than three walls going in to joint 11, true
  202.      
  203.      );
  204.      
  205.      
  206.      
  207.      
  208.      
  209.      
  210.      
  211.    
  212.    
  213.    
  214.      
  215.    
  216.    
  217.    
  218.    
  219.  
  220.      
  221.    
  222.  
  223. test: () -> bool
  224. test() == isValid(setWall([[mk_SET_WALL(),mk_SET_WALL(),mk_UNKNOWN()], --ROW
  225.                                 [mk_UNKNOWN(),mk_UNKNOWN(),mk_UNKNOWN()],
  226.                                 [mk_UNKNOWN(),mk_UNKNOWN(),mk_UNKNOWN()]],
  227.                             [
  228.                                 [mk_UNKNOWN(),mk_UNKNOWN()], --COL
  229.                                 [mk_UNKNOWN(),mk_UNKNOWN()],
  230.                                 [mk_UNKNOWN(),mk_UNKNOWN()],
  231.                                 [mk_UNKNOWN(),mk_UNKNOWN()]],
  232.                                
  233.                                
  234.                                 initB([3,-1,3],[-1,3,-1]))); --BOARD
  235.  
  236. operations
  237. -- TODO Define operations here
  238. end test
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement