src/canonical_cards.cpp
// board is not sorted from high to low
// Do not assume we can modify board
// Assume board is a max street board
// We don't update suit groups (unsafe, no?)
board is not sorted from high to low
Do not assume we can modify board
Assume board is a max street board
We don't update suit groups (unsafe, no?)
board is not sorted from high to low Do not assume we can modify board Assume board is a max street board We don ' t update suit groups ( unsafe no? )
void CanonicalCards::SortByHandStrength(const Card *board) {
  int num_board_cards = Game::NumBoardCards(Game::MaxStreet());
  unique_ptr<Card []> sorted_board(new Card[num_board_cards]);
  for (int i = 0; i < num_board_cards; ++i) sorted_board[i] = board[i];
  qsort((void *)sorted_board.get(), (size_t)num_board_cards, sizeof(Card),
	g_ui_larger_compare);
#if 0
  for (int j = 0; j < num_board_cards; ++j) {
    for (int k = j + 1; k < num_board_cards; ++k) {
      if (sorted_board.get()[j] == sorted_board.get()[k]) {
	fprintf(stderr, "Illegal board\n");
	for (int l = 0; l < num_board_cards; ++l) {
	  fprintf(stderr, "%i ", (int)sorted_board.get()[l]);
	}
	fprintf(stderr, "\n");
	exit(-1);
      }
    }
  }
#endif
  vector<Hand> hands(num_raw_);
  Hand h;
  int hole_cards[2];
  for (int i = 0; i < num_raw_; ++i) {
    Card *cards = &cards_[i * n_];
    hole_cards[0] = cards[0];
    hole_cards[1] = cards[1];
#if 0
    for (int j = 0; j < num_board_cards; ++j) {
      fprintf(stderr, "%i ", (int)sorted_board.get()[j]);
    }
    fprintf(stderr, "/ %i %i\n", hole_cards[0], hole_cards[1]);
#endif
    h.hv = HandValueTree::Val(sorted_board.get(), hole_cards);
    h.index = i;
    hands[i] = h;
  }
  std::sort(hands.begin(), hands.end(), g_hand_lower_compare);
  hand_values_.reset(new int[num_raw_]);
  Card *new_cards = new Card[num_raw_ * n_];
  unsigned char *new_num_variants = new unsigned char[num_raw_];
  int *new_canon = new int[num_raw_];
  for (int i = 0; i < num_raw_; ++i) {
    int hv = hands[i].hv;
    int index = hands[i].index;
    Card hi = cards_[index * n_];
    Card lo = cards_[index * n_ + 1];
    new_cards[i * n_] = hi;
    new_cards[i * n_ + 1] = lo;
    new_num_variants[i] = num_variants_[index];
    new_canon[i] = canon_[index];
    hand_values_[i] = hv;
  }
  cards_.reset(new_cards);
  num_variants_.reset(new_num_variants);
  canon_.reset(new_canon);
}
void CanonicalCards :: SortByHandStrength ( const Card * board ) { int num_board_cards = Game :: NumBoardCards ( Game :: MaxStreet ( ) ) ; unique_ptr < Card [ ] > sorted_board ( new Card [ num_board_cards ] ) ; for ( int i = 0 ; i < num_board_cards ; ++ i ) sorted_board [ i ] = board [ i ] ; qsort ( ( void * ) sorted_board . get ( ) , ( size_t ) num_board_cards , sizeof ( Card ) , g_ui_larger_compare ) ; #if 0 for ( int j = 0 ; j < num_board_cards ; ++ j ) { for ( int k = j + 1 ; k < num_board_cards ; ++ k ) { if ( sorted_board . get ( ) [ j ] == sorted_board . get ( ) [ k ] ) { fprintf ( stderr , " \n " ) ; for ( int l = 0 ; l < num_board_cards ; ++ l ) { fprintf ( stderr , " " , ( int ) sorted_board . get ( ) [ l ] ) ; } fprintf ( stderr , " \n " ) ; exit ( -1 ) ; } } } #endif vector < Hand > hands ( num_raw_ ) ; Hand h ; int hole_cards [ 2 ] ; for ( int i = 0 ; i < num_raw_ ; ++ i ) { Card * cards = & cards_ [ i * n_ ] ; hole_cards [ 0 ] = cards [ 0 ] ; hole_cards [ 1 ] = cards [ 1 ] ; #if 0 for ( int j = 0 ; j < num_board_cards ; ++ j ) { fprintf ( stderr , " " , ( int ) sorted_board . get ( ) [ j ] ) ; } fprintf ( stderr , " \n " , hole_cards [ 0 ] , hole_cards [ 1 ] ) ; #endif h . hv = HandValueTree :: Val ( sorted_board . get ( ) , hole_cards ) ; h . index = i ; hands [ i ] = h ; } std :: sort ( hands . begin ( ) , hands . end ( ) , g_hand_lower_compare ) ; hand_values_ . reset ( new int [ num_raw_ ] ) ; Card * new_cards = new Card [ num_raw_ * n_ ] ; unsigned char * new_num_variants = new unsigned char [ num_raw_ ] ; int * new_canon = new int [ num_raw_ ] ; for ( int i = 0 ; i < num_raw_ ; ++ i ) { int hv = hands [ i ] . hv ; int index = hands [ i ] . index ; Card hi = cards_ [ index * n_ ] ; Card lo = cards_ [ index * n_ + 1 ] ; new_cards [ i * n_ ] = hi ; new_cards [ i * n_ + 1 ] = lo ; new_num_variants [ i ] = num_variants_ [ index ] ; new_canon [ i ] = canon_ [ index ] ; hand_values_ [ i ] = hv ; } cards_ . reset ( new_cards ) ; num_variants_ . reset ( new_num_variants ) ; canon_ . reset ( new_canon ) ; }
board is not sorted from high to low
Do not assume we can modify board
Assume board is a max street board
We don't update suit groups (unsafe, no?)
board is not sorted from high to low Do not assume we can modify board Assume board is a max street board We don ' t update suit groups ( unsafe no? )
// We know hole cards are sorted