Ejemplo n.º 1
0
 def setUpClass(self):
     #       # 0 1 2 3 4 5 6 7 #  #
     grid = (' . . . . . . . . '  # 0
             ' . . . . . . . . '  # 1
             ' . . . . . . . . '  # 2
             ' . . . ● ○ . . . '  # 3
             ' . . . ○ ● . . . '  # 4
             ' . . . . . . . . '  # 5
             ' . . . . . . . . '  # 6
             ' . . . . . . . . ')  #7
     self.grid_dark = Reversi(hash_grid(to_grid(grid), player=0))
     self.grid_light = Reversi(hash_grid(to_grid(grid), player=1))
Ejemplo n.º 2
0
 def standard_test_case(self,
     expected_value, expected_terminal, expected_actions_count, grid):
     for player in range(2):
         grid_hash = hash_grid(grid, player)
         game_state = TicTacToe(grid_hash)
         self.assertEqual(expected_value, game_state.value)
         self.assertEqual(expected_terminal, game_state.terminal)
         self.assertEqual(expected_actions_count, len(game_state.actions))
Ejemplo n.º 3
0
 def standard_test_case(self, expected, grid):
     cases = [{"hash":expected, "player":0}, {"hash":-expected, "player":1}]
     for case in cases:
         grid_hash = hash_grid(grid, case["player"])
         self.assertEqual(case["hash"], grid_hash)
         result, player = TicTacToe.reconstruct(grid_hash)
         self.assertEqual(grid, result)
         self.assertEqual(case["player"], player)
         game_state = TicTacToe(grid_hash)
         self.assertEqual(case["hash"], game_state.grid_hash)
         self.assertEqual(case["player"], game_state.player)
         self.assertEqual(grid, game_state.grid)
Ejemplo n.º 4
0
 def test_move_on_occupied_cell(self):
     #       # 0 1 2 3 4 5 6 7 #  #
     grid = (
         " . . . . . . . . "  # 0
         " . . . . . . . . "  # 1
         " . . . . . . . . "  # 2
         " . . . ○ ● . . . "  # 3
         " . . . ● ○ . . . "  # 4
         " . . . . . . . . "  # 5
         " . . . . . . . . "  # 6
         " . . . . . . . . "
     )  # 7
     #      #  0 1 2 3 4 5 6 7    #
     player, move = 1, (3, 3)
     game_state = Reversi(hash_grid(to_grid(grid), player))
     self.assertRaises(IndexError, game_state.result, move)
Ejemplo n.º 5
0
 def assertHashes(self, expected, grid):
     self.assertEqual(expected, hash_grid(grid, 0))
     self.assertEqual(-expected, hash_grid(grid, 1))
Ejemplo n.º 6
0
 def assertLight(self, expected, grid_str, player=1):
     game_state = Reversi(hash_grid(to_grid(grid_str), player))
     self.assertEqual(expected, game_state.find_actions())
Ejemplo n.º 7
0
 def standard_test_case(self, expected, grid):
     for player in range(2):
         grid_hash = hash_grid(grid, player)
         game_state = TicTacToe(grid_hash)
         self.assertEqual(expected, game_state.utility())
Ejemplo n.º 8
0
 def assertValue(self, expected, grid_str):
     game_state = Reversi(hash_grid(to_grid(grid_str)))
     self.assertEqual(expected, game_state.utility())
Ejemplo n.º 9
0
 def assertResultsIn(self, expd_str, expd_player, grid_str, player, move):
     game_state_before = Reversi(hash_grid(to_grid(grid_str), player))
     game_state_after = Reversi(hash_grid(to_grid(expd_str), expd_player))
     result_state = Reversi(game_state_before.result(move))
     self.assertEqual(result_state.grid, game_state_after.grid)
     self.assertEqual(result_state.player, expd_player)
Ejemplo n.º 10
0
 def standard_test_case(self, expected, grid, player, move):
     grid_hash = hash_grid(grid, player)
     game_state = TicTacToe(grid_hash)
     result = TicTacToe.reconstruct(game_state.result(move))
     self.assertEqual(expected, result)