def build_watten_train_big_agent(self,
                                     agent_profile,
                                     native_multi_gpu_enabled=False):

        game = self.game_mapping[agent_profile.game]

        x, y = game.get_observation_size()
        nnet = WattenNNetFirstLayerBig(x, y, 1, game.get_action_size())

        agent_nnet = AgentNNet(nnet)

        if agent_profile == EnvironmentSelector.WATTEN_AGENT_BIG_TRAIN:
            print("Configuring build_watten_train_big_agent...")
            return AgentMCTS(agent_nnet,
                             exp_rate=AgentMCTS.EXPLORATION_RATE_MEDIUM,
                             numMCTSSims=100,
                             max_predict_time=10,
                             num_threads=16)
        elif agent_profile == EnvironmentSelector.WATTEN_AGENT_BIG_EVALUATE:
            print("Configuring build_watten_evaluate_big_agent...")
            return AgentMCTS(agent_nnet,
                             exp_rate=AgentMCTS.EXPLORATION_RATE_MEDIUM,
                             numMCTSSims=2,
                             max_predict_time=10,
                             num_threads=16,
                             name="build_watten_evaluate_big_agent")
        elif agent_profile == EnvironmentSelector.WATTEN_AGENT_HUMAN:
            return WattenHumanAgent(game)

        return None
    def build_watten_train_4_512_agent(self,
                                       agent_profile,
                                       native_multi_gpu_enabled=False):

        game = self.game_mapping[agent_profile.game]

        x, y = game.get_observation_size()
        nnet = WattenNNet4x512(x, y, 1, game.get_action_size())

        agent_nnet = AgentNNet(nnet)

        if agent_profile == EnvironmentSelector.WATTEN_AGENT_4_512_TRAIN:
            print("Configuring build_watten_train_4_512_agent...")
            return AgentMCTS(agent_nnet,
                             exp_rate=AgentMCTS.EXPLORATION_RATE_MEDIUM,
                             numMCTSSims=100,
                             max_predict_time=10,
                             num_threads=16)
        elif agent_profile == EnvironmentSelector.WATTEN_AGENT_4_512_EVALUATE:
            print("Configuring build_watten_evaluate_4_512_agent...")
            return AgentMCTS(agent_nnet,
                             exp_rate=AgentMCTS.EXPLORATION_RATE_MEDIUM,
                             numMCTSSims=30,
                             max_predict_time=10,
                             num_threads=16,
                             name="build_watten_evaluate_4_512_agent")
        elif agent_profile == EnvironmentSelector.WATTEN_AGENT_HUMAN:
            return WattenHumanAgent(game)
        elif agent_profile == EnvironmentSelector.WATTEN_AGENT_NNET:
            agent_nnet.load(
                os.path.abspath(
                    "../games/watten/training/best-4-512-new-4.h5"))
            return agent_nnet

        return None
Exemplo n.º 3
0
    def build_horovod_checkers_agent(self,
                                     agent_profile,
                                     native_multi_gpu_enabled=False):
        from games.checkers.nnet.CheckersResNNetDistributed import CheckersResNNetDistributed

        assert not native_multi_gpu_enabled, "ERROR: Horovod NNet does not support native multi-gpu mode!"

        game = self.game_mapping[agent_profile.game]

        nnet = CheckersResNNetDistributed(game.get_observation_size()[0],
                                          game.get_observation_size()[1],
                                          game.get_observation_size()[2],
                                          game.get_action_size(),
                                          horovod_distributed=True)

        agent_nnet = AgentNNet(nnet)

        if agent_profile == EnvironmentSelector.CHECKERS_AGENT_TRAIN_RCNN_DISTRIBUTED:
            return AgentMCTS(agent_nnet,
                             exp_rate=AgentMCTS.EXPLORATION_RATE_INIT,
                             numMCTSSims=1500,
                             max_predict_time=5)
        elif agent_profile == EnvironmentSelector.CHECKERS_AGENT_TEST_AGENT_RCNN_DISTRIBUTED:
            return AgentMCTS(agent_nnet,
                             exp_rate=AgentMCTS.NO_EXPLORATION,
                             numMCTSSims=1500,
                             max_predict_time=10)
        else:
            return None
Exemplo n.º 4
0
    def build_native_checkers_rcnn_agent(self,
                                         agent_profile,
                                         native_multi_gpu_enabled=False):
        game = self.game_mapping[agent_profile.game]

        if not native_multi_gpu_enabled:
            nnet = CheckersResNNet(game.get_observation_size()[0],
                                   game.get_observation_size()[1],
                                   game.get_observation_size()[2],
                                   game.get_action_size())
        else:
            nnet = CheckersResNNet(game.get_observation_size()[0],
                                   game.get_observation_size()[1],
                                   game.get_observation_size()[2],
                                   game.get_action_size(),
                                   multi_gpu=True,
                                   multi_gpu_n=len(GPUtil.getGPUs()))

        agent_nnet = AgentNNet(nnet)

        if agent_profile == EnvironmentSelector.CHECKERS_AGENT_TRAIN_RCNN_DEFAULT:
            return AgentMCTS(agent_nnet,
                             exp_rate=AgentMCTS.EXPLORATION_RATE_INIT,
                             numMCTSSims=1500,
                             max_predict_time=3,
                             num_threads=1)
        elif agent_profile == EnvironmentSelector.CHECKERS_AGENT_TEST_AGENT_RCNN_DEFAULT:
            return AgentMCTS(agent_nnet,
                             exp_rate=AgentMCTS.NO_EXPLORATION,
                             numMCTSSims=1500,
                             max_predict_time=10,
                             num_threads=2,
                             verbose=True)
        else:
            return None
    def build_hand_watten_train_agent(self,
                                      agent_profile,
                                      native_multi_gpu_enabled=False):
        game = self.game_mapping[agent_profile.game]

        if agent_profile == EnvironmentSelector.HAND_WATTEN_TRAIN:
            x, y = game.get_observation_size()
            nnet = HandWattenNNet(x, y, 1, game.get_action_size())
            agent_nnet = AgentNNet(nnet)

            print("Configuring build_hand_watten_train_agent...")
            return AgentMCTS(agent_nnet,
                             exp_rate=AgentMCTS.EXPLORATION_RATE_MEDIUM,
                             numMCTSSims=30,
                             max_predict_time=10,
                             num_threads=1)
        elif agent_profile == EnvironmentSelector.HAND_WATTEN_TRAIN_S_S:
            x, y = game.get_observation_size()
            nnet = EasyEasyNNet(x, y, 1, game.get_action_size())
            agent_nnet = AgentNNet(nnet)
            print("Configuring build_hand_watten_s_s...")
            return AgentMCTS(agent_nnet,
                             exp_rate=AgentMCTS.EXPLORATION_RATE_MEDIUM,
                             numMCTSSims=30,
                             max_predict_time=10,
                             num_threads=1)
        elif agent_profile == EnvironmentSelector.HAND_WATTEN_TRAIN_M_M:
            x, y = game.get_observation_size()
            nnet = MediumMediumNNet(x, y, 1, game.get_action_size())
            agent_nnet = AgentNNet(nnet)
            print("Configuring build_hand_watten_m_m...")
            return AgentMCTS(agent_nnet,
                             exp_rate=AgentMCTS.EXPLORATION_RATE_MEDIUM,
                             numMCTSSims=30,
                             max_predict_time=10,
                             num_threads=1)
        elif agent_profile == EnvironmentSelector.HAND_WATTEN_TRAIN_CNN:
            x, y, z = game.get_observation_size()
            nnet = CNNWatten(x, y, z, game.get_action_size())
            agent_nnet = AgentNNet(nnet)
            print("Configuring build hand watten CNN....")
            return AgentMCTS(agent_nnet,
                             exp_rate=AgentMCTS.EXPLORATION_RATE_MEDIUM,
                             numMCTSSims=30,
                             max_predict_time=10,
                             num_threads=1)

        return None
    def build_sub_watten_train_agent(self,
                                     agent_profile,
                                     native_multi_gpu_enabled=False):

        game = self.game_mapping[agent_profile.game]

        x, y = game.get_observation_size()

        if agent_profile == EnvironmentSelector.SUB_WATTEN_AGENT_TRAIN:
            nnet = SubWattenNNet(x, y, 1, game.get_action_size())
        elif agent_profile == EnvironmentSelector.SUB_WATTEN_AGENT_TRAIN_SIMPLE:
            nnet = SubWattenSimplerNNet(x, y, 1, game.get_action_size())

        agent_nnet = AgentNNet(nnet)

        if agent_profile == EnvironmentSelector.SUB_WATTEN_AGENT_TRAIN or \
                agent_profile == EnvironmentSelector.SUB_WATTEN_AGENT_TRAIN_SIMPLE:
            print("Configuring build_sub_watten_train_agent...")
            return AgentMCTS(agent_nnet,
                             exp_rate=AgentMCTS.EXPLORATION_RATE_MEDIUM,
                             numMCTSSims=100,
                             max_predict_time=10,
                             num_threads=1)

        return None
Exemplo n.º 7
0
    def build_tpu_checkers_agent(self,
                                 agent_profile,
                                 native_multi_gpu_enabled=False):
        from games.checkers.nnet.CheckersResNNetTPU import CheckersResNNetTPU

        assert not native_multi_gpu_enabled, "ERROR: TPU NNet does not support native multi-gpu mode!"

        game = self.game_mapping[agent_profile.game]

        nnet = CheckersResNNetTPU(game.get_observation_size()[0],
                                  game.get_observation_size()[1],
                                  game.get_observation_size()[2],
                                  game.get_action_size())

        agent_nnet = AgentNNet(nnet)

        if agent_profile == EnvironmentSelector.CHECKERS_AGENT_TRAIN_RCNN_TPU:
            return AgentMCTS(agent_nnet,
                             exp_rate=AgentMCTS.EXPLORATION_RATE_INIT,
                             numMCTSSims=200,
                             max_predict_time=None,
                             verbose=False,
                             num_threads=1)
        else:
            return None
    def build_durak_train_agent(self,
                                agent_profile,
                                native_multi_gpu_enabled=False):

        game = self.game_mapping[agent_profile.game]

        x, y = game.get_observation_size()
        nnet = DurakNNet(x, y, 1, game.get_action_size())

        agent_nnet = AgentNNet(nnet)

        if agent_profile == EnvironmentSelector.DURAK_AGENT_TRAIN:
            return AgentMCTS(agent_nnet,
                             exp_rate=AgentMCTS.EXPLORATION_RATE_MEDIUM,
                             numMCTSSims=100,
                             max_predict_time=10)
        return None
    def build_tictactoe_train_agent(self,
                                    agent_profile,
                                    native_multi_gpu_enabled=False):

        game = self.game_mapping[agent_profile.game]

        nnet = TicTacToeNNet(game.get_observation_size()[0],
                             game.get_observation_size()[1],
                             game.get_observation_size()[2],
                             game.get_action_size())

        agent_nnet = AgentNNet(nnet)

        if agent_profile == EnvironmentSelector.TICTACTOE_AGENT_TRAIN:
            return AgentMCTS(agent_nnet,
                             exp_rate=AgentMCTS.EXPLORATION_RATE_MEDIUM,
                             numMCTSSims=100,
                             max_predict_time=10)
        return None