Пример #1
0
void CTable::distributeBoard()
{
    if (!board_) return;

    CPlayer *player;
    CRingIterator it(ring_);
    CCard *pCard;

    // all-in players must be evaluated too
    int state = PLAYER_STATE_PLAYING|PLAYER_STATE_ALLIN;

    if (it.start(state))
    {
        do {
            player = it.current()->getPlayer();
            // if player has been all-in for longer
            // than a complete hand, he doesn't have cards
            if (player->hasHand())
            {
                pCard = board_->getCard();
                while (pCard != NULL)
                {
                    player->getHand()->addCard(pCard);
                    pCard = pCard->getNext();
                }
            }
        } while (it.next(state));
    }
}
Пример #2
0
int CpduShowdown::sendShowdown(CPlayer* player,
                               int numCards,
                               const char* message)
{
    // Sending dummy cards for now!
    
    CCard *pCard = player->getHand()->getCard();
    int msglen = (message != NULL ? strlen(message) : 0);

    length_ += numCards * sizeof(pdu_card) + msglen;
    stuffHeader();

    if (length_ < MAXBUFFERSIZE)
    {
        char* buf = value_ + PDU_HEADER_SIZE;
        pdu_showdown data;

        data.slot = htons(player->getSlot());
        data.numCards = htons(numCards);
        data.msglen = htons(msglen);
        memcpy(buf, &data, sizeof(data));
        buf += sizeof(data);
    
        // copy cards to buffer
        for (int i = 0; i < numCards; i++)
        {
            pdu_card card;
            card.suit = htons(pCard->getSuit());
            card.value = htons(pCard->getValue());
            memcpy(buf, &card, sizeof(card));
            buf += sizeof(card);
            pCard = pCard->getNext();
        }

        // copy showdown message to buffer
        if (msglen > 0)
            memcpy(buf, message, msglen);

        return broadcastTo(table_->getRing());
    }
    else
    {
        Sys_LogError("CpduShowdown: buffer size too small.\n");
        return 0;
    }
}
Пример #3
0
// In 7-stud, the odd chip goes to player with
// highest card of suit in this order:
// Spades, Hearts, Diamonds, Clubs.
CPlayer* Cplm_7Stud::getOddChipWinner(Winners& winners)
{
    CPlayer* player = NULL;

    u_int16_t highestCard = 0;

    for (Winners::iterator it = winners.begin(),
            end = winners.end();
            it != end;
            ++it)
    {
        CWinner& winnerEntry = const_cast<CWinner&>(*it);
        CPlayer* winner = winnerEntry.player_;

        if (winner && winner->hasHand())
        {
            Chand* hand = winner->getHand();
            if (hand)
            {
                CCard* card = hand->getCard();
                while (card != NULL)
                {
                    u_int16_t thisCard = card->getSuit() * 13 + card->getValue();
                    if (thisCard > highestCard)
                    {
                        highestCard = thisCard;
                        player = winner;
                    }
                    card = card->getNext();
                }
            }
        }
    }

    if (!player)
        player = getPlayerClosestToLeftOfDealer(winners);

    return player;
}