Large diffs are not rendered by default.

@@ -1,35 +1,36 @@
import game

print 'Empty Board Tests'
state = game.GobletState()
state.printState()

legalActions1 = state.getLegalActions(0)
legalActions2 = state.getLegalActions(1)
if legalActions2 != legalActions1:
print 'PROBLEM: LEGAL ACTIONS EMPTY STATE'
if len(legalActions1) is not 16:
print 'PROBLEM: TOO MANY LEGAL ACTIONS'
print len(legalActions1), 'legal actions'

size = state.getSize()
players = state.getPlayers()

print 'Diagonal Board Tests'
diagBoard = [[[0 if y is x else game.EMPTY_SPOT for p in range(size)] for y in range(size)] for x in range(size)]
state._setBoard(diagBoard)
state._setPeices([[size - 1 if p is 0 else size - 2 for x in range(size)] for p in range(players)])
state.printState()


print 'Horizonatal Board Tests'
horBoard = [[[0 if x is 0 else game.EMPTY_SPOT for p in range(size)] for y in range(size)] for x in range(size)]
state._setBoard(horBoard)
state.printState()


print 'Vertical Board Tests'
vertBoard = [[[0 if y is 0 else game.EMPTY_SPOT for p in range(size)] for y in range(size)] for x in range(size)]
state._setBoard(vertBoard)
state.printState()

import game

print 'Empty Board Tests'
state = game.GobletState()
state.printState()

legalActions1 = state.getLegalActions(0)
legalActions2 = state.getLegalActions(1)
if legalActions2 != legalActions1:
print 'PROBLEM: LEGAL ACTIONS EMPTY STATE'
if len(legalActions1) is not 16:
print 'PROBLEM: TOO MANY LEGAL ACTIONS'
print len(legalActions1), 'legal actions'

size = state.getSize()
players = state.getPlayers()

print 'Diagonal Board Tests'
diagBoard = [[[0 if y is x else game.EMPTY_SPOT for p in range(size)] for y in range(size)] for x in range(size)]
state._setBoard(diagBoard)
state._setPeices([[size - 1 if p is 0 else size - 2 for x in range(size)] for p in range(players)])
state.printState()


print 'Horizonatal Board Tests'
horBoard = [[[0 if x is 0 else game.EMPTY_SPOT for p in range(size)] for y in range(size)] for x in range(size)]
state._setBoard(horBoard)
state.printState()


print 'Vertical Board Tests'
vertBoard = [[[0 if y is 0 else game.EMPTY_SPOT for p in range(size)] for y in range(size)] for x in range(size)]
state._setBoard(vertBoard)
state.printState()

player2 = gameAgents.PerceptronAgent(1, False)
@@ -1,53 +1,74 @@
import game
import gameAgents

NUM_GAMES = 5


player1 = gameAgents.ExpectimaxAgent(0)
# player2 = gameAgents.ExpectimaxAgent(1)
player2 = gameAgents.PerceptronAgent(1)

players = [ player1, player2 ]
playerCount = len(players)

playerWins = [0 for i in range(playerCount)]


for gameCount in range(1, 1 + NUM_GAMES):
state = game.GobletState()
playerId = 0

while not state.isEndState():
# print '\nTURN', playerId
# print state.printState()

player = players[playerId]
action = player.getAction(state)

state.applyAction(playerId, action)
playerId = (playerId + 1) % playerCount

for i in range(playerCount):
win = state.isGoalState(i)
if win:
print 'Player ' + str(i) + ' wins.'
playerWins[i] += 1

if player.getType() is 'Perceptron':
player.classifyActions(win)

print '\nGAME', gameCount
print state.printState()

print '\n'
# print player2.getWeights()

for i in range(playerCount):
print 'Player ' + str(i) + '(' + players[i].getType() + ') Wins:', playerWins[i]






import game
import gameAgents

NUM_GAMES = 1000
PRINT_GAMES = False
PRINT_PRECEPT = True

# player1 = gameAgents.ExpectimaxAgent(0)
player1 = gameAgents.GameAgent(0)
# player1 = gameAgents.InputAgent(0)
# player2 = gameAgents.ExpectimaxAgent(1)
player2 = gameAgents.PerceptronAgent(1, False)
# player2.printWeights()

# player3 = gameAgents.RandomAgent(0)
# player3 = gameAgents.ExpectimaxAgent(0)

players = [ player1, player2 ]
playerCount = len(players)

playerWins = [0 for i in range(playerCount)]


for gameCount in range(1, 1 + NUM_GAMES):
state = game.GobletState()
playerId = 0

while not state.isEndState():
# print '\nTURN', playerId
# print state.printState()

player = players[playerId]
action = player.getAction(state)

# print "Player", playerId, ":", action

state.applyAction(playerId, action)
playerId = (playerId + 1) % playerCount


print '\nGAME', gameCount

for i in range(playerCount):
win = state.isGoalState(i)
player = players[i]
if win:
print 'Player ' + str(i) + ' wins.'
playerWins[i] += 1

if player.getType() is 'Perceptron':
# print 'UPDATING PERCEPTRON ' + str(i)
player.classifyActions(win)

if PRINT_GAMES:
print state.toString()
print '\n'

"""
weights = player2.getWeights()
for action in weights.keys():
if weights[action].totalCount() is not 0:
print action, ":", weights[action]
"""
if player2.getType() is 'Perceptron' and PRINT_PRECEPT:
player2.printWeights()

for i in range(playerCount):
print 'Player ' + str(i) + '(' + players[i].getType() + ') Wins:', playerWins[i]






616 util.py

Large diffs are not rendered by default.