コード例 #1
0
def play_arena(model):
    game = GobangGame(col=12, row=4, nir=7, defender=-1)
    heur = Heuristic(game)
    heuristic = Heuristic(game).random_play
    model_player = lambda b, p: np.argmax(model.predict(h.b))
    arena = Arena.Arena(model_player, heuristic, game, display=display)
    return arena.playGames(100, verbose=True)
コード例 #2
0
 def __init__(self, model):
     self.game = GobangGame(col=12, row=4, nir=7, defender=-1)
     self.heuristic = Heuristic(self.game)
     heuristic_player = Heuristic(self.game).random_play
     model_player = lambda b, p: Model_Arena.model_player(self, b, p, model)
     self.arena = Arena.Arena(model_player,
                              heuristic_player,
                              self.game,
                              display=display)
コード例 #3
0
import Arena
from MCTS import MCTS
from gobang.GobangGame import GobangGame, display
from gobang.GobangPlayers import *
from gobang.keras.NNet import NNetWrapper as NNet

import numpy as np
from utils import *
"""
use this script to play any two agents against each other, or play manually with
any agent.
"""

g = GobangGame()

# all players
rp = RandomPlayer(g).play
gp = GreedyGobangPlayer(g).play
hp = HumanGobangPlayer(g).play

# nnet players
n1 = NNet(g)
n1.load_checkpoint('./temp/', 'best.pth.tar')
args1 = dotdict({'numMCTSSims': 50, 'cpuct': 1.0})
mcts1 = MCTS(g, n1, args1)
n1p = lambda x: np.argmax(mcts1.getActionProb(x, temp=0))

#n2 = NNet(g)
#n2.load_checkpoint('/dev/8x50x25/','best.pth.tar')
#args2 = dotdict({'numMCTSSims': 25, 'cpuct':1.0})
#mcts2 = MCTS(g, n2, args2)
 def test_gobang_tensorflow(self):
     self.execute_game_test(GobangGame(), GobangTensorflowNNet)
 def test_gobang_keras(self):
     self.execute_game_test(GobangGame(), GobangKerasNNet)
コード例 #6
0
ファイル: pit.py プロジェクト: gms2009/HybridAlpha
from utils import *
"""
use this script to play any two agents against each other, or play manually with
any agent.
"""
choice = "othello"

if choice == "tictactoe":
    g = TicTacToeGame(3)
    n1 = NNet(g)
    n1.load_checkpoint('./temp/', 'best75_eps95_dim3.pth.tar')
    gamename = "tictactoe"
    display = display
    hp = HumanTicTacToePlayer(g).play
if choice == "gobang":
    g = GobangGame(5, 4)
    n1 = NNet1(g)
    n1.load_checkpoint('./temp/', 'curent13temp_iter75_eps350_dim5.pth.tar')
    gamename = "gobang"
    display = display1
    hp = HumanGobangPlayer(g).play
if choice == "othello":
    g = OthelloGame(8)
    n1 = NNet2(g)
    n1.load_checkpoint('./temp/', 'curent14temp:iter14:eps200:dim8.pth.tar')
    gamename = "othello"
    display = display2
    hp = MinMaxOthelloPlayer(g, 3).play
if choice == "connect4":
    g = Connect4Game(5, 6)
    n1 = NNet3(g)
コード例 #7
0
ファイル: pit.py プロジェクト: sfrias/AlphaZero-1
import numpy as np
from utils import *
"""
use this script to play any two agents against each other, or play manually with
any agent.
"""
choice = "othello"

if choice == "tictactoe":
    g = TicTacToeGame(5)
    n1 = NNet(g)
    n1.load_checkpoint('./temp/', 'best75_eps95_dim5.pth.tar')
    display = display
    hp = MinMaxTicTacToePlayer(g, 4).play
if choice == "gobang":
    g = GobangGame(6, 6)
    n1 = NNet1(g)
    n1.load_checkpoint('./temp/', 'temp:iter75:eps5:dim6.pth.tar')
    display = display1
    hp = MinMaxGobangPlayer(g, 6).play
if choice == "othello":
    g = OthelloGame(6)
    n1 = NNet2(g)
    n1.load_checkpoint('./temp/', 'best75:eps140:dim6.pth.tar')
    display = display2
    hp = MinMaxOthelloPlayer(g, 4).play
if choice == "connect4":
    g = Connect4Game(6, 7)
    n1 = NNet3(g)
    n1.load_checkpoint('./temp/', 'best75:eps1:dim6.pth.tar')
    display = display3
コード例 #8
0
ファイル: pit.py プロジェクト: danielvarga/alpha-zero-general
        pool.close()
        pool.join()

        oneWon = 0
        twoWon = 0
        draws = 0
        for i in res:
            result.append(i.get())
        for i in result:
            oneWon += i[0]
            twoWon += i[1]
            draws += i[2]
        print("Model 1 Win:",oneWon," Model 2 Win:",twoWon," Draw:",draws)


    g = GobangGame(col=12, row=4, nir=7, defender=-1)
    os.environ["CUDA_VISIBLE_DEVICES"] = modeargs.gpu
    args1 = dotdict({'numMCTSSims': 1000, 'cpuct':1.0, 'evaluationDepth':1, 'multiGPU': True,
                     'setGPU':'0,1','alpha':0.3,'epsilon':0.25,'fast_eval':True,
                     'numSelfPlayProcess': 10,'numPerProcessSelfPlay': 150,})
    # all players
    rp = RandomPlayer(g).play
    hp = HumanGobangPlayer(g).play
    heuristic_rand = Heuristic(g).random_play
    heuristic = Heuristic(g).play
    
    if modeargs.mode == 'learn':
        #arena = Arena.Arena(n1p, heuristic_rand,  g, display=display, mcts=mcts1)
        #print(arena.playGames(50, verbose=True))
        parallel_play_arena(args1, g, heuristic_rand)
        print("Well Done")
コード例 #9
0
ファイル: gobang_pit.py プロジェクト: Gitdeon/RL
any agent.

Author: Gideon Hanse, Dyon van Vreumingen
"""

import numpy as np
import py_compile as cmp
from utils import *

from Arena import *
from gobang.GobangGame import GobangGame, display
from gobang.GobangPlayers import *

from MCS import MCSPlayer
from Qlearning import QlearningPlayer
#from MCTS import MCTSPlayer

cmp.compile("gobang/GobangPlayers.py")

g = GobangGame(9)

# p1 = MCSPlayer(g)
p1 = QlearningPlayer(g)
p1.train(10000)

p2 = RandomPlayer(g)


print("Gobang")
arena = Arena(p1.play, p2.play, g, display=display)
print(arena.playGames(1000, verbose=False))