예제 #1
0
def play_wo_human(agent1, agent2, first_player):
    '''
	Default: agent 1 plays RED
	agent 2 plays YELLOW
	'''
    turn_dict = {1: RED, 2: YELLOW}
    agent_turn_dict = {RED: agent1.name, YELLOW: agent2.name}
    times = {agent1.name: 0, agent2.name: 0}

    count_moves = 0
    winner = None

    g = Game()

    # #randomize turn who starts first
    # turn_ind = random.randint(1,2)
    # turn = turn_dict[turn_ind]

    turn = turn_dict[first_player]

    print "Starting with turn = ", agent_turn_dict[turn]
    while True:
        g.printBoard()
        if turn == RED:
            print agent1.name, "'s turn"
            start = time.time()
            move = agent1.play_move()
            end = time.time()
            times[agent1.name] += (end - start)
            if move is None:
                print "DRAW GAME"
                break
            w = g.insert(move, turn)
            if w:
                winner = agent_turn_dict[w]
                print "####################WINNER: ", winner, " TOTAL MOVES: ", count_moves
                break
            agent2.play_opponent_move(move)
        else:
            print agent2.name, "'s turn"
            start = time.time()
            move = agent2.play_move()
            end = time.time()
            times[agent2.name] += (end - start)
            if move is None:
                print "DRAW GAME"
                break
            w = g.insert(move, turn)
            if w:
                winner = agent_turn_dict[w]
                print "#################WINNER: ", winner, " TOTAL MOVES: ", count_moves
                break
            agent1.play_opponent_move(move)
        count_moves += 1
        turn = YELLOW if turn == RED else RED
    return winner, count_moves, times
예제 #2
0
def play_w_human():
    g = Game()
    # agent = MinimaxAgent() #MCTSAgent()
    agent = QLearningAgent('q_values')
    turn = RED

    while True:
        g.printBoard()
        if turn == RED:
            row = input(
                '{}\'s turn: '.format('Red' if turn == RED else 'Yellow'))
            w = g.insert(int(row), turn)
            agent.play_opponent_move(int(row))
        else:
            move = agent.play_move()
            w = g.insert(move, turn)
        if w:
            print "WINNER: ", w
            break
        turn = YELLOW if turn == RED else RED