-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTTT.flow
131 lines (88 loc) · 3.85 KB
/
TTT.flow
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
blockdiag {
initialization_code="
global X
X=lambda i: 'X'+str(i)
global O
O=lambda i: 'O'+str(i)
global anyX
anyX = (lambda e: e[0]=='X')
global anyMove
anyMove = (lambda e: anyX(e) or anyO(e))
global anyO
anyO = (lambda e: e[0]=='O')
global toX
toX = (lambda e: 'X' + e[1:])
global toO
toO = (lambda e: 'O' + e[1:])
"
event_selection_mechanism = "priority"
lines [type=start, initial="[{1:1,2:2,3:3}, {1:4,2:5,3:6}, {1:7,2:8,3:9}, {1:1,2:4,3:7}, {1:2,2:5,3:8}, {1:3,2:6,3:9},{1:1,2:5,3:9},{1:3,2:5,3:7}]", width=350];
perm [type=permutation, keys="[1,2,3]"]
lines -> perm -> def_wt1 -> def_wt2 -> def_req;
def_wt1 [type=sync, wait="[X(t[1])]", width=100, tokens_display="count only"]
def_wt2 [type=sync, wait="[X(t[2])]", width=150, tokens_display="count only"]
def_req [type=sync, req="[O(t[3])]", width=150, tokens_display="count only"]
########################################################################
perm -> ofn_wt1 -> ofn_wt2 -> ofn_req;
ofn_wt1 [type=sync, wait="[O(t[1])]", width=100, tokens_display="count only"]
ofn_wt2 [type=sync, wait="[O(t[2])]", width=150, tokens_display="count only"]
ofn_req [type=sync, req="[O(t[3])]", priority=10, width=150, tokens_display="count only"]
########################################################################
perm -> owin_wt1 -> owin_wt2 -> owin_wt3 -> owin_req;
owin_wt1 [type=sync, wait="[O(t[1])]", width=100, tokens_display="count only"]
owin_wt2 [type=sync, wait="[O(t[2])]", width=150, tokens_display="count only"]
owin_wt3 [type=sync, wait="[O(t[3])]", width=150, tokens_display="count only"]
owin_req [type=sync, req="['Player O wins']", block=anyMove, priority=100, width=150]
########################################################################
perm -> xwin_wt1 -> xwin_wt2 ->xwin_wt3 -> xwin_req;
xwin_wt1 [type=sync, wait="[X(t[1])]", width=100, tokens_display="count only"]
xwin_wt2 [type=sync, wait="[X(t[2])]", width=150, tokens_display="count only"]
xwin_wt3 [type=sync, wait="[X(t[3])]", width=150, tokens_display="count only"]
xwin_req [type=sync, req="['Player X wins']", block=anyMove, priority=100, width=150]
########################################################################
tie_st -> tie_loop -> tie_wait -> tie_loop
tie_loop -> tie_req [label=after]
tie_st [type=start]
tie_loop [type=loop, count=9, width=200]
tie_wait [type=sync, wait=anyMove]
tie_req [type=sync, req="['No winner']", priority=100]
########################################################################
int_st -> int_1 -> int_2 -> int_1;
int_st [type=start]
int_1 [type=sync, wait=anyX, block=anyO, width=100]
int_2 [type=sync, wait=anyO, block=anyX, width=100]
###########
once_st -> once_wt -> once_bl
once_wt -> once_wt
once_st [type=start]
once_wt [type=sync, wait=anyMove]
once_bl [type=sync, block="[toX(t['event']), toO(t['event'])]", width=300, tokens_display="full with event"]
############
st -> rq1
st [type=start]
rq1 [type=sync, req="['O5']", priority="-1"]
st -> rq2 -> rq2
rq2 [type=sync, req="['O1','O3','O7','O9']", priority="-2", width=200]
st -> rq3 -> rq3
rq3 [type=sync, req="['O2','O4','O6','O8']", priority="-3", width=200]
run="
run_init(diagram)
setup_diagram(diagram)
print_state(False)
board = [' ' for i in range(9)]
while True:
while step_to_next_state(diagram): print_state(False)
try:
e = select_event(diagram)
except:
e = 'X'+input('Enter cell number to put X in:')
if e[0] in ['O','X'] and e[1] in ['1','2','3','4','5','6','7','8','9']:
board[int(e[1])-1] = e[0]
print( '\n-----\n'.join([ '|'.join(board[i*3:(i+1)*3]) for i in range(3)]))
print()
wake_up_tokens(diagram, e)
else:
print('Game ended: ' + e)
break
"
}