Skip to content

Instantly share code, notes, and snippets.

@deliciousreya
Last active December 18, 2018 04:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deliciousreya/9e9eb65dddcd1494c71dc8c43bad8ca3 to your computer and use it in GitHub Desktop.
Save deliciousreya/9e9eb65dddcd1494c71dc8c43bad8ca3 to your computer and use it in GitHub Desktop.
Index: bot.py
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- bot.py (revision 2507e76be5518920914dc84a18a274aeb93b8fad)
+++ bot.py (revision 84e64add528e142960fedf18e9c36973c79612a6)
@@ -4,7 +4,7 @@
import discord
-from game import Game, GAME_OPTIONS, GameState
+from game import Game, GAME_OPTIONS, GameState, as_height
POKER_BOT_TOKEN = os.getenv("POKER_BOT_TOKEN")
@@ -116,7 +116,7 @@
f"{game.current_player.user.name}'s turn."]
elif game.current_player.cur_bet != game.cur_bet:
return [f"You can't check, {message.author.name} because you need to "
- f"put in ${game.cur_bet - game.current_player.cur_bet} to "
+ f"put in {as_height(game.cur_bet - game.current_player.cur_bet)} to "
"call."]
else:
return game.check()
@@ -141,15 +141,16 @@
if len(tokens) < 2:
return [f"Please follow !raise with the amount that you would "
"like to raise it by."]
+ amount_str = tokens[1]
try:
- amount = int(tokens[1])
+ amount = int(amount_str)
if game.cur_bet >= game.current_player.max_bet:
- return ["You don't have enough money to raise the current bet "
- f"of ${game.cur_bet}."]
+ return ["You aren't tall enough to raise the current bet "
+ f"of {as_height(game.cur_bet)}."]
elif game.cur_bet + amount > game.current_player.max_bet:
- return [f"You don't have enough money to raise by ${amount}.",
+ return [f"You aren't tall enough to raise by {as_height(amount)}.",
"The most you can raise it by is "
- f"${game.current_player.max_bet - game.cur_bet}."]
+ f"{as_height(game.current_player.max_bet - game.cur_bet)}."]
return game.raise_bet(amount)
except ValueError:
return ["Please follow !raise with an integer. "
@@ -225,9 +226,9 @@
# the current chip standings.
def chip_count(game: Game, message: discord.Message) -> List[str]:
if game.state in (GameState.NO_GAME, GameState.WAITING):
- return ["You can't request a chip count because the game "
+ return ["You can't request a height count because the game "
"hasn't started yet."]
- return [f"{player.user.name} has ${player.balance}."
+ return [f"{game.list_player_balance(player)}."
for player in game.players]
# Handles a player going all-in, returning an error message if the player
@@ -266,7 +267,7 @@
call_bet),
'!raise': Command('Increase the size of current bet',
raise_bet),
- '!check': Command('Bet no money',
+ '!check': Command('Bet no height',
check),
'!fold': Command('Discard your hand and forfeit the pot',
fold_hand),
@@ -276,9 +277,9 @@
show_options),
'!set': Command('Set the value of an option',
set_option),
- '!count': Command('Shows how many chips each player has left',
+ '!count': Command('Shows how tall each player is',
chip_count),
- '!all-in': Command('Bets the entirety of your remaining chips',
+ '!all-in': Command('Bets your entire self',
all_in),
}
Index: game.py
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- game.py (revision 2507e76be5518920914dc84a18a274aeb93b8fad)
+++ game.py (revision 84e64add528e142960fedf18e9c36973c79612a6)
@@ -1,6 +1,7 @@
from collections import namedtuple
from datetime import datetime, timedelta
from enum import Enum
+from math import floor, ceil
from typing import Dict, List
import discord
@@ -12,10 +13,11 @@
Option = namedtuple("Option", ["description", "default"])
GAME_OPTIONS: Dict[str, Option] = {
- "blind": Option("The current price of the small blind", 5),
- "buy-in": Option("The amount of money all players start out with", 500),
+ "blind": Option("The current price of the small blind", 25),
+ "buy-in": Option("The amount of height (above the minimum) all players start out with", 1500),
"raise-delay": Option("The number of minutes before blinds double", 30),
- "starting-blind": Option("The starting price of the small blind", 5)
+ "starting-blind": Option("The starting price of the small blind", 25),
+ "minimum-height": Option("The height below which you have no choice but to go all in", 200),
}
# An enumeration that says what stage of the game we've reached
@@ -35,6 +37,21 @@
# We just dealt the river
RIVER_DEALT = 7
+
+def as_height(mm):
+ inches = int(round(mm / 25.4))
+ if mm == 0:
+ return '0mm (0")'
+ elif inches < 1:
+ return f'{mm}mm (less than an inch)'
+ elif inches < 12:
+ return f'{mm}mm ({inches}")'
+ else:
+ feet = int(floor(inches / 12))
+ inches = int(inches % 12)
+ return f'{mm}mm ({feet}\'{inches}")'
+
+
# A class that keeps track of all the information having to do with a game
class Game:
def __init__(self) -> None:
@@ -100,11 +117,17 @@
if self.turn_index >= len(self.in_hand):
self.turn_index = 0
+ def list_player_balance(self, player):
+ total_height_mm = player.balance + self.options["minimum-height"]
+ return (
+ f"{player.user.name} is currently {as_height(total_height_mm)}, "
+ f"with {as_height(player.balance)} to spare.")
+
# Returns some messages to update the players on the state of the game
def status_between_rounds(self) -> List[str]:
messages = []
for player in self.players:
- messages.append(f"{player.user.name} has ${player.balance}.")
+ messages.append(self.list_player_balance(player))
messages.append(f"{self.dealer.user.name} is the current dealer. "
"Message !deal to deal when you're ready.")
return messages
@@ -205,16 +228,16 @@
self.first_bettor = self.dealer_index - 1
messages.append(f"{small_player.name} has paid the small blind "
- f"of ${blind}.")
+ f"of {as_height(blind)}.")
if self.pot.pay_blind(small_player, blind):
- messages.append(f"{small_player.name} is all in!")
+ messages.append(f"{small_player.name} is putting themself on the line!")
self.leave_hand(small_player)
messages.append(f"{big_player.name} has paid the big blind "
- f"of ${blind * 2}.")
+ f"of {as_height(blind * 2)}.")
if self.pot.pay_blind(big_player, blind * 2):
- messages.append(f"{big_player.name} is all in!")
+ messages.append(f"{big_player.name} is putting themself on the line!")
self.leave_hand(big_player)
return messages
@@ -222,15 +245,14 @@
# Returns messages telling the current player their options
def cur_options(self) -> List[str]:
messages = [f"It is {self.current_player.name}'s turn. "
- f"{self.current_player.user.name} currently has "
- f"${self.current_player.balance}. "
- f"The pot is currently ${self.pot.value}."]
+ f"{self.list_player_balance(self.current_player)} "
+ f"The pot is currently {as_height(self.pot.value)}."]
if self.pot.cur_bet > 0:
- messages.append(f"The current bet to meet is ${self.cur_bet}, "
+ messages.append(f"The current bet to meet is {as_height(self.cur_bet)}, "
f"and {self.current_player.name} has bet "
- f"${self.current_player.cur_bet}.")
+ f"{as_height(self.current_player.cur_bet)}.")
else:
- messages.append(f"The current bet to meet is ${self.cur_bet}.")
+ messages.append(f"The current bet to meet is {as_height(self.cur_bet)}.")
if self.current_player.cur_bet == self.cur_bet:
messages.append("Message !check, !raise or !fold.")
elif self.current_player.max_bet > self.cur_bet:
@@ -292,7 +314,7 @@
winners = self.pot.get_winners(self.shared_cards)
for winner, winnings in sorted(winners.items(), key=lambda item: item[1]):
hand_name = str(best_possible_hand(self.shared_cards, winner.cards))
- messages.append(f"{winner.name} wins ${winnings} with a {hand_name}.")
+ messages.append(f"{winner.name} wins {as_height(winnings)} with a {hand_name}.")
winner.balance += winnings
# Remove players that went all in and lost
@@ -302,11 +324,11 @@
if player.balance > 0:
i += 1
else:
- messages.append(f"{player.name} has been knocked out of the game!")
+ messages.append(f"{player.name} has become one of the prizes of the game!")
self.players.pop(i)
if len(self.players) == 1:
# There's only one player, so they win
- messages.append(f"{self.players[0].user.name} wins the game! "
+ messages.append(f"{self.players[0].user.name} wins the game - and the other players! "
"Congratulations!")
self.state = GameState.NO_GAME
return messages
@@ -327,9 +349,9 @@
# Has the current player raise a certain amount
def raise_bet(self, amount: int) -> List[str]:
self.pot.handle_raise(self.current_player, amount)
- messages = [f"{self.current_player.name} raises by ${amount}."]
+ messages = [f"{self.current_player.name} raises by {as_height(amount)}."]
if self.current_player.balance == 0:
- messages.append(f"{self.current_player.name} is all in!")
+ messages.append(f"{self.current_player.name} is putting themself on the line!")
self.leave_hand(self.current_player)
self.turn_index -= 1
return messages + self.next_turn()
@@ -339,7 +361,7 @@
self.pot.handle_call(self.current_player)
messages = [f"{self.current_player.name} calls."]
if self.current_player.balance == 0:
- messages.append(f"{self.current_player.name} is all in!")
+ messages.append(f"{self.current_player.name} is putting themself on the line!")
self.leave_hand(self.current_player)
self.turn_index -= 1
return messages + self.next_turn()
@@ -359,7 +381,7 @@
# If only one person is left in the pot, give it to them instantly
if len(self.pot.in_pot()) == 1:
winner = list(self.pot.in_pot())[0]
- messages += [f"{winner.name} wins ${self.pot.value}!"]
+ messages += [f"{winner.name} wins {as_height(self.pot.value)}!"]
winner.balance += self.pot.value
self.state = GameState.NO_HANDS
self.next_dealer()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment