예제 #1
0
 def updateChips(self, bet, money):
     if bet > 0:
         self.bet.set_label(PokerChips.tostring(bet))
         self.bet.show()
     else:
         self.bet.hide()
     self.money.set_label(PokerChips.tostring(money))
예제 #2
0
 def buyInParams(self, minimum, maximum, legend, max_label):
     packet = [
         "buy_in", "params",
         PokerChips.tostring(minimum),
         PokerChips.tostring(maximum), legend, max_label
     ]
     if self.verbose > 1:
         print "PokerInterfaceProtocol:requestBuyIn " + str(packet)
     self.command(*packet)
예제 #3
0
    def updateLobby(self, players_count, tables_count, game_id, file2name, my_tables, tables):
        selected_variant = ""
        variant2tables = {}
        for table in tables:
            if not variant2tables.has_key(table.variant):
                variant2tables[table.variant] = []
            if table.id == game_id:
                selected_variant = table.variant
            my = table.id in my_tables and "yes" or "no"
            info = ( str(table.id),
                     my,
                     table.name,
                     file2name(table.betting_structure),
                     str(table.seats),
                     PokerChips.tostring(table.average_pot),
                     str(table.hands_per_hour),
                     str(table.percent_flop),
                     str(table.players),
                     str(table.observers),
                     str(table.waiting),
                     str(table.player_timeout) )
            variant2tables[table.variant].append(info)

        for (variant, tables) in variant2tables.iteritems():
            selected = variant == selected_variant and str(game_id) or '0'
            packet = ['lobby', variant, selected, str(len(tables)) ]
            for table in tables:
                packet.extend(table)
            self.command(*packet)

        self.command('lobby', 'info', _("Players: %d") % players_count, _("Tables: %d") % tables_count)
예제 #4
0
    def updateLobby(self, players_count, tables_count, game_id, file2name,
                    my_tables, tables):
        selected_variant = ""
        variant2tables = {}
        for table in tables:
            if not variant2tables.has_key(table.variant):
                variant2tables[table.variant] = []
            if table.id == game_id:
                selected_variant = table.variant
            my = table.id in my_tables and "yes" or "no"
            info = (str(table.id), my, table.name,
                    file2name(table.betting_structure), str(table.seats),
                    PokerChips.tostring(table.average_pot),
                    str(table.hands_per_hour), str(table.percent_flop),
                    str(table.players), str(table.observers),
                    str(table.waiting), str(table.player_timeout))
            variant2tables[table.variant].append(info)

        for (variant, tables) in variant2tables.iteritems():
            selected = variant == selected_variant and str(game_id) or '0'
            packet = ['lobby', variant, selected, str(len(tables))]
            for table in tables:
                packet.extend(table)
            self.command(*packet)

        self.command('lobby', 'info',
                     _("Players: %d") % players_count,
                     _("Tables: %d") % tables_count)
예제 #5
0
 def updateLobbyPlayersList(self, players):
     packet = ["lobby", "players", str(len(players))]
     if len(players) > 0:
         for player in players:
             (name, chips, flag) = player
             packet.extend((name, PokerChips.tostring(chips), str(flag)))
     self.command(*packet)
예제 #6
0
 def normalizeChips(self, game, chips):
     if game.unit in self.chips_values:
         values = self.chips_values[self.chips_values.index(game.unit):]
     else:
         values = []
     chips_list = PokerChips(values, chips).tolist()
     return chips_list
예제 #7
0
 def updateLobbyPlayersList(self, players):
     packet = [ "lobby", "players", str(len(players)) ]
     if len(players) > 0:
         for player in players:
             ( name, chips, flag ) = player
             packet.extend((name, PokerChips.tostring(chips), str(flag)))
     self.command(*packet)
예제 #8
0
 def normalizeChips(self, game, chips):
     if game.unit in self.factory.chips_values:
         values = self.factory.chips_values[self.factory.chips_values.index(game.unit):]
     else:
         values = []
     chips_list = PokerChips(values, chips).tolist()
     self.log.debug("normalizeChips: %s %s", chips_list, values)
     return chips_list
예제 #9
0
 def normalizeChips(self, game, chips):
     if game.unit in self.chips_values:
         values = self.chips_values[self.chips_values.index(game.unit):]
     else:
         values = []
     list = PokerChips(values, chips).tolist()
     if self.verbose > 4: self.message("normalizeChips: " + str(list) + " " + str(values))
     return list
 class TestPacket(packets.Packet):
     info = packets.Packet.info + (
         ('f1', [1, 10], 'c'),
         ('f2',
          [PokerChips([1], [3]),
           PokerCards([255, 255]), ["a", 1]], 'j'),
     )
     fields = (
         "\x0a",  # type
         "\0\0",  # length
         "\0\0\0\x0a",  # f1
         '\x00-[["Chips", 3], ["Cards", 255, 255], ["a", 1]]',  # f2
     )
     binary = fields[0] + pack('!H', len("".join(fields))) + "".join(
         fields[2:])
예제 #11
0
 def decode_objects(something):
     if type(something) is types.ListType:
         if something[0] in ('Cards', 'Chips'):
             if something[0] == 'Cards':
                 return PokerCards(something[1:])
             elif something[0] == 'Chips':
                 return PokerChips([1], [something[1]])
         else:
             return map(PokerClientPacketJSON.decode_objects, something)
     elif type(something) is types.DictType:
         return dict(
             map(
                 lambda
                 (k, v): [k, PokerClientPacketJSON.decode_objects(v)],
                 something.iteritems()))
     else:
         return something
예제 #12
0
    def pot2player(self, packet):
        if self.verbose > 2: self.message("pot2player: move %s from %s to %s" % ( packet.chips, self.table.widget_pots[packet.pot], self.widget_bet))
        value = 0
        while packet.chips:
            chip_value = packet.chips.pop(0)
            count = packet.chips.pop(0)
            value += chip_value * count

        ( pot, pot_x, pot_y ) = self.table.widget_pots[packet.pot]
        ( bet, bet_x, bet_y ) = self.widget_bet
        label = gtk.Label()
        label.set_text(PokerChips.tostring(value))
        player_pot = gtk.EventBox()
        player_pot.add(label)
        player_pot.set_name("animation_sit")
        player_pot.show_all()
        animation = AnimationMoveWidget(fixed = self.table.screen,
                                        position_start = ( pot_x, pot_y ),
                                        position_end = ( bet_x, bet_y ),
                                        widget = player_pot,
                                        verbose = self.table.verbose)
        self.animationRegister(animation)
        animation.schedule(0, 2)
        return animation
예제 #13
0
    def test2(self):
        pokerchips.MAX_CHIPS_PER_STACK = 30
        values = [100, 200, 500, 1000, 2500, 500000]
        chips = PokerChips(values, 0)
        self.assertEqual(chips.chips, [0, 0, 0, 0, 0, 0])

        chips = PokerChips(values, 20000)
        self.assertEqual(chips.chips, [8, 6, 4, 6, 4, 0])
        chips.add([150, 0, 0, 0, 0, 0])
        self.assertEqual(chips.chips, [30, 30, 20, 6, 4, 0])
        self.assertEqual(chips.toint(), 35000)

        chips = PokerChips(values, 20000)
        total = 20000 + sum(map(lambda x: x * 150, values))
        chips.add([150, 150, 150, 150, 150, 150])
        self.assertEqual(chips.chips, [30, 30, 30, 31, 44, 151])
        self.assertEqual(chips.toint(), total)

        chips = PokerChips(values, 20000)
        chips.subtract([0, 20, 0, 0, 0, 0])
        self.assertEqual(chips.chips, [8, 6, 3, 5, 3, 0])
        self.assertEqual(chips.toint(), 16000)

        chips = PokerChips(values, 600000)
        self.assertEqual(chips.chips, [8, 6, 4, 6, 36, 1])

        chips = PokerChips(values)
        chips.add(600000)
        self.assertEqual(chips.chips, [8, 6, 4, 6, 36, 1])

        chips = PokerChips(values)
        chips.set([200, 0, 0, 0, 0, 0])
        self.assertEqual(chips.chips, [30, 30, 22, 0, 0, 0])

        chips = PokerChips(values, 20000)
        chips.subtract(25000)
        self.assertEqual(chips.chips, [0, 0, 0, 0, 0, 0])

        chips = PokerChips(values, 20000)
        self.assertEqual(chips.__str__(),
                         "PokerChips([8, 6, 4, 6, 4, 0]) = 20000 (-0)")
        self.assertEqual(chips.__repr__(), "PokerChips([8, 6, 4, 6, 4, 0])")
예제 #14
0
    def render(self, packet):
        if self.verbose > 3: self.message("render: " + str(packet))

        if packet.type == PACKET_POKER_TABLE_DESTROY:
            self.deleteTable()
            
        elif packet.type == PACKET_POKER_PLAYER_ARRIVE:
            self.serial2player[packet.serial] = PokerPlayer2D(packet, self)
            if packet.serial == self.display.protocol.getSerial():
                self.self_seated = True
                for seat in self.seats:
                    seat.hide()
            else:
                self.seats[packet.seat].hide()

        elif packet.type == PACKET_POKER_START:
            for (serial, player) in self.serial2player.iteritems():
                player.start()
            for winner in self.winners:
                winner.hide()
            self.updateTableStatus()

        elif packet.type == PACKET_POKER_CHIPS_POT_RESET:
            for pot in self.pots:
                pot.hide()

        elif packet.type == PACKET_POKER_BOARD_CARDS:
            board = self.game.eval.card2string(self.game.board.cards)
            board_length = len(board)
            for i in xrange(5):
                if i >= board_length:
                    self.board[i].hide()
                else:
                    self.board[i].set_from_file(self.glade.relative_file("cards/small-%s.png" % board[i]))
                    self.board[i].show()

        elif packet.type == PACKET_POKER_BET_LIMIT:
            self.bet_limit = packet

        elif packet.type == PACKET_POKER_HIGHEST_BET_INCREASE:
            self.display.updateRaiseRange(selected_amount = None)

        elif packet.type == PACKET_POKER_DEALER:
            self.dealer_buttons[packet.dealer].show()
            if packet.previous_dealer >= 0:
                self.dealer_buttons[packet.previous_dealer].hide()

        elif packet.type == PACKET_POKER_POT_CHIPS:
            pots = self.game.getPots()
            pot = self.pots[packet.index]
            pot.set_label(PokerChips.tostring(pots['pots'][packet.index][0]))
            pot.show()

        elif packet.type == PACKET_POKER_CHIPS_POT2PLAYER:
            if packet.reason != "win":
                return
            best_cards = self.serial2player[packet.serial].best_cards
            winner = self.winners[packet.pot]
            if self.game.hasLow() and self.game.hasHigh():
                if best_cards['hi'] and best_cards['low']:
                    label = "High: " + best_cards['hi'].hand + ", Low: " + best_cards['low'].hand
                elif best_cards['hi']:
                    label = "High: " + best_cards['hi'].hand
                elif best_cards['low']:
                    label = "Low: " + best_cards['low'].hand
                else:
                    label = None
                if label:
                    winner.set_label(label)
                    winner.show()
            elif self.game.hasHigh() and best_cards['hi']:
                winner.set_label(best_cards['hi'].hand)
                winner.show()
            elif self.game.hasLow() and best_cards['low']:
                winner.set_label(best_cards['low'].hand)
                winner.show()

        elif packet.type == PACKET_POKER_POSITION:
            for player in self.serial2player.values():
                playerInPosition = player.serial == packet.serial
                name = player.player.name
                if playerInPosition:
                    name = "<u>%s</u>" % name 
                player.name.set_use_markup(True)
                player.name.set_label(name)
                
        elif hasattr(packet, "serial") and self.serial2player.has_key(packet.serial):
            self.serial2player[packet.serial].render(packet)
            if packet.type == PACKET_POKER_PLAYER_LEAVE:
                serial = self.display.protocol.getSerial()
                if ( packet.serial == serial and
                     not self.game.isTournament() ):
                    for seat in self.seats:
                        seat.show()
                    for player in self.serial2player.values():
                        self.seats[player.seat].hide()
                elif serial in self.serial2player.keys():
                    self.seats[packet.seat].hide()
                else:
                    self.seats[packet.seat].show()
예제 #15
0
    def test2(self):
        pokerchips.MAX_CHIPS_PER_STACK = 30
        values = [100, 200, 500, 1000, 2500, 500000]
        chips = PokerChips(values, 0)
        self.assertEqual(chips.chips, [0, 0, 0, 0, 0, 0])

        chips = PokerChips(values, 20000)
        self.assertEqual(chips.chips, [8, 6, 4, 6, 4, 0])
        chips.add([150, 0, 0, 0, 0, 0])
        self.assertEqual(chips.chips, [30, 30, 20, 6, 4, 0])
        self.assertEqual(chips.toint(), 35000)
        
        chips = PokerChips(values, 20000)
        total = 20000 + sum(map(lambda x: x * 150, values))
        chips.add([150, 150, 150, 150, 150, 150])
        self.assertEqual(chips.chips, [30, 30, 30, 31, 44, 151])
        self.assertEqual(chips.toint(), total)
        
        chips = PokerChips(values, 20000)
        chips.subtract([0, 20, 0, 0, 0, 0])
        self.assertEqual(chips.chips, [8, 6, 3, 5, 3, 0])
        self.assertEqual(chips.toint(), 16000)

        chips = PokerChips(values, 600000)
        self.assertEqual(chips.chips, [8, 6, 4, 6, 36, 1])

        chips = PokerChips(values)
        chips.add(600000)
        self.assertEqual(chips.chips, [8, 6, 4, 6, 36, 1])

        chips = PokerChips(values)
        chips.set([200, 0, 0, 0, 0, 0])
        self.assertEqual(chips.chips, [30, 30, 22, 0, 0, 0])

        chips = PokerChips(values, 20000)
        chips.subtract(25000)
        self.assertEqual(chips.chips, [0, 0, 0, 0, 0, 0])
        
        chips = PokerChips(values, 20000)
        self.assertEqual(chips.__str__(), "PokerChips([8, 6, 4, 6, 4, 0]) = 20000 (-0)")
        self.assertEqual(chips.__repr__(), "PokerChips([8, 6, 4, 6, 4, 0])")
예제 #16
0
def pokerEvent(id, type, *args):
    global game, mySerial
    if type == "all-in":
        if args[0] == mySerial:
            info(_("You are all in"))
        else:
            info(_("Player %d is all in") % args[0])
    elif type == "bet2pot":
        pass
    elif type == "blind":
        if args[0] == mySerial:
            info(_("You pay blind %s") % PokerChips.tostring(args[1]))
        else:
            info(
                _("Player %d pays blind %s") %
                (args[0], PokerChips.tostring(args[1])))
    elif type == "call":
        if args[0] == mySerial:
            info(_("You call %s") % PokerChips.tostring(args[1]))
        else:
            info(
                _("Player %d calls %s") %
                (args[0], PokerChips.tostring(args[1])))
    elif type == "check":
        if args[0] == mySerial:
            info(_("You check"))
        else:
            info(_("Player %d checks") % args[0])
    elif type == "end":
        (winners, showdown_stack) = args
        if showdown_stack:
            game_state = showdown_stack[0]
            if not game_state.has_key('serial2best'):
                serial = winners[0]
                if serial == mySerial:
                    info(
                        _("You receive %(amount)s (everyone else folded)") % {
                            'amount':
                            PokerChips.tostring(
                                game_state['serial2share'][serial])
                        })
                else:
                    info(
                        _("Player %(number)d receives %(amount)s (everyone else folded)"
                          ) % {
                              'number':
                              serial,
                              'amount':
                              PokerChips.tostring(
                                  game_state['serial2share'][serial])
                          })
            else:
                serial2displayed = {}
                hands = showdown_stack[0]['serial2best']
                for frame in showdown_stack[1:]:
                    message = None
                    if frame['type'] == 'left_over':
                        if frame['serial'] == mySerial:
                            message = _("You receive %(amount)s odd chips") % {
                                'amount': PokerChips.tostring(
                                    frame['chips_left'])
                            }
                        else:
                            message = _(
                                "Player %(number)s receives %(amount)s odd chips"
                            ) % {
                                'number': frame['serial'],
                                'amount': PokerChips.tostring(
                                    frame['chips_left'])
                            }
                    elif frame['type'] == 'uncalled':
                        message = _(
                            "returning uncalled bet %(amount)s to %(name)s"
                        ) % {
                            'amount': PokerChips.tostring(frame['uncalled']),
                            'name': serial2name(frame['serial'])
                        }
                    elif frame['type'] == 'resolve':
                        best = {'hi': 0, 'low': 0x0FFFFFFF}
                        for serial in frame['serials']:
                            for side in ('hi', 'low'):
                                if not hands.has_key(serial):
                                    continue
                                hand = hands[serial]
                                if not hand.has_key(side):
                                    continue
                                if hand[side][1][0] == 'Nothing':
                                    continue

                                hand = hand[side]
                                show = False
                                if ((side == 'hi' and best['hi'] <= hand[0])
                                        or (side == 'low'
                                            and best['low'] >= hand[0])):
                                    best[side] = hand[0]
                                    show = True

                                if serial2displayed.has_key(
                                        serial) and not serial in frame[side]:
                                    # If the player already exposed the hand and is not going
                                    # to win this side of the pot, there is no need to issue
                                    # a message.
                                    continue

                                if show:
                                    serial2displayed[serial] = True
                                    value = game.readableHandValueLong(
                                        side, hand[1][0], hand[1][1:])
                                    if serial == mySerial:
                                        info(
                                            _("You show %(value)s") % {
                                                'value': value,
                                                'side': side
                                            })
                                    else:
                                        info(
                                            _("Player %(number)d shows %(value)s"
                                              ) % {
                                                  'number': serial,
                                                  'value': value,
                                                  'side': side
                                              })
                                else:
                                    if serial == mySerial:
                                        info(_("You muck loosing hand"))
                                    else:
                                        info(
                                            _("Player %(number)d mucks loosing hand"
                                              ) % {'number': serial})

                        for side in ('hi', 'low'):
                            if not frame.has_key(side):
                                continue
                            if len(frame[side]) > 1:
                                msg = join([
                                    serial2name(serial)
                                    for serial in frame[side]
                                ], ", ")
                                msg += _(" tie") % {'side': side}
                                info(msg)
                            else:
                                if frame[side][0] == mySerial:
                                    info(_("You win") % {'side': side})
                                else:
                                    info(
                                        _("Player %(number)d wins") % {
                                            'number': frame[side][0],
                                            'side': side
                                        })

                        if len(frame['serial2share']) > 1:
                            msg = _("winners share a pot of %(pot)s") % {
                                'pot': PokerChips.tostring(frame['pot'])
                            }
                            if frame.has_key('chips_left'):
                                msg += _(
                                    " (minus %(chips_left)d odd chips)") % {
                                        'chips_left': frame['chips_left']
                                    }
                            info(msg)

                        for (serial,
                             share) in frame['serial2share'].iteritems():
                            if serial == mySerial:
                                info(
                                    _("You receive %(amount)s") %
                                    {'amount': PokerChips.tostring(share)})
                            else:
                                info(
                                    _("Player %(number)d receives %(amount)s")
                                    % {
                                        'number': serial,
                                        'amount': PokerChips.tostring(share)
                                    })

                    if message:
                        info(message)
        else:
            print
            "ERROR empty showdown_stack"
    elif type == "fold":
        if args[0] == mySerial:
            info(_("You fold"))
        else:
            info(_("Player %d folds") % args[0])
    elif type == "end_round_last":
        pass
    elif type == "finish":
        pass
    elif type == "game":
        (level, hand_serial, hands_count, time, variant, betting_structure,
         player_list, dealer, serial2chips) = args
        info(
            _("Hand #%(hand_serial)d, %(variant)s, %(betting_structure)s") % {
                'hand_serial': hand_serial,
                'variant': _(variant),
                'betting_structure': _(betting_structure)
            })
        if len(set(serial2chips.values())) == 1:
            info(
                _("All players have %s in chips") %
                PokerChips.tostring(serial2chips.values()[0]))
        else:
            for serial in player_list:
                if serial == mySerial:
                    info(
                        _("You have %(chips)s in chips") %
                        {'chips': PokerChips.tostring(serial2chips[serial])})
                else:
                    info(
                        _("Player %(serial)d has %(chips)s in chips") % {
                            'serial': serial,
                            'chips': PokerChips.tostring(serial2chips[serial])
                        })
        if game.seats()[dealer] == mySerial:
            info(_("You receive the dealer button"))
        else:
            info(
                _("Player %d receives the dealer button") %
                game.seats()[dealer])
    elif type == "money2bet":
        pass
    elif type == "position":
        pass
    elif type == "raise":
        if args[0] == mySerial:
            info(_("You raise by %s") % PokerChips.tostring(args[1]))
        else:
            info(
                _("Player %d raises by %s") %
                (args[0], PokerChips.tostring(args[1])))
    elif type == "rake":
        pass
    elif type == "round":
        info(_(args[0]))
        if not autoPlay:
            info(_("Your cards: %s") % game.getHandAsString(mySerial))
        if not args[1].isEmpty():
            info(_("The board: %s") % game.getBoardAsString())
    elif type == "round_cap_decrease":
        pass
    elif type == "showdown":
        pass
    elif type == "sitOut":
        if args[0] == mySerial:
            info(_("Game over"))
            exit()
        else:
            info(_("Player %d is out of chips") % args[0])
    else:
        print
        "%s" % type
        print
        args
예제 #17
0
 def buyInParams(self, minimum, maximum, legend, max_label):
     packet = [ "buy_in", "params", PokerChips.tostring(minimum), PokerChips.tostring(maximum), legend, max_label ]
     if self.verbose > 1: print "PokerInterfaceProtocol:requestBuyIn " + str(packet)
     self.command(*packet)