Permalink
Browse files

removed half-hearted 'security' measure. better to have real security

than worthless workarounds.
  • Loading branch information...
1 parent ead1abc commit 908f508d224b7b36ebb444edba69d1f4145e316e Your Name committed Jan 2, 2011
Showing with 15 additions and 43 deletions.
  1. +1 −1 srv/adapter.py
  2. +2 −3 srv/awarder.py
  3. +12 −39 srv/script.py
View
@@ -46,7 +46,7 @@ def start(self, script_obj):
def privmsg_hands(self, cardsDealt):
players = cardsDealt.players
for player in players:
- c = cardsDealt.get_player_hand(player)
+ c = player.cards
self.adapter.privmsg(player.nickname, {'cards': c})
def display_action(self):
View
@@ -82,17 +82,16 @@ def hand_name(handrank):
return handrank[1][0]
class AwardHands:
- def __init__(self, invested_players, gethand, pots, board):
+ def __init__(self, invested_players, pots, board):
self.players = invested_players
- self.gethand = gethand
self.pots = pots
self.board = board
self.pokereval = pokereval.PokerEval()
self.rankings = {}
def calculate_rankings(self):
for player in self.players:
- cards = list(self.gethand(player)) + self.board
+ cards = list(player.cards) + self.board
self.rankings[player] = self.pokereval.best('hi', cards)
return self.rankings
View
@@ -62,23 +62,6 @@ class Action:
'autopost': AUTOPOST_BLINDS
}
- """actionRepr = {
- SIT_IN: 'Sit In',
- SIT_OUT: 'Sit Out',
- POST_SB: 'Post Small-Blind',
- POST_BB: 'Post Big-Blind',
- POST_SB_BB: 'Post Small & Big Blinds',
- POST_ANTE: 'Post Ante',
- FOLD: 'Fold',
- CALL: 'Call',
- CHECK: 'Check',
- BET: 'Bet',
- RAISE: 'Raise',
- ALL_IN: 'Go All In',
- LEAVE_SEAT: 'Leave Seat',
- WAIT_BB: 'Wait for BB'
- }"""
-
def __init__(self, player):
self.player = player
self.actions = []
@@ -109,9 +92,8 @@ def notation(self):
return notat
class CardsDealt:
- def __init__(self, players, get_player_hand):
+ def __init__(self, players):
self.players = players
- self.get_player_hand = get_player_hand
class CollectedMoney:
def __init__(self, player, amount):
@@ -148,13 +130,12 @@ def notation(self):
return self.notationBase('river')
class ShowHands:
- def __init__(self, players, gethand):
+ def __init__(self, players):
self.players = players
- self.gethand = gethand
def notation(self):
cards = []
for p in self.players:
- cards.append({'player': p.nickname, 'cards': self.gethand(p)})
+ cards.append({'player': p.nickname, 'cards': p.cards})
return {'show hands': cards}
class ShowDown:
@@ -277,22 +258,15 @@ def __init__(self):
suits = "hdcs"
self.deck = [rank + suit for rank in ranks for suit in suits]
random.shuffle(self.deck)
- # Player hands are stored here in a map for added security
- # since this object is created on the heap.
- self.player_hands = {}
def new_card(self):
return self.deck.pop()
def deal_hands(self, players):
- for p in players:
- hand = self.new_card(), self.new_card()
- self.player_hands[p] = hand
-
- def get_player_hand(self, player):
- return self.player_hands[player]
+ for player in players:
+ player.cards = self.new_card(), self.new_card()
-class StreetStateMachine2:
+class StreetStateMachine:
Preflop = 0
Flop = 1
Turn = 2
@@ -415,10 +389,10 @@ def run(self):
#------------------
card_deck = CardDeck()
card_deck.deal_hands(active_players)
- yield CardsDealt(active_players, card_deck.get_player_hand)
+ yield CardsDealt(active_players)
- street_statemachine = StreetStateMachine2(active_players, self.board,
- card_deck.new_card)
+ street_statemachine = StreetStateMachine(active_players, self.board,
+ card_deck.new_card)
pots = None
while not street_statemachine.finished():
@@ -504,10 +478,9 @@ def run(self):
first_pot = pots.pots[0]
all_contestors = first_pot.contestors
invested_players = [b.parent for b in all_contestors]
- gethand = card_deck.get_player_hand
- response = yield ShowHands(invested_players, gethand)
- award_hands = awarder.AwardHands(invested_players, gethand,
- pots, self.board)
+ response = yield ShowHands(invested_players)
+ award_hands = awarder.AwardHands(invested_players, pots,
+ self.board)
rankings = award_hands.calculate_rankings()
response = yield ShowRankings(rankings)
winners = award_hands.calculate_winners()

0 comments on commit 908f508

Please sign in to comment.