예제 #1
0
def main():
    circ = QuantumCircuit(5, 5)
    q = QuantumRegister(5, 'q')
    c = ClassicalRegister(5, 'c')
    game = Dealer(circ)
    player = Player()

    while not player.broke():
        if player.rounds > 0:
            circ = QuantumCircuit(5, 5)
            game.reset(circ)
        state_position = []
        state_string = ["0", "0", "0", "0", "0"]
        state_position.append(random.randint(0, 4))
        state_position.append(random.randint(0, 4))

        state_string[state_position[0]] = "1"
        state_string[state_position[1]] = "1"
        circ.x(q[state_position[0]])
        if state_position[0] != state_position[1]:
            circ.x(q[state_position[1]])

        print("Your starting state is:")
        print("|" + ''.join(state_string[::-1]) + ">")

        while not game.finished():
            state_string[game.current_qubit] = mark_qubit(
                state_string, game.current_qubit)

            print("--" * 30)
            print("Total Points: %d" % player.points)
            print("Round: %d/5" % (game.current_qubit + 1))
            print("Cash: $%d" % player.wallet)
            print("Current status of qubits:")
            print("|" + ' '.join(state_string[::-1]) + ">")

            choice = input("'0': Hit($5)  '1': Stand($10)?")
            while choice not in ["0", "1"]:
                choice = input("Please input '0'(Hit) or '1'(Stand)")
            if (player.wallet < 10 and choice == "1") or (player.wallet < 5):
                print(
                    "insufficient funds... proceeding with draw (this is on the house!)"
                )
                choice = "0"

            new_gate = game.action(int(choice), player)
            state_string[game.current_qubit -
                         1] = new_gate + state_string[game.current_qubit -
                                                      1][1]
            if new_gate == "C":
                state_string[game.current_qubit -
                             2] = "N" + state_string[game.current_qubit - 2]
                new_gate = "CNOT"
            print("You drew %s!" % new_gate)

        print("--" * 30)
        print("Your final state is:")
        time.sleep(1)
        print("|" + ' '.join(state_string[::-1]) + ">")
        print("Time for measurement!")
        time.sleep(1)
        final_string = game.evaluate()
        method, points = score(final_string)
        player.win(points)
        print("The result:")
        print("|" + ''.join(final_string[::+1]) + ">")
        print("You won %d points by means of %s" % (points, method))
        if not player.broke():
            print("Prepare for the next game!")
        time.sleep(1)
        print("\n" * 5)

    print("You finished %d rounds with %d points!" %
          (player.rounds, player.points))
    print("Your points/$ was %3f" % (player.points / 100))
예제 #2
0
    dealer = Dealer()
    player = Player()

    # introduce
    dealer.greet(player)

    # make tools
    deck = Deck()
    # deck is shuffled
    deck.shuffle()

    dealer.first_draw(deck)
    player.first_draw(deck)

    # game
    dealer.show_hand(True)
    player.show_hand()

    # Player's turn
    command()

    # dealer's turn
    while True:
        if not dealer.action(deck):
            break

    dealer.show_hand(False)
    player.show_hand()

    judge(player, dealer)