-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpeggame.tla
75 lines (59 loc) · 3.14 KB
/
peggame.tla
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
------------------------------ MODULE peggame ------------------------------
EXTENDS TLC, Integers, FiniteSets
VARIABLES state,xx,yy,dd
\* Spots
\* The set of <<x,y>> \in <<1..5,1..5>> where (x+y<=6)
Spots == { <<x,y>> \in {1,2,3,4,5}\X{1,2,3,4,5} : x+y<=6 }
\* Init
\* state = The set of Spots except (4,1)
Init == /\ state = Spots \ { <<4,1>> } /\ xx=-1 /\ yy=-1 /\ dd=""
\* CanJumpUpRight(x,y)
\* A function f(x,y) returning true if:
\* - The tuple <<x,y>> is in Spots, is in the current state
\* - The tuple <<x+1,y>> is in Spots, is in the current state
\* - The tuple <<x+2,y>> is in Spots, is not in the current state
CanJumpUpRight(x,y) == /\ <<x,y>> \in state
/\ <<x+1,y>> \in state
/\ <<x+2,y>> \in (Spots \ state)
CanJumpDownLeft(x,y) == /\ <<x,y>> \in state
/\ <<x-1,y>> \in state
/\ <<x-2,y>> \in (Spots \ state)
CanJumpUpLeft(x,y) == /\ <<x,y>> \in state
/\ <<x+1,y-1>> \in state
/\ <<x+2,y-2>> \in (Spots \ state)
CanJumpDownRight(x,y) == /\ <<x,y>> \in state
/\ <<x-1,y+1>> \in state
/\ <<x-2,y+2>> \in (Spots \ state)
CanJumpRight(x,y) == /\ <<x,y>> \in state
/\ <<x,y+1>> \in state
/\ <<x,y+2>> \in (Spots \ state)
CanJumpLeft(x,y) == /\ <<x,y>> \in state
/\ <<x,y-1>> \in state
/\ <<x,y-2>> \in (Spots \ state)
\* JumpUpRight(x,y)
\* The current state, except...
\* - Minus <<x,y>>
\* - Minus <<x+1,y>>
\* - Plus <<x+2,y>>
JumpUpRight(x,y) == (((state \ {<<x,y>>}) \ {<<x+1,y>>}) \cup {<<x+2,y>>})
JumpDownLeft(x,y) == (((state \ {<<x,y>>}) \ {<<x-1,y>>}) \cup {<<x-2,y>>})
JumpUpLeft(x,y) == (((state \ {<<x,y>>}) \ {<<x+1,y-1>>}) \cup {<<x+2,y-2>>})
JumpDownRight(x,y) == (((state \ {<<x,y>>}) \ {<<x-1,y+1>>}) \cup {<<x-2,y+2>>})
JumpRight(x,y) == (((state \ {<<x,y>>}) \ {<<x,y+1>>}) \cup {<<x,y+2>>})
JumpLeft(x,y) == (((state \ {<<x,y>>}) \ {<<x,y-1>>}) \cup {<<x,y-2>>})
\* Win returns TRUE if there is one peg left
Win == Cardinality(state) = 1
\* Next
\* The next state(s) are those which are the JumpUp(..) of the current state
Next == \E <<x,y>> \in Spots :
/\ xx'=x /\ yy'=y
/\ \/ CanJumpUpRight(x,y) /\ state' = JumpUpRight(x,y) /\ dd'="UpRight"
\/ CanJumpDownLeft(x,y) /\ state' = JumpDownLeft(x,y) /\ dd'="DownLeft"
\/ CanJumpUpLeft(x,y) /\ state' = JumpUpLeft(x,y) /\ dd'="UpLeft"
\/ CanJumpDownRight(x,y) /\ state' = JumpDownRight(x,y) /\ dd'="DownRight"
\/ CanJumpRight(x,y) /\ state' = JumpRight(x,y) /\ dd'="Right"
\/ CanJumpLeft(x,y) /\ state' = JumpLeft(x,y) /\ dd'="Left"
=============================================================================
\* Modification History
\* Last modified Tue Mar 12 10:23:54 EDT 2019 by jay
\* Created Sun Mar 10 00:12:41 EST 2019 by jay