示例#1
0
def get_player(player_type):
    players = {
        'random': Players.RandomPlayer(),
        'manual': Players.ManualPlayer(),
        'monte_carlo': Players.MonteCarloPlayer(100),
        'minimax': Players.MinimaxPlayer(4),
        'en_masse': Players.EnMassePlayer(),
        'flanking': Players.FlankingPlayer(),
        'aggressive': Players.AggressivePlayer(),
    }
    return players[player_type]
import Game
import Players
import MCTS
import Arena
import numpy as np
import NNet
from utils import *

game = Game.Game2048()
player = Players.RandomPlayer(game)
nnet_player = NNet.NNetWrapper(game)
nnet_player.load_checkpoint('./temp', 'best.pth.tar')
args = dotdict({
    'numIters': 1000,
    'numEps': 100,  # Number of complete self-play games to simulate during a new iteration.
    'tempThreshold': 15,  #
    'updateThreshold': 0.6,
    # During arena playoff, new neural net will be accepted if threshold or more of games are won.
    'maxlenOfQueue': 200000,  # Number of game examples to train the neural networks.
    'numMCTSSims': 25,  # Number of games moves for MCTS to simulate.
    'arenaCompare': 40,  # Number of games to play during arena play to determine if new net will be accepted.
    'cpuct': 1,

    'checkpoint': './temp/',
    'load_model': False,
    'load_folder_file': ('/dev/models/8x100x50', 'best.pth.tar'),
    'numItersForTrainExamplesHistory': 20,

})

mcts = MCTS.MCTS(game, nnet_player, args)
示例#3
0
			
		self.board.makemove(self.turn,move[0],move[1])
		if self.turn == 1:
			self.turn = 2
		else:
			self.turn = 1
		
	def play(self):
		while self.checkwin(self.board) == 0:
			self.board.printboard_debug()
			self.prompt_for_move()
			
		self.board.printboard();
		if self.checkwin(self.board) == 1:
			self.player1.report_win()
			self.player2.report_loss()
		elif self.checkwin(self.board) == 2:
			self.player2.report_win()
			self.player1.report_loss()
		elif self.checkwin(self.board) == -1:
			self.player1.report_draw()
			self.player2.report_draw()
		else:
			print("Something went wrong, checkwin is {0}".format(self.checkwin(self.board)))

			
ReinforceInt = Reinforce.ReinforceInterface()
Player1 = Players.RandomPlayer(1)#ReinforceInt.generate_reinforceplayer(1)
Player2 = Players.RandomPlayer(2)
KaspGame = Game(Player1, Player2)
KaspGame.play();