def runOneTest(): othello.resetGame() player1.newGame(othello,random.choice([othello.WHITE_PLAYER,othello.BLACK_PLAYER])) player2.newGame(othello,player1.enemy) playGame(othello,player1,player2) if othello.getWinner() == player1.color: return 1.0 elif othello.getWinner() == player2.color: return 0.0 else: return 0.0
def runOneTest(): rvrP1Wins = 0 rvrP2Wins = 0 rvrTies = 0 gvrP1Wins = 0 gvrP2Wins = 0 gvrTies = 0 nvrP1Wins = 0 nvrP2Wins = 0 nvrTies = 0 for x in xrange(0,1):#run 100 gamess #print "Iteration " + str(x+1) #print "Random vs Random" othello.resetGame() player1.newGame(othello,random.choice([othello.WHITE_PLAYER,othello.BLACK_PLAYER])) opponentPlayer.newGame(othello,player1.enemy) playGame(othello,player1,opponentPlayer) if othello.getWinner() == player1.color: rvrP1Wins += 1 #print "Random Player 1 is vicotorious! Glory to the RNG!" elif othello.getWinner() == opponentPlayer.color: rvrP2Wins += 1 #print "Random Player 2 is victorious! Glory to the RNG!" else: rvrTies += 1 #print "Tie game! :(" othello.resetGame() player2.newGame(othello,random.choice([othello.WHITE_PLAYER,othello.BLACK_PLAYER])) opponentPlayer.newGame(othello,player2.enemy) playGame(othello,player2,opponentPlayer) if othello.getWinner() == player2.color: gvrP1Wins += 1 #print "Random Player 1 is vicotorious! Glory to the RNG!" elif othello.getWinner() == opponentPlayer.color: gvrP2Wins += 1 #print "Random Player 2 is victorious! Glory to the RNG!" else: gvrTies += 1 #print "Tie game! :(" othello.resetGame() player3.newGame(othello,random.choice([othello.WHITE_PLAYER,othello.BLACK_PLAYER])) opponentPlayer.newGame(othello,player3.enemy) playGame(othello,player3,opponentPlayer) if othello.getWinner() == player3.color: nvrP1Wins += 1 #print "Smart Player is victorious! Glory to the Machine Brains!" elif othello.getWinner() == opponentPlayer.color: nvrP2Wins += 1 #print "Random Player is victorious!" else: nvrTies += 1 #print "Tie game! D:" #print "Random vs Random win rate: " + str(rvrP1Wins / float(rvrP1Wins + rvrP2Wins + rvrTies)) #print "Network vs Random win rate: " + str(nvrP1Wins / float(nvrP1Wins + nvrP2Wins + nvrTies)) return (rvrP1Wins / float(rvrP1Wins + rvrP2Wins + rvrTies),gvrP1Wins / float(gvrP1Wins + gvrP2Wins + gvrTies),nvrP1Wins / float(nvrP1Wins + nvrP2Wins + nvrTies))
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 semicount += 1 semiwincnt += 1 else:
nn.addModule(hiddenLayer2) nn.addModule(hiddenLayer3) nn.addConnection(FullConnection(inLayer, hiddenLayer1)) nn.addConnection(FullConnection(inLayer, hiddenLayer2)) nn.addConnection(FullConnection(hiddenLayer2, hiddenLayer3)) nn.addConnection(FullConnection(hiddenLayer1, outLayer)) nn.addConnection(FullConnection(hiddenLayer3, outLayer)) nn.sortModules() othello = Othello() smartPlayer = SmartPlayer(nn, othello.boardSize) randomPlayer = TacticalPlayer() randomPlayer.newGame(othello, random.choice([othello.WHITE_PLAYER, othello.BLACK_PLAYER])) smartPlayer.newGame(othello, randomPlayer.enemy) playGame(othello, randomPlayer, smartPlayer) if othello.getWinner() == randomPlayer.color: outcome = -1 print "Tactical Player wins over Network Player 1" count += 1 semicount += 1 elif othello.getWinner() == smartPlayer.color: outcome = 1 print "Network Player 1 wins over Tactical Player" wincnt += 1 count += 1 semicount += 1 semiwincnt += 1 else: outcome = 0 print "Tie Game"
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 semicount += 1 semiwincnt += 1 else:
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! :("