Example #1
0
## Play the game
    
if __name__ == '__main__':
    player = GameState()
    state = new_game()
    numMoves = 0
    numGames = 0
    startTime = time.time()

    ## Play games until hash recieved (challenge requires 50 games)
    while True:
        print('Game Number: {0}'.format(numGames))
        print('Time Elapsed: {0:3f}'.format(time.time() - startTime))

        ## Make moves until game is over (games requires you make 30 moves without losing.)
        while numMoves < 30:
    ##        print(str(state[0]) + str(state[1]) + str(state[2]))
    ##        print(str(state[3]) + str(state[4]) + str(state[5]))
    ##        print(str(state[6]) + str(state[7]) + str(state[8]))
    ##        print('\n')
            
            moveInfo = player.get_next_move(state)

            if len(moveInfo) == 1:
                state = place(moveInfo[0])
            else:
                numMoves, state = move(moveInfo[0], moveInfo[1])
        
        numGames, state = next_game()
        numMoves = 0
Example #2
0
## We have the GameState play against itself.
## Since it is a FSM designed to never reach a terminal state, the games should go on indefinitely.
## GameState() will ramdomly select a path given multiple possible moves allowing for complete path coverage eventually.
testPlayer = GameState()

## Run 100 games
for i in range(100):
    state = list('---------')

    ##    print("%c%c%c" %(state[0],state[1],state[2]))
    ##    print("%c%c%c" %(state[3],state[4],state[5]))
    ##    print("%c%c%c\n" %(state[6],state[7],state[8]))

    ## Play 100 moves
    for _ in range(100):
        update = testPlayer.get_next_move(state, player=1)

        if len(update) == 1:
            state[update[0] - 1] = 'p'
        else:
            state[update[0] - 1] = '-'
            state[update[1] - 1] = 'p'

##        print("Player 1")
##        print("%c%c%c" %(state[0],state[1],state[2]))
##        print("%c%c%c" %(state[3],state[4],state[5]))
##        print("%c%c%c\n" %(state[6],state[7],state[8]))

        update = testPlayer.get_next_move(state, player=-1)

        if len(update) == 1: