Skip to content
Newer
Older
100644 249 lines (213 sloc) 7.89 KB
2013578 @masak [t] added new test file
authored
1 use v6;
819042b @masak added &count to Test::Ix and test file
authored
2 use Test::Ix;
63c4bb5 @masak [t/01-game-rules.t] added 'our' to everything
authored
3 use Test;
8fe205e @masak added test and code to pass it
authored
4 use Druid::Game;
e62acec @masak wrote twenty-first test
authored
5 use Druid::Player;
2013578 @masak [t] added new test file
authored
6
7 my @tests =
8 'the player to move' => [
9 'is vertical at the beginning of the game',
10 'is horizontal after the first move',
11 'alternates with every move',
12 ],
13 'a sarsen move' => [
14 'must have a certain syntax',
15 'must be within the limits of the board',
16 'can be made directly on the ground',
17 'can be made on top of the same color',
18 'can not be made on top of another color',
19 ],
20 'a lintel move' => [
21 'must have a certain syntax',
22 'must be within the limits of the board',
23 'can not be made directly on the ground',
24 'must be made two units apart',
25 'must have support at both ends',
26 'can not have less than two friendly stones under it',
27 'can not have more than two friendly stones under it',
28 'can form a bridge',
29 'can claim enemy territory',
30 ],
31 'swapping' => [
a811452 @masak [01-game-rules.t] added some more stubbed tests
authored
32 'is allowed as the second move',
33 'is not allowed as the first move',
34 'is not allowed after the second move',
69d5c95 @masak rethought swapping mechanics
authored
35 'exchanges the colors of the players',
36 "makes it the second player's turn again",
2013578 @masak [t] added new test file
authored
37 ],
38 'passing' => [
39 'does not change the board',
40 "makes it the other player's turn",
837fa5b @masak added, wrote twenty-fifth test
authored
41 'twice ends the game',
2013578 @masak [t] added new test file
authored
42 ],
43 'resigning' => [
d8dec0d @masak wrote tests 26 and 27; 26 fails
authored
44 'must have a certain syntax',
2013578 @masak [t] added new test file
authored
45 'does not change the board',
46 'ends the game',
47 ],
48 'a chain' => [
49 "wins the game if it connects a player's edges",
50 "does not win the game if it connects the enemy's edges",
51 ]
52 ;
5f22c50 @masak added vim filetype line
authored
53
8c8f50d @timo chase rakudo CALLER:: semantics.
timo authored
54 my &*before = sub {
8fe205e @masak added test and code to pass it
authored
55 my Druid::Game $game .= new(:size(3));
e62acec @masak wrote twenty-first test
authored
56 # XXX: Maybe we should mock these instead of depending on Druid::Player.
57 my Druid::Player ($player1, $player2)
9dcd6a0 @masak [Druid::Player] replaced .init() with .new()
authored
58 = map { Druid::Player.new(:game($game), :color($_)) }, 1, 2;
e62acec @masak wrote twenty-first test
authored
59
60 return ($game, $player1, $player2);
939ce2a @masak [t] made use of the new &before convention
authored
61 }
62
8c8f50d @timo chase rakudo CALLER:: semantics.
timo authored
63 my &*the-player-to-move-is-vertical-at-the-beginning-of-the-game = sub {
b3a1deb @masak replaced explicit param lists with placeholder vars
authored
64 is $^game.player-to-move, 1,
8fe205e @masak added test and code to pass it
authored
65 "the player to move is vertical at the beginning of the game";
2b8ab6e @masak added the test stub subs
authored
66 }
67
8c8f50d @timo chase rakudo CALLER:: semantics.
timo authored
68 my &*the-player-to-move-is-horizontal-after-the-first-move = sub {
b3a1deb @masak replaced explicit param lists with placeholder vars
authored
69 $^game.make-move('a1');
900406c @masak implemented third test; satisfied immediately
authored
70 is $game.player-to-move, 2,
bd5d6aa @masak specified second test
authored
71 "the player to move is horizontal after the first move";
2b8ab6e @masak added the test stub subs
authored
72 }
73
8c8f50d @timo chase rakudo CALLER:: semantics.
timo authored
74 my &*the-player-to-move-alternates-with-every-move = sub {
b3a1deb @masak replaced explicit param lists with placeholder vars
authored
75 $^game; # must mention it outside of the gather
900406c @masak implemented third test; satisfied immediately
authored
76 my @move-order = gather for ^10 {
77 take 0+$game.player-to-move;
e2cbb4d @masak [Druid::Game] s/make_move/make-move/
authored
78 $game.make-move('a1');
900406c @masak implemented third test; satisfied immediately
authored
79 take 0+$game.player-to-move;
e2cbb4d @masak [Druid::Game] s/make_move/make-move/
authored
80 $game.make-move('b1');
6c3638e @masak implemented fourth test, passed right away
authored
81 };
900406c @masak implemented third test; satisfied immediately
authored
82 is @move-order, [(1, 2) xx 10],
83 "the player to move alternates with every move";
2b8ab6e @masak added the test stub subs
authored
84 }
85
8c8f50d @timo chase rakudo CALLER:: semantics.
timo authored
86 my &*a-sarsen-move-must-have-a-certain-syntax = sub {
b7f7f84 @timo "defined" is no longer a prefix operator.
timo authored
87 ok (!defined $^game.make-move("1a")),
6c3638e @masak implemented fourth test, passed right away
authored
88 "a sarsen move must have a certain syntax";
2b8ab6e @masak added the test stub subs
authored
89 }
90
8c8f50d @timo chase rakudo CALLER:: semantics.
timo authored
91 my &*a-sarsen-move-must-be-within-the-limits-of-the-board = sub {
b7f7f84 @timo "defined" is no longer a prefix operator.
timo authored
92 ok (!defined $^game.make-move("a5")),
304fbbe @masak implemented fifth test -- passed right away
authored
93 "a sarsen move must be within the limits of the board";
2b8ab6e @masak added the test stub subs
authored
94 }
95
8c8f50d @timo chase rakudo CALLER:: semantics.
timo authored
96 my &*a-sarsen-move-can-be-made-directly-on-the-ground = sub {
b7f7f84 @timo "defined" is no longer a prefix operator.
timo authored
97 ok (defined $^game.make-move("b2")),
51e73c3 @masak implemented sixthtest -- passed right away
authored
98 "a sarsen move can be made directly on the ground";
2b8ab6e @masak added the test stub subs
authored
99 }
100
8c8f50d @timo chase rakudo CALLER:: semantics.
timo authored
101 my &*a-sarsen-move-can-be-made-on-top-of-the-same-color = sub {
b3a1deb @masak replaced explicit param lists with placeholder vars
authored
102 $^game.make-move($_) for <b2 a1>;
b7f7f84 @timo "defined" is no longer a prefix operator.
timo authored
103 ok (defined $game.make-move("b2")),
cca0299 @masak implemented seventh test; passed right away
authored
104 "a sarsen move can be made on top of the same color";
2b8ab6e @masak added the test stub subs
authored
105 }
106
8c8f50d @timo chase rakudo CALLER:: semantics.
timo authored
107 my &*a-sarsen-move-can-not-be-made-on-top-of-another-color = sub {
b3a1deb @masak replaced explicit param lists with placeholder vars
authored
108 $^game.make-move($_) for <b2 a1>;
b7f7f84 @timo "defined" is no longer a prefix operator.
timo authored
109 ok (!defined $game.make-move("a1")),
2d0467e @masak implemented eighth test; it fails
authored
110 "a sarsen move can not be made on top of another color";
2b8ab6e @masak added the test stub subs
authored
111 }
112
8c8f50d @timo chase rakudo CALLER:: semantics.
timo authored
113 my &*a-lintel-move-must-have-a-certain-syntax = sub {
b7f7f84 @timo "defined" is no longer a prefix operator.
timo authored
114 ok (!defined $^game.make-move("a3-3c")),
8e50a9e @masak wrote ninth test -- passes right away
authored
115 "a lintel move must have a certain syntax";
2b8ab6e @masak added the test stub subs
authored
116 }
117
8c8f50d @timo chase rakudo CALLER:: semantics.
timo authored
118 my &*a-lintel-move-must-be-within-the-limits-of-the-board = sub {
b7f7f84 @timo "defined" is no longer a prefix operator.
timo authored
119 ok (!defined $^game.make-move("a4-c4")),
fb0414c @masak implemented tenth test; passed right away
authored
120 "a lintel move must be within the limits of the board";
2b8ab6e @masak added the test stub subs
authored
121 }
122
8c8f50d @timo chase rakudo CALLER:: semantics.
timo authored
123 my &*a-lintel-move-can-not-be-made-directly-on-the-ground = sub {
b7f7f84 @timo "defined" is no longer a prefix operator.
timo authored
124 ok (!defined $^game.make-move("a1-c1")),
f0790ff @masak implemented eleventh test
authored
125 "a lintel move can not be made directly on the ground";
2b8ab6e @masak added the test stub subs
authored
126 }
127
8c8f50d @timo chase rakudo CALLER:: semantics.
timo authored
128 my &*a-lintel-move-must-be-made-two-units-apart = sub {
b3a1deb @masak replaced explicit param lists with placeholder vars
authored
129 $^game.make-move($_) for <a1 a3 b1>;
b7f7f84 @timo "defined" is no longer a prefix operator.
timo authored
130 ok (!defined $game.make-move("a1-b1")),
1777a96 @masak added twelfth test; causes Druid::Game to die
authored
131 "a lintel move must be made two units apart";
2b8ab6e @masak added the test stub subs
authored
132 }
133
8c8f50d @timo chase rakudo CALLER:: semantics.
timo authored
134 my &*a-lintel-move-must-have-support-at-both-ends = sub {
b3a1deb @masak replaced explicit param lists with placeholder vars
authored
135 $^game.make-move($_) for <a1 a3>;
b7f7f84 @timo "defined" is no longer a prefix operator.
timo authored
136 ok (!defined $game.make-move("a1-c1")),
723ad33 @masak added thirteenth test -- passes right away
authored
137 "a lintel move must have support at both ends";
2b8ab6e @masak added the test stub subs
authored
138 }
139
8c8f50d @timo chase rakudo CALLER:: semantics.
timo authored
140 my &*a-lintel-move-can-not-have-less-than-two-friendly-stones-under-it = sub {
b3a1deb @masak replaced explicit param lists with placeholder vars
authored
141 $^game.make-move($_) for <a1 b1 a3 c1>;
b7f7f84 @timo "defined" is no longer a prefix operator.
timo authored
142 ok (!defined $game.make-move('a1-c1')),
fd5536d @masak implemented fourteenth test
authored
143 "a lintel move can not have less than two friendly stones under it";
2b8ab6e @masak added the test stub subs
authored
144 }
145
8c8f50d @timo chase rakudo CALLER:: semantics.
timo authored
146 my &*a-lintel-move-can-not-have-more-than-two-friendly-stones-under-it = sub {
b3a1deb @masak replaced explicit param lists with placeholder vars
authored
147 $^game.make-move($_) for <a1 a3 b1 b3 c1 c3>;
b7f7f84 @timo "defined" is no longer a prefix operator.
timo authored
148 ok (!defined $game.make-move('a1-c1')),
a18200c @masak added fifteenth test; passed right away
authored
149 "a lintel move can not have more than two friendly stones under it";
2b8ab6e @masak added the test stub subs
authored
150 }
151
8c8f50d @timo chase rakudo CALLER:: semantics.
timo authored
152 my &*a-lintel-move-can-form-a-bridge = sub {
b3a1deb @masak replaced explicit param lists with placeholder vars
authored
153 $^game.make-move($_) for <a2 a1 c2 c1>;
b7f7f84 @timo "defined" is no longer a prefix operator.
timo authored
154 ok (defined $game.make-move('a2-c2')), "a lintel move can form a bridge";
2b8ab6e @masak added the test stub subs
authored
155 }
156
8c8f50d @timo chase rakudo CALLER:: semantics.
timo authored
157 my &*a-lintel-move-can-claim-enemy-territory = sub {
b3a1deb @masak replaced explicit param lists with placeholder vars
authored
158 $^game.make-move($_) for <a1 a3 b1 c1>;
b7f7f84 @timo "defined" is no longer a prefix operator.
timo authored
159 ok (defined $game.make-move('a1-c1')),
ddce1bf @masak wrote seventeenth test; passes right away
authored
160 "a lintel move can claim enemy territory";
2b8ab6e @masak added the test stub subs
authored
161 }
162
8c8f50d @timo chase rakudo CALLER:: semantics.
timo authored
163 my &*swapping-is-allowed-as-the-second-move = sub {
f9e0634 @masak wrote eighteenth test
authored
164 $^game.make-move('a1');
b7f7f84 @timo "defined" is no longer a prefix operator.
timo authored
165 ok (defined $game.make-move('swap')),
f9e0634 @masak wrote eighteenth test
authored
166 "swapping is allowed as the second move";
a811452 @masak [01-game-rules.t] added some more stubbed tests
authored
167 }
168
8c8f50d @timo chase rakudo CALLER:: semantics.
timo authored
169 my &*swapping-is-not-allowed-as-the-first-move = sub {
b7f7f84 @timo "defined" is no longer a prefix operator.
timo authored
170 ok (!defined $^game.make-move('swap')),
919b8c4 @masak wrote nineteenth test
authored
171 "swapping is not allowed as the first move";
a811452 @masak [01-game-rules.t] added some more stubbed tests
authored
172 }
173
8c8f50d @timo chase rakudo CALLER:: semantics.
timo authored
174 my &*swapping-is-not-allowed-after-the-second-move = sub {
ad73460 @masak wrote twentieth test; passes right away
authored
175 $^game.make-move($_) for <a1 a2>;
b7f7f84 @timo "defined" is no longer a prefix operator.
timo authored
176 ok (!defined $^game.make-move('swap')),
ad73460 @masak wrote twentieth test; passes right away
authored
177 "swapping is not allowed after the second move";
a811452 @masak [01-game-rules.t] added some more stubbed tests
authored
178 }
179
8c8f50d @timo chase rakudo CALLER:: semantics.
timo authored
180 my &*swapping-exchanges-the-colors-of-the-players = sub {
e62acec @masak wrote twenty-first test
authored
181 $^game.make-move($_) for <a1 swap>;
182 ok $^player1.color == 2 && $^player2.color == 1,
183 "swapping exchanges the colors of the players";
69d5c95 @masak rethought swapping mechanics
authored
184 }
185
8c8f50d @timo chase rakudo CALLER:: semantics.
timo authored
186 my &*swapping-makes-it-the-second-player's-turn-again = sub {
cbb1bd0 @masak wrote twenty-second test
authored
187 $^game.make-move($_) for <a1 swap>;
2a40967 @masak implemented 23rd and 24th tests; pass right away
authored
188 is $game.player-to-move, 2,
cbb1bd0 @masak wrote twenty-second test
authored
189 "swapping makes it the second player's turn again";
69d5c95 @masak rethought swapping mechanics
authored
190 }
191
8c8f50d @timo chase rakudo CALLER:: semantics.
timo authored
192 my &*passing-does-not-change-the-board = sub {
2a40967 @masak implemented 23rd and 24th tests; pass right away
authored
193 $^game.make-move($_) for <a2 b3 c1 b3>;
194 my @heights-snapshot = $game.heights;
195 my @colors-snapshot = $game.colors;
196 $game.make-move('pass');
cd2237a @timo remove a few old workarounds for 4-year-old rakudo
timo authored
197 ok @heights-snapshot eqv $game.heights
198 || @colors-snapshot eqv $game.colors,
2a40967 @masak implemented 23rd and 24th tests; pass right away
authored
199 "passing does not change the board";
2b8ab6e @masak added the test stub subs
authored
200 }
201
8c8f50d @timo chase rakudo CALLER:: semantics.
timo authored
202 my &*passing-makes-it-the-other-player's-turn = sub {
2a40967 @masak implemented 23rd and 24th tests; pass right away
authored
203 $^game.make-move('pass');
204 is $game.player-to-move, 2,
205 "passing makes it the other player's turn";
2b8ab6e @masak added the test stub subs
authored
206 }
207
8c8f50d @timo chase rakudo CALLER:: semantics.
timo authored
208 my &*passing-twice-ends-the-game = sub {
837fa5b @masak added, wrote twenty-fifth test
authored
209 $^game.make-move($_) for <pass pass>;
210 ok $game.finished, "passing twice ends the game";
211 }
212
8c8f50d @timo chase rakudo CALLER:: semantics.
timo authored
213 my &*resigning-must-have-a-certain-syntax = sub {
b7f7f84 @timo "defined" is no longer a prefix operator.
timo authored
214 ok (defined $^game.make-move('resign')),
d8dec0d @masak wrote tests 26 and 27; 26 fails
authored
215 "resigning must have a certain syntax";
216 }
217
8c8f50d @timo chase rakudo CALLER:: semantics.
timo authored
218 my &*resigning-does-not-change-the-board = sub {
d8dec0d @masak wrote tests 26 and 27; 26 fails
authored
219 $^game.make-move($_) for <a2 b3 c1 b3>;
220 my @heights-snapshot = $game.heights;
221 my @colors-snapshot = $game.colors;
222 $game.make-move('resign');
cd2237a @timo remove a few old workarounds for 4-year-old rakudo
timo authored
223 ok @heights-snapshot eqv $game.heights
224 || @colors-snapshot eqv $game.colors,
d8dec0d @masak wrote tests 26 and 27; 26 fails
authored
225 "resigning does not change the board";
2b8ab6e @masak added the test stub subs
authored
226 }
227
8c8f50d @timo chase rakudo CALLER:: semantics.
timo authored
228 my &*resigning-ends-the-game = sub {
d3e444b @masak wrote 28th test; passes right away
authored
229 $^game.make-move('resign');
230 ok $game.finished, "resigning ends the game";
2b8ab6e @masak added the test stub subs
authored
231 }
232
8c8f50d @timo chase rakudo CALLER:: semantics.
timo authored
233 my &*a-chain-wins-the-game-if-it-connects-a-player's-edges = sub {
f970249 @masak wrote twenty-ninth test
authored
234 $^game.make-move($_) for <b1 b2 c1 b2 c2 b2 c3>;
235 ok $game.finished,
236 "a chain wins the game if it connects a player's edges";
2b8ab6e @masak added the test stub subs
authored
237 }
238
8c8f50d @timo chase rakudo CALLER:: semantics.
timo authored
239 my &*a-chain-does-not-win-the-game-if-it-connects-the-enemy's-edges = sub {
cc3ce02 @masak wrote thirtieth test; passes right away
authored
240 $^game.make-move($_) for <a2 b1 b2 b1 c2>;
241 ok !$game.finished,
242 "a chain does not win the game if it connects the enemy's edges";
2b8ab6e @masak added the test stub subs
authored
243 }
244
8c8f50d @timo chase rakudo CALLER:: semantics.
timo authored
245 plan count-tests(@tests);
246 run-tests(@tests);
247
5f22c50 @masak added vim filetype line
authored
248 # vim: filetype=perl6
Something went wrong with that request. Please try again.