Exemple #1
0
 def test_replay_without_winner(self):
     initial_board = Board()
     trace = Trace(initial_board, [None, None])
     with open(self.replay_file_name, "w") as file:
         trace.write(file)
     with open(self.replay_file_name, "r") as file:
         replay = json.load(file)
         self.assertEqual(replay['winner'], 0)
Exemple #2
0
 def test_play_should_reset_credits_every_turn(self):
     credits = [5.0, 3.0, 3.0, 3.0]
     trace4 = Trace(self.board4, credits[0:4])
     viewer = HeadlessViewer()
     game4 = Game(self.agents[0:4], self.board4, viewer, credits, trace4)
     self.board4.is_finished = MagicMock(
         side_effect=[False, False, False, False, False, True])
     self.agent1.play = MagicMock(return_value=[(WALL_H, 1,
                                                 2), (WALL_H, 3, 4)])
     self.agent2.play = MagicMock(return_value=(WALL_H, 5, 7))
     self.agent3.play = MagicMock(return_value=(MOVE, 7, 4))
     self.agent4.play = MagicMock(return_value=(WALL_H, 2, 2))
     game4.play()
     self.assertAlmostEqual(self.agent1.play.call_args[0][3], 5.0)
Exemple #3
0
 def test_export_json(self):
     board = Board()
     trace = Trace(board, [None, None])
     trace.add_action(1, (MOVE, 7, 4), 1.0)
     with open(self.replay_file_name, "w") as file:
         trace.write(file)
     with open(self.replay_file_name, "r") as file:
         content = file.readline()
         self.assertNotEqual(content, "")
Exemple #4
0
 def setUp(self):
     credits = [None, None, None, None]
     self.agent1 = Agent()
     self.agent2 = Agent()
     self.agent3 = Agent()
     self.agent4 = Agent()
     self.agents = [self.agent1, self.agent2, self.agent3, self.agent4]
     for agent in self.agents:
         agent.initialize = MagicMock()
         agent.play = MagicMock()
     self.board2 = Board()
     self.board4 = Board(player_count=4)
     self.trace2 = Trace(self.board2, credits[0:2])
     self.trace2.set_winner = MagicMock()
     self.trace2.set_ranking = MagicMock()
     self.trace4 = Trace(self.board4, credits[0:4])
     self.trace4.set_winner = MagicMock()
     self.trace4.set_ranking = MagicMock()
     self.viewer = HeadlessViewer()
     self.viewer.finished = MagicMock()
     self.game2 = Game(self.agents[0:2], self.board2, self.viewer,
                       credits[0:2], self.trace2)
     self.game4 = Game(self.agents[0:4], self.board4, self.viewer,
                       credits[0:4], self.trace4)
Exemple #5
0
 def setUp(self):
     credits = [None, None]
     self.agent1 = Agent()
     self.agent2 = Agent()
     agents = [self.agent1, self.agent2]
     for agent in agents:
         agent.initialize = MagicMock()
         agent.play = MagicMock()
     self.board2 = Board()
     self.trace2 = Trace(self.board2, credits[0:2])
     self.trace2.set_winner = MagicMock()
     self.trace2.set_ranking = MagicMock()
     self.board2.is_player_on_goal = MagicMock(return_value=False)
     self.viewer = HeadlessViewer()
     self.viewer.finished = MagicMock()
     self.game2 = Game(agents[0:2], self.board2, self.viewer, credits[0:2],
                       self.trace2)
Exemple #6
0
 def test_export_and_load(self):
     initial_board = Board()
     trace = Trace(initial_board, [None, None])
     trace.add_action(1, (MOVE, 7, 4), 1.0)
     with open(self.replay_file_name, "w") as file:
         trace.write(file)
     with open(self.replay_file_name, "r") as file2:
         loaded_trace = load_trace(file2)
         initial_loaded_game = loaded_trace.get_initial_board()
         (player, action, t) = loaded_trace.actions[0]
         pre_move_board = initial_loaded_game.clone()
         first_move_loaded_game = initial_loaded_game.play_action(
             action, player)
         self.assertEqual(pre_move_board.pawns[1], (8, 4))
         self.assertEqual(first_move_loaded_game.pawns[1], (7, 4))