pokdeng


Namepokdeng JSON
Version 0.0.3 PyPI version JSON
download
home_pagehttps://github.com/papillonbee/pokdeng
Summarypokdeng is a package for simulating rounds of pokdeng games!
upload_time2025-01-25 11:33:39
maintainerNone
docs_urlNone
authorPapan Yongmalwong
requires_python>=3.7
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pokdeng

[pokdeng](https://pypi.org/project/pokdeng/) is a Python package for simulating rounds of pokdeng games!

[Visit repository on Github](https://github.com/papillonbee/pokdeng)

---

## Quick Guide
Create player ```Kanye``` where he will
- place bet amount = 2 if his pocket has a minimum balance of 3 after deducting the bet amount
- draw the third card if his two cards on hand are not two deng or score less than 4
```python
from pokdeng.cardholder import Dealer, Player
from pokdeng.hand import Hand
from pokdeng.game import Game
from pokdeng.pocket import Pocket
from decimal import Decimal

class Kanye(Player):
    def place_bet(self, round: int, pocket: Pocket) -> Decimal:
        bet = Decimal("2")
        if pocket.total_amount - bet >= Decimal("3"):
            return bet
        return None
    def draw_card(self, round: int, pocket: Pocket, hand: Hand) -> bool:
        return hand.deng() != 2 or hand.score() < 4
```

```python
kanye = Kanye()
```

Create player ```Ben``` where he will
- place bet amount = 1 if his pocket has a minimum balance of 0 after deducting the bet amount
- draw the third card if his two cards on hand score lesss than 5

```python
ben = Player()
```

Create dealer ```Anita``` where she will
- fight her two cards on hand with three cards on other player's hands if two deng and score more than 4
- draw the third card if her two cards on hand score less than 3
```python
class Anita(Dealer):
    def two_fight_three(self, round: int, pocket: Pocket, hand: Hand) -> bool:
        return hand.deng() == 2 and hand.score() > 4
    def draw_card(self, round: int, pocket: Pocket, hand: Hand) -> bool:
        return hand.score() < 3
```

```python
anita = Anita()
```

Create dealer ```Dixon``` where he will
- fight his two cards on hand with three cards on other player's hands if score more than 5
- draw the third card if his two cards on hand score less than 5

```python
dixon = Dealer()
```

Create pocket for each dealer/player with some amount where dealer's pocket usually starts with 0 amount while player's pocket starts with positive amount
```python
kanye_pocket = Pocket(kanye.card_holder_id, Decimal(10))
ben_pocket = Pocket(ben.card_holder_id, Decimal(10))
anita_pocket = Pocket(anita.card_holder_id, Decimal(0))
```

Create a collection of pockets by dealer/player
```python
pockets = {pocket.card_holder_id: pocket for pocket in [kanye_pocket, ben_pocket, anita_pocket]}
```

Create a game of 1 dealer, a list of players, and a collection of pockets by dealer/player
```python
game = Game(dealer = anita, players = [kanye, ben], pockets = pockets)
```

Play the game for 200 rounds
```python
game.play(200)
```

Check total amount in each pocket afterwards
```python
[(card_holder_id.value, pocket.total_amount) for card_holder_id, pocket in pockets.items()]
```

Pokdeng is a zero sum game, meaning the total amount of every pockets after each play always sums to the initial total amount of every pockets

---

## Understanding hand comparison rules

```python
from pokdeng.card import Card, Rank, Suit
```

Case #1: JQK same suit (straight flush) ties with TJQ same suit (straight flush)
```python
hand1 = Hand(cards = [Card(Rank.JACK, Suit.CLUB), Card(Rank.KING, Suit.CLUB), Card(Rank.QUEEN, Suit.CLUB)])
hand2 = Hand(cards = [Card(Rank.TEN, Suit.HEART), Card(Rank.JACK, Suit.HEART), Card(Rank.QUEEN, Suit.HEART)])
print(hand1.straight_flush(), hand2.straight_flush()) # True True
print(hand1.score(), hand2.score()) # 0 0
print(hand1.deng(), hand2.deng()) # 5 5
print(hand1 == hand2) # True
```
Case #2: 555 (tong) wins 567 same suit (straight flush)
```python
hand1 = Hand(cards = [Card(Rank.FIVE, Suit.CLUB), Card(Rank.FIVE, Suit.SPADE), Card(Rank.FIVE, Suit.DIAMOND)])
hand2 = Hand(cards = [Card(Rank.FIVE, Suit.HEART), Card(Rank.SIX, Suit.HEART), Card(Rank.SEVEN, Suit.HEART)])
print(hand1.tong(), hand2.tong()) # True False
print(hand1.straight_flush(), hand2.straight_flush()) # False True
print(hand1 > hand2) # True
```
Case #3: KKK (tong) loses 222 (tong)
```python
hand1 = Hand(cards = [Card(Rank.KING, Suit.CLUB), Card(Rank.KING, Suit.SPADE), Card(Rank.KING, Suit.DIAMOND)])
hand2 = Hand(cards = [Card(Rank.TWO, Suit.CLUB), Card(Rank.TWO, Suit.SPADE), Card(Rank.TWO, Suit.HEART)])
print(hand1.tong(), hand2.tong()) # True True
print(hand1.score(), hand2.score()) # 0 6
print(hand1 < hand2) # True
```
Case #4: 345 different suit (straight) wins JJQ (three yellow)
```python
hand1 = Hand(cards = [Card(Rank.THREE, Suit.CLUB), Card(Rank.FOUR, Suit.SPADE), Card(Rank.FIVE, Suit.CLUB)])
hand2 = Hand(cards = [Card(Rank.JACK, Suit.CLUB), Card(Rank.JACK, Suit.SPADE), Card(Rank.QUEEN, Suit.HEART)])
print(hand1.straight(), hand2.straight()) # True False
print(hand1.three_yellow(), hand2.three_yellow()) # False True
print(hand1 > hand2) # True
```
Case #5: KA2 same suit (normal 3 3 deng) loses JJQ (three yellow)
```python
hand1 = Hand(cards = [Card(Rank.KING, Suit.CLUB), Card(Rank.ACE, Suit.CLUB), Card(Rank.TWO, Suit.CLUB)])
hand2 = Hand(cards = [Card(Rank.JACK, Suit.CLUB), Card(Rank.JACK, Suit.SPADE), Card(Rank.QUEEN, Suit.HEART)])
print(hand1.three_yellow(), hand2.three_yellow()) # False True
print(hand1 < hand2) # True
```
Case #6: JQK same suit (straight flush) wins 234 different suit (straight)
```python
hand1 = Hand(cards = [Card(Rank.JACK, Suit.CLUB), Card(Rank.QUEEN, Suit.CLUB), Card(Rank.KING, Suit.CLUB)])
hand2 = Hand(cards = [Card(Rank.TWO, Suit.CLUB), Card(Rank.THREE, Suit.SPADE), Card(Rank.FOUR, Suit.HEART)])
print(hand1.straight_flush(), hand2.straight_flush()) # True False
print(hand1.straight(), hand2.straight()) # True True
print(hand1 > hand2) # True
```
Case #7: KA2 same suit (normal 3 3 deng) loses A25 different suit (normal 8 1 deng)
```python
hand1 = Hand(cards = [Card(Rank.KING, Suit.CLUB), Card(Rank.ACE, Suit.CLUB), Card(Rank.TWO, Suit.CLUB)])
hand2 = Hand(cards = [Card(Rank.ACE, Suit.CLUB), Card(Rank.TWO, Suit.SPADE), Card(Rank.FIVE, Suit.HEART)])
print(hand1.score(), hand2.score()) # 3 8
print(hand1 < hand2) # True
```
Case #8: A2 same suit (normal 3 2 deng) ties with A2T same suit (normal 3 3 deng)
```python
hand1 = Hand(cards = [Card(Rank.ACE, Suit.SPADE), Card(Rank.TWO, Suit.SPADE)])
hand2 = Hand(cards = [Card(Rank.ACE, Suit.HEART), Card(Rank.TEN, Suit.HEART), Card(Rank.TWO, Suit.HEART)])
print(hand1.score(), hand2.score()) # 3 3
print(hand1.deng(), hand2.deng()) # 2 3
print(hand1 == hand2) # True
```
Case #9: A2 different suit (normal 1 deng) wins ATJ different suit (normal 1 deng)
```python
hand1 = Hand(cards = [Card(Rank.ACE, Suit.SPADE), Card(Rank.TWO, Suit.HEART)])
hand2 = Hand(cards = [Card(Rank.ACE, Suit.HEART), Card(Rank.TEN, Suit.HEART), Card(Rank.JACK, Suit.DIAMOND)])
print(hand1.score(), hand2.score()) # 3 1
print(hand1 > hand2) # True
```
Case #10: 45 different suit (pok nine 1 deng) wins 99 (pok eight 2 deng)
```python
hand1 = Hand(cards = [Card(Rank.FIVE, Suit.SPADE), Card(Rank.FOUR, Suit.CLUB)])
hand2 = Hand(cards = [Card(Rank.NINE, Suit.SPADE), Card(Rank.NINE, Suit.DIAMOND)])
print(hand1.pok_nine(), hand2.pok_nine()) # True False
print(hand1.pok_eight(), hand2.pok_eight()) # False True
print(hand1 > hand2) # True
```
Case #11: A67 same suit (normal 4 3 deng) ties with 22 (normal 4 2 deng)
```python
hand1 = Hand(cards = [Card(Rank.ACE, Suit.CLUB), Card(Rank.SIX, Suit.CLUB), Card(Rank.SEVEN, Suit.CLUB)])
hand2 = Hand(cards = [Card(Rank.TWO, Suit.SPADE), Card(Rank.TWO, Suit.HEART)])
print(hand1.score(), hand2.score()) # 4 4
print(hand1.deng(), hand2.deng()) # 3 2
print(hand1 == hand2) # True
```
More cases under ```tests/test_hand.py```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/papillonbee/pokdeng",
    "name": "pokdeng",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": null,
    "author": "Papan Yongmalwong",
    "author_email": "papillonbee@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/c1/5d/53e89dac7d45fceff322c7210a0ddb1b7303c05f6a9059080793ebe6c2f1/pokdeng-0.0.3.tar.gz",
    "platform": null,
    "description": "# pokdeng\n\n[pokdeng](https://pypi.org/project/pokdeng/) is a Python package for simulating rounds of pokdeng games!\n\n[Visit repository on Github](https://github.com/papillonbee/pokdeng)\n\n---\n\n## Quick Guide\nCreate player ```Kanye``` where he will\n- place bet amount = 2 if his pocket has a minimum balance of 3 after deducting the bet amount\n- draw the third card if his two cards on hand are not two deng or score less than 4\n```python\nfrom pokdeng.cardholder import Dealer, Player\nfrom pokdeng.hand import Hand\nfrom pokdeng.game import Game\nfrom pokdeng.pocket import Pocket\nfrom decimal import Decimal\n\nclass Kanye(Player):\n    def place_bet(self, round: int, pocket: Pocket) -> Decimal:\n        bet = Decimal(\"2\")\n        if pocket.total_amount - bet >= Decimal(\"3\"):\n            return bet\n        return None\n    def draw_card(self, round: int, pocket: Pocket, hand: Hand) -> bool:\n        return hand.deng() != 2 or hand.score() < 4\n```\n\n```python\nkanye = Kanye()\n```\n\nCreate player ```Ben``` where he will\n- place bet amount = 1 if his pocket has a minimum balance of 0 after deducting the bet amount\n- draw the third card if his two cards on hand score lesss than 5\n\n```python\nben = Player()\n```\n\nCreate dealer ```Anita``` where she will\n- fight her two cards on hand with three cards on other player's hands if two deng and score more than 4\n- draw the third card if her two cards on hand score less than 3\n```python\nclass Anita(Dealer):\n    def two_fight_three(self, round: int, pocket: Pocket, hand: Hand) -> bool:\n        return hand.deng() == 2 and hand.score() > 4\n    def draw_card(self, round: int, pocket: Pocket, hand: Hand) -> bool:\n        return hand.score() < 3\n```\n\n```python\nanita = Anita()\n```\n\nCreate dealer ```Dixon``` where he will\n- fight his two cards on hand with three cards on other player's hands if score more than 5\n- draw the third card if his two cards on hand score less than 5\n\n```python\ndixon = Dealer()\n```\n\nCreate pocket for each dealer/player with some amount where dealer's pocket usually starts with 0 amount while player's pocket starts with positive amount\n```python\nkanye_pocket = Pocket(kanye.card_holder_id, Decimal(10))\nben_pocket = Pocket(ben.card_holder_id, Decimal(10))\nanita_pocket = Pocket(anita.card_holder_id, Decimal(0))\n```\n\nCreate a collection of pockets by dealer/player\n```python\npockets = {pocket.card_holder_id: pocket for pocket in [kanye_pocket, ben_pocket, anita_pocket]}\n```\n\nCreate a game of 1 dealer, a list of players, and a collection of pockets by dealer/player\n```python\ngame = Game(dealer = anita, players = [kanye, ben], pockets = pockets)\n```\n\nPlay the game for 200 rounds\n```python\ngame.play(200)\n```\n\nCheck total amount in each pocket afterwards\n```python\n[(card_holder_id.value, pocket.total_amount) for card_holder_id, pocket in pockets.items()]\n```\n\nPokdeng is a zero sum game, meaning the total amount of every pockets after each play always sums to the initial total amount of every pockets\n\n---\n\n## Understanding hand comparison rules\n\n```python\nfrom pokdeng.card import Card, Rank, Suit\n```\n\nCase #1: JQK same suit (straight flush) ties with TJQ same suit (straight flush)\n```python\nhand1 = Hand(cards = [Card(Rank.JACK, Suit.CLUB), Card(Rank.KING, Suit.CLUB), Card(Rank.QUEEN, Suit.CLUB)])\nhand2 = Hand(cards = [Card(Rank.TEN, Suit.HEART), Card(Rank.JACK, Suit.HEART), Card(Rank.QUEEN, Suit.HEART)])\nprint(hand1.straight_flush(), hand2.straight_flush()) # True True\nprint(hand1.score(), hand2.score()) # 0 0\nprint(hand1.deng(), hand2.deng()) # 5 5\nprint(hand1 == hand2) # True\n```\nCase #2: 555 (tong) wins 567 same suit (straight flush)\n```python\nhand1 = Hand(cards = [Card(Rank.FIVE, Suit.CLUB), Card(Rank.FIVE, Suit.SPADE), Card(Rank.FIVE, Suit.DIAMOND)])\nhand2 = Hand(cards = [Card(Rank.FIVE, Suit.HEART), Card(Rank.SIX, Suit.HEART), Card(Rank.SEVEN, Suit.HEART)])\nprint(hand1.tong(), hand2.tong()) # True False\nprint(hand1.straight_flush(), hand2.straight_flush()) # False True\nprint(hand1 > hand2) # True\n```\nCase #3: KKK (tong) loses 222 (tong)\n```python\nhand1 = Hand(cards = [Card(Rank.KING, Suit.CLUB), Card(Rank.KING, Suit.SPADE), Card(Rank.KING, Suit.DIAMOND)])\nhand2 = Hand(cards = [Card(Rank.TWO, Suit.CLUB), Card(Rank.TWO, Suit.SPADE), Card(Rank.TWO, Suit.HEART)])\nprint(hand1.tong(), hand2.tong()) # True True\nprint(hand1.score(), hand2.score()) # 0 6\nprint(hand1 < hand2) # True\n```\nCase #4: 345 different suit (straight) wins JJQ (three yellow)\n```python\nhand1 = Hand(cards = [Card(Rank.THREE, Suit.CLUB), Card(Rank.FOUR, Suit.SPADE), Card(Rank.FIVE, Suit.CLUB)])\nhand2 = Hand(cards = [Card(Rank.JACK, Suit.CLUB), Card(Rank.JACK, Suit.SPADE), Card(Rank.QUEEN, Suit.HEART)])\nprint(hand1.straight(), hand2.straight()) # True False\nprint(hand1.three_yellow(), hand2.three_yellow()) # False True\nprint(hand1 > hand2) # True\n```\nCase #5: KA2 same suit (normal 3 3 deng) loses JJQ (three yellow)\n```python\nhand1 = Hand(cards = [Card(Rank.KING, Suit.CLUB), Card(Rank.ACE, Suit.CLUB), Card(Rank.TWO, Suit.CLUB)])\nhand2 = Hand(cards = [Card(Rank.JACK, Suit.CLUB), Card(Rank.JACK, Suit.SPADE), Card(Rank.QUEEN, Suit.HEART)])\nprint(hand1.three_yellow(), hand2.three_yellow()) # False True\nprint(hand1 < hand2) # True\n```\nCase #6: JQK same suit (straight flush) wins 234 different suit (straight)\n```python\nhand1 = Hand(cards = [Card(Rank.JACK, Suit.CLUB), Card(Rank.QUEEN, Suit.CLUB), Card(Rank.KING, Suit.CLUB)])\nhand2 = Hand(cards = [Card(Rank.TWO, Suit.CLUB), Card(Rank.THREE, Suit.SPADE), Card(Rank.FOUR, Suit.HEART)])\nprint(hand1.straight_flush(), hand2.straight_flush()) # True False\nprint(hand1.straight(), hand2.straight()) # True True\nprint(hand1 > hand2) # True\n```\nCase #7: KA2 same suit (normal 3 3 deng) loses A25 different suit (normal 8 1 deng)\n```python\nhand1 = Hand(cards = [Card(Rank.KING, Suit.CLUB), Card(Rank.ACE, Suit.CLUB), Card(Rank.TWO, Suit.CLUB)])\nhand2 = Hand(cards = [Card(Rank.ACE, Suit.CLUB), Card(Rank.TWO, Suit.SPADE), Card(Rank.FIVE, Suit.HEART)])\nprint(hand1.score(), hand2.score()) # 3 8\nprint(hand1 < hand2) # True\n```\nCase #8: A2 same suit (normal 3 2 deng) ties with A2T same suit (normal 3 3 deng)\n```python\nhand1 = Hand(cards = [Card(Rank.ACE, Suit.SPADE), Card(Rank.TWO, Suit.SPADE)])\nhand2 = Hand(cards = [Card(Rank.ACE, Suit.HEART), Card(Rank.TEN, Suit.HEART), Card(Rank.TWO, Suit.HEART)])\nprint(hand1.score(), hand2.score()) # 3 3\nprint(hand1.deng(), hand2.deng()) # 2 3\nprint(hand1 == hand2) # True\n```\nCase #9: A2 different suit (normal 1 deng) wins ATJ different suit (normal 1 deng)\n```python\nhand1 = Hand(cards = [Card(Rank.ACE, Suit.SPADE), Card(Rank.TWO, Suit.HEART)])\nhand2 = Hand(cards = [Card(Rank.ACE, Suit.HEART), Card(Rank.TEN, Suit.HEART), Card(Rank.JACK, Suit.DIAMOND)])\nprint(hand1.score(), hand2.score()) # 3 1\nprint(hand1 > hand2) # True\n```\nCase #10: 45 different suit (pok nine 1 deng) wins 99 (pok eight 2 deng)\n```python\nhand1 = Hand(cards = [Card(Rank.FIVE, Suit.SPADE), Card(Rank.FOUR, Suit.CLUB)])\nhand2 = Hand(cards = [Card(Rank.NINE, Suit.SPADE), Card(Rank.NINE, Suit.DIAMOND)])\nprint(hand1.pok_nine(), hand2.pok_nine()) # True False\nprint(hand1.pok_eight(), hand2.pok_eight()) # False True\nprint(hand1 > hand2) # True\n```\nCase #11: A67 same suit (normal 4 3 deng) ties with 22 (normal 4 2 deng)\n```python\nhand1 = Hand(cards = [Card(Rank.ACE, Suit.CLUB), Card(Rank.SIX, Suit.CLUB), Card(Rank.SEVEN, Suit.CLUB)])\nhand2 = Hand(cards = [Card(Rank.TWO, Suit.SPADE), Card(Rank.TWO, Suit.HEART)])\nprint(hand1.score(), hand2.score()) # 4 4\nprint(hand1.deng(), hand2.deng()) # 3 2\nprint(hand1 == hand2) # True\n```\nMore cases under ```tests/test_hand.py```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "pokdeng is a package for simulating rounds of pokdeng games!",
    "version": "0.0.3",
    "project_urls": {
        "Homepage": "https://github.com/papillonbee/pokdeng"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "54eb0dbe2e52540a541fe6e41a532a346f66388d033c8e98786bb654b4319711",
                "md5": "9987dfc61f26f224c04f98c476d7526d",
                "sha256": "23dfea2a8cb94394442033a79e4c3576d5cd5847ef16d455b334edd0acf875ba"
            },
            "downloads": -1,
            "filename": "pokdeng-0.0.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9987dfc61f26f224c04f98c476d7526d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 8378,
            "upload_time": "2025-01-25T11:15:05",
            "upload_time_iso_8601": "2025-01-25T11:15:05.135111Z",
            "url": "https://files.pythonhosted.org/packages/54/eb/0dbe2e52540a541fe6e41a532a346f66388d033c8e98786bb654b4319711/pokdeng-0.0.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c15d53e89dac7d45fceff322c7210a0ddb1b7303c05f6a9059080793ebe6c2f1",
                "md5": "511b796713635f69efa4b9747d01523e",
                "sha256": "fbb8719389d56f2d4b91afc5a1abb92b98dd1ea9aa9ea4c46076f9dcff1e8595"
            },
            "downloads": -1,
            "filename": "pokdeng-0.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "511b796713635f69efa4b9747d01523e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 15635,
            "upload_time": "2025-01-25T11:33:39",
            "upload_time_iso_8601": "2025-01-25T11:33:39.147153Z",
            "url": "https://files.pythonhosted.org/packages/c1/5d/53e89dac7d45fceff322c7210a0ddb1b7303c05f6a9059080793ebe6c2f1/pokdeng-0.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-25 11:33:39",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "papillonbee",
    "github_project": "pokdeng",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pokdeng"
}
        
Elapsed time: 0.35660s