Exemplo n.º 1
0
 def test_play_moves(self):
     game = Game(num_rows=8, num_cols=9, line_length_to_win=4)
     game.play_move(0)
     game.play_move(0)
     game.play_move(4)
     game.play_move(2)
     game.play_move(4)
     game.play_move(8)
     game.play_move(8)
     game.play_move(8)
     for i in range(8):
         game.play_move(7)
     self.assertListEqual(
         game.get_board(),
         board_utils.from_char_matrix([
             ["-", "-", "-", "-", "-", "-", "-", "O", "-"],
             ["-", "-", "-", "-", "-", "-", "-", "X", "-"],
             ["-", "-", "-", "-", "-", "-", "-", "O", "-"],
             ["-", "-", "-", "-", "-", "-", "-", "X", "-"],
             ["-", "-", "-", "-", "-", "-", "-", "O", "-"],
             ["-", "-", "-", "-", "-", "-", "-", "X", "O"],
             ["O", "-", "-", "-", "X", "-", "-", "O", "X"],
             ["X", "-", "O", "-", "X", "-", "-", "X", "O"],
         ]),
     )
     self.assertTrue(game.is_p1_to_move())
     self.assertEqual(game.get_outcome(), Outcome.ONGOING)
Exemplo n.º 2
0
 def test_start_new_after_draw(self):
     game = Game(num_rows=4, num_cols=4, line_length_to_win=3)
     moves = [0, 0, 0, 0, 2, 1, 2, 1, 1, 2, 1, 3, 3, 3, 3, 2]
     for move in moves:
         game.play_move(move)
     game.start_new()
     self.assertListEqual(
         game.get_board(),
         board_utils.from_char_matrix([
             ["-", "-", "-", "-"],
             ["-", "-", "-", "-"],
             ["-", "-", "-", "-"],
             ["-", "-", "-", "-"],
         ]),
     )
     self.assertTrue(game.is_p1_to_move())
     self.assertEqual(game.get_outcome(), Outcome.ONGOING)
     self.assertListEqual(game.get_move_history(), [])
Exemplo n.º 3
0
 def test_fresh_game(self):
     game = Game(num_rows=8, num_cols=9, line_length_to_win=4)
     self.assertListEqual(
         game.get_board(),
         board_utils.from_char_matrix([
             ["-", "-", "-", "-", "-", "-", "-", "-", "-"],
             ["-", "-", "-", "-", "-", "-", "-", "-", "-"],
             ["-", "-", "-", "-", "-", "-", "-", "-", "-"],
             ["-", "-", "-", "-", "-", "-", "-", "-", "-"],
             ["-", "-", "-", "-", "-", "-", "-", "-", "-"],
             ["-", "-", "-", "-", "-", "-", "-", "-", "-"],
             ["-", "-", "-", "-", "-", "-", "-", "-", "-"],
             ["-", "-", "-", "-", "-", "-", "-", "-", "-"],
         ]),
     )
     self.assertTrue(game.is_p1_to_move())
     self.assertEqual(game.get_outcome(), Outcome.ONGOING)
     self.assertListEqual(game.get_move_history(), [])