Пример #1
0
def test_capture_pieces_on_end():
    game = Game()

    # Sequence to end the game
    game.take_slot(2)
    game.take_slot(5)
    game.take_slot(1)
    game.take_slot(5)
    game.take_slot(0)
    game.take_slot(3)
    game.take_slot(2)
    game.take_slot(2)
    game.take_slot(0)
    game.take_slot(4)
    game.take_slot(2)
    game.take_slot(5)

    game.end_game()
    state = game.get_state()
    assert state[0][6] == 42 and state[1][6] == 6 and sum(state[0][0:6] + state[1][0:6]) == 0
Пример #2
0
        player_turn = game.get_player_turn()
        print("\nIt is player {0}'s turn".format(1 + player_turn))

        slot = None
        if player_turn == 0:
            slot = check_input("Choose which slot to pick up (index at 0): ")
            # Player
        else:
            # AI
            print("AI computing best move:", end="")
            tree = MancalaTreeBuilder(rec_limit)
            tree.set_root(Node(game))
            tree.build()

            v, slot = minimax.alpha_beta_search(tree)
            print(" {1} (utility: {0})".format(v, 5 - slot))

        game_seq.append((player_turn, slot))
        # Reverse slot if player 2 is playing
        game.take_slot(slot)

        winner = 0
        if game.is_terminal_state():
            winner = game.end_game()
            should_end = True
            print_game(game)

    print("Game over, winner is Player {0}".format(winner))
    print("Game sequence:", game_seq)
    input("Press Enter to end...")