コード例 #1
0
def assess_hand(player):
    hand = player.hand
    # 21
    if hand.get_total() == 21:
        hand.is_21 = True
        # blackjack
        if cards.count(hand) == 2 and \
           hand[0].rank >= 10 and hand[1].rank == 1 or \
           hand[1].rank >= 10 and hand[0].rank == 1:
            hand.is_blackjack = True
            log("%s has blackjack!" % player.name)
    # splittable
    if not player.is_dealer and cards.count(hand) == 2 and \
       hand[0].rank == hand[1].rank and not hand.is_split:
        hand.is_splittable = True
    # doublable
    if not player.is_dealer and not hand.is_21 and \
       cards.count(hand) == 2 and player.cash >= player.bet and \
       not hand.is_doubled:
        hand.is_doublable = True
    # hittable / standable
    if hand.get_total() < 21 and not hand.is_doubled:
        hand.is_hittable = True
        hand.is_standable = True
    else:
        hand.is_hittable = False
        hand.is_standable = False
        # bust
        if hand.get_total() > 21:
            hand.is_bust = True
            log("%s is bust!" % player.name)
コード例 #2
0
def test_delete(db_non_empty):
    # GIVEN a non empty db
    a_card = cards.list_cards()[0]
    id = a_card.id
    count_before = cards.count()

    # WHEN we delete one item
    cards.delete_card(id)
    count_after = cards.count()

    # THEN the card is no longer in the db
    all_cards = cards.list_cards()
    assert a_card not in all_cards
    assert count_after == count_before - 1
コード例 #3
0
def count(
    noowner: bool = typer.Option(
        None,
        "-n",
        "--noowner",
        "--no-owner",
        help="count cards without owners",
    ),
    owner: str = typer.Option(
        None,
        "-o",
        "--owner",
        help="count cards with given owner",
    ),
    priority: int = typer.Option(
        None,
        "-p",
        "--priority",
        help="count cards with given priority",
    ),
    done: bool = typer.Option(
        None,
        "-d",
        "--done",
        help="count cards with given done state (True or False)",
    ),
):
    """Return number of cards in db."""
    set_cards_db_path()
    print(cards.count(noowner, owner, priority, done))
コード例 #4
0
async def pokemon(ctx, *args):
    member = ctx.message.author
    print(member)
    if args[0] == "new":
        pass
        # response = rpg.new_user(member)
        # print(response)
    await ctx.send(cards.count())
コード例 #5
0
def test_delete_all(db_non_empty):
    # GIVEN a non empty db

    # WHEN we delete_all()
    cards.delete_all()

    # THEN the count is 0
    count = cards.count()
    assert count == 0
コード例 #6
0
def test_add_card(db_empty):
    c = Card(summary="something", owner="okken")
    id = cards.add_card(c)
    assert id is not None
    assert cards.count() == 1
コード例 #7
0
async def deckStatus(ctx):
    await ctx.send(cards.count())
コード例 #8
0
def main(stdscr):
    init(stdscr)

    n_players = 1
    game_over = False

    players = [Player() for x in range(n_players)]
    dealer = Player()
    dealer.is_dealer = True
    dealer.name = "Dealer"

    players[0].name = "Player 1"
    players[0].starting_cash = 100000
    players[0].cash = players[0].starting_cash
    # players[1].name = "Player 2"
    # players[1].starting_cash = 5000
    # players[1].cash = players[1].starting_cash

    deck = cards.Deck()
    cards.shuffle(deck)
    discard_pile = []

    # Tests --------------------------------------------------------- |

    # deck[51] = cards.Card(10, 1)    # player 1
    # deck[50] = cards.Card(8, 2)     # player 2
    # deck[49] = cards.Card(11, 3)    # dealer
    # deck[48] = cards.Card(5, 1)     # player 1
    # deck[47] = cards.Card(8, 2)     # player 2
    # deck[46] = cards.Card(1, 3)     # dealer

    # ----------------------------------------------------------------|

    while not game_over:

        round_over = False
        print_deck(deck)

        # Get bets
        for player in players:

            clear_options()

            if player.cash > 0:
                option_list[0] = "(B)et"
                if player.bet > 0:
                    option_list[0] = "(N)ew Bet"
                    option_list[1] = "(B)et Again"
                if player.bet != max_bet and player.bet != player.cash:
                    option_list[2] = "(M)ax Bet"
                option_list[3] = "(C)ash Out"
                print_options()

                print_player_details(player)
                log("%s, place a bet or cash out:" % player.name)
                log(
                    "(Table limits: £%s to £%s)" %
                    ("{:,}".format(min_bet), "{:,}".format(max_bet)), False)

                valid_input = False
                while not valid_input:
                    input = stdscr.getkey()
                    if input == "B" or input == "b" and player.bet == 0:
                        valid_input = get_bet(player)
                    elif input == "N" or input == "n" and player.bet > 0:
                        valid_input = get_bet(player)
                    elif input == "B" or input == "b" and player.bet > 0:
                        valid_input = get_last_bet(player)
                    elif input == "M" or input == "m" and player.bet != max_bet:
                        valid_input = get_max_bet(player)
                    elif input == "C" or input == "c":
                        log("%s cashes out" % player.name)
                        print_exit_status(player)
                        player.is_playing = False
                        valid_input = True
                        stdscr.getkey()
            else:
                log("Thanks for playing, %s!" % player.name)
                print_exit_status(player)
                player.is_playing = False

        # End game if all cashed out
        playing_count = 0
        for player in players:
            if player.is_playing:
                playing_count += 1
        if playing_count == 0:
            game_over = True

        # Play round
        if not game_over:

            clear_card_windows()
            # Deal initial cards
            log("Dealing cards...")
            for i in range(2):
                for player in players:
                    deal_card(deck, player, False)
                    print_player_details(player)
                deal_card(deck, dealer, False)

            if dealer.hand[1].rank == 1:
                dealer.hand.is_insurable = True

            while not round_over:

                for player in players:

                    print_player_details(player)
                    update_hand_windows(player)
                    player.turn_active = True
                    log("Waiting on %s" % player.name)

                    while player.turn_active:

                        assess_hand(player)

                        clear_options()
                        if player.hand.is_hittable:
                            option_list[0] = "(H)it"
                            option_list[1] = "(S)tand"
                            if player.hand.is_doublable:
                                option_list[2] = "(D)ouble"
                            if player.hand.is_splittable:
                                option_list[3] = "S(p)lit"
                            if dealer.hand.is_insurable and not player.is_insured and \
                               player.cash >= player.bet and cards.count(player.hand) == 2:
                                option_list[4] = "(I)nsurance"
                            print_options()

                            valid_input = False
                            while not valid_input:
                                input = stdscr.getkey()

                                if input == "H" or input == "h" and player.hand.is_hittable:
                                    deal_card(deck, player)
                                    valid_input = True
                                elif input == "S" or input == "s" and player.hand.is_standable:
                                    log("%s stands on %d" %
                                        (player.name, player.hand.get_total()))
                                    player.turn_active = False
                                    valid_input = True
                                elif input == "D" or input == "d" and player.hand.is_doublable:
                                    double_down(player)
                                    deal_card(deck, player)
                                    valid_input = True
                                elif input == "P" or input == "p" and player.hand.is_splittable:
                                    pass
                                elif input == "I" or input == "i" and dealer.hand.is_insurable and \
                                   not player.is_insured and player.cash >= player.bet:
                                    buy_insurance(player)
                                    valid_input = True
                        else:
                            if not player.hand.is_blackjack and not player.hand.is_bust:
                                log("%s has %d" %
                                    (player.name, player.hand.get_total()))
                            player.turn_active = False

                dealer.turn_active = True
                update_hand_windows(dealer)

                while dealer.turn_active:

                    assess_hand(dealer)

                    if dealer.hand.get_total() < 17:
                        deal_card(deck, dealer)
                    else:
                        if not dealer.hand.is_blackjack and not dealer.hand.is_bust:
                            log("Dealer has %d" % dealer.hand.get_total())
                        dealer.turn_active = False

                round_over = True

            # Calculate outcome and payout bets
            for player in players:
                calc_outcome(player, dealer)
                payout(player)

            # Discard and reset hands
            for player in players:
                for i in range(cards.count(player.hand)):
                    discard_pile.append(player.hand.pop())
                player.hand.reset()
            for i in range(cards.count(dealer.hand)):
                discard_pile.append(dealer.hand.pop())
            dealer.hand.reset()
コード例 #9
0
def print_deck(deck):
    window = window_dict["deck"]
    if cards.count(deck) > 0:
        print_card_rear(window)
    window.refresh()
コード例 #10
0
def test_count(db_empty):
    some_cards = [Card(summary='one'), Card(summary='two')]
    for c in some_cards:
        cards.add_card(c)

    assert cards.count() == 2
コード例 #11
0
def test_count_owner(four_items):
    assert cards.count(owner="brian") == 2
コード例 #12
0
def test_count_no_owner(four_items):
    assert cards.count(noowner=True) == 1
コード例 #13
0
def test_count(db_empty):
    some_cards = [Card(summary="one"), Card(summary="two")]
    for c in some_cards:
        cards.add_card(c)

    assert cards.count() == 2
コード例 #14
0
def test_add_card(db_empty):
    c = Card(summary='something', owner='okken')
    id = cards.add_card(c)
    assert id is not None
    assert cards.count() == 1
コード例 #15
0
ファイル: cli.py プロジェクト: kpinjari/cards
def count(noowner, owner, priority, done):
    """Return number of cards in db."""
    set_cards_db_path()
    print(cards.count(noowner, owner, priority, done))
コード例 #16
0
def test_count_not_done(four_items):
    assert cards.count(done=False) == 3
コード例 #17
0
def test_count_done(four_items):
    assert cards.count(done=True) == 2