def play(player_id, hand, history): # just two cards? call any pair, fold otherwise # if 2 == len(hand): rank0, suit0 = rank_suit(hand[0]) rank1, suit1 = rank_suit(hand[1]) if rank0 == rank1: return 'C' return 'F' # three cards? bet on a flush or better, call on a pair or straight, # fold otherwise # if 3 == len(hand): v = hand_value(hand) c = hand_value_class(v) if c in (FLUSH, TRIP, STRF): return 'B' if c in (PAIR, STR): return 'C' return 'F' # four cards? bet on trips or straight flush, call on a straight or flush, fold otherwise # if 4 == len(hand): v = best_hand_value(hand) c = hand_value_class(v) if c in (TRIP, STRF): return 'B' if c in (STR, FLUSH): return 'C' return 'F'
def play(player_id, hand, history): # just two cards? call on any pair or matched suits, fold otherwise # if 2 == len(hand): rank0, suit0 = rank_suit(hand[0]) rank1, suit1 = rank_suit(hand[1]) if rank0 == rank1 or suit0 == suit1: return 'C' return 'F' # three cards? bet on trips or straight flush, call on a straight or flush, # otherwise fold # if 3 == len(hand): v = hand_value(hand) c = hand_value_class(v) if c in (TRIP, STRF, FLUSH): return 'B' if c in (STR, ): return 'C' return 'F' # four cards? bet on straight flush, call on trips or flush, # fold otherwise # if 4 == len(hand): v = best_hand_value(hand) c = hand_value_class(v) if c in (STRF, TRIP): return 'B' if c in (FLUSH, ): return 'C' return 'F'
def play(player_id, hand, history): print 'History:' hand_over = False for i in history.split(): player, code, x = i.split(':') if 0: pass elif 'S' == code: print '\t%-10s sits down with %d chips' % (player, int(x)) elif 'A' == code: print '\t%-10s antes %d chips' % (player, int(x)) elif 'D' == code: print '\t%-10s is dealt hole card face down' % (player, ) elif 'U' == code: print '\t%-10s is dealt %s face up' % (player, x) elif 'C' == code: if 0 == int(x): print '\t%-10s checks' % (player, ) else: print '\t%-10s calls %d' % (player, int(x)) elif 'F' == code: print '\t%-10s folds' % (player, ) elif 'B' == code: print '\t%-10s bets %d' % (player, int(x)) elif 'R' == code: hand = monkeystud.str_to_hand(x) print '\t%-10s reveals %s -- %s' % (player, x, \ monkeystud.hand_value_str(monkeystud.best_hand_value(hand))) elif 'W' == code: print '\t%-10s wins %d' % (player, int(x)) hand_over = True elif 'Z' == code: print '\t%-10s wins lucky %d' % (player, int(x)) if hand_over: print 'Press return to continue.' else: print 'You are player "%s". Your hand is: %s. ' % (player_id, monkeystud.hand_str(hand)) print '[F]old, (C)all, or (B)et?' s = None try: s = raw_input() except KeyboardInterrupt: raise s = s.upper() if s.startswith('F'): return 'F' if s.startswith('C'): return 'C' if s.startswith('B'): return 'B' return 'F'
def parse_history(history): g = Game() g.players = {} g.pot = 0 g.player_count = 0 for i in history.split(): player_id, code, x = i.split(':') if not g.players.has_key(player_id): p = Player() p.seat = len(g.players) p.player_id = player_id p.chips = 0 p.bet = 0 p.hand = [] p.history = [] p.folded = True g.players[player_id] = p g.players[player_id].history.append((code, x)) if 0: pass elif 'S' == code: p.chips = int(x) g.player_count += 1 pass elif 'A' == code: g.pot += int(x) g.players[player_id].chips -= int(x) g.players[player_id].bet += int(x) elif 'D' == code: g.players[player_id].hand.append(monkeystud.INVALID_CARD) elif 'U' == code: g.players[player_id].hand.append(monkeystud.str_to_card(x)) elif 'C' == code: pass elif 'F' == code: g.players[player_id].folded = True g.player_count -= 1 elif 'B' == code: g.players[player_id].bet += int(x) elif 'R' == code: hand = monkeystud.str_to_hand(x) g.players[player_id].cards = hand g.players[player_id].best_hand = monkeystud.best_hand_value(hand) elif 'W' == code: g.players[player_id].chips += int(x) elif 'Z' == code: g.players[player_id].chips += int(x) return g