コード例 #1
0
ファイル: main.py プロジェクト: JoieDFW/wargame
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))
コード例 #2
0
ファイル: main.py プロジェクト: JoieDFW/wargame
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))
コード例 #3
0
ファイル: main.py プロジェクト: JoieDFW/wargame
def main(human, cpu):
    """Run the game."""

    while True:
        # print("\tTOTALS\t\tH {} + {}  \tC {} + {}".format(
        #    len(human[0]), len(human[1]), len(cpu[0]), len(cpu[1])))

        try:
            (human, cpu) = play_turn(human, cpu, [])
        except cards.OutOfCardsError:
            break

        interface.wait_for_input(DISABLE_WAIT)  # Set at the top of the script

    if len(human[0]) > len(cpu[0]):
        print("You win! Well done!")
        return True
    else:
        print("Sorry, you lost!")
        return False
コード例 #4
0
ファイル: main.py プロジェクト: JoieDFW/wargame
def main(human, cpu):
    """Run the game."""

    while True:
        #print("\tTOTALS\t\tH {} + {}  \tC {} + {}".format(
        #    len(human[0]), len(human[1]), len(cpu[0]), len(cpu[1])))

        try:
            (human, cpu) = play_turn(human, cpu, [])
        except cards.OutOfCardsError:
            break

        interface.wait_for_input(DISABLE_WAIT)  # Set at the top of the script

    if len(human[0]) > len(cpu[0]):
        print("You win! Well done!")
        return True
    else:
        print("Sorry, you lost!")
        return False
コード例 #5
0
ファイル: test_interface.py プロジェクト: JoieDFW/wargame
def test_wait_disabling():
    interface.wait_for_input(disabled=True)
    assert "If we reach this point it works!"
コード例 #6
0
ファイル: test_interface.py プロジェクト: JoieDFW/wargame
def test_wait_disabling():
    interface.wait_for_input(disabled=True)
    assert "If we reach this point it works!"
コード例 #7
0
ファイル: main.py プロジェクト: JoieDFW/wargame
        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))


if __name__ == "__main__":

    deck = cards.create_deck()
    deck = cards.shuffle_cards(deck)
    (h_hand, c_hand) = cards.deal_cards(deck)

    interface.wait_for_input(DISABLE_WAIT)
    won = main((h_hand, []), (c_hand, []))
コード例 #8
0
ファイル: main.py プロジェクト: JoieDFW/wargame
        #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))


if __name__ == '__main__':

    deck = cards.create_deck()
    deck = cards.shuffle_cards(deck)
    (h_hand, c_hand) = cards.deal_cards(deck)

    interface.wait_for_input(DISABLE_WAIT)
    won = main((h_hand, []), (c_hand, []))