def playTTTAndPlotResults():

    learningPlayer = RLTTTPlayer()

    randomPlayer = RandomTTTPlayer()

    results = []

    numberOfSetsOfGames = 50

    for i in range(numberOfSetsOfGames):

        games = GameSequence(100, learningPlayer, randomPlayer)

        results.append(games.playGamesAndGetWinPercent())

    plotValues = {
        'X Win Fraction':
        list(zip(list(range(numberOfSetsOfGames)), [x[0] for x in results])),
        'O Win Fraction':
        list(zip(list(range(numberOfSetsOfGames)), [x[1] for x in results])),
        'Draw Fraction':
        list(zip(list(range(numberOfSetsOfGames)), [x[2] for x in results]))
    }

    drawXYPlotByFactor(plotValues,
                       'Number of Sets (of 100 Games)',
                       'Fraction',
                       title='RL Player (X) vs. Random Player (O)')
Exemplo n.º 2
0
def playUltimateAndPlotResults():
    learningModel = NNUltimateLearning(UTTTBoardDecision)
    learningPlayer = RLUTTTPlayer(learningModel)
    randomPlayer = RandomUTTTPlayer()
    results = []
    numberOfSetsOfGames = 60
    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))
    }
    drawXYPlotByFactor(plotValues,
                       'Number of Sets (of 100 Games)',
                       'Fraction',
                       title='RL Player (O) vs. Random Player (X)')
def plotResultsFromFile(resultsFile):

    results = []

    with open(resultsFile, 'r') as infile:

        reader = csv.reader(infile)

        results = list(map(tuple, reader))

    numberOfSetsOfGames = len(results)

    plotValues = {
        'X Win Fraction':
        list(zip(list(range(numberOfSetsOfGames)), [x[0] for x in results])),
        'O Win Fraction':
        list(zip(list(range(numberOfSetsOfGames)), [x[1] for x in results])),
        'Draw Fraction':
        list(zip(list(range(numberOfSetsOfGames)), [x[2] for x in results]))
    }

    drawXYPlotByFactor(plotValues,
                       'Number of Sets (of 100 Games)',
                       'Fraction',
                       title='RL Player (O) vs. Random Player (X)')
Exemplo n.º 4
0
def plotMemoryUsageFromFile(memoryFile):
    results = []
    with open(memoryFile, 'r') as infile:
        reader = csv.reader(infile)
        results = map(tuple, reader)
    plotValues = {
        'Memory Usage':
        zip(map(lambda x: x[1], results), map(lambda x: x[2], results))
    }
    drawXYPlotByFactor(plotValues, 'Number of Simulations',
                       'Memory Usage (MB)')
def plotMemoryUsageFromFile(memoryFile):

    results = []

    with open(memoryFile, 'r') as infile:

        reader = csv.reader(infile)

        results = list(map(tuple, reader))

    plotValues = {
        'Memory Usage':
        list(zip([x[1] for x in results], [x[2] for x in results]))
    }

    drawXYPlotByFactor(plotValues, 'Number of Simulations',
                       'Memory Usage (MB)')