File tree Expand file tree Collapse file tree 1 file changed +23
-23
lines changed
exercises/practice/state-of-tic-tac-toe/.meta Expand file tree Collapse file tree 1 file changed +23
-23
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,27 @@ enum State as u8 {
66 win
77}
88
9+ fn is_win (bitset int ) bool {
10+ lines := [
11+ 0x007 ,
12+ 0x070 ,
13+ 0x700 ,
14+ 0x111 ,
15+ 0x222 ,
16+ 0x444 ,
17+ 0x124 ,
18+ 0x421 ,
19+ ]
20+
21+ for line in lines {
22+ if (bitset & line) == line {
23+ return true
24+ }
25+ }
26+
27+ return false
28+ }
29+
930fn gamestate (board []string ) ! State {
1031 mut count_x := 0
1132 mut count_o := 0
@@ -33,29 +54,8 @@ fn gamestate(board []string) !State {
3354 return error ('Wrong turn order: X went twice' )
3455 }
3556
36- mut win_x := false
37- mut win_o := false
38-
39- lines := [
40- 0x007 ,
41- 0x070 ,
42- 0x700 ,
43- 0x111 ,
44- 0x222 ,
45- 0x444 ,
46- 0x124 ,
47- 0x421 ,
48- ]
49-
50- for line in lines {
51- if (bitset_x & line) == line {
52- win_x = true
53- }
54-
55- if (bitset_o & line) == line {
56- win_o = true
57- }
58- }
57+ mut win_x := is_win (bitset_x)
58+ mut win_o := is_win (bitset_o)
5959
6060 if win_x || win_o {
6161 if win_x && win_o {
You can’t perform that action at this time.
0 commit comments