Exemple #1
0
def playGame(timed = False):
    board = startingBoard()
    player = "B"
    history = []
    while (not isGameOver(board)):
        if not timed:
            print boardToString(board)
        if not existsValidMove(board,player):
            if not timed:
                print "\nPlayer " + player + " has no valid moves\n"
            player = otherPlayer(player)
        if not timed:
            print "\n----------------------\n" + str(player) + " is playing\n----------------------\n"
        position = computeBestMove(copy.deepcopy(board),player)
        assert validMove(board,player,position), "The move given is not valid!"
        board = makeMove(board,player,position)
        history.append([player,position])
        player = otherPlayer(player)
    print boardToString(board)
    print "\n**EndGame**\n"
    winner = getWinner(board)
    print winner + " wins"
    print "\nHistory:"
    print history
    updateRecords(startingBoard(),history,winner)
    return winner
def mergeRecords(recordsA,recordsB):
    fullRecords = recordsA.append(recordsB,ignore_index=True)
    fullRecords['Board'] = map(lambda x: boardToString(x),fullRecords['Board'])
    fullRecords = fullRecords.groupby(['Board','Player'],as_index=False).sum()
    fullRecords['Board'] = map(lambda x: stringToBoard(x),fullRecords['Board'])
    fullRecords['BoardValue'] = map(lambda w,l: computeLowerBound(w,l),fullRecords['Wins'],fullRecords['Losses'])
    return fullRecords