Exemplo n.º 1
0
 def __init__(self, logger: Callable = noop_print, random_seed: int = 54):
     self.winners = []
     self.logger = logger
     self.agent = SarsaAgent(1)
     self.opponent = SarsaAgent(-1)
     self.game = TicTacToeGame()
     self.env = Environment(self.game, self.opponent)
     self._random = random.Random(random_seed)
Exemplo n.º 2
0
    def test_check_game_over_1(self):
        """Test case for the check_game_over function.

        Test for game over with a win.
        """
        game = TicTacToeGame()
        game.state = [[1, 0, -1], [1, 0, -1], [1, 0, -1]]
        game_over, value = game.check_game_over(1)

        self.assertEqual(game_over, True)
        self.assertEqual(value, 1)
Exemplo n.º 3
0
    def test_check_game_over_4(self):
        """Test case for the check_game_over function.

        Test for game not over.
        """
        game = TicTacToeGame()
        game.state = [[-1, 0, 0], [0, -1, 0], [0, 1, 0]]
        game_over, value = game.check_game_over(-1)

        self.assertEqual(game_over, False)
        self.assertEqual(value, 0)
Exemplo n.º 4
0
    CFG.dirichlet_alpha = arguments.dirichlet_alpha
    CFG.epsilon = arguments.epsilon
    CFG.model_directory = arguments.model_directory
    CFG.num_eval_games = arguments.num_eval_games
    CFG.eval_win_rate = arguments.eval_win_rate
    CFG.load_model = arguments.load_model
    CFG.human_play = arguments.human_play
    CFG.resnet_blocks = arguments.resnet_blocks
    CFG.record_loss = arguments.record_loss
    CFG.loss_file = arguments.loss_file
    CFG.game = arguments.game

    # Initialize the game object with the chosen game.
    game = object
    if CFG.game == 0:
        game = TicTacToeGame()
    elif CFG.game == 1:
        game = OthelloGame()
    elif CFG.game == 2:
        game = ConnectFourGame()
    elif CFG.game == 3:
        game = RubiksCubeGame()

    net = NeuralNetworkWrapper(game)

    # Initialize the network with the best model.
    if CFG.load_model:
        file_path = CFG.model_directory + "best_model.meta"
        if os.path.exists(file_path):
            net.load_model("best_model")
        else: