Example #1
0
def doArena(n: mcts2.INeuralNet, doTrain=True):
    # otherPlayer = Player("Marcel", lambda x: HumanPlayer().play(x))
    mcts = mcts2.MCTS(n)
    otherPlayer = Player("random", lambda x: RandomPlayer().play(x))
    neuralPlayer = Player("neural", lambda x: np.argmax(mcts.getActionProbabilities(x, 0)))
    a = Arena(neuralPlayer, otherPlayer, moaraGame, moara.args, mcts)

    result = a.playGames(5, verbose=False)
    if doTrain:
        # train the network based on the arena games
        trainExamples = []
        for e in a.trainExamplesHistory:
            trainExamples.extend(e)
        shuffle(trainExamples)
        if trainExamples != []:
            n.train(trainExamples)

            # test against the previous
            # if i % 5 == 0:
            #     # self.PitAgainst('no36.neural.data-ITER-390')
            #     PitAgainst(moara.filename - 1)
            n.save_checkpoint(folder=moara.args.checkpoint, filename_no=moara.args.filename)
Example #2
0
    result = a.playGames(5, verbose=False)
    if doTrain:
        # train the network based on the arena games
        trainExamples = []
        for e in a.trainExamplesHistory:
            trainExamples.extend(e)
        shuffle(trainExamples)
        if trainExamples != []:
            n.train(trainExamples)

            # test against the previous
            # if i % 5 == 0:
            #     # self.PitAgainst('no36.neural.data-ITER-390')
            #     PitAgainst(moara.filename - 1)
            n.save_checkpoint(folder=moara.args.checkpoint, filename_no=moara.args.filename)


print("mcts 3")
moaraGame: MoaraNew = MoaraNew()
# moaraGame.LoadValidMoves()
n = NeuralNetNew(moaraGame, mcts2.moara.args)
n.load_checkpoint(folder=moara.args.checkpoint, filename_no=moara.args.filename)
n2 = NeuralNetNew(moaraGame, mcts2.moara.args)
n2.load_checkpoint(folder=moara.args.checkpoint, filename_no='no181210NoHistExtra')

mcts = mcts2.MCTS(n)
mcts_2 = mcts2.MCTS(n2)
mcts2.learn(moaraGame, mcts, n, doArena)

# doArena(n, mcts)
Example #3
0
    result = a.playGames(5, verbose=False)
    if doTrain:
        # train the network based on the arena games
        trainExamples = []
        for e in a.trainExamplesHistory:
            trainExamples.extend(e)
        shuffle(trainExamples)
        if trainExamples != []:
            n.train(trainExamples)

            # test against the previous
            # if i % 5 == 0:
            #     # self.PitAgainst('no36.neural.data-ITER-390')
            #     PitAgainst(moara.filename - 1)
            n.save_checkpoint(folder=moara.args.checkpoint,
                              filename_no=moara.args.filename)


print("moara 4")
moaraGame: MoaraNew = MoaraNew()
# moaraGame.LoadValidMoves()
n = NeuralNetNew(moaraGame, mcts2.moara.args)
n.load_checkpoint(folder=moara.args.checkpoint,
                  filename_no=moara.args.filename)

mcts = mcts2.MCTS(n)
mcts2.learn(moaraGame, mcts, n, doArena)

# doArena(n, mcts)