Skip to content

Commit

Permalink
Show a helpful picture of the game
Browse files Browse the repository at this point in the history
  • Loading branch information
shayakbanerjee committed Dec 15, 2017
1 parent aa4b52a commit 37f34ea
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
Binary file added figures/sequence-of-moves.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 4 additions & 2 deletions game.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from ultimateboard import UTTTBoard, UTTTBoardDecision
from player import RandomTTTPlayer, RLTTTPlayer
from ultimateplayer import RandomUTTTPlayer, RLUTTTPlayer
from learning import NNUltimateLearning
from plotting import drawXYPlotByFactor
import os

Expand Down Expand Up @@ -52,16 +53,17 @@ def playTTTAndPlotResults():
drawXYPlotByFactor(plotValues, 'Set Number', 'Fraction')

def playUltimateAndPlotResults():
learningPlayer = RLUTTTPlayer()
learningPlayer = RLUTTTPlayer(NNUltimateLearning)
randomPlayer = RandomUTTTPlayer()
results = []
numberOfSetsOfGames = 4
numberOfSetsOfGames = 40
if os.path.isfile(LEARNING_FILE):
learningPlayer.loadLearning(LEARNING_FILE)
for i in range(numberOfSetsOfGames):
games = GameSequence(100, learningPlayer, randomPlayer, BoardClass=UTTTBoard, BoardDecisionClass=UTTTBoardDecision)
results.append(games.playGamesAndGetWinPercent())
learningPlayer.saveLearning(LEARNING_FILE)
writeResultsToFile(results)
plotValues = {'X Win Fraction': zip(range(numberOfSetsOfGames), map(lambda x: x[0], results)),
'O Win Fraction': zip(range(numberOfSetsOfGames), map(lambda x: x[1], results)),
'Draw Fraction': zip(range(numberOfSetsOfGames), map(lambda x: x[2], results))}
Expand Down
6 changes: 6 additions & 0 deletions learning.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,21 @@

class GenericLearning(object):
def getBoardStateValue(self, player, board, boardState):
# Return the perceived `value` of a given board state
raise NotImplementedError

def learnFromMove(self, player, board, prevBoardState):
# Learn from the previous board state and the current state of the board
raise NotImplementedError

def saveModel(self, filename):
# Save to file (use pass if no implementation is necessary)
# Useful for saving intermediate states of the learning model
raise NotImplementedError

def loadModel(self, filename):
# Load an intermediate state of the learning model from file
# Use only if also saving the intermediate state above
raise NotImplementedError

class TableLearning(GenericLearning):
Expand Down
5 changes: 2 additions & 3 deletions ultimateplayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ def learnFromMove(self, prevBoardState):
pass # Random player does not learn from move

class RLUTTTPlayer(UTTTPlayer):
def __init__(self):
#self.learningAlgo = TableLearning(UTTTBoardDecision)
self.learningAlgo = NNUltimateLearning(UTTTBoardDecision)
def __init__(self, Learning=TableLearning):
self.learningAlgo = Learning(UTTTBoardDecision)
super(RLUTTTPlayer, self).__init__()

def printValues(self):
Expand Down

0 comments on commit 37f34ea

Please sign in to comment.