Пример #1
0
    def test_execute_move_legal_p2(self):
        # current player is p2
        game_env = GameWrapper(1)
        game_env.current_player = GameBoard.PLAYER_2

        # place a piece, to flip (4,5)
        env_observation, reward, done, game_env, is_valid = game_env.execute_move(
            8 * 4 + 5)
        # expection:
        #   player switched to p1,
        #   not done game,
        #   new board observation,
        #   reward 0.01, +1 new pieces
        self.assertTrue(is_valid)
        self.assertEqual(game_env.current_player, GameBoard.PLAYER_1)
        self.assertFalse(done)
        self.assertEqual(reward, 0.01)
        np.testing.assert_array_equal(
            env_observation,
            np.asarray([
                0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
                0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
                0.0, 0.0, 0.0, 1.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0,
                -1.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
                0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
                0.0, 0.0, 0.0, 0.0
            ]))
Пример #2
0
 def test_execute_move_tie_p2(self):
     game_env = GameWrapper(1)
     game_env.current_player = GameBoard.PLAYER_2
     game_env.game_board.board = \
         list(map(lambda r: list(map(lambda i: i * -1.0, r)),
                  [[-1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, ],
                   [-1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, ],
                   [-1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, ],
                   [-1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, ],
                   [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, ],
                   [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, ],
                   [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, ],
                   [1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, 0.0]]))
     # place at the last spot to win
     env_observation, reward, done, game_env, is_valid = game_env.execute_move(
         63)
     # expection:
     #   player switched to p1,
     #   game is done
     #   new board observation,
     #   reward 0.01, +1 new pieces
     self.assertTrue(is_valid)
     self.assertEqual(game_env.current_player, GameBoard.PLAYER_2)
     self.assertTrue(done)
     self.assertEqual(reward, 0)
     np.testing.assert_array_equal(
         env_observation,
         np.asarray([
             -1.0,
             -1.0,
             -1.0,
             -1.0,
             -1.0,
             -1.0,
             -1.0,
             -1.0,
             -1.0,
             -1.0,
             -1.0,
             -1.0,
             -1.0,
             -1.0,
             -1.0,
             -1.0,
             -1.0,
             -1.0,
             -1.0,
             -1.0,
             -1.0,
             -1.0,
             -1.0,
             -1.0,
             -1.0,
             -1.0,
             -1.0,
             -1.0,
             -1.0,
             -1.0,
             -1.0,
             -1.0,
             1.0,
             1.0,
             1.0,
             1.0,
             1.0,
             1.0,
             1.0,
             1.0,
             1.0,
             1.0,
             1.0,
             1.0,
             1.0,
             1.0,
             1.0,
             1.0,
             1.0,
             1.0,
             1.0,
             1.0,
             1.0,
             1.0,
             1.0,
             1.0,
             1.0,
             1.0,
             1.0,
             1.0,
             1.0,
             1.0,
             1.0,
             1.0,
         ]))