Exemplo n.º 1
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))
Exemplo n.º 2
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))
Exemplo n.º 3
0
def test_pull_top_error():
    with pytest.raises(cards.OutOfCardsError):
        cards.pull_three([(3,)])
Exemplo n.º 4
0
def test_pull_top_three():
    deck = [(2,), (5,), (11,)]
    cs = cards.pull_three(deck)
    assert len(deck) == 0
    assert type(cs) is list
    assert cs == [(11,), (5,), (2,)]
Exemplo n.º 5
0
def test_pull_top_error():
    with pytest.raises(cards.OutOfCardsError):
        cards.pull_three([(3, )])
Exemplo n.º 6
0
def test_pull_top_three():
    deck = [(2, ), (5, ), (11, )]
    cs = cards.pull_three(deck)
    assert len(deck) == 0
    assert type(cs) is list
    assert cs == [(11, ), (5, ), (2, )]