Example #1
0
def main():
    print("Would you like to go 1st or 2nd?\n    Go 1st: 1\n    Go 2nd: 2")
    if int(input()) == 2:
        players = {-1: "Human", 1: 'AI'}
    else:
        players = {1: "Human", -1: 'AI'}
    board = Board()
    mc = MonteCarlo(board, seconds=3)
    game_history = []
    game_state = board.start()
    game_history.append(game_state)
    mc.update(game_state)
    legals = board.legal_plays(game_history)
    winner = board.winner(game_history)
    board.show(game_history[-1])
    while legals and winner == 0:
        current_player = board.current_player(game_state)
        #print(current_player)
        if players[current_player] == 'Human':
            print("Please enter the square you'd like to play: ")
            pos = int(input())
            game_state = board.next_state(game_state, (pos, current_player))
        elif players[board.current_player(game_state)] == 'AI':
            print("AI is thinking....")
            game_state = board.next_state(game_state, mc.get_play())
        mc.update(game_state)
        game_history.append(game_state)
        legals = board.legal_plays([game_state])
        winner = board.winner([game_state])
        board.show(game_history[-1])

    print("The game is over!\n Plauer: ", winner, "has won")
Example #2
0
def main2():
    b = Board()
    mc = MonteCarlo(b, seconds=20)
    game_state = b.start()
    mc.update(game_state)
    mc.get_play()