Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module test
- exports all
- definitions
- state StateName of
- -- TODO Define state here
- end
- types
- -- TODO Define types here
- SET_WALL:: ;
- NO_WALL::;
- UNKNOWN:: ;
- WALL= SET_WALL | NO_WALL | UNKNOWN;
- ROW= seq of WALL;
- COL= seq of WALL;
- NUMBERS= seq of int;
- BOARD::
- r: seq of ROW
- c: seq of COL
- n: seq of NUMBERS;
- values
- -- TODO Define values here
- functions
- -- TODO Define functions here
- initB: NUMBERS * NUMBERS -> BOARD
- initB(n1,n2) == mk_BOARD([[mk_UNKNOWN(),mk_UNKNOWN(),mk_UNKNOWN()], --ROW
- [mk_UNKNOWN(),mk_UNKNOWN(),mk_UNKNOWN()],
- [mk_UNKNOWN(),mk_UNKNOWN(),mk_UNKNOWN()]],
- [
- [mk_UNKNOWN(),mk_UNKNOWN()], --COL
- [mk_UNKNOWN(),mk_UNKNOWN()],
- [mk_UNKNOWN(),mk_UNKNOWN()],
- [mk_UNKNOWN(),mk_UNKNOWN()]],
- [
- n1, --NUMBERS
- n2]
- );
- setWall: seq of ROW * seq of COL * BOARD -> BOARD
- setWall(r, c, b) == mk_BOARD(r,c,b.n);-- b(0)[y][x]=w ;
- isValid: BOARD -> bool
- isValid(b) ==
- --General varibles
- --Horizontal variables
- let h11 = b.r(1)(1) in -- Horizntal (1,1)
- let h12 = b.r(1)(2) in -- Horizntal (1,2)
- let h13 = b.r(1)(3) in --Horizontal(1,3)
- let h21 = b.r(2)(1) in --Horizontal(2,1)
- let h22 = b.r(2)(2) in --Horizontal(2,2)
- let h23 = b.r(2)(3) in --Horizontal(2,3)
- let h31 = b.r(3)(1) in --Horizontal(3,1)
- let h32 = b.r(3)(2) in --Horizontal(3,2)
- let h33 = b.r(3)(3) in --Horizontal(3,3)
- let h11s = (h11=mk_SET_WALL()) in -- Horizntal (1,1) SET_WALL
- let h11u = (h11=mk_UNKNOWN()) in -- Horizntal (1,1) UNKNOWN
- let h11n = (h11=mk_NO_WALL()) in -- Horizntal (1,1) NO_WALL
- let h12s = (h12=mk_SET_WALL()) in -- Horizntal (1,2) SET_WALL
- let h13s = (h13=mk_SET_WALL()) in -- Horizntal (1,3) SET_WALL
- let h13u = (h13=mk_UNKNOWN()) in --Horizontal (1,3) UNKNOWN
- let h13n = (h13=mk_NO_WALL()) in --Horizontal (1,3) NO_WALL
- let h21s = (h21=mk_SET_WALL()) in -- Horizntal (2,1) SET_WALL
- let h22s = (h22=mk_SET_WALL()) in -- Horizntal (2,2) SET_WALL
- let h23s = (h23=mk_SET_WALL()) in -- Horizntal (2,3) SET_WALL
- let h31s = (h31=mk_SET_WALL()) in -- Horizntal (3,1) SET_WALL
- let h31u = (h31=mk_UNKNOWN()) in --Horizontal (3,1) UNKNOWN
- let h31n = (h31=mk_NO_WALL()) in --Horizontal (3,1) NO_WALL
- let h32s = (h32=mk_SET_WALL()) in -- Horizntal (3,2) SET_WALL
- let h33s = (h33=mk_SET_WALL()) in -- Horizntal (3,3) SET_WALL
- let h33u = (h33=mk_UNKNOWN()) in --Horizontal (3,3) UKNOWN
- let h33n = (h33=mk_NO_WALL()) in --Horizontal (3,3) NO_WALL
- --Vertical variables
- let v11 = b.c(1)(1) in -- Vertical (1,1)
- let v12 = b.c(1)(2) in -- Vertical (1,2)
- let v21 = b.c(2)(1) in -- Vertical (2,1)
- let v22 = b.c(2)(2) in -- Vertical (2,2)
- let v31 = b.c(3)(1) in --Vertical(3,1)
- let v32 = b.c(3)(2) in --Vertical(3,2)
- --let v12 = b.c(3)(3) in --vertical(3,3)
- let v41 = b.c(4)(1) in --Vertical(4,1)
- let v42 = b.c(4)(2) in --Vertical(4,2)
- let v11s = (v11=mk_SET_WALL()) in -- Vertical (1,1) SET_WALL
- let v11u = (v11=mk_UNKNOWN()) in -- Vertical (1,1) UNKNOWN
- let v11n = (v11=mk_NO_WALL()) in -- Vertical (1,1) NO_WALL
- let v12s = (v12=mk_SET_WALL()) in -- Vertical (1,2) SET_WALL
- let v42u = (v42=mk_UNKNOWN()) in -- Vertical (1,3) UNKNOWN
- let v42n = (v42=mk_NO_WALL()) in --Vertical (1,3) NO_WALL
- let v21s = (v21=mk_SET_WALL()) in -- Vertical (2,1) SET_WALL
- let v22s = (v22=mk_SET_WALL()) in -- Vertical (2,2) SET_WALL
- let v31s = (v31=mk_SET_WALL()) in -- Vertical (3,1) SET_WALL
- let v31u = (v31=mk_UNKNOWN()) in --Vertical (3,1) UNKNOWN
- let v31n = (v31=mk_NO_WALL()) in --Vertical (3,1) NO_WALL
- let v32s = (v32=mk_SET_WALL()) in -- Vertical (3,2) SET_WALL
- let v12u = (v12=mk_UNKNOWN()) in -- Vertical (1,2) UNKNOWN
- let v12n = (v12=mk_NO_WALL()) in --Vertical (1,2) NO_WALL
- let v41s = (v41=mk_SET_WALL()) in -- Vertical (4,1) SET_WALL
- let v42s = (v42=mk_SET_WALL()) in -- Vertical (4,2) SET_WALL
- --number values in a given square
- let ulc_b_nr_1 = (b.n(1)(1) = 1) in --Upper left corner has number value 1
- let urc_b_nr_1 = (b.n(1)(3) = 1) in --Upper right corner has number value 1
- let llc_b_nr_1 = (b.n(2)(1) = 1) in --Lower left corner has number value 1
- let lrc_b_nr_1 = (b.n(2)(3) = 1) in --Lower right corner has number value 1
- --upper left corner
- let ulc_ou = h11u or v11u in -- Upper left corner One is UNKNOWN
- let ulc_bu = h11u and v11u in -- Upper left corner Both are UNKNOWN
- let ulc_os = h11s or v11s in -- Upper left corner One is SET_WALL
- let ulc_bs = h11s and v11s in -- Upper left corner Both are SET_WALL
- (ulc_ou and ulc_os)
- or
- ulc_bs or ulc_bu and (
- --upper left corner containing value = 1
- let one_ulc_bu = h11u and v11u in --both corner values unknown
- let one_ulc_bn = h11n and v11n in --both corner values set to NO_WALL
- let one_ulc_h11n = h11n and v11u in --horizontal corner value set to NO_WALL vertical corner value UNKNOWN
- let one_ulc_v11n = h11u and v11n in -- horizontal corner value UNKNOWN vertical corner value set to NO_WALL
- let one_ulc_num = ulc_b_nr_1 in --horizontal left corner square value is set to one.
- (one_ulc_bu or one_ulc_bn or
- one_ulc_h11n or one_ulc_v11n )and one_ulc_num) and (
- --upper right corner containing value = 1
- let one_urc_bu = h13u and v31u in ----both corner values unknown
- let one_urc_bn = h13n and v31n in --both corner values set to NO_WALL
- let one_urc_h13n = h13n and v31u in --horizontal corner value set to NO_WALL vertical corner value UNKNOWN
- let one_urc_v31n = h13u and v31n in --- horizontal corner value UNKNOWN vertical corner value set to NO_WALL
- let one_urc_num = urc_b_nr_1 in --horizontal right corner square value is set to one.
- (one_urc_bu or one_urc_bn or
- one_urc_h13n or one_urc_v31n) and one_urc_num) and (
- --lower right corner containing value = 1
- let one_llc_bu = h31u and v42u in --both corner values unknown
- let one_llc_bn = h31n and v42n in --both cornervalues set to NO_WALL
- let one_llc_h31n = h31n and v42u in --horizontal corner value set to NO_WALL vertical corner value UNKNOWN
- let one_llc_v42n = h31u and v42n in --horizontal corner value UNKNOWN vertical corner value set to NO_WALL
- let one_llc_num = llc_b_nr_1 in --lower left corner value is set to one
- (one_llc_bu or one_llc_bn or
- one_llc_h31n or one_llc_v42n) and one_llc_num) and (
- --lower left corner containing value = 1
- let one_lrc_bu = h33u and v12u in --both corner values unknown
- let one_lrc_bn = h33n and v12n in --both corner values se to NO_WALL
- let one_lrc_h33n = h33n and v12u in --horizontal lower right corner value set to NO_WALL, vertical corner UNKNOWN
- let one_lrc_v12n = h33u and v12n in --horizontal lower right corner UNKNOWN, vertical corner set to NO_WALL
- let one_lrc_num = lrc_b_nr_1 in --lower right corner value set to one
- (one_lrc_bu or one_lrc_bn or one_lrc_h33n or one_lrc_v12n) and one_lrc_num) and (
- --checking number of walls connected to joint 2
- if h11s and h12s and v21s then false --all walls goint in to joint 2 is set, then false
- else true --Less than three walls going into joint 2, true
- ) and (
- --checking number of walls connected to joint 3
- if h12s and h13s and v31s then false --all walls going in to joint 3 is set, then false
- else true --Less than three walls going into joint 3, true
- ) and (
- --checking number of walls connceted to joint 5
- if v11s and v12s and h21s then false --all walls going in to joint 5 is set, then false
- else true --Less than three walls going into joint 5, true
- ) and (
- --checking number of walls connected to joint 6
- if v21s and v22s and h21s and h22s then false --all walls going in to joint 6 is set, then false
- elseif v21s and v22s and h21s then false --differen combos of three joints going in to joint 6 is set, then false.
- elseif v21s and v22s and h22s then false
- else if v21s and h21s and h22s then false
- elseif v22s and h21s and h22s then false
- else true --less than three walls going in to joint 6, true
- ) and(
- --checking number of walls connected to joint 7
- if v31s and v32s and h22s and h23s then false --all walls going in to joint 7 is set, then false
- elseif v31s and v32s and h22s then false --differen combos of three joints going in to joint 7 is set, then false.
- elseif v31s and v32s and h23s then false
- else if v31s and h22s and h23s then false
- elseif v32s and h22s and h23s then false
- else true --less than three walls going in to joint 7, true
- ) and(
- --checking number of walls connected to joint 8
- if v41s and v42s and h23s then false --all walls going in to joint 8 is set, then false
- else true --less than three walls going in to joint 8, true
- ) and (
- --checking number of walls connected to joint 10
- if h31s and h32s and v22s then false --all walls going in to joint 10 is set, then false
- else true --less than three walls going in to joint 10, true
- ) and (
- --checking number of walls connected to joint 11
- if h32s and h33s and v32s then false --all walls going in to joint 11 is set, then false
- else true --less than three walls going in to joint 11, true
- );
- test: () -> bool
- test() == isValid(setWall([[mk_SET_WALL(),mk_SET_WALL(),mk_UNKNOWN()], --ROW
- [mk_UNKNOWN(),mk_UNKNOWN(),mk_UNKNOWN()],
- [mk_UNKNOWN(),mk_UNKNOWN(),mk_UNKNOWN()]],
- [
- [mk_UNKNOWN(),mk_UNKNOWN()], --COL
- [mk_UNKNOWN(),mk_UNKNOWN()],
- [mk_UNKNOWN(),mk_UNKNOWN()],
- [mk_UNKNOWN(),mk_UNKNOWN()]],
- initB([3,-1,3],[-1,3,-1]))); --BOARD
- operations
- -- TODO Define operations here
- end test
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement