outLayer = SoftmaxLayer(64) nn.addInputModule(inLayer) nn.addOutputModule(outLayer) nn.addModule(hiddenLayer1) nn.addConnection(FullConnection(inLayer, hiddenLayer1, inSliceTo=16)) nn.addConnection(FullConnection(inLayer, hiddenLayer1, inSliceFrom=16, inSliceTo=32)) nn.addConnection(FullConnection(inLayer, hiddenLayer1, inSliceFrom=32, insliceTo=48)) nn.addConnection(FullConnection(inLayer, hiddenLayer1, inSliceFrom=48)) nn.addConnection(FullConnection(hiddenLayer1, outLayer)) nn.sortModules() othello = Othello() smartPlayer = SmartPlayer(nn,othello.boardSize) greedyPlayer = TacticalPlayer() greedyPlayer.newGame(othello,random.choice([othello.WHITE_PLAYER,othello.BLACK_PLAYER])); smartPlayer.newGame(othello,greedyPlayer.enemy); playGame(othello,greedyPlayer,smartPlayer) if othello.getWinner() == greedyPlayer.color: outcome = -1 print "Tactical Player wins over Network Player 5" count += 1 semicount += 1 elif othello.getWinner() == smartPlayer.color: outcome = 1 print "Network Player 5 wins over Tactical Player" count += 1 wincnt += 1
nn.addModule(hiddenLayer5) nn.addConnection(FullConnection(inLayer, hiddenLayer1)) nn.addConnection(FullConnection(inLayer, hiddenLayer2)) nn.addConnection(FullConnection(hiddenLayer1, hiddenLayer3)) nn.addConnection(FullConnection(hiddenLayer2, hiddenLayer3)) nn.addConnection(FullConnection(hiddenLayer2, hiddenLayer5)) nn.addConnection(FullConnection(hiddenLayer3, hiddenLayer4)) nn.addConnection(FullConnection(hiddenLayer3, hiddenLayer5)) nn.addConnection(FullConnection(hiddenLayer3, outLayer)) nn.addConnection(FullConnection(hiddenLayer4, outLayer)) nn.addConnection(FullConnection(hiddenLayer5, outLayer)) nn.sortModules() othello = Othello() smartPlayer = SmartPlayer(nn,othello.boardSize) tacticalPlayer = TacticalPlayer() tacticalPlayer.newGame(othello,random.choice([othello.WHITE_PLAYER,othello.BLACK_PLAYER])); smartPlayer.newGame(othello,tacticalPlayer.enemy); playGame(othello,tacticalPlayer,smartPlayer) if othello.getWinner() == tacticalPlayer.color: outcome = -1 print "Tactical Player wins over Network Player 4" count += 1 semicount += 1 elif othello.getWinner() == smartPlayer.color: outcome = 1 print "Network Player 4 wins over Tactical Player" count += 1 wincnt += 1
from SmartPlayer import SmartPlayer from RandomPlayer import RandomPlayer from GreedyPlayer import GreedyPlayer from Othello import Othello from Player import playGame from HumanPlayer import HumanPlayer from pybrain.tools.customxml.networkreader import NetworkReader from TacticalPlayer import TacticalPlayer import random #nn = NetworkReader.readFrom("othelloNetwork.xml") #opponentPlayer = SmartPlayer(nn,8) #change this to change the opponent to be testing against opponentPlayer = TacticalPlayer() humanPlayer = HumanPlayer() othello = Othello() othello.resetGame() humanPlayer.newGame(othello,random.choice([othello.WHITE_PLAYER,othello.BLACK_PLAYER])) opponentPlayer.newGame(othello,humanPlayer.enemy) playGame(othello,humanPlayer,opponentPlayer) if othello.getWinner() == humanPlayer.color: print "You won!" elif othello.getWinner() == opponentPlayer.color: print "You lost!" else: print "Tie game! :("