Skip to content
This repository was archived by the owner on Jul 16, 2024. It is now read-only.

Short script to play a round but choosing each player's cards and the community cards ourselves #148

@jaimeggb

Description

@jaimeggb

Is your feature request related to a problem? Please describe.
I would like to be able to play a round of poker but choosing each player's cards and the community cards myself. Currently I am only able to play a round of poker with random players doing random actions getting random cards which I cannot see, by using the script in the README.md file titled "Playing a game of poker"

Describe the solution you'd like
A short script like the following one (copied from the project README.md file) but which doesn't just call: engine.play_one_round(). One that is more fine grained, so that we can choose the cards for each player, the chips they have at the start of the round, and the community cards that appear.

import utils
from poker_ai.poker.random_player import RandomPlayer
from poker_ai.poker.table import PokerTable
from poker_ai.poker.engine import PokerEngine
from poker_ai.poker.pot import Pot

# Seed so things are deterministic.
utils.random.seed(42)

# Some settings for the amount of chips.
initial_chips_amount = 10000
small_blind_amount = 50
big_blind_amount = 100

# Create the pot.
pot = Pot()
# Instanciate six players that will make random moves, make sure 
# they can reference the pot so they can add chips to it.
players = [
    RandomPlayer(
        name=f'player {player_i}',
        initial_chips=initial_chips_amount,
        pot=pot)
    for player_i in range(6)
]
# Create the table with the players on it.
table = PokerTable(players=players, pot=pot)
# Create the engine that will manage the poker game lifecycle.
engine = PokerEngine(
    table=table,
    small_blind=small_blind_amount,
    big_blind=big_blind_amount)
# Play a round of Texas Hold'em Poker!
engine.play_one_round()

Describe alternatives you've considered
I've tried implementing card picking by changing the pick function in the deck.py file, but it did not work for me, don't know why. Where I implemented input('Pick a card:') doesn't seem to work because I do not get prompted to pick cards when I run the round.

    def pick(self, random: int = 0) -> Card:
        """Return a card from the deck.

        Parameters
        ----------
        random : int
            If this is 0, return a completely random card, else return the
            next card in the deck (1), else you pick (2)

        Returns
        -------
        card : Card
            The card that was picked.
        """
        if not len(self._cards_in_deck):
            raise ValueError("Deck is empty - please use Deck.reset()")
        elif 0:
            index: int = np.random.randint(len(self._cards_in_deck), size=None)
        elif 1:
            index: int = len(self._cards_in_deck) - 1
        elif 2:
            index: int = self._cards_in_deck.index(input('Pick a card:'))
        card: Card = self._cards_in_deck.pop(index)
        self._dealt_cards.append(card)
        return card

Metadata

Metadata

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions