Пример #1
0
 def __init__(self, c, rm, nnet):
     self.c = c
     self.rm = rm
     self.ai = snnAI.SnnAI(c, nnet, add_noise=True)
     # The list of the GenGameState objets representing the games
     # played in parallel.
     self.states = []
Пример #2
0
 def __init__(self, c, rm, nnet):
     self.c = c
     self.rm = rm
     self.ai1 = snnAI.SnnAI(c, nnet, add_noise=True)
     self.ai2 = randomAI.RandomAI()
     # The length of this set is the number of distinct games
     # generated in the current iteration.
     self.game_codes = set()
     # The list of the GenGameState objets representing the games
     # played in parallel.
     self.states1 = []
     self.states2 = []
Пример #3
0
        if self.num_games != self.num_draws:
            self.win_no_draws_perc = 100 * self.num_wins / (self.num_games -
                                                            self.num_draws)
            self.avg_game_length = self.num_moves / (self.num_games -
                                                     self.num_draws)


if __name__ == '__main__':

    c = Configuration()
    ###
    # import nnet
    # nnet = nnet.NNet(32, 2).cuda()
    # evaluated_ai = snnAI.SnnAI(c, nnet, add_noise=False)
    ###
    evaluated_ai = snnAI.SnnAI(c, add_noise=False)
    # evaluated_ai = randomAI.RandomAI()

    num_games = 100000

    ev = Evaluator('random', num_games)
    ev.evaluate_ai(evaluated_ai)

    # print(
    #     f"\n\nwins: {round(ev.win_perc)} % | "
    #     f"draws: {round(ev.draw_perc)} % | "
    #     f"wins no draws: {round(ev.win_no_draws_perc)} %"

    #     f"\naverage length: {round(ev.avg_game_length)} | "
    #     f"duration: {round(ev.duration, 2)}"
    # )
Пример #4
0
 def evaluation(self):
     ai = snnAI.SnnAI(self.c, self.nnet)
     self.evaluator.evaluate_ai(ai)
     self.rm.eval_ai(self.evaluator)
Пример #5
0
 def evaluation(self):
     ai = snnAI.SnnAI(self.c, self.nnet, add_noise=False)
     self.evaluator.evaluate_ai(ai)
     self.rm.eval_ai(self.evaluator)
Пример #6
0
        while True:
            if s.playing_side == player_side:
                move = input(f"Move number {i} by {s.playing_side} : ")
                s.update(move)
            else:
                move = self.AI.best_move()
                s.update(move)
                print(f"Move number {i} by {s.playing_side} : {move}")
            if move == "quit":
                break
            elif move == "resign":
                print(f"{s.playing_side} resigns")
                break
            print("Board after move :")
            print(s.string_board())
            print()
            i += 1


if __name__ == "__main__":

    ai = randomAI.RandomAI()
    c = Configuration()
    ai = snnAI.SnnAI(c)

    org = GameOrganizer(ai)
    
    # org.usi_engine("SNN AI")
    org.ai_vs_ai(512, print_moves=True, print_outcome=True)
    # org.ai_vs_player()
    # org.player_vs_player()
Пример #7
0
                    res += 'O' + blank
                else:
                    res += '.' + blank
            if x != 2: res += '\n\n'
        return res


if __name__ == '__main__':

    from encoding import *
    from configuration import Configuration

    c = Configuration()

    randAI = randomAI.RandomAI()
    nnAI = snnAI.SnnAI(c)

    nnAI_plays = True
    human_plays = True

    s = GameState()
    while not s.finished:

        if human_plays and not nnAI_plays:
            move_str = input("\nChoose your move: ")
            move = tuple(int(x) for x in move_str.split(','))

        elif nnAI_plays:
            v = nnAI.nnet(encode_game_state(s).unsqueeze(0).cuda())  # pylint: disable=E
            v = v.squeeze(0).detach().cpu().numpy()
            print(f"\n{v}")