Ejemplo n.º 1
0
def test_compare_cards_normal_usage():
    assert cards.compare_cards((4,), (7,)) == 1
    assert cards.compare_cards((9,), (7,)) == -1
    assert cards.compare_cards((5,), (5,)) == 0
    assert cards.compare_cards((1,), (5,)) == -1
    assert cards.compare_cards((13,), (1,)) == 1
    assert cards.compare_cards((1,), (1,)) == 0
Ejemplo n.º 2
0
def test_compare_cards_normal_usage():
    assert cards.compare_cards((4, ), (7, )) == 1
    assert cards.compare_cards((9, ), (7, )) == -1
    assert cards.compare_cards((5, ), (5, )) == 0
    assert cards.compare_cards((1, ), (5, )) == -1
    assert cards.compare_cards((13, ), (1, )) == 1
    assert cards.compare_cards((1, ), (1, )) == 0
Ejemplo n.º 3
0
def play_turn(human, cpu, pot):
    #global TOTAL_TURNS
    #TOTAL_TURNS += 1
    (h_hand, h_reserve) = flip_if_needed(human)
    (c_hand, c_reserve) = flip_if_needed(cpu)

    h_card = cards.pull_top(h_hand)
    c_card = cards.pull_top(c_hand)
    pot.extend([h_card, c_card])

    h_pic = interface.pic_repr(h_card)
    c_pic = interface.pic_repr(c_card)
    for (h_line, c_line) in zip(h_pic, c_pic):
        print("{}\t\t\t{}".format(h_line, c_line))
    print("You play the above \tComputer plays the above")

    winner = cards.compare_cards(h_card, c_card)
    if winner == -1:  # Human wins
        print("{} > {} --- You win this round.".format(h_card, c_card))
        print("You win {} cards!".format(len(pot)))
        #print(" WIN", end="")
        h_reserve.extend(pot)

    elif winner == 1:  # Computer wins
        print("{} > {} --- You lose this round.".format(c_card, h_card))
        print("You lose {} cards!".format(len(pot)))
        #print("LOSE", end="")
        c_reserve.extend(pot)

    elif winner == 0:  # A tie; a cause for WAR!
        print("There is a tie.")
        print("Declare War!")
        interface.wait_for_input()
        #print(" TIE", end="\n")

        (h_hand, h_reserve) = flip_if_needed((h_hand, h_reserve), n=3)
        (c_hand, c_reserve) = flip_if_needed((c_hand, c_reserve), n=3)

        pot.extend(cards.pull_three(h_hand))
        pot.extend(cards.pull_three(c_hand))

        # Weeeee, recursion!
        ((h_hand, h_reserve), (c_hand, c_reserve)) = play_turn(
            (h_hand, h_reserve), (c_hand, c_reserve), pot)

    return ((h_hand, h_reserve), (c_hand, c_reserve))
Ejemplo n.º 4
0
def play_turn(human, cpu, pot):
    # global TOTAL_TURNS
    # TOTAL_TURNS += 1
    (h_hand, h_reserve) = flip_if_needed(human)
    (c_hand, c_reserve) = flip_if_needed(cpu)

    h_card = cards.pull_top(h_hand)
    c_card = cards.pull_top(c_hand)
    pot.extend([h_card, c_card])

    h_pic = interface.pic_repr(h_card)
    c_pic = interface.pic_repr(c_card)
    for (h_line, c_line) in zip(h_pic, c_pic):
        print("{}\t\t\t{}".format(h_line, c_line))
    print("You play the above \tComputer plays the above")

    winner = cards.compare_cards(h_card, c_card)
    if winner == -1:  # Human wins
        print("{} > {} --- You win this round.".format(h_card, c_card))
        print("You win {} cards!".format(len(pot)))
        # print(" WIN", end="")
        h_reserve.extend(pot)

    elif winner == 1:  # Computer wins
        print("{} > {} --- You lose this round.".format(c_card, h_card))
        print("You lose {} cards!".format(len(pot)))
        # print("LOSE", end="")
        c_reserve.extend(pot)

    elif winner == 0:  # A tie; a cause for WAR!
        print("There is a tie.")
        print("Declare War!")
        interface.wait_for_input()
        # print(" TIE", end="\n")

        (h_hand, h_reserve) = flip_if_needed((h_hand, h_reserve), n=3)
        (c_hand, c_reserve) = flip_if_needed((c_hand, c_reserve), n=3)

        pot.extend(cards.pull_three(h_hand))
        pot.extend(cards.pull_three(c_hand))

        # Weeeee, recursion!
        ((h_hand, h_reserve), (c_hand, c_reserve)) = play_turn((h_hand, h_reserve), (c_hand, c_reserve), pot)

    return ((h_hand, h_reserve), (c_hand, c_reserve))