arimaa_engine_step/
engine_tests.rs

1#[cfg(test)]
2mod tests {
3    use super::super::{take_actions, PushPullState, Terminal};
4    use super::super::{GameState, Piece, Square};
5
6    fn place_major_pieces(game_state: GameState) -> GameState {
7        take_actions!(game_state => h, c, d, m, e, d, c, h)
8    }
9
10    fn place_8_rabbits(game_state: GameState) -> GameState {
11        take_actions!(game_state => r, r, r, r, r, r, r, r)
12    }
13
14    fn initial_play_state() -> GameState {
15        let game_state = GameState::initial();
16        let game_state = place_8_rabbits(game_state);
17        let game_state = place_major_pieces(game_state);
18
19        let game_state = place_major_pieces(game_state);
20        place_8_rabbits(game_state)
21    }
22
23    #[test]
24    fn test_action_placing_pieces() {
25        let game_state = initial_play_state();
26        let piece_board = game_state.piece_board();
27
28        assert_eq!(
29            piece_board.rabbits,
30            0b__00000000__11111111__00000000__00000000__00000000__00000000__11111111__00000000
31        );
32        assert_eq!(
33            piece_board.cats,
34            0b__01000010__00000000__00000000__00000000__00000000__00000000__00000000__01000010
35        );
36        assert_eq!(
37            piece_board.dogs,
38            0b__00100100__00000000__00000000__00000000__00000000__00000000__00000000__00100100
39        );
40        assert_eq!(
41            piece_board.horses,
42            0b__10000001__00000000__00000000__00000000__00000000__00000000__00000000__10000001
43        );
44        assert_eq!(
45            piece_board.camels,
46            0b__00001000__00000000__00000000__00000000__00000000__00000000__00000000__00001000
47        );
48        assert_eq!(
49            piece_board.elephants,
50            0b__00010000__00000000__00000000__00000000__00000000__00000000__00000000__00010000
51        );
52        assert_eq!(
53            piece_board.p1_pieces,
54            0b__11111111__11111111__00000000__00000000__00000000__00000000__00000000__00000000
55        );
56
57        assert!(game_state.is_p1_turn_to_move());
58        assert_eq!(game_state.unwrap_play_phase().step(), 0);
59        assert_eq!(
60            game_state.unwrap_play_phase().push_pull_state(),
61            PushPullState::None
62        );
63    }
64
65    #[test]
66    fn test_action_move_up() {
67        let game_state = initial_play_state();
68        let game_state = take_actions!(game_state => a2n);
69        let piece_board = game_state.piece_board();
70
71        assert_eq!(
72            piece_board.rabbits,
73            0b__00000000__11111110__00000001__00000000__00000000__00000000__11111111__00000000
74        );
75        assert_eq!(
76            piece_board.p1_pieces,
77            0b__11111111__11111110__00000001__00000000__00000000__00000000__00000000__00000000
78        );
79        assert_eq!(game_state.unwrap_play_phase().step(), 1);
80        assert!(game_state.is_p1_turn_to_move());
81
82        let game_state = take_actions!(game_state => a3n);
83        let piece_board = game_state.piece_board();
84        assert_eq!(
85            piece_board.rabbits,
86            0b__00000000__11111110__00000000__00000001__00000000__00000000__11111111__00000000
87        );
88        assert_eq!(
89            piece_board.p1_pieces,
90            0b__11111111__11111110__00000000__00000001__00000000__00000000__00000000__00000000
91        );
92        assert_eq!(game_state.unwrap_play_phase().step(), 2);
93        assert!(game_state.is_p1_turn_to_move());
94
95        let game_state = take_actions!(game_state => a4n);
96        let piece_board = game_state.piece_board();
97        assert_eq!(
98            piece_board.rabbits,
99            0b__00000000__11111110__00000000__00000000__00000001__00000000__11111111__00000000
100        );
101        assert_eq!(
102            piece_board.p1_pieces,
103            0b__11111111__11111110__00000000__00000000__00000001__00000000__00000000__00000000
104        );
105        assert_eq!(game_state.unwrap_play_phase().step(), 3);
106        assert!(game_state.is_p1_turn_to_move());
107
108        let game_state = take_actions!(game_state => b2n);
109        let piece_board = game_state.piece_board();
110        assert_eq!(
111            piece_board.rabbits,
112            0b__00000000__11111100__00000010__00000000__00000001__00000000__11111111__00000000
113        );
114        assert_eq!(
115            piece_board.p1_pieces,
116            0b__11111111__11111100__00000010__00000000__00000001__00000000__00000000__00000000
117        );
118        assert_eq!(game_state.unwrap_play_phase().step(), 0);
119        assert!(!game_state.is_p1_turn_to_move());
120    }
121
122    #[test]
123    fn test_action_move_down() {
124        let game_state = initial_play_state();
125        let game_state = take_actions!(game_state => d7s);
126        let piece_board = game_state.piece_board();
127
128        assert_eq!(
129            piece_board.rabbits,
130            0b__00000000__11111111__00000000__00000000__00000000__00001000__11110111__00000000
131        );
132        assert_eq!(
133            piece_board.p1_pieces,
134            0b__11111111__11111111__00000000__00000000__00000000__00000000__00000000__00000000
135        );
136        assert_eq!(game_state.unwrap_play_phase().step(), 1);
137        assert!(game_state.is_p1_turn_to_move());
138
139        let game_state = take_actions!(game_state => d6s);
140        let piece_board = game_state.piece_board();
141        assert_eq!(
142            piece_board.rabbits,
143            0b__00000000__11111111__00000000__00000000__00001000__00000000__11110111__00000000
144        );
145        assert_eq!(
146            piece_board.p1_pieces,
147            0b__11111111__11111111__00000000__00000000__00000000__00000000__00000000__00000000
148        );
149        assert_eq!(game_state.unwrap_play_phase().step(), 2);
150        assert!(game_state.is_p1_turn_to_move());
151
152        let game_state = take_actions!(game_state => d5s);
153        let piece_board = game_state.piece_board();
154        assert_eq!(
155            piece_board.rabbits,
156            0b__00000000__11111111__00000000__00001000__00000000__00000000__11110111__00000000
157        );
158        assert_eq!(
159            piece_board.p1_pieces,
160            0b__11111111__11111111__00000000__00000000__00000000__00000000__00000000__00000000
161        );
162        assert_eq!(game_state.unwrap_play_phase().step(), 3);
163        assert!(game_state.is_p1_turn_to_move());
164
165        let game_state = take_actions!(game_state => d4s);
166        let piece_board = game_state.piece_board();
167        assert_eq!(
168            piece_board.rabbits,
169            0b__00000000__11111111__00001000__00000000__00000000__00000000__11110111__00000000
170        );
171        assert_eq!(
172            piece_board.p1_pieces,
173            0b__11111111__11111111__00000000__00000000__00000000__00000000__00000000__00000000
174        );
175        assert_eq!(game_state.unwrap_play_phase().step(), 0);
176        assert!(!game_state.is_p1_turn_to_move());
177    }
178
179    #[test]
180    fn test_action_move_left() {
181        let game_state = initial_play_state();
182        let game_state = take_actions!(game_state => d7s);
183        let piece_board = game_state.piece_board();
184
185        assert_eq!(
186            piece_board.rabbits,
187            0b__00000000__11111111__00000000__00000000__00000000__00001000__11110111__00000000
188        );
189        assert_eq!(
190            piece_board.p1_pieces,
191            0b__11111111__11111111__00000000__00000000__00000000__00000000__00000000__00000000
192        );
193        assert_eq!(game_state.unwrap_play_phase().step(), 1);
194        assert!(game_state.is_p1_turn_to_move());
195
196        let game_state = take_actions!(game_state => d6w);
197        let piece_board = game_state.piece_board();
198        assert_eq!(
199            piece_board.rabbits,
200            0b__00000000__11111111__00000000__00000000__00000000__00000100__11110111__00000000
201        );
202        assert_eq!(
203            piece_board.p1_pieces,
204            0b__11111111__11111111__00000000__00000000__00000000__00000000__00000000__00000000
205        );
206        assert_eq!(game_state.unwrap_play_phase().step(), 2);
207        assert!(game_state.is_p1_turn_to_move());
208
209        let game_state = take_actions!(game_state => c6w);
210        let piece_board = game_state.piece_board();
211        assert_eq!(
212            piece_board.rabbits,
213            0b__00000000__11111111__00000000__00000000__00000000__00000010__11110111__00000000
214        );
215        assert_eq!(
216            piece_board.p1_pieces,
217            0b__11111111__11111111__00000000__00000000__00000000__00000000__00000000__00000000
218        );
219        assert_eq!(game_state.unwrap_play_phase().step(), 3);
220        assert!(game_state.is_p1_turn_to_move());
221
222        let game_state = take_actions!(game_state => b6w);
223        let piece_board = game_state.piece_board();
224        assert_eq!(
225            piece_board.rabbits,
226            0b__00000000__11111111__00000000__00000000__00000000__00000001__11110111__00000000
227        );
228        assert_eq!(
229            piece_board.p1_pieces,
230            0b__11111111__11111111__00000000__00000000__00000000__00000000__00000000__00000000
231        );
232        assert_eq!(game_state.unwrap_play_phase().step(), 0);
233        assert!(!game_state.is_p1_turn_to_move());
234    }
235
236    #[test]
237    fn test_action_move_right() {
238        let game_state = initial_play_state();
239        let game_state = take_actions!(game_state => d7s);
240        let piece_board = game_state.piece_board();
241
242        assert_eq!(
243            piece_board.rabbits,
244            0b__00000000__11111111__00000000__00000000__00000000__00001000__11110111__00000000
245        );
246        assert_eq!(
247            piece_board.p1_pieces,
248            0b__11111111__11111111__00000000__00000000__00000000__00000000__00000000__00000000
249        );
250        assert_eq!(game_state.unwrap_play_phase().step(), 1);
251        assert!(game_state.is_p1_turn_to_move());
252
253        let game_state = take_actions!(game_state => d6e);
254        let piece_board = game_state.piece_board();
255        assert_eq!(
256            piece_board.rabbits,
257            0b__00000000__11111111__00000000__00000000__00000000__00010000__11110111__00000000
258        );
259        assert_eq!(
260            piece_board.p1_pieces,
261            0b__11111111__11111111__00000000__00000000__00000000__00000000__00000000__00000000
262        );
263        assert_eq!(game_state.unwrap_play_phase().step(), 2);
264        assert!(game_state.is_p1_turn_to_move());
265
266        let game_state = take_actions!(game_state => e6e);
267        let piece_board = game_state.piece_board();
268        assert_eq!(
269            piece_board.rabbits,
270            0b__00000000__11111111__00000000__00000000__00000000__00100000__11110111__00000000
271        );
272        assert_eq!(
273            piece_board.p1_pieces,
274            0b__11111111__11111111__00000000__00000000__00000000__00000000__00000000__00000000
275        );
276        assert_eq!(game_state.unwrap_play_phase().step(), 3);
277        assert!(game_state.is_p1_turn_to_move());
278
279        let game_state = take_actions!(game_state => f6e);
280        let piece_board = game_state.piece_board();
281        assert_eq!(
282            piece_board.rabbits,
283            0b__00000000__11111111__00000000__00000000__00000000__01000000__11110111__00000000
284        );
285        assert_eq!(
286            piece_board.p1_pieces,
287            0b__11111111__11111111__00000000__00000000__00000000__00000000__00000000__00000000
288        );
289        assert_eq!(game_state.unwrap_play_phase().step(), 0);
290        assert!(!game_state.is_p1_turn_to_move());
291    }
292
293    #[test]
294    fn test_action_move_trap_unsupported() {
295        let game_state = initial_play_state();
296        let game_state = take_actions!(game_state => c2n);
297        let piece_board = game_state.piece_board();
298
299        assert_eq!(
300            piece_board.rabbits,
301            0b__00000000__11111011__00000000__00000000__00000000__00000000__11111111__00000000
302        );
303        assert_eq!(
304            piece_board.p1_pieces,
305            0b__11111111__11111011__00000000__00000000__00000000__00000000__00000000__00000000
306        );
307        assert_eq!(game_state.unwrap_play_phase().step(), 1);
308        assert!(game_state.is_p1_turn_to_move());
309    }
310
311    #[test]
312    fn test_action_move_trap_supported_right() {
313        let game_state = initial_play_state();
314        let game_state = take_actions!(game_state => b2n);
315        let game_state = take_actions!(game_state => c2n);
316        let piece_board = game_state.piece_board();
317
318        assert_eq!(
319            piece_board.rabbits,
320            0b__00000000__11111001__00000110__00000000__00000000__00000000__11111111__00000000
321        );
322        assert_eq!(
323            piece_board.p1_pieces,
324            0b__11111111__11111001__00000110__00000000__00000000__00000000__00000000__00000000
325        );
326        assert_eq!(game_state.unwrap_play_phase().step(), 2);
327        assert!(game_state.is_p1_turn_to_move());
328    }
329
330    #[test]
331    fn test_action_move_trap_supported_left() {
332        let game_state = initial_play_state();
333        let game_state = take_actions!(game_state => d2n);
334        let game_state = take_actions!(game_state => c2n);
335        let piece_board = game_state.piece_board();
336
337        assert_eq!(
338            piece_board.rabbits,
339            0b__00000000__11110011__00001100__00000000__00000000__00000000__11111111__00000000
340        );
341        assert_eq!(
342            piece_board.p1_pieces,
343            0b__11111111__11110011__00001100__00000000__00000000__00000000__00000000__00000000
344        );
345        assert_eq!(game_state.unwrap_play_phase().step(), 2);
346        assert!(game_state.is_p1_turn_to_move());
347    }
348
349    #[test]
350    fn test_action_move_trap_supported_top() {
351        let game_state = initial_play_state();
352        let game_state = take_actions!(game_state => b2n);
353        let game_state = take_actions!(game_state => b3e);
354        let piece_board = game_state.piece_board();
355
356        assert_eq!(
357            piece_board.rabbits,
358            0b__00000000__11111101__00000100__00000000__00000000__00000000__11111111__00000000
359        );
360        assert_eq!(
361            piece_board.p1_pieces,
362            0b__11111111__11111101__00000100__00000000__00000000__00000000__00000000__00000000
363        );
364        assert_eq!(game_state.unwrap_play_phase().step(), 2);
365        assert!(game_state.is_p1_turn_to_move());
366    }
367
368    #[test]
369    fn test_action_move_trap_supported_bottom() {
370        let game_state = initial_play_state();
371        let game_state = take_actions!(game_state => b2n);
372        let game_state = take_actions!(game_state => b3n);
373        let game_state = take_actions!(game_state => b4e);
374        let game_state = take_actions!(game_state => c2n);
375        let piece_board = game_state.piece_board();
376
377        assert_eq!(
378            piece_board.rabbits,
379            0b__00000000__11111001__00000100__00000100__00000000__00000000__11111111__00000000
380        );
381        assert_eq!(
382            piece_board.p1_pieces,
383            0b__11111111__11111001__00000100__00000100__00000000__00000000__00000000__00000000
384        );
385        assert_eq!(game_state.unwrap_play_phase().step(), 0);
386        assert!(!game_state.is_p1_turn_to_move());
387    }
388
389    #[test]
390    fn test_action_move_trap_adjacent_opp_unsupported() {
391        let game_state = initial_play_state();
392        let game_state = take_actions!(game_state => b2n);
393        let game_state = take_actions!(game_state => c2n);
394        let game_state = take_actions!(game_state => c3n);
395        let game_state = take_actions!(game_state => c4n);
396
397        let game_state = take_actions!(game_state => c7s);
398        let piece_board = game_state.piece_board();
399
400        assert_eq!(
401            piece_board.rabbits,
402            0b__00000000__11111001__00000010__00000000__00000100__00000000__11111011__00000000
403        );
404        assert_eq!(
405            piece_board.p1_pieces,
406            0b__11111111__11111001__00000010__00000000__00000100__00000000__00000000__00000000
407        );
408        assert_eq!(game_state.unwrap_play_phase().step(), 1);
409        assert!(!game_state.is_p1_turn_to_move());
410    }
411
412    #[test]
413    fn test_action_move_push_must_push_rabbit() {
414        let game_state = initial_play_state();
415        let game_state = take_actions!(game_state => b7s);
416
417        assert_eq!(
418            game_state.unwrap_play_phase().push_pull_state(),
419            PushPullState::MustCompletePush(Square::new('b', 7), Piece::Rabbit)
420        );
421    }
422
423    #[test]
424    fn test_action_move_push_must_push_elephant() {
425        let game_state = initial_play_state();
426        let game_state = take_actions!(game_state => a2n);
427        let game_state = take_actions!(game_state => p);
428        let game_state = take_actions!(game_state => e7s);
429        let game_state = take_actions!(game_state => p);
430        let game_state = take_actions!(game_state => e8s);
431
432        assert_eq!(
433            game_state.unwrap_play_phase().push_pull_state(),
434            PushPullState::MustCompletePush(Square::new('e', 8), Piece::Elephant)
435        );
436    }
437
438    #[test]
439    fn test_action_place_initial() {
440        let game_state = GameState::initial();
441
442        assert_eq!(
443            format!("{:?}", game_state.valid_actions()),
444            "[e, m, h, d, c, r]"
445        );
446    }
447
448    #[test]
449    fn test_action_place_elephant() {
450        let game_state = GameState::initial();
451        let game_state = take_actions!(game_state => e);
452
453        assert_eq!(
454            format!("{:?}", game_state.valid_actions()),
455            "[m, h, d, c, r]"
456        );
457    }
458
459    #[test]
460    fn test_action_place_camel() {
461        let game_state = GameState::initial();
462        let game_state = take_actions!(game_state => m);
463        let game_state = take_actions!(game_state => m);
464
465        assert_eq!(
466            format!("{:?}", game_state.valid_actions()),
467            "[e, h, d, c, r]"
468        );
469    }
470
471    #[test]
472    fn test_action_place_horse() {
473        let game_state = GameState::initial();
474        let game_state = take_actions!(game_state => h);
475
476        assert_eq!(
477            format!("{:?}", game_state.valid_actions()),
478            "[e, m, h, d, c, r]"
479        );
480
481        let game_state = take_actions!(game_state => h);
482
483        assert_eq!(
484            format!("{:?}", game_state.valid_actions()),
485            "[e, m, d, c, r]"
486        );
487    }
488
489    #[test]
490    fn test_action_place_dog() {
491        let game_state = GameState::initial();
492        let game_state = take_actions!(game_state => d);
493
494        assert_eq!(
495            format!("{:?}", game_state.valid_actions()),
496            "[e, m, h, d, c, r]"
497        );
498
499        let game_state = take_actions!(game_state => d);
500
501        assert_eq!(
502            format!("{:?}", game_state.valid_actions()),
503            "[e, m, h, c, r]"
504        );
505    }
506
507    #[test]
508    fn test_action_place_rabbits() {
509        let game_state = GameState::initial();
510
511        let game_state = place_8_rabbits(game_state);
512
513        assert_eq!(
514            format!("{:?}", game_state.valid_actions()),
515            "[e, m, h, d, c]"
516        );
517    }
518
519    #[test]
520    fn test_action_place_majors() {
521        let game_state = GameState::initial();
522
523        let game_state = place_major_pieces(game_state);
524
525        assert_eq!(format!("{:?}", game_state.valid_actions()), "[r]");
526    }
527
528    #[test]
529    fn test_action_place_p2_initial() {
530        let game_state = GameState::initial();
531
532        let game_state = place_major_pieces(game_state);
533        let game_state = place_8_rabbits(game_state);
534
535        assert_eq!(
536            format!("{:?}", game_state.valid_actions()),
537            "[e, m, h, d, c, r]"
538        );
539    }
540
541    #[test]
542    fn test_action_place_p2_camel() {
543        let game_state = GameState::initial();
544
545        let game_state = place_major_pieces(game_state);
546        let game_state = place_8_rabbits(game_state);
547        let game_state = take_actions!(game_state => m);
548
549        assert_eq!(
550            format!("{:?}", game_state.valid_actions()),
551            "[e, h, d, c, r]"
552        );
553    }
554
555    #[test]
556    fn test_action_correct_state_after_4_steps() {
557        let game_state: GameState = "
558             1g
559              +-----------------+
560             8|   r   r r   r   |
561             7|                 |
562             6|     x     x     |
563             5|     E r         |
564             4|                 |
565             3|     x     x     |
566             2|                 |
567             1| R               |
568              +-----------------+
569                a b c d e f g h"
570            .parse()
571            .unwrap();
572
573        let game_state = take_actions!(game_state => a1n, a2n, a3n, a4n);
574
575        let game_state = take_actions!(game_state => d8s);
576
577        assert_eq!(
578            game_state.to_string(),
579            "1s
580 +-----------------+
5818|   r     r   r   |
5827|       r         |
5836|     x     x     |
5845| R   E r         |
5854|                 |
5863|     x     x     |
5872|                 |
5881|                 |
589 +-----------------+
590   a b c d e f g h
591"
592        );
593    }
594
595    #[test]
596    fn test_action_correct_state_after_pull_with_trap() {
597        let game_state: GameState = "
598             1g
599              +-----------------+
600             8|   r   r r   r   |
601             7|                 |
602             6|     x     x     |
603             5|     E r         |
604             4|                 |
605             3|     x     x     |
606             2|                 |
607             1| R               |
608              +-----------------+
609                a b c d e f g h"
610            .parse()
611            .unwrap();
612
613        let game_state = take_actions!(game_state => c5n);
614
615        assert_eq!(
616            game_state
617                .unwrap_play_phase()
618                .push_pull_state()
619                .as_possible_pull()
620                .unwrap(),
621            (Square::new('c', 5), Piece::Elephant)
622        );
623        assert_eq!(
624            format!("{:?}", game_state.valid_actions()),
625            "[d5w, a1n, a1e, p]"
626        );
627        assert_eq!(
628            game_state.to_string(),
629            "1g
630 +-----------------+
6318|   r   r r   r   |
6327|                 |
6336|     x     x     |
6345|       r         |
6354|                 |
6363|     x     x     |
6372|                 |
6381| R               |
639 +-----------------+
640   a b c d e f g h
641"
642        );
643
644        let game_state = take_actions!(game_state => a1n);
645        assert_eq!(format!("{:?}", game_state.valid_actions()), "[a2n, a2e, p]");
646        assert_eq!(
647            game_state.to_string(),
648            "1g
649 +-----------------+
6508|   r   r r   r   |
6517|                 |
6526|     x     x     |
6535|       r         |
6544|                 |
6553|     x     x     |
6562| R               |
6571|                 |
658 +-----------------+
659   a b c d e f g h
660"
661        );
662
663        let game_state = take_actions!(game_state => p);
664        assert_eq!(
665            format!("{:?}", game_state.valid_actions()),
666            "[b8e, e8e, g8e, d5e, b8s, d8s, e8s, g8s, d5s, b8w, d8w, g8w, d5w]"
667        );
668        assert_eq!(
669            game_state.to_string(),
670            "1s
671 +-----------------+
6728|   r   r r   r   |
6737|                 |
6746|     x     x     |
6755|       r         |
6764|                 |
6773|     x     x     |
6782| R               |
6791|                 |
680 +-----------------+
681   a b c d e f g h
682"
683        );
684    }
685
686    #[test]
687    fn test_action_correct_state_after_pull_with_trap_accepted() {
688        let game_state: GameState = "
689             1g
690              +-----------------+
691             8|   r   r r   r   |
692             7|                 |
693             6|     x     x     |
694             5|     E r         |
695             4|                 |
696             3|     x     x     |
697             2| r               |
698             1| D               |
699              +-----------------+
700                a b c d e f g h"
701            .parse()
702            .unwrap();
703
704        let game_state = take_actions!(game_state => c5n);
705
706        assert_eq!(
707            game_state
708                .unwrap_play_phase()
709                .push_pull_state()
710                .as_possible_pull()
711                .unwrap(),
712            (Square::new('c', 5), Piece::Elephant)
713        );
714        assert_eq!(
715            format!("{:?}", game_state.valid_actions()),
716            "[a2n, a2e, d5w, a1e, p]"
717        );
718        assert_eq!(
719            game_state.to_string(),
720            "1g
721 +-----------------+
7228|   r   r r   r   |
7237|                 |
7246|     x     x     |
7255|       r         |
7264|                 |
7273|     x     x     |
7282| r               |
7291| D               |
730 +-----------------+
731   a b c d e f g h
732"
733        );
734
735        let game_state = take_actions!(game_state => d5w);
736        assert_eq!(
737            format!("{:?}", game_state.valid_actions()),
738            "[a2n, a2e, a1e, p]"
739        );
740        assert_eq!(
741            game_state.to_string(),
742            "1g
743 +-----------------+
7448|   r   r r   r   |
7457|                 |
7466|     x     x     |
7475|     r           |
7484|                 |
7493|     x     x     |
7502| r               |
7511| D               |
752 +-----------------+
753   a b c d e f g h
754"
755        );
756
757        let game_state = take_actions!(game_state => a2e);
758        assert_eq!(format!("{:?}", game_state.valid_actions()), "[a1n]");
759        assert_eq!(
760            game_state.to_string(),
761            "1g
762 +-----------------+
7638|   r   r r   r   |
7647|                 |
7656|     x     x     |
7665|     r           |
7674|                 |
7683|     x     x     |
7692|   r             |
7701| D               |
771 +-----------------+
772   a b c d e f g h
773"
774        );
775
776        let game_state = take_actions!(game_state => a1n);
777        assert_eq!(
778            format!("{:?}", game_state.valid_actions()),
779            "[b8e, e8e, g8e, c5e, b8s, d8s, e8s, g8s, c5s, b8w, d8w, g8w, c5w]"
780        );
781        assert_eq!(
782            game_state.to_string(),
783            "1s
784 +-----------------+
7858|   r   r r   r   |
7867|                 |
7876|     x     x     |
7885|     r           |
7894|                 |
7903|     x     x     |
7912| D r             |
7921|                 |
793 +-----------------+
794   a b c d e f g h
795"
796        );
797    }
798
799    #[test]
800    fn test_action_cant_push_on_last_step() {
801        let game_state: GameState = "
802             1g
803              +-----------------+
804             8|   r   r r   r   |
805             7|                 |
806             6|     x     x     |
807             5|     E r         |
808             4|                 |
809             3|     x     x     |
810             2| r         D     |
811             1| D               |
812              +-----------------+
813                a b c d e f g h"
814            .parse()
815            .unwrap();
816
817        let game_state = take_actions!(game_state => f2n);
818        let game_state = take_actions!(game_state => c5n);
819
820        assert_eq!(
821            game_state
822                .unwrap_play_phase()
823                .push_pull_state()
824                .as_possible_pull()
825                .unwrap(),
826            (Square::new('c', 5), Piece::Elephant)
827        );
828        assert_eq!(
829            format!("{:?}", game_state.valid_actions()),
830            "[a2n, a2e, d5w, a1e, p]"
831        );
832        assert_eq!(
833            game_state.to_string(),
834            "1g
835 +-----------------+
8368|   r   r r   r   |
8377|                 |
8386|     x     x     |
8395|       r         |
8404|                 |
8413|     x     x     |
8422| r               |
8431| D               |
844 +-----------------+
845   a b c d e f g h
846"
847        );
848
849        let game_state = take_actions!(game_state => d5w);
850        assert_eq!(format!("{:?}", game_state.valid_actions()), "[a1e, p]");
851        assert_eq!(
852            game_state.to_string(),
853            "1g
854 +-----------------+
8558|   r   r r   r   |
8567|                 |
8576|     x     x     |
8585|     r           |
8594|                 |
8603|     x     x     |
8612| r               |
8621| D               |
863 +-----------------+
864   a b c d e f g h
865"
866        );
867
868        let game_state = take_actions!(game_state => a1e);
869        assert_eq!(
870            format!("{:?}", game_state.valid_actions()),
871            "[b8e, e8e, g8e, c5e, a2e, b8s, d8s, e8s, g8s, c5s, a2s, b8w, d8w, g8w, c5w]"
872        );
873        assert_eq!(
874            game_state.to_string(),
875            "1s
876 +-----------------+
8778|   r   r r   r   |
8787|                 |
8796|     x     x     |
8805|     r           |
8814|                 |
8823|     x     x     |
8832| r               |
8841|   D             |
885 +-----------------+
886   a b c d e f g h
887"
888        );
889
890        let game_state = take_actions!(game_state => a2s);
891        assert_eq!(
892            format!("{:?}", game_state.valid_actions()),
893            "[b8e, e8e, g8e, c5e, b8s, d8s, e8s, g8s, c5s, b8w, d8w, g8w, c5w, p]"
894        );
895        assert_eq!(
896            game_state.to_string(),
897            "1s
898 +-----------------+
8998|   r   r r   r   |
9007|                 |
9016|     x     x     |
9025|     r           |
9034|                 |
9043|     x     x     |
9052|                 |
9061| r D             |
907 +-----------------+
908   a b c d e f g h
909"
910        );
911
912        assert_eq!(game_state.is_terminal(), None);
913
914        let game_state = take_actions!(game_state => p);
915        assert_eq!(game_state.is_terminal(), Some(Terminal::SilverWin));
916    }
917
918    #[test]
919    fn test_action_cant_push_and_pull_simultaneously() {
920        let game_state: GameState = "
921             1s
922              +-----------------+
923             8|                 |
924             7|                 |
925             6|     x     x     |
926             5|                 |
927             4| R               |
928             3| c   x     x     |
929             2| R               |
930             1|                 |
931              +-----------------+
932                a b c d e f g h"
933            .parse()
934            .unwrap();
935
936        assert_eq!(
937            format!("{:?}", game_state.valid_actions()),
938            "[a4n, a4e, a2e, a2s, a3e]"
939        );
940
941        let game_state = take_actions!(game_state => a2e);
942        assert_eq!(format!("{:?}", game_state.valid_actions()), "[a3s]");
943        assert_eq!(
944            game_state.to_string(),
945            "1s
946 +-----------------+
9478|                 |
9487|                 |
9496|     x     x     |
9505|                 |
9514| R               |
9523| c   x     x     |
9532|   R             |
9541|                 |
955 +-----------------+
956   a b c d e f g h
957"
958        );
959
960        let game_state = take_actions!(game_state => a3s);
961        assert_eq!(
962            format!("{:?}", game_state.valid_actions()),
963            "[b2n, b2e, b2s, a2n, a2s, p]"
964        );
965        assert_eq!(
966            game_state.to_string(),
967            "1s
968 +-----------------+
9698|                 |
9707|                 |
9716|     x     x     |
9725|                 |
9734| R               |
9743|     x     x     |
9752| c R             |
9761|                 |
977 +-----------------+
978   a b c d e f g h
979"
980        );
981
982        let game_state = take_actions!(game_state => a2s);
983        assert_eq!(
984            format!("{:?}", game_state.valid_actions()),
985            "[b2w, a1n, a1e, p]"
986        );
987        assert_eq!(
988            game_state.to_string(),
989            "1s
990 +-----------------+
9918|                 |
9927|                 |
9936|     x     x     |
9945|                 |
9954| R               |
9963|     x     x     |
9972|   R             |
9981| c               |
999 +-----------------+
1000   a b c d e f g h
1001"
1002        );
1003
1004        let game_state = take_actions!(game_state => p);
1005        assert_eq!(
1006            format!("{:?}", game_state.valid_actions()),
1007            "[a4n, b2n, a4e, b2e, b2w]"
1008        );
1009        assert_eq!(
1010            game_state.to_string(),
1011            "2g
1012 +-----------------+
10138|                 |
10147|                 |
10156|     x     x     |
10165|                 |
10174| R               |
10183|     x     x     |
10192|   R             |
10201| c               |
1021 +-----------------+
1022   a b c d e f g h
1023"
1024        );
1025    }
1026
1027    #[test]
1028    fn test_can_pass_first_move() {
1029        let game_state: GameState = "
1030             1g
1031              +-----------------+
1032             8|   r   r r   r   |
1033             7|                 |
1034             6|     x     x     |
1035             5|     E r         |
1036             4|                 |
1037             3|     x     x     |
1038             2|                 |
1039             1| R               |
1040              +-----------------+
1041                a b c d e f g h"
1042            .parse()
1043            .unwrap();
1044
1045        assert!(!game_state.can_pass(true));
1046    }
1047
1048    #[test]
1049    fn test_can_pass_during_possible_pull() {
1050        let game_state: GameState = "
1051             1g
1052              +-----------------+
1053             8|   r   r r   r   |
1054             7|                 |
1055             6|     x     x     |
1056             5|     E r         |
1057             4|                 |
1058             3|     x     x     |
1059             2|                 |
1060             1| R               |
1061              +-----------------+
1062                a b c d e f g h"
1063            .parse()
1064            .unwrap();
1065
1066        let game_state = take_actions!(game_state => c5s);
1067        assert!(game_state.can_pass(true));
1068    }
1069
1070    #[test]
1071    fn test_can_pass_during_must_push() {
1072        let game_state: GameState = "
1073             1g
1074              +-----------------+
1075             8|   r   r r   r   |
1076             7|                 |
1077             6|     x     x     |
1078             5|     E r         |
1079             4|                 |
1080             3|     x     x     |
1081             2|                 |
1082             1| R               |
1083              +-----------------+
1084                a b c d e f g h"
1085            .parse()
1086            .unwrap();
1087
1088        let game_state = take_actions!(game_state => d5s);
1089        assert!(!game_state.can_pass(true));
1090    }
1091
1092    #[test]
1093    fn test_can_pass_during_place_phase() {
1094        let game_state = GameState::initial();
1095
1096        assert!(!game_state.can_pass(true));
1097
1098        let game_state = take_actions!(game_state => e);
1099        assert!(!game_state.can_pass(true));
1100    }
1101
1102    #[test]
1103    fn test_can_pass_false_if_same_as_start_of_move_state() {
1104        let game_state: GameState = "
1105             1g
1106              +-----------------+
1107             8|   r   r r   r   |
1108             7|                 |
1109             6|     x     x     |
1110             5|     E r         |
1111             4|                 |
1112             3|     x     x     |
1113             2|                 |
1114             1| R               |
1115              +-----------------+
1116                a b c d e f g h"
1117            .parse()
1118            .unwrap();
1119
1120        assert!(!game_state.can_pass(true));
1121
1122        let game_state = take_actions!(game_state => c5s);
1123        assert!(game_state.can_pass(true));
1124
1125        let game_state = take_actions!(game_state => c4n);
1126        assert!(!game_state.can_pass(true));
1127
1128        let game_state = take_actions!(game_state => c5s);
1129        assert!(game_state.can_pass(true));
1130    }
1131
1132    #[test]
1133    fn test_is_terminal_no_winner() {
1134        let game_state: GameState = "
1135             1g
1136              +-----------------+
1137             8| M r   r r   r   |
1138             7|                 |
1139             6|     x     x     |
1140             5|                 |
1141             4|                 |
1142             3|     x     x     |
1143             2|                 |
1144             1| m R             |
1145              +-----------------+
1146                a b c d e f g h"
1147            .parse()
1148            .unwrap();
1149
1150        assert_eq!(game_state.is_terminal(), None);
1151    }
1152
1153    #[test]
1154    fn test_is_terminal_mid_turn() {
1155        let game_state: GameState = "
1156             1g
1157              +-----------------+
1158             8|   r   r r   r   |
1159             7| R               |
1160             6|     x     x     |
1161             5|                 |
1162             4|                 |
1163             3|     x     x     |
1164             2|                 |
1165             1| m               |
1166              +-----------------+
1167                a b c d e f g h"
1168            .parse()
1169            .unwrap();
1170
1171        let game_state = take_actions!(game_state => a7n);
1172        assert_eq!(game_state.is_terminal(), None);
1173
1174        let game_state = take_actions!(game_state => a8s);
1175        assert_eq!(game_state.is_terminal(), None);
1176
1177        let game_state = take_actions!(game_state => p);
1178        assert_eq!(game_state.is_terminal(), None);
1179    }
1180
1181    #[test]
1182    fn test_is_terminal_p1_winner_as_p1() {
1183        let game_state: GameState = "
1184             1s
1185              +-----------------+
1186             8| R r   r r   r   |
1187             7|                 |
1188             6|     x     x     |
1189             5|                 |
1190             4|                 |
1191             3|     x     x     |
1192             2|                 |
1193             1|   R             |
1194              +-----------------+
1195                a b c d e f g h"
1196            .parse()
1197            .unwrap();
1198
1199        assert_eq!(game_state.is_terminal(), Some(Terminal::GoldWin));
1200    }
1201
1202    #[test]
1203    fn test_is_terminal_p2_winner_as_p1() {
1204        let game_state: GameState = "
1205             1s
1206              +-----------------+
1207             8|   r   r r   r   |
1208             7|                 |
1209             6|     x     x     |
1210             5|                 |
1211             4|                 |
1212             3|     x     x     |
1213             2|                 |
1214             1| r R             |
1215              +-----------------+
1216                a b c d e f g h"
1217            .parse()
1218            .unwrap();
1219
1220        assert_eq!(game_state.is_terminal(), Some(Terminal::SilverWin));
1221    }
1222
1223    #[test]
1224    fn test_is_terminal_p1_winner_as_p2() {
1225        let game_state: GameState = "
1226             1g
1227              +-----------------+
1228             8| R r   r r   r   |
1229             7|                 |
1230             6|     x     x     |
1231             5|                 |
1232             4|                 |
1233             3|     x     x     |
1234             2|                 |
1235             1|   R             |
1236              +-----------------+
1237                a b c d e f g h"
1238            .parse()
1239            .unwrap();
1240
1241        assert_eq!(game_state.is_terminal(), Some(Terminal::GoldWin));
1242    }
1243
1244    #[test]
1245    fn test_is_terminal_p2_winner_as_p2() {
1246        let game_state: GameState = "
1247             1g
1248              +-----------------+
1249             8|   r   r r   r   |
1250             7|                 |
1251             6|     x     x     |
1252             5|                 |
1253             4|                 |
1254             3|     x     x     |
1255             2|                 |
1256             1| r R             |
1257              +-----------------+
1258                a b c d e f g h"
1259            .parse()
1260            .unwrap();
1261
1262        assert_eq!(game_state.is_terminal(), Some(Terminal::SilverWin));
1263    }
1264
1265    #[test]
1266    fn test_is_terminal_p1_and_p2_met_as_p1() {
1267        let game_state: GameState = "
1268             1s
1269              +-----------------+
1270             8| R r   r r   r   |
1271             7|                 |
1272             6|     x     x     |
1273             5|                 |
1274             4|                 |
1275             3|     x     x     |
1276             2|                 |
1277             1| r R             |
1278              +-----------------+
1279                a b c d e f g h"
1280            .parse()
1281            .unwrap();
1282
1283        assert_eq!(game_state.is_terminal(), Some(Terminal::GoldWin));
1284    }
1285
1286    #[test]
1287    fn test_is_terminal_p1_and_p2_met_as_p2() {
1288        let game_state: GameState = "
1289             1g
1290              +-----------------+
1291             8| R r   r r   r   |
1292             7|                 |
1293             6|     x     x     |
1294             5|                 |
1295             4|                 |
1296             3|     x     x     |
1297             2|                 |
1298             1| r R             |
1299              +-----------------+
1300                a b c d e f g h"
1301            .parse()
1302            .unwrap();
1303
1304        assert_eq!(game_state.is_terminal(), Some(Terminal::SilverWin));
1305    }
1306
1307    #[test]
1308    fn test_is_terminal_p2_lost_rabbits_as_p1() {
1309        let game_state: GameState = "
1310             1s
1311              +-----------------+
1312             8|                 |
1313             7|   e             |
1314             6|     x     x     |
1315             5|                 |
1316             4|                 |
1317             3|     x     x     |
1318             2|   E R           |
1319             1|                 |
1320              +-----------------+
1321                a b c d e f g h"
1322            .parse()
1323            .unwrap();
1324
1325        assert_eq!(game_state.is_terminal(), Some(Terminal::GoldWin));
1326    }
1327
1328    #[test]
1329    fn test_is_terminal_p1_lost_rabbits_as_p2() {
1330        let game_state: GameState = "
1331             1g
1332              +-----------------+
1333             8|   r             |
1334             7|   e             |
1335             6|     x     x     |
1336             5|                 |
1337             4|                 |
1338             3|     x     x     |
1339             2|   E             |
1340             1|                 |
1341              +-----------------+
1342                a b c d e f g h"
1343            .parse()
1344            .unwrap();
1345
1346        assert_eq!(game_state.is_terminal(), Some(Terminal::SilverWin));
1347    }
1348
1349    #[test]
1350    fn test_is_terminal_p1_lost_rabbits_as_p1() {
1351        let game_state: GameState = "
1352             1s
1353              +-----------------+
1354             8|   r             |
1355             7|   e             |
1356             6|     x     x     |
1357             5|                 |
1358             4|                 |
1359             3|     x     x     |
1360             2|   E             |
1361             1|                 |
1362              +-----------------+
1363                a b c d e f g h"
1364            .parse()
1365            .unwrap();
1366
1367        assert_eq!(game_state.is_terminal(), Some(Terminal::SilverWin));
1368    }
1369
1370    #[test]
1371    fn test_is_terminal_p2_lost_rabbits_as_p2() {
1372        let game_state: GameState = "
1373             1g
1374              +-----------------+
1375             8|                 |
1376             7|   e             |
1377             6|     x     x     |
1378             5|                 |
1379             4|                 |
1380             3|     x     x     |
1381             2|   E R           |
1382             1|                 |
1383              +-----------------+
1384                a b c d e f g h"
1385            .parse()
1386            .unwrap();
1387
1388        assert_eq!(game_state.is_terminal(), Some(Terminal::GoldWin));
1389    }
1390
1391    #[test]
1392    fn test_is_terminal_p1_and_p2_lost_rabbits_as_p1() {
1393        let game_state: GameState = "
1394             1s
1395              +-----------------+
1396             8|                 |
1397             7|   e             |
1398             6|     x     x     |
1399             5|                 |
1400             4|                 |
1401             3|     x     x     |
1402             2|   E             |
1403             1|                 |
1404              +-----------------+
1405                a b c d e f g h"
1406            .parse()
1407            .unwrap();
1408
1409        assert_eq!(game_state.is_terminal(), Some(Terminal::GoldWin));
1410    }
1411
1412    #[test]
1413    fn test_is_terminal_p1_and_p2_lost_rabbits_as_p2() {
1414        let game_state: GameState = "
1415            1g
1416              +-----------------+
1417             8|                 |
1418             7|   e             |
1419             6|     x     x     |
1420             5|                 |
1421             4|                 |
1422             3|     x     x     |
1423             2|   E             |
1424             1|                 |
1425              +-----------------+
1426                a b c d e f g h"
1427            .parse()
1428            .unwrap();
1429
1430        assert_eq!(game_state.is_terminal(), Some(Terminal::SilverWin));
1431    }
1432
1433    #[test]
1434    fn test_action_cant_push_while_frozen() {
1435        let game_state: GameState = "
1436              +-----------------+
1437             8|                 |
1438             7|                 |
1439             6|     x     x     |
1440             5|       e         |
1441             4|       M r       |
1442             3|     x     x     |
1443             2|                 |
1444             1| R               |
1445              +-----------------+
1446                a b c d e f g h"
1447            .parse()
1448            .unwrap();
1449
1450        assert_eq!(format!("{:?}", game_state.valid_actions()), "[a1n, a1e]");
1451    }
1452
1453    #[test]
1454    fn test_action_cant_push_while_frozen_2() {
1455        let game_state: GameState = "
1456            35s
1457             +-----------------+
1458            8|     d           |
1459            7| r e r r h c r r |
1460            6| H R m r r X c R |
1461            5| d R E R R h R r |
1462            4| R         M   C |
1463            3|     X     X     |
1464            2|   D       D   H |
1465            1|             C   |
1466             +-----------------+
1467               a b c d e f g h
1468            "
1469        .parse()
1470        .unwrap();
1471
1472        let game_state = take_actions!(game_state => c8w);
1473        let game_state = take_actions!(game_state => g5s);
1474
1475        assert_eq!(format!("{:?}", game_state.valid_actions()), "[g6s]");
1476    }
1477
1478    #[test]
1479    fn test_action_move_possible_pull_with_valid_pull() {
1480        let game_state: GameState = "
1481              +-----------------+
1482             8|   r   r r   r   |
1483             7|                 |
1484             6|     x     x     |
1485             5|                 |
1486             4|     E m         |
1487             3|     x     x     |
1488             2|                 |
1489             1|   R   R R   R   |
1490              +-----------------+
1491                a b c d e f g h"
1492            .parse()
1493            .unwrap();
1494
1495        let game_state = take_actions!(game_state => c4n);
1496        assert_eq!(
1497            game_state.unwrap_play_phase().push_pull_state(),
1498            PushPullState::PossiblePull(Square::new('c', 4), Piece::Elephant)
1499        );
1500
1501        let game_state = take_actions!(game_state => d4w);
1502        assert_eq!(
1503            game_state.unwrap_play_phase().push_pull_state(),
1504            PushPullState::None
1505        );
1506    }
1507
1508    #[test]
1509    fn test_action_move_pull_into_trap() {
1510        let game_state: GameState = "
1511              +-----------------+
1512             8|   r   r r   r   |
1513             7|                 |
1514             6|     x     x     |
1515             5|                 |
1516             4|     E m         |
1517             3|     x     x     |
1518             2|                 |
1519             1|   R   R R   R   |
1520              +-----------------+
1521                a b c d e f g h"
1522            .parse()
1523            .unwrap();
1524
1525        let game_state = take_actions!(game_state => c4s);
1526        assert_eq!(
1527            game_state.unwrap_play_phase().push_pull_state(),
1528            PushPullState::PossiblePull(Square::new('c', 4), Piece::Elephant)
1529        );
1530
1531        let game_state = take_actions!(game_state => d4w);
1532        assert_eq!(
1533            game_state.unwrap_play_phase().push_pull_state(),
1534            PushPullState::None
1535        );
1536    }
1537
1538    #[test]
1539    fn test_action_move_possible_pull_with_invalid_pull() {
1540        let game_state: GameState = "
1541              +-----------------+
1542             8|   r   r r   r   |
1543             7|                 |
1544             6|     x     x     |
1545             5|                 |
1546             4|     E e         |
1547             3|     x     x     |
1548             2|                 |
1549             1|   R   R R   R   |
1550              +-----------------+
1551                a b c d e f g h"
1552            .parse()
1553            .unwrap();
1554
1555        let game_state = take_actions!(game_state => c4n);
1556        assert_eq!(
1557            game_state.unwrap_play_phase().push_pull_state(),
1558            PushPullState::PossiblePull(Square::new('c', 4), Piece::Elephant)
1559        );
1560
1561        let game_state = take_actions!(game_state => d4w);
1562        assert_eq!(
1563            game_state.unwrap_play_phase().push_pull_state(),
1564            PushPullState::MustCompletePush(Square::new('d', 4), Piece::Elephant)
1565        );
1566    }
1567
1568    #[test]
1569    fn test_action_move_possible_pull_with_invalid_pull_2() {
1570        let game_state: GameState = "
1571              +-----------------+
1572             8|   r   r r   r   |
1573             7|                 |
1574             6|     x     x     |
1575             5|                 |
1576             4|     M e         |
1577             3|     x     x     |
1578             2|                 |
1579             1|   R   R R   R   |
1580              +-----------------+
1581                a b c d e f g h"
1582            .parse()
1583            .unwrap();
1584
1585        let game_state = take_actions!(game_state => c4n);
1586        assert_eq!(
1587            game_state.unwrap_play_phase().push_pull_state(),
1588            PushPullState::PossiblePull(Square::new('c', 4), Piece::Camel)
1589        );
1590
1591        let game_state = take_actions!(game_state => d4w);
1592        assert_eq!(
1593            game_state.unwrap_play_phase().push_pull_state(),
1594            PushPullState::MustCompletePush(Square::new('d', 4), Piece::Elephant)
1595        );
1596    }
1597
1598    #[test]
1599    fn test_action_pass() {
1600        let game_state = initial_play_state();
1601        let game_state = take_actions!(game_state => d7s);
1602
1603        assert_eq!(game_state.unwrap_play_phase().step(), 1);
1604        assert!(game_state.is_p1_turn_to_move());
1605
1606        let game_state = take_actions!(game_state => p);
1607
1608        assert_eq!(game_state.unwrap_play_phase().step(), 0);
1609        assert!(!game_state.is_p1_turn_to_move());
1610    }
1611
1612    #[test]
1613    fn test_valid_actions() {
1614        let game_state = initial_play_state();
1615
1616        assert_eq!(
1617            format!("{:?}", game_state.valid_actions()),
1618            "[a2n, b2n, c2n, d2n, e2n, f2n, g2n, h2n]"
1619        );
1620    }
1621
1622    #[test]
1623    fn test_valid_actions_p2() {
1624        let game_state: GameState = "
1625             1s
1626              +-----------------+
1627             8| h c d m e d c h |
1628             7| r r r r r r r r |
1629             6|     x     x     |
1630             5|                 |
1631             4|                 |
1632             3|     x     x     |
1633             2| R R R R R R R R |
1634             1| H C D M E D C H |
1635              +-----------------+
1636                a b c d e f g h
1637            "
1638        .parse()
1639        .unwrap();
1640
1641        assert_eq!(
1642            format!("{:?}", game_state.valid_actions()),
1643            "[a7s, b7s, c7s, d7s, e7s, f7s, g7s, h7s]"
1644        );
1645    }
1646
1647    #[test]
1648    fn test_valid_actions_2() {
1649        let game_state: GameState = "
1650              +-----------------+
1651             8| h c d m e d c h |
1652             7| r r r r r r r r |
1653             6|     x     x     |
1654             5|                 |
1655             4|                 |
1656             3|     x   R x     |
1657             2| R R R R   R R R |
1658             1| H C D M E D C H |
1659              +-----------------+
1660                a b c d e f g h
1661            "
1662        .parse()
1663        .unwrap();
1664
1665        assert_eq!(
1666            format!("{:?}", game_state.valid_actions()),
1667            "[e3n, a2n, b2n, c2n, d2n, f2n, g2n, h2n, e1n, e3e, d2e, e3w, f2w]"
1668        );
1669    }
1670
1671    #[test]
1672    fn test_valid_actions_3() {
1673        let game_state: GameState = "
1674             1s
1675              +-----------------+
1676             8| h c d m e d c h |
1677             7| r r r r   r r   |
1678             6|     x   r x   r |
1679             5|                 |
1680             4|                 |
1681             3|     x     x     |
1682             2| R R R R R R R R |
1683             1| H C D M E D C H |
1684              +-----------------+
1685                a b c d e f g h
1686            "
1687        .parse()
1688        .unwrap();
1689
1690        assert_eq!(
1691            format!("{:?}", game_state.valid_actions()),
1692            "[d7e, g7e, e6e, e8s, h8s, a7s, b7s, c7s, d7s, f7s, g7s, e6s, h6s, f7w, e6w, h6w]"
1693        );
1694    }
1695
1696    #[test]
1697    fn test_valid_actions_4() {
1698        let game_state: GameState = "
1699             1g
1700              +-----------------+
1701             8| h c d m e d c h |
1702             7| r r r r r r r r |
1703             6|     x     x     |
1704             5|                 |
1705             4|                 |
1706             3|     x   E x     |
1707             2| R R R R   R R R |
1708             1| H C D M R D C H |
1709              +-----------------+
1710                a b c d e f g h
1711            "
1712        .parse()
1713        .unwrap();
1714
1715        assert_eq!(
1716            format!("{:?}", game_state.valid_actions()),
1717            "[e3n, a2n, b2n, c2n, d2n, f2n, g2n, h2n, e1n, e3e, d2e, e3s, e3w, f2w]"
1718        );
1719    }
1720
1721    #[test]
1722    fn test_valid_actions_5() {
1723        let game_state: GameState = "
1724             1s
1725              +-----------------+
1726             8| h c d m r d c h |
1727             7| r r r r   r r r |
1728             6|     x   e x     |
1729             5|                 |
1730             4|                 |
1731             3|     x     x     |
1732             2| R R R R E R R R |
1733             1| H C D M R D C H |
1734              +-----------------+
1735                a b c d e f g h
1736            "
1737        .parse()
1738        .unwrap();
1739
1740        assert_eq!(
1741            format!("{:?}", game_state.valid_actions()),
1742            "[e6n, d7e, e6e, e8s, a7s, b7s, c7s, d7s, f7s, g7s, h7s, e6s, f7w, e6w]"
1743        );
1744    }
1745
1746    #[test]
1747    fn test_valid_actions_6() {
1748        let game_state: GameState = "
1749              +-----------------+
1750             8|   r   r r   r   |
1751             7| m   h     e   c |
1752             6|   r x r r x r   |
1753             5| h   d     c   d |
1754             4| E   H         M |
1755             3|   R x R R H R   |
1756             2| D   C     C   D |
1757             1|   R   R R   R   |
1758              +-----------------+
1759                a b c d e f g h"
1760            .parse()
1761            .unwrap();
1762
1763        assert_eq!(format!("{:?}", game_state.valid_actions()), "[a5n, c5n, h5n, a5e, c5e, c5w, h5w, b3n, d3n, e3n, f3n, g3n, a2n, c2n, h2n, b1n, d1n, e1n, g1n, a4e, c4e, b3e, g3e, a2e, c2e, f2e, b1e, e1e, g1e, a4s, c4s, h4s, a2s, c2s, f2s, h2s, c4w, h4w, b3w, d3w, c2w, f2w, h2w, b1w, d1w, g1w]");
1764    }
1765
1766    #[test]
1767    fn test_valid_actions_7() {
1768        let game_state: GameState = "
1769             1s
1770              +-----------------+
1771             8|   r   r r   r   |
1772             7| m   h     e   c |
1773             6|   r x r r x r   |
1774             5| h   d     c   d |
1775             4| E   H         M |
1776             3|   R x R R H R   |
1777             2| D   C     C   D |
1778             1|   R   R R   R   |
1779              +-----------------+
1780                a b c d e f g h"
1781            .parse()
1782            .unwrap();
1783
1784        assert_eq!(format!("{:?}", game_state.valid_actions()), "[a7n, c7n, f7n, h7n, f5n, b8e, e8e, g8e, a7e, c7e, f7e, b6e, e6e, g6e, f5e, b8s, d8s, e8s, g8s, a7s, c7s, f7s, h7s, b6s, d6s, e6s, g6s, f5s, b8w, d8w, g8w, c7w, f7w, h7w, b6w, d6w, g6w, f5w]");
1785    }
1786
1787    #[test]
1788    fn test_valid_actions_frozen_piece_p1() {
1789        let game_state: GameState = "
1790             1g
1791              +-----------------+
1792             8|                 |
1793             7|                 |
1794             6|     x     x     |
1795             5|       e         |
1796             4|       M         |
1797             3|     x     x     |
1798             2|                 |
1799             1| R               |
1800              +-----------------+
1801                a b c d e f g h"
1802            .parse()
1803            .unwrap();
1804
1805        assert_eq!(format!("{:?}", game_state.valid_actions()), "[a1n, a1e]");
1806    }
1807
1808    #[test]
1809    fn test_valid_actions_frozen_piece_p1_2() {
1810        let game_state: GameState = "
1811             1g
1812              +-----------------+
1813             8|                 |
1814             7|                 |
1815             6|     x     x     |
1816             5|       m         |
1817             4|       M         |
1818             3|     x     x     |
1819             2|                 |
1820             1|                 |
1821              +-----------------+
1822                a b c d e f g h"
1823            .parse()
1824            .unwrap();
1825
1826        assert_eq!(
1827            format!("{:?}", game_state.valid_actions()),
1828            "[d4e, d4s, d4w]"
1829        );
1830    }
1831
1832    #[test]
1833    fn test_valid_actions_frozen_piece_p1_mid_move() {
1834        let game_state: GameState = "
1835             1g
1836              +-----------------+
1837             8|                 |
1838             7|                 |
1839             6|     x     x     |
1840             5|       e         |
1841             4|     M           |
1842             3|     x     x     |
1843             2|                 |
1844             1| R               |
1845              +-----------------+
1846                a b c d e f g h"
1847            .parse()
1848            .unwrap();
1849
1850        assert_eq!(
1851            format!("{:?}", game_state.valid_actions()),
1852            "[c4n, a1n, c4e, a1e, c4s, c4w]"
1853        );
1854
1855        let game_state = take_actions!(game_state => c4e);
1856
1857        assert_eq!(format!("{:?}", game_state.valid_actions()), "[a1n, a1e, p]");
1858    }
1859
1860    #[test]
1861    fn test_valid_actions_frozen_piece_p2() {
1862        let game_state: GameState = "
1863             1s
1864              +-----------------+
1865             8|                 |
1866             7|                 |
1867             6|     x     x     |
1868             5|       m         |
1869             4|       M         |
1870             3|     x     x     |
1871             2|                 |
1872             1| R               |
1873              +-----------------+
1874                a b c d e f g h"
1875            .parse()
1876            .unwrap();
1877
1878        assert_eq!(
1879            format!("{:?}", game_state.valid_actions()),
1880            "[d5n, d5e, d5w]"
1881        );
1882    }
1883
1884    #[test]
1885    fn test_valid_actions_frozen_piece_p2_2() {
1886        let game_state: GameState = "
1887             1s
1888              +-----------------+
1889             8| r               |
1890             7|                 |
1891             6|     x     x     |
1892             5|       h         |
1893             4|       M         |
1894             3|     x     x     |
1895             2|                 |
1896             1| R               |
1897              +-----------------+
1898                a b c d e f g h"
1899            .parse()
1900            .unwrap();
1901
1902        assert_eq!(format!("{:?}", game_state.valid_actions()), "[a8e, a8s]");
1903    }
1904
1905    #[test]
1906    fn test_valid_actions_frozen_piece_p2_3() {
1907        let game_state: GameState = "
1908             1s
1909              +-----------------+
1910             8| r               |
1911             7|                 |
1912             6|     x     x     |
1913             5|       r         |
1914             4|       M         |
1915             3|     x     x     |
1916             2|                 |
1917             1| R               |
1918              +-----------------+
1919                a b c d e f g h"
1920            .parse()
1921            .unwrap();
1922
1923        assert_eq!(format!("{:?}", game_state.valid_actions()), "[a8e, a8s]");
1924    }
1925
1926    #[test]
1927    fn test_valid_actions_frozen_piece_p2_4() {
1928        let game_state: GameState = "
1929             1s
1930              +-----------------+
1931             8|                 |
1932             7|                 |
1933             6|     x     x     |
1934             5|       e         |
1935             4|       E         |
1936             3|     x     x     |
1937             2|                 |
1938             1| R               |
1939              +-----------------+
1940                a b c d e f g h"
1941            .parse()
1942            .unwrap();
1943
1944        assert_eq!(
1945            format!("{:?}", game_state.valid_actions()),
1946            "[d5n, d5e, d5w]"
1947        );
1948    }
1949
1950    #[test]
1951    fn test_valid_actions_frozen_push_p2_1() {
1952        let game_state: GameState = "
1953             1s
1954              +-----------------+
1955             8|                 |
1956             7|                 |
1957             6|     x     x     |
1958             5|       e         |
1959             4|       M         |
1960             3|     x     x     |
1961             2|                 |
1962             1| R               |
1963              +-----------------+
1964                a b c d e f g h"
1965            .parse()
1966            .unwrap();
1967
1968        assert_eq!(
1969            format!("{:?}", game_state.valid_actions()),
1970            "[d4e, d4s, d4w, d5n, d5e, d5w]"
1971        );
1972    }
1973
1974    #[test]
1975    fn test_valid_actions_frozen_push_p2_2() {
1976        let game_state: GameState = "
1977             1s
1978              +-----------------+
1979             8| r               |
1980             7|                 |
1981             6|     x     x     |
1982             5|       e         |
1983             4|       M         |
1984             3|     x     x     |
1985             2|                 |
1986             1| R               |
1987              +-----------------+
1988                a b c d e f g h"
1989            .parse()
1990            .unwrap();
1991
1992        assert_eq!(
1993            format!("{:?}", game_state.valid_actions()),
1994            "[d4e, d4s, d4w, d5n, a8e, d5e, a8s, d5w]"
1995        );
1996
1997        let game_state = take_actions!(game_state => d4e);
1998
1999        assert_eq!(format!("{:?}", game_state.valid_actions()), "[d5s]");
2000
2001        let game_state = take_actions!(game_state => d5s);
2002
2003        assert_eq!(
2004            format!("{:?}", game_state.valid_actions()),
2005            "[e4n, e4e, e4s, d4n, a8e, a8s, d4s, d4w, p]"
2006        );
2007    }
2008
2009    #[test]
2010    fn test_valid_actions_frozen_push_p2_3() {
2011        let game_state: GameState = "
2012             1s
2013              +-----------------+
2014             8| r               |
2015             7|                 |
2016             6|     x     x     |
2017             5|       e         |
2018             4|       R         |
2019             3|     x c   x     |
2020             2|                 |
2021             1| R               |
2022              +-----------------+
2023                a b c d e f g h"
2024            .parse()
2025            .unwrap();
2026
2027        assert_eq!(
2028            format!("{:?}", game_state.valid_actions()),
2029            "[d4e, d4w, d5n, a8e, d5e, d3e, a8s, d3s, d5w, d3w]"
2030        );
2031
2032        let game_state = take_actions!(game_state => d4e);
2033
2034        assert_eq!(format!("{:?}", game_state.valid_actions()), "[d3n, d5s]");
2035
2036        let game_state = take_actions!(game_state => d5s);
2037
2038        assert_eq!(
2039            format!("{:?}", game_state.valid_actions()),
2040            "[e4n, e4e, e4s, d4n, a8e, d3e, a8s, d3s, d4w, d3w, p]"
2041        );
2042    }
2043
2044    #[test]
2045    fn test_valid_actions_frozen_push_p2_4() {
2046        let game_state: GameState = "
2047             1s
2048              +-----------------+
2049             8| r               |
2050             7|                 |
2051             6|     x     x     |
2052             5|       e         |
2053             4|     E R         |
2054             3|     x c   x     |
2055             2|                 |
2056             1| R               |
2057              +-----------------+
2058                a b c d e f g h"
2059            .parse()
2060            .unwrap();
2061
2062        assert_eq!(
2063            format!("{:?}", game_state.valid_actions()),
2064            "[d4e, d5n, a8e, d5e, d3e, a8s, d3s, d5w, d3w]"
2065        );
2066
2067        let game_state = take_actions!(game_state => d4e);
2068
2069        assert_eq!(format!("{:?}", game_state.valid_actions()), "[d3n, d5s]");
2070
2071        let game_state = take_actions!(game_state => d5s);
2072
2073        assert_eq!(
2074            format!("{:?}", game_state.valid_actions()),
2075            "[e4n, e4e, e4s, d4n, a8e, d3e, a8s, d3s, d3w, p]"
2076        );
2077    }
2078
2079    #[test]
2080    fn test_valid_actions_supported_piece_p2_1() {
2081        let game_state: GameState = "
2082             1s
2083              +-----------------+
2084             8|                 |
2085             7|                 |
2086             6|     x     x     |
2087             5|     r m         |
2088             4|     C E         |
2089             3|     x     x     |
2090             2|                 |
2091             1| R               |
2092              +-----------------+
2093                a b c d e f g h"
2094            .parse()
2095            .unwrap();
2096
2097        assert_eq!(
2098            format!("{:?}", game_state.valid_actions()),
2099            "[d5n, d5e, c5w]"
2100        );
2101    }
2102
2103    #[test]
2104    fn test_valid_actions_matches_first_step() {
2105        let game_state: GameState = "
2106             1g
2107              +-----------------+
2108             8|                 |
2109             7|                 |
2110             6|     x     x     |
2111             5|       m         |
2112             4|       E         |
2113             3|     x     x     |
2114             2|                 |
2115             1|                 |
2116              +-----------------+
2117                a b c d e f g h"
2118            .parse()
2119            .unwrap();
2120
2121        let game_state = take_actions!(game_state => d4e);
2122        let game_state = take_actions!(game_state => d5s);
2123
2124        let game_state = take_actions!(game_state => d4n);
2125
2126        assert_eq!(format!("{:?}", game_state.valid_actions()), "[]");
2127    }
2128
2129    #[test]
2130    fn test_valid_actions_matches_first_step_2() {
2131        let game_state: GameState = "
2132             1g
2133              +-----------------+
2134             8|               r |
2135             7|             d C |
2136             6|     x     x     |
2137             5|                 |
2138             4|                 |
2139             3|     x     x     |
2140             2| E             h |
2141             1|   e           R |
2142              +-----------------+
2143                a b c d e f g h"
2144            .parse()
2145            .unwrap();
2146
2147        let game_state = take_actions!(game_state => a2s);
2148        let game_state = take_actions!(game_state => a1n);
2149
2150        let game_state = take_actions!(game_state => a2s);
2151
2152        assert_eq!(format!("{:?}", game_state.valid_actions()), "[p]");
2153    }
2154
2155    #[test]
2156    fn test_valid_actions_matches_is_terminal_if_only_passing() {
2157        let game_state: GameState = "
2158             1g
2159              +-----------------+
2160             8|                 |
2161             7|                 |
2162             6|     x     x     |
2163             5|       m         |
2164             4|       E         |
2165             3|     x     x     |
2166             2|                 |
2167             1|                 |
2168              +-----------------+
2169                a b c d e f g h"
2170            .parse()
2171            .unwrap();
2172
2173        let game_state = take_actions!(game_state => d4e);
2174        let game_state = take_actions!(game_state => d5s);
2175
2176        let game_state = take_actions!(game_state => d4n);
2177
2178        assert_eq!(game_state.is_terminal(), Some(Terminal::SilverWin));
2179
2180        assert_eq!(format!("{:?}", game_state.valid_actions()), "[]");
2181    }
2182
2183    #[test]
2184    fn test_valid_actions_repeated_positions() {
2185        let game_state: GameState = "
2186             1g
2187              +-----------------+
2188             8|               r |
2189             7|               d |
2190             6|     x     x     |
2191             5|       m         |
2192             4|                 |
2193             3|     x E   x     |
2194             2|                 |
2195             1|               R |
2196              +-----------------+
2197                a b c d e f g h"
2198            .parse()
2199            .unwrap();
2200
2201        let game_state = take_actions!(game_state => d3n);
2202        assert_eq!(
2203            format!("{:?}", game_state.valid_actions()),
2204            "[d5n, d5e, d5w, h1n, d4e, d4s, d4w, h1w, p]"
2205        );
2206        let game_state = take_actions!(game_state => p);
2207
2208        // First occurance of position
2209
2210        let game_state = take_actions!(game_state => h7s);
2211        let game_state = take_actions!(game_state => p);
2212
2213        let game_state = take_actions!(game_state => d4s);
2214        let game_state = take_actions!(game_state => p);
2215
2216        let game_state = take_actions!(game_state => h6n);
2217        let game_state = take_actions!(game_state => p);
2218
2219        assert_eq!(
2220            format!("{:?}", game_state.valid_actions()),
2221            "[d3n, h1n, d3e, d3s, d3w, h1w]"
2222        );
2223
2224        let game_state = take_actions!(game_state => d3n);
2225        assert_eq!(
2226            format!("{:?}", game_state.valid_actions()),
2227            "[d5n, d5e, d5w, h1n, d4e, d4s, d4w, h1w, p]"
2228        );
2229        let game_state = take_actions!(game_state => p);
2230
2231        // Second occurance of position
2232
2233        let game_state = take_actions!(game_state => h7s);
2234        let game_state = take_actions!(game_state => p);
2235
2236        assert_eq!(
2237            format!("{:?}", game_state.valid_actions()),
2238            "[d5n, d5e, d5w, h1n, d4e, d4s, d4w, h1w]"
2239        );
2240
2241        let game_state = take_actions!(game_state => d4s);
2242        let game_state = take_actions!(game_state => d3s);
2243        let game_state = take_actions!(game_state => p);
2244
2245        let game_state = take_actions!(game_state => h6n);
2246        let game_state = take_actions!(game_state => p);
2247
2248        // Would be third occurance of position
2249
2250        let game_state = take_actions!(game_state => d2n);
2251        let game_state = take_actions!(game_state => d3n);
2252
2253        // Should not allow pass here
2254        assert_eq!(
2255            format!("{:?}", game_state.valid_actions()),
2256            "[d5n, d5e, d5w, h1n, d4e, d4s, d4w, h1w]"
2257        );
2258
2259        let game_state = take_actions!(game_state => d4s);
2260
2261        // Should not allow last move to be the final repeat
2262        assert_eq!(
2263            format!("{:?}", game_state.valid_actions()),
2264            "[d5s, h1n, d3e, d3w, h1w, p]"
2265        );
2266    }
2267
2268    #[test]
2269    fn test_valid_actions_does_not_duplicate_piece_that_can_be_both_pushed_and_pull() {
2270        let game_state: GameState = "
2271             1g
2272              +-----------------+
2273             8|                 |
2274             7|                 |
2275             6|     x     x     |
2276             5|                 |
2277             4|       E c H     |
2278             3|     x     x     |
2279             2|                 |
2280             1|   e             |
2281              +-----------------+
2282                a b c d e f g h"
2283            .parse()
2284            .unwrap();
2285
2286        let game_state = take_actions!(game_state => f4n);
2287
2288        assert_eq!(
2289            format!("{:?}", game_state.valid_actions()),
2290            "[e4n, e4e, e4s, f5n, d4n, f5e, f5s, d4s, f5w, d4w, p]"
2291        );
2292    }
2293
2294    #[test]
2295    fn test_hash_initial_play_state() {
2296        let game_state: GameState = "
2297             1g
2298              +-----------------+
2299             8| h c d m e d c h |
2300             7| r r r r r r r r |
2301             6|     x     x     |
2302             5|                 |
2303             4|                 |
2304             3|     x     x     |
2305             2| R R R R R R R R |
2306             1| H C D M E D C H |
2307              +-----------------+
2308                a b c d e f g h
2309            "
2310        .parse()
2311        .unwrap();
2312
2313        let game_state_2 = initial_play_state();
2314
2315        assert_eq!(
2316            game_state.transposition_hash(),
2317            game_state_2.transposition_hash()
2318        );
2319    }
2320
2321    #[test]
2322    fn test_hash_should_account_for_player_not_equal() {
2323        let game_state: GameState = "
2324             1s
2325              +-----------------+
2326             8| h c d m e d c h |
2327             7| r r r r r r r r |
2328             6|     x     x     |
2329             5|                 |
2330             4|                 |
2331             3|     x     x     |
2332             2| R R R R R R R R |
2333             1| H C D M E D C H |
2334              +-----------------+
2335                a b c d e f g h
2336            "
2337        .parse()
2338        .unwrap();
2339
2340        let game_state_2 = initial_play_state();
2341
2342        assert_ne!(
2343            game_state.transposition_hash(),
2344            game_state_2.transposition_hash()
2345        );
2346    }
2347
2348    #[test]
2349    fn test_hash_should_account_for_step_not_equal() {
2350        let game_state: GameState = "
2351             1g
2352              +-----------------+
2353             8| h c d m e d c h |
2354             7| r r r r r r r r |
2355             6|     x     x     |
2356             5|                 |
2357             4|                 |
2358             3|     x   R x     |
2359             2| R R R R   R R R |
2360             1| H C D M E D C H |
2361              +-----------------+
2362                a b c d e f g h
2363            "
2364        .parse()
2365        .unwrap();
2366
2367        let game_state_2 = initial_play_state();
2368        let game_state_2 = take_actions!(game_state_2 => e2n);
2369
2370        assert_ne!(
2371            game_state.transposition_hash(),
2372            game_state_2.transposition_hash()
2373        );
2374    }
2375
2376    #[test]
2377    fn test_hash_should_account_for_step_equal() {
2378        let game_state: GameState = "
2379             1g
2380              +-----------------+
2381             8| h c d m e d c h |
2382             7| r r r r r r r r |
2383             6|     x     x     |
2384             5|                 |
2385             4|                 |
2386             3|     x   R x     |
2387             2| R R R R   R R R |
2388             1| H C D M E D C H |
2389              +-----------------+
2390                a b c d e f g h
2391            "
2392        .parse()
2393        .unwrap();
2394
2395        let game_state_2 = initial_play_state();
2396        let game_state_2 = take_actions!(game_state_2 => e2n);
2397        assert_ne!(
2398            game_state.transposition_hash(),
2399            game_state_2.transposition_hash()
2400        );
2401
2402        let game_state_2 = take_actions!(game_state_2 => p);
2403        let game_state_2 = take_actions!(game_state_2 => p);
2404
2405        assert_eq!(
2406            game_state.transposition_hash(),
2407            game_state_2.transposition_hash()
2408        );
2409    }
2410
2411    #[test]
2412    fn test_hash_should_allow_for_pass_to_equal() {
2413        let game_state: GameState = "
2414             1g
2415              +-----------------+
2416             8| h c d m e d c h |
2417             7| r r r r r r r r |
2418             6|     x     x     |
2419             5|                 |
2420             4|                 |
2421             3|     x     x     |
2422             2| R R R R R R R R |
2423             1| H C D M E D C H |
2424              +-----------------+
2425                a b c d e f g h
2426            "
2427        .parse()
2428        .unwrap();
2429
2430        let game_state_2 = initial_play_state();
2431
2432        let game_state_2 = take_actions!(game_state_2 => p);
2433        assert_ne!(
2434            game_state.transposition_hash(),
2435            game_state_2.transposition_hash()
2436        );
2437
2438        let game_state_2 = take_actions!(game_state_2 => p);
2439        assert_eq!(
2440            game_state.transposition_hash(),
2441            game_state_2.transposition_hash()
2442        );
2443    }
2444
2445    #[test]
2446    fn test_hash_should_switch_player_on_pass_for_step() {
2447        let game_state: GameState = "
2448             1g
2449              +-----------------+
2450             8| h c d m e d c h |
2451             7| r r r r r r r r |
2452             6|     x     x     |
2453             5|                 |
2454             4|                 |
2455             3|     x   R x     |
2456             2| R R R R   R R R |
2457             1| H C D M E D C H |
2458              +-----------------+
2459                a b c d e f g h
2460            "
2461        .parse()
2462        .unwrap();
2463
2464        let game_state_2 = initial_play_state();
2465        let game_state_2 = take_actions!(game_state_2 => e2n);
2466
2467        assert_ne!(
2468            game_state.transposition_hash(),
2469            game_state_2.transposition_hash()
2470        );
2471    }
2472
2473    #[test]
2474    fn test_hash_should_account_for_trapped_pieces() {
2475        let game_state: GameState = "
2476             1g
2477              +-----------------+
2478             8| h c d m e d c h |
2479             7| r r r r     r r |
2480             6|     x E r x     |
2481             5|                 |
2482             4|                 |
2483             3|     x     x     |
2484             2| R R R R   R R R |
2485             1| H C D M   D C H |
2486              +-----------------+
2487                a b c d e f g h
2488            "
2489        .parse()
2490        .unwrap();
2491
2492        let game_state_final: GameState = "
2493             1s
2494              +-----------------+
2495             8| h c d m e d c h |
2496             7| r r r r     r r |
2497             6|     x   E x     |
2498             5|                 |
2499             4|                 |
2500             3|     x     x     |
2501             2| R R R R   R R R |
2502             1| H C D M   D C H |
2503              +-----------------+
2504                a b c d e f g h
2505            "
2506        .parse()
2507        .unwrap();
2508
2509        let game_state = take_actions!(game_state => e6e);
2510        assert_ne!(
2511            game_state.transposition_hash(),
2512            game_state_final.transposition_hash()
2513        );
2514
2515        let game_state = take_actions!(game_state => d6e);
2516        assert_ne!(
2517            game_state.transposition_hash(),
2518            game_state_final.transposition_hash()
2519        );
2520
2521        let game_state = take_actions!(game_state => p);
2522        assert_eq!(
2523            game_state.transposition_hash(),
2524            game_state_final.transposition_hash()
2525        );
2526    }
2527
2528    #[test]
2529    fn test_hash_should_account_for_four_actions() {
2530        let game_state: GameState = "
2531             1g
2532              +-----------------+
2533             8| h c d m e d c h |
2534             7| r r r r     r r |
2535             6|     x E r x     |
2536             5|         r       |
2537             4|                 |
2538             3|     x     x     |
2539             2| R R R R   R R R |
2540             1| H C D M   D C H |
2541              +-----------------+
2542                a b c d e f g h
2543            "
2544        .parse()
2545        .unwrap();
2546
2547        let game_state_final: GameState = "
2548             1s
2549              +-----------------+
2550             8| h c d m e d c h |
2551             7| r r r r E   r r |
2552             6|     x   r x     |
2553             5|                 |
2554             4|                 |
2555             3|     x     x     |
2556             2| R R R R   R R R |
2557             1| H C D M   D C H |
2558              +-----------------+
2559                a b c d e f g h
2560            "
2561        .parse()
2562        .unwrap();
2563
2564        let game_state = take_actions!(game_state => e6e);
2565        assert_ne!(
2566            game_state.transposition_hash(),
2567            game_state_final.transposition_hash()
2568        );
2569
2570        let game_state = take_actions!(game_state => d6e);
2571        assert_ne!(
2572            game_state.transposition_hash(),
2573            game_state_final.transposition_hash()
2574        );
2575
2576        let game_state = take_actions!(game_state => e6n);
2577        assert_ne!(
2578            game_state.transposition_hash(),
2579            game_state_final.transposition_hash()
2580        );
2581
2582        let game_state = take_actions!(game_state => e5n);
2583        assert_eq!(
2584            game_state.transposition_hash(),
2585            game_state_final.transposition_hash()
2586        );
2587    }
2588}