コード例 #1
0
static int cardCmpSol(const void *c1, const void *c2) { // ace is lowest
  Card card1 = *(Card*)c1;
  Card card2 = *(Card*)c2;
  int suit1 = CARDSUIT(card1);
  int suit2 = CARDSUIT(card2);

  if(suit1 != suit2) {
    return suitSortOrder[suit1] - suitSortOrder[suit2];
  }
  return CARDVALUE(card1) - CARDVALUE(card2);
}
コード例 #2
0
int CGameRecord::DetermineRoundWinner(const int nRound) const
{
	ASSERT((nRound >= 0) && (nRound < 13));
	// can't determine winner if < 4 cards played in round)
	if (m_numCardsPlayed < ((nRound+1) * 4))
		return -1;
	int nStart = nRound * 4;
	int nEnd = nStart + 4;
	int nTop = NONE;
	int nTopTrump = NONE;
	int nTopPos = NONE;
	BOOL bTrumpPlayed = FALSE;
	int nContractSuit = BID_SUIT(m_nContract);
	//
	int nPos = m_nRoundLead[nRound];
	int nCardLed = m_nGameTrick[nRound][nPos];
	int nSuitLed = CARDSUIT(nCardLed);
	//
	for(int i=nStart;i<nEnd;i++)
	{
		int nCard = m_nGameTrick[nRound][nPos];
		int nSuit = CARDSUIT(nCard);
		int nFaceVal = FACEVAL(nCard);
		//
		if (nSuit == nContractSuit)
		{
			// a trump card was played -- see if it's high
			if (nFaceVal > nTopTrump)
			{
				nTopTrump = nFaceVal;
				nTopPos = nPos;
				bTrumpPlayed = TRUE;
			}
		}
		else if (!bTrumpPlayed)
		{
			// else if no trump was played so far, check if this card is high
			if ((nSuit == nSuitLed) && (nFaceVal > nTop))
			{
				nTop = nFaceVal;
				nTopPos = nPos;
			}
		}
		//
		nPos = ::GetNextPlayer(nPos);
	}

	//
	ASSERT(nTopPos != NONE);
	return nTopPos;
}
コード例 #3
0
int CardHand::findLowestHigherThanAceHisgest(Card card) const {
  int result = -1;
  int lv = 15;
  for(int i = 0; i < 13; i++) {
    const Card c = m_card[i];
    if(c >= 0 && CARDSUIT(c) == CARDSUIT(card)
              && CARDVALUEAH(c) > CARDVALUEAH(card)
              && CARDVALUEAH(c) < lv) {
      lv = CARDVALUEAH(c);
      result = i;
    }
  }
  return result;
}
コード例 #4
0
int CardHand::findHigestLowerThan(Card card) const {
  int result = -1;
  int hv = 0;
  for(int i = 0; i < 13; i++) {
    const Card c = m_card[i];
    if(c >= 0 && CARDSUIT(c) == CARDSUIT(card)
              && CARDVALUE(c) < CARDVALUE(card)
              && CARDVALUE(c) > hv) {
      hv = CARDVALUE(c);
      result = i;
    }
  }
  return result;
}
コード例 #5
0
Suit CardHand::getMaxSuit(int &count, double &bavg) const { // find the best suit
  int    a[4];
  double avg[4];
  int i;
  Suit result;

  for(i = 0; i < 4; i++) {
    a[i] = 0;
  }
  for(i = 0; i < 13; i++) {
    const Card c = m_card[i];
    if(c >= 0) {
      a[CARDSUIT(c)]++;
    }
  }
  for(i = 0; i < 4; i++) {
    avg[i] = getCardSuitAverage((Suit)i);
  }
  for(i = 1, result = (Suit)0; i < 4; i++) {
    if(i == SPAR) {
      continue; // spar does not count
    }
    if(a[i] > a[result] || (a[i] == a[result] && avg[i] > avg[result])) {
      result = (Suit)i;
    }
  }

  count = a[result];
  bavg  = avg[result];

  return result;
}
コード例 #6
0
int CardHand::getSuitGreaterThanAceHigestCount(Suit suit, int value) const {
  int count = 0;
  for(int i = 0; i < 13; i++) {
    const Card c = m_card[i];
    if(c >= 0 && CARDSUIT(c) == suit && CARDVALUEAH(c) > value)
      count++;
  }
  return count;
}
コード例 #7
0
int CardHand::getNotSuitCount(Suit suit) const {
  int count = 0;
  for(int i = 0; i < 13; i++) {
    const Card c = m_card[i];
    if(c >= 0 && CARDSUIT(c) != suit)
      count++;
  }
  return count;
}
コード例 #8
0
int CardHand::findLowestNotInSuitAceHigest(Suit suit) const {
  int result = -1;
  int lv = 15;
  for(int i = 0; i < 13; i++) {
    const Card c = m_card[i];
    if(c >= 0 && CARDSUIT(c) != suit && CARDVALUEAH(c) < lv) {
      lv = CARDVALUEAH(c);
      result = i;
    }
  }
  return result;
}
コード例 #9
0
int CardHand::findHigestInSuitAceHigest(Suit suit) const {     // find the index of higest card in the hand
  int result = -1;                                      // with the specified suit, ace higest
  int hv     = 0;                                       // returns -1 if none found
  for(int i = 0; i < 13; i++) {
    const Card c = m_card[i];
    if(c >= 0 && CARDSUIT(c) == suit && CARDVALUEAH(c) > hv) {
      hv = CARDVALUEAH(c);
      result = i;
    }
  }
  return result;
}
コード例 #10
0
int CardHand::findLowestInSuit(Suit suit) const {     // find the index of the lowest card in the hand
  int result = -1;                                    // with the specified suit
  int lv     = 15;                                    // returns -1 if none found
  for(int i = 0; i < 13; i++) {
    const Card c = m_card[i];
    if(c >= 0 && CARDSUIT(c) == suit && CARDVALUE(c) < lv) {
      lv = CARDVALUE(c);
      result = i;
    }
  }
  return result;
}
コード例 #11
0
double CardHand::getCardSuitAverage(Suit suit) const {
  int count = 0;
  int sum   = 0;
  for(int i = 0; i < 13; i++) {
    const Card c = m_card[i];
    if(c >= 0 && CARDSUIT(c) == suit) {
      sum += CARDVALUEAH(c);
      count++;
    }
  }
  return count ? sum/count : 0;
}