コード例 #1
0
ファイル: GameLib.cpp プロジェクト: aodkrisda/jackmate
// returns 0 if the tables are the same, 1 if they are different
int checkDiffTables(gameTable *TableA, gameTable *tableB){

    // different number of cards on the table
    if (TableA->numCards != tableB->numCards) return 1;
    // different number of hands on the table
    if (TableA->players.size() != tableB->players.size()) return 1;
    // run over the hands - they are ordered so theyre place in the vector should be the same
    uint i = 0;
    int diff = 0;
    for (i = 0; i < TableA->players.size(); i++){
        // compare the two hands
        diff = compareHands(TableA->players.at(i), tableB->players.at(i));
        if (!diff) return 1;
    }

    return 0;
}
コード例 #2
0
ファイル: Utils.cpp プロジェクト: JoakimMisund/Poker
std::vector<Card> findBestCombination( std::vector<Card> &cards )
{
  assert( cards.size() == 7 );
  
  std::vector<Card> currentHand;
  std::vector<Card> bestHand;

  //i is the index of a card to exclude
  for( unsigned int i = 0; i < cards.size(); ++i ) {
    //j is the index of a card to exclude.
    for( unsigned int j = i+1; j < cards.size(); ++j ) {
    
      currentHand.clear();
      //add cards
      for( unsigned int k = 0; k < cards.size() && currentHand.size() != 5; ++k ) {
	if( k != i && k != j ) {
	  currentHand.push_back(cards[k]);
	}
      }

      if( bestHand.size() == 0 ) {
	bestHand = currentHand;
      } else {
	
	/*	std::cout << "Best so far: ";
	for_each( begin(bestHand), end(bestHand), printCard );
	std::cout << " Challenger: ";
	for_each( begin(currentHand), end(currentHand), printCard );
	std::cout << "\n";
	*/
	if( compareHands( currentHand, bestHand ) == 1 ) {
	  bestHand = currentHand;
	}
      }
      
    }
  }

  return bestHand;

}
コード例 #3
0
ファイル: s0054.c プロジェクト: recursion-ninja/ProjectEuler
int main(int argc, char* argv[]) {
    uint32_t player1Wins,player2Wins,hands;
    uint8_t  *player1,*player2;
    winner   result;

    if(argc > 1 && !strcmp(argv[1],"--help"))
        return print_help(argv[0]), EXIT_SUCCESS;

    player1 = malloc(HAND_SIZE * sizeof *player1);
    player2 = malloc(HAND_SIZE * sizeof *player2);
    player1Wins = player2Wins = 0;

    for(hands=0; getNextSetOfHands(player1,player2); ++hands)
        if((result = compareHands(player1,player2)) != TIE)
            result==PLAYER_ONE ? ++player1Wins : ++player2Wins;

    printf("Player 1 wins: %6u\n",player1Wins);
    printf("Player 2 wins: %6u\n",player2Wins);
    printf("Ties:          %6u\n",hands-(player1Wins+player2Wins));

    return EXIT_SUCCESS;
}