Example #1
0
void CTable::dealCards(CPlayer *player, int numcards)
{
    CCard *tmpCard;
    CpduDealCardsFlex pdu;
    char message[100] = { '\0' };
    char vChar[3] = { '\0' };
    char sChar;

    if (numcards)
        sprintf(message, "%s was dealt ", player->getUsername());

    pdu.setDeal(0xffff, Hole);
    
    for (; numcards > 0; numcards--)
    {
        tmpCard = deck_.popCard();

        player->getHand()->addCard(tmpCard);

        memset(vChar, 0x0, sizeof(vChar));
        
        switch (tmpCard->getValue())
        {
        case (10):  strcpy(vChar, "10"); break;
        case (11):  vChar[0] = 'J'; break;
        case (12):  vChar[0] = 'Q'; break;
        case (13):  vChar[0] = 'K'; break;
        case (14):  vChar[0] = 'A'; break;
        default: itoa(tmpCard->getValue(), vChar, 10); break;
        }

        switch (tmpCard->getSuit())
        {
        case (1):   sChar = 'C'; break;         // Clubs
        case (2):   sChar = 'D'; break;         // Diamonds
        case (3):   sChar = 'H'; break;         // Hearts
        case (4):   sChar = 'S'; break;         // Spades
        }
        
        sprintf(message, "%s [%s%c]", message, vChar, sChar);

        pdu.addCard(tmpCard->getValue(), tmpCard->getSuit());

        delete tmpCard;
    }

    pdu.sendDealCards(player);

    setLog(message);
  
}
Example #2
0
void CTable::dealCards(Cring *ring, int numcards)
{
    CCard *tmpCard;
    CpduDealCommunity pdu;
    char message[100] = "Community Cards dealt ";
    char vChar[3] = { '\0' };
    char sChar;

    

    for (; numcards > 0; numcards--)
    {
        tmpCard = deck_.popCard();

        memset(vChar, 0x0, sizeof(vChar));

        switch (tmpCard->getValue())
        {
        case (10):  strcpy(vChar, "10"); break;
        case (11):  vChar[0] = 'J'; break;
        case (12):  vChar[0] = 'Q'; break;
        case (13):  vChar[0] = 'K'; break;
        case (14):  vChar[0] = 'A'; break;
        default: itoa(tmpCard->getValue(), vChar, 10); break;
        }

        switch (tmpCard->getSuit())
        {
        case (1):   sChar = 'C'; break;         // Clubs
        case (2):   sChar = 'D'; break;         // Diamonds
        case (3):   sChar = 'H'; break;         // Hearts
        case (4):   sChar = 'S'; break;         // Spades
        }

        getBoard()->addCard(tmpCard);

        sprintf(message, "%s [%s%c]", message, vChar, sChar);
        pdu.sendDealCommunity(ring, tmpCard->getValue(), tmpCard->getSuit(), 500);
        delete tmpCard;
    }

    setLog(message);
}
Example #3
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;
    }
}
Example #4
0
// finds a num card and sets its value to thiscard
void CDeck::SetCard(CCard thiscard, int num)
{
	int i = 0;
	const_deckIterator deckitr;

	deckitr = getDeckIterator();

	while ((deckitr != NULL) && (i != num)) {
		deckitr = deckitr->next;
		i++;
	}

	if (deckitr != NULL) {
		deckitr->data->setCard(thiscard.getRank(), thiscard.getSuit());
	}

	return;
}
Example #5
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;
}