Пример #1
0
def run_game_loop(board, agent1, agent2, do_print=False):
    game = Game(board)
    while not game.is_finished():
        dice = game.roll_dice()
        if do_print:
            board.print()
            print("Dice for AI1 were {}.".format(dice))
        ai_moves = agent1.move(dice)
        if do_print:
            print("Resulting moves: {}.".format(", ".join(
                [str(move) for move in ai_moves])))
        game.apply(game.PLAYER1, ai_moves)

        if game.is_finished():
            break

        dice = game.roll_dice()
        if do_print:
            board.print()
            print("Dice for AI2 were {}.".format(dice))
        ai_moves = agent2.move(dice)
        if do_print:
            print("Resulting moves: {}.".format(", ".join(
                [str(move) for move in ai_moves])))
        game.apply(game.PLAYER2, ai_moves)

    return game.get_winner()
Пример #2
0
def run_game_loop(board, agent1, agent2, do_print=False):
    game = Game(board)
    while not game.is_finished():
        agent1.learn()
        #agent1.backprop()
        dice = game.roll_dice()
        if do_print:
            board.print()
            print("Dice for AI1 were {}.".format(dice))
        ai_moves = agent1.move(dice)
        if do_print:
            print("Resulting moves: {}.".format(", ".join(
                [str(move) for move in ai_moves])))
        game.apply(game.PLAYER1, ai_moves)

        if game.is_finished():
            break

        agent2.learn()
        #agent2.backprop()
        dice = game.roll_dice()
        if do_print:
            board.print()
            print("Dice for AI2 were {}.".format(dice))
        ai_moves = agent2.move(dice)
        if do_print:
            print("Resulting moves: {}.".format(", ".join(
                [str(move) for move in ai_moves])))
        game.apply(game.PLAYER2, ai_moves)

    winner = game.get_winner()
    if winner > 0:
        agent1.learn(np.array([1.0, 0.0]))
        agent2.learn(np.array([0.0, 1.0]))
        #agent1.backprop(np.array([1.0, 0.0]))
        #agent2.backprop(np.array([0.0, 1.0]))
    else:
        agent1.learn(np.array([0.0, 1.0]))
        agent2.learn(np.array([1.0, 0.0]))
        #agent1.backprop(np.array([0.0, 1.0]))
        #agent2.backprop(np.array([1.0, 0.0]))

    return winner, game.get_num_moves()
Пример #3
0
def main():
    #random.seed(42)
    board = Board()
    game = Game(board)
    agent = RandomAgent(board)
    while not game.is_finished():
        dice = game.roll_dice()
        board.print()
        allowed_moves_made = False
        while allowed_moves_made is False:
            human_moves = present_dice_to_human_and_ask_move(dice)
            try:
                allowed_moves_made = game.apply(game.PLAYER1, human_moves)
            except Exception as e:
                print(e)
                allowed_moves_made = False
        dice = game.roll_dice()
        ai_moves = agent.move(dice)
        print("Dice for AI were {}. Resulting moves: {}".format(dice, ", ".join([str(move) for move in ai_moves])))
        game.apply(game.PLAYER2, ai_moves)