def test_initialise_agent(self):
        """ Test the Initialisation of the Agent Config
        """
        c = Config(**dict(MODEL_NAME="TESTING"))

        assert c.__repr__() == '< Player Config >'
        assert isinstance(c, Config)
        assert c.MODEL_NAME == "TESTING"
예제 #2
0
def create_keras_models(config1=Config(), config2=Config()):
    """ Create two Keras Models for either player specifically for the TicTacToe Game

        :param config1:     Configuration settings for player one
        :param config2:     Configuration settings for player two
        :return:            Dictionary of Two Keras Models

    """
    return {"1": KerasModel(config=config1), "-1": KerasModel(config=config2)}
예제 #3
0
    def __init__(self,
                 name,
                 value,
                 display,
                 fn=None,
                 use_nn=False,
                 config=Config()):
        self.name = name
        self.value = value
        self.display = display

        self.nn = use_nn

        # Get all the Config
        self.c = config

        if fn is not None:
            self.eval_function = fn
    def __init__(self, config: Config = Config()):
        """ Initialise a Keras Model with its own configuration

            Default will not include any ResNet blocks.

            :param config:

        """
        super().__init__()

        if config.MODEL_TYPE == PolicyEnum.RESNET.value:
            self.net = ResidualNet(config=config)
            self.optimisation, self.model = self.net.compile_model()

        elif config.MODEL_TYPE == "LoadingExisting":
            logging.warning("Awaiting load...")
            self.net = "Awaiting load..."

        else:
            logging.warning("Neural Network selection not known.")
            raise NotImplementedError

        self.config = config
def main():
    """ Play two Monte Carlo Tree searches against one another...
    """
    # ##########################################################
    # params (Testing w/o NN):
    new_game = Game(players=DEFAULT_PLAYERS)

    # Play until end
    while new_game.legal_plays() and new_game.winner is None:
        print(new_game.player)
        # Rollout the Tree
        tree = MonteCarloTreeSearch(game=new_game,
                                    evaluation_func=new_game.player.func,
                                    node_param=new_game.player.mcts_params,
                                    use_nn=new_game.player.use_nn)

        # Run the Tree Search
        tree.search(*new_game.player.mcts_search)

        # Find the recommended move
        # Note: Replace to use the Stochastic action selection
        move, _ = tree.recommended_play(train=False)
        # Stochastic: move, _ = tree.recommended_play(train=True)

        # Play the recommended move and store the move
        tree.show_tree(level=1)
        new_game.play(move=move)

        # Show the tree and board, debugging
        new_game.show_board()

    # ##########################################################
    # params (Testing w NN):
    game = Game(players=NNetPlayers, using_nn=True, nn_player=0)
    models = create_keras_models(config1=Config(**{}), config2=Config(**{}))
    models['1'].load_checkpoint("RLBook/Chapter8/20180214_KerasModel_TTT_V1")

    # Play until end
    while game.legal_plays() and game.winner is None:
        print(game.player)
        # Rollout the Tree
        tree = MonteCarloTreeSearch(game=game,
                                    evaluation_func=models[str(
                                        game.player.value)].predict,
                                    node_param=game.player.mcts_params,
                                    use_nn=game.player.use_nn)

        # Run the Tree Search
        tree.search(*game.player.mcts_search)

        # Find the recommended move
        # Note: Replace to use the Stochastic action selection
        move, _ = tree.recommended_play(train=False)
        # Stochastic: move, _ = tree.recommended_play(train=True)

        # Play the recommended move and store the move
        tree.show_tree(level=1)
        game.play(move=move)

        # Show the tree and board, debugging
        game.show_board()