Ejemplo n.º 1
0
DTerr HWVideoPlayerFFPacketQueue::push_back (AVPacket *pkt)
{
    // Duplicate if not a flush packet
    if (!is_flush(pkt) && !is_play(pkt) && !is_pause(pkt)) {
        if(av_dup_packet(pkt) < 0)
            return DT3_ERR_FILE_OPEN_FAILED;
    }
    
    AVPacketList *packet_list = (AVPacketList *) ::av_malloc(sizeof(AVPacketList));
    
    packet_list->pkt = *pkt;
    packet_list->next = NULL;
    
    _lock.lock();
    
    // Queue is empty
    if (!_first_pkt) {
        _first_pkt = _last_pkt = packet_list;
    } else {
        _last_pkt->next = packet_list;
        _last_pkt = packet_list;
    }
    
    ++_size;
    
    _lock.unlock();
    
    return 0;
}
Ejemplo n.º 2
0
HandRank EvaluateHand(int hand[5])
{    
    int rankcount[13]= {0};
    for (int i=0; i< 5; i++)
        rankcount[RANK(hand[i])]++;

    if (is_royal(hand))
        return eRoyal;
    if (is_straight_flush(hand, rankcount))
        return eStraightFlush;
    if (is_four(rankcount))
        return eFour;
    if (is_full(rankcount))
        return eFull;
    if (is_flush(hand))
        return eFlush;
    if (is_straight(rankcount))
        return eStraight;
    if (is_three(rankcount))
        return eThree;
    if (is_TwoPair(rankcount))
        return eTwoPair;
    if (is_Pair(rankcount))
        return ePair;

    return eBust;
}
Ejemplo n.º 3
0
static int get_component_type( Coeff_p tuple_ptr,
			       int comp,
			       int tr,
			       int pl)
 {/* Init get_component_type */
  int c,r,s;
  int sync = 0;
  int proj = 0;
  int succ = 0;
  int prec = 0;
  int ret_value = UNKNOWN;

  c = GET_COLOR_COMPONENT(comp,pl);
  r = GET_COLOR_REPETITIONS(c,tr);
  s = GET_STATIC_SUBCLASS(c);

  sync = count_synchronization_coefficients(tuple_ptr,comp,s);
  proj = count_coefficients(tuple_ptr,comp,r,PROJECTION);
  succ = count_coefficients(tuple_ptr,comp,r,SUCCESSOR);
  prec = count_coefficients(tuple_ptr,comp,r,PREDECESSOR);

  if(sync && !proj && !succ && !prec)
   {
    if(only_S(tuple_ptr,comp,s))
     ret_value = SYNCHRONIZATION;
#ifdef FLUSH_FUNCTION
    else if(is_flush(tuple_ptr,comp,s))
     ret_value = FLUSH_VALUE;
#endif
    else
     ret_value = MIXED;
   }
  else if(!sync && proj && !succ && !prec)
   {
    if(proj == 1)
     ret_value = PROJECTION;
    else
     ret_value = MIXED;
   }
  else if(!sync && !proj && succ && !prec)
   {
    if(succ == 1)
     ret_value = SUCCESSOR;
    else
     ret_value = MIXED;
   }
  else if(!sync && !proj && !succ && prec)
   {
    if(prec == 1)
     ret_value = PREDECESSOR;
    else
     ret_value = MIXED;
   }
  else
   ret_value = MIXED;
  return(ret_value);
 }/* End get_component_type */
Ejemplo n.º 4
0
int TopCard(card h[5]) {
	int x = 0;
			
	if(is_flush(h) && is_straight(h)) {	
		printf("Straight Flush.\n");
		x = 300;
	}
	else if(is_flush(h)) {
		printf("Flush.\n");
		x = 200;
	}
	else if(is_straight(h)) {
		printf("Straight.\n");
		x = 150;
	}
	else if(x = is_kind(h)) {
		printf("(%d)x of a kind.\n",x);
	}
	else { x = 0; }
	
	return x;
}
Ejemplo n.º 5
0
void Evaluator::determine_strength(HandStrength *strength)
{
    // sort cards descending
    std::sort(all_cards.begin(), all_cards.end(), Card::greater);

    // clear combination cards and kicker_cards
    strength->clear_combination_cards();
    strength->clear_kicker_cards();

    // test for all combinations
    bool isFlush;
    if ((isFlush = is_flush(strength)) &&
        is_straight(strength,
                    strength->get_combination_cards()->front()->get_suit())) {
        strength->set_combination(HandStrength::STRAIGHT_FLUSH);
        // check royal flush
        if (strength->get_combination_cards()->front()->get_face() == Card::ACE) {
            strength->set_combination(HandStrength::ROYAL_FLUSH);
        }
    } else if (is_X_of_a_kind(FOUR_OF_A_KIND_SIZE, strength)) {
        strength->set_combination(HandStrength::FOUR_OF_A_KIND);
    } else if (is_full_house(strength)) {
        strength->set_combination(HandStrength::FULL_HOUSE);
    } else if (isFlush) {
        strength->set_combination(HandStrength::FLUSH);
    } else if (is_straight(strength)) {
        strength->set_combination(HandStrength:: STRAIGHT);
    } else if (is_X_of_a_kind(THREE_OF_A_KIND_SIZE, strength)) {
        strength->set_combination(HandStrength::TREE_OF_A_KIND);
    } else if (is_two_pairs(strength)) {
        strength->set_combination(HandStrength::TWO_PAIRS);
    } else if (is_X_of_a_kind(PAIR_SIZE, strength)) {
        strength->set_combination(HandStrength::PAIR);
    } else {
        strength->set_combination(HandStrength::HIGH_CARD);

        strength->clear_combination_cards();
        strength->add_to_combination_cards(all_cards.front());

        strength->clear_kicker_cards();
        for (card_it card = all_cards.begin() + 1;
             card != all_cards.end() && strength->get_kicker_cards()->size() <
             HandStrength::KICKER_CARDS_SIZE - 1; ++card) {
            strength->add_to_kicker_cards(*card);
        }
    }
}
Ejemplo n.º 6
0
/****************************************************************
 * analyze_hand: Determines whether the hand contains a
 *               royal_flush, straight, a flush, four-of-a-kind,
 *               and/or three-of-a-kind; determines the
 *               number of pairs; stores the results into
 *               the external variables straight, flush,
 *               four, three, and pairs.
 ****************************************************************/
void analyze_hand(int hand[][2])
{
    int card, min_rank, max_rank, hash_pair;
    int ranks_in_hand[NUM_CARDS][2];

    flush = is_flush(hand);

    /* find the smallest and largest ranks */
    max_rank = min_rank = hand[0][RANK];
    for (card = 1; card < NUM_CARDS; card++) {
        if (hand[card][RANK] < min_rank)
            min_rank = hand[card][RANK];
        if (hand[card][RANK] > max_rank)
            max_rank = hand[card][RANK];
    }

    /* difference will be 4 (for a 5 card hand) if they're all consecutive */
    straight =  max_rank - min_rank == NUM_CARDS - 1;

    /* if we're consecutive starting at 10, then max must be the Ace */
    royal_flush = flush && straight && min_rank == 10;

    four  = false;
    three = false;
    pairs = 0;

    if (flush || straight || royal_flush)
        return;

    count_ranks_in_hand(hand, ranks_in_hand);
    /* a hand can have from 1 to 5 ranks */

    /* [> check for 4-of-a-kind, 3-of-a-kind, and pairs <] */
    for (hash_pair = 0; hash_pair < NUM_CARDS && ranks_in_hand[hash_pair][KEY] != 0; hash_pair++) {
        if (ranks_in_hand[hash_pair][VALUE] == 4) four = true;
        if (ranks_in_hand[hash_pair][VALUE] == 3) three = true;
        if (ranks_in_hand[hash_pair][VALUE] == 2) pairs++;
    }
}
Ejemplo n.º 7
0
static void determine_hand(struct hand *const best_hand, const unsigned long long HAND){
        enum hand_t type = HIGH_CARD;

        const unsigned CLUB = HAND & 0x1FFF;
        const unsigned DIAMOND = HAND>>13 & 0x1FFF;
        const unsigned HEART = HAND>>26 & 0x1FFF;
        const unsigned SPADE = HAND>>39 & 0x1FFF;

        const unsigned CLUB_ACED = CLUB | (CLUB & 0x1) << 13;
        const unsigned DIAMOND_ACED = DIAMOND | (DIAMOND & 0x1) << 13;
        const unsigned HEART_ACED = HEART | (HEART & 0x1) << 13;
        const unsigned SPADE_ACED = SPADE | (SPADE & 0x1) << 13;

        const unsigned LUMP = CLUB_ACED | DIAMOND_ACED | HEART_ACED | SPADE_ACED;

        unsigned rank;
        for(unsigned i = 0; i < 10; i++){
                const unsigned SMASK = 0x3E00 >> i;

                // check for straight
                if(is_straight(LUMP, SMASK)){
                        // check for straight-flush
                        if(is_straight_flush(CLUB_ACED, DIAMOND_ACED, HEART_ACED, SPADE_ACED, SMASK)){
                                type = STRAIGHT_FLUSH;
                        }else{
                                type = STRAIGHT;
                        }

                        rank = 9 - i;

                        break;
                }
        }

        const unsigned CLUB_NORMALIZED = CLUB_ACED >> 1;
        const unsigned DIAMOND_NORMALIZED = DIAMOND_ACED >> 1;
        const unsigned HEART_NORMALIZED = HEART_ACED >> 1;
        const unsigned SPADE_NORMALIZED = SPADE_ACED >> 1;
        const unsigned LUMP_NORMALIZED = LUMP >> 1;

        unsigned pairs = 0;
        unsigned triplet = 0;
        unsigned quadruplet = 0;

        unsigned chits = 0;
        unsigned dhits = 0;
        unsigned hhits = 0;
        unsigned shits = 0;

        for(unsigned i = 0; type < FOUR_OF_A_KIND && i < 13; i++){
                const unsigned C = CLUB_NORMALIZED & 1<<i;
                const unsigned D = DIAMOND_NORMALIZED & 1<<i;
                const unsigned H = HEART_NORMALIZED & 1<<i;
                const unsigned S = SPADE_NORMALIZED & 1<<i;

                const unsigned C_HIT = (C > 0);
                const unsigned D_HIT = (D > 0);
                const unsigned H_HIT = (H > 0);
                const unsigned S_HIT = (S > 0);

                switch(C_HIT + D_HIT + H_HIT + S_HIT){
                        case 4:
                                quadruplet = 1<<i;
                                type = FOUR_OF_A_KIND;
                                continue;
                        case 3:
                                triplet = 1<<i;
                                if(type < THREE_OF_A_KIND){
                                        type = THREE_OF_A_KIND;
                                }
                        case 2:
                                pairs |= 1<<i;
                                if(type < ONE_PAIR){
                                        type = ONE_PAIR;
                                }
                                break;
                }

                chits += C_HIT;
                dhits += D_HIT;
                hhits += H_HIT;
                shits += S_HIT;
        }

        unsigned suit;
        // check for full-house, flush, and two pair
        if(type < FULL_HOUSE && is_full_house(triplet, &pairs)){
                type = FULL_HOUSE;
        }else if(type < FLUSH && (suit = is_flush(chits, dhits, hhits, shits))){
                switch(suit){
                        case 1:
                                rank = CLUB_NORMALIZED;
                                break;
                        case 2:
                                rank = DIAMOND_NORMALIZED;
                                break;
                        case 3:
                                rank = HEART_NORMALIZED;
                                break;
                        case 4:
                                rank = SPADE_NORMALIZED;
                                break;
                }

                type = FLUSH;
        }else if(type < TWO_PAIR && is_two_pair(&pairs)){
                type = TWO_PAIR;
        }

        switch(type){
                case HIGH_CARD:
                        rank = find_extrema(LUMP_NORMALIZED, 5);
                        break;
                case ONE_PAIR:
                        rank = find_extrema(LUMP_NORMALIZED & (~pairs), 3);
                        break;
                case TWO_PAIR:
                        rank = find_extrema(LUMP_NORMALIZED & (~pairs), 1);
                        break;
                case THREE_OF_A_KIND:
                        rank = find_extrema(LUMP_NORMALIZED & (~triplet), 2);
                        break;
                case FLUSH:
                        rank = find_extrema(rank, 5);
                        break;
                case FOUR_OF_A_KIND:
                        rank = find_extrema(LUMP_NORMALIZED & (~quadruplet), 1);
                        break;
        }

        best_hand->category = type;
        best_hand->quadruplet = quadruplet;
        best_hand->triplet = triplet;
        best_hand->pairs = pairs;
        best_hand->rank = rank;
}
Ejemplo n.º 8
0
bool is_straight_flush(int* hand, int* rankcount)
{
    return is_straight(rankcount) && is_flush(hand);
}
Ejemplo n.º 9
0
/* compares the hands based on rank -- if the ranks (and rank values) are
 * identical, compares the hands based on their highcards.
 * returns 0 if h1 > h2, 1 if h2 > h1.
 */
int compare_hands (hand_t h1, hand_t h2) {
	int h2Rank = 0;
	int h1Rank = 0;
/**Finds rank of first hand **/

	if (is_onepair(h1) == 1) {
		h1Rank = 0;
	}
	if (is_twopairs(h1) == 1) {
		h1Rank = 1;
	}
	if (is_threeofakind(h1) == 1) {
		h1Rank = 2;
	}
	if (is_straight(h1) == 1) {
		h1Rank = 3;
	}
	if (is_flush(h1) == 1) {
	        h1Rank = 4;
	}
	if (is_fullhouse(h1) == 1) {
		h1Rank = 5;
	}
	if (is_fourofakind(h1) == 1) {
		h1Rank = 6;
	}
	if (is_straightflush(h1) == 1) {
		h1Rank = 7;
	}
	if (is_royalflush(h1) == 1) {
		h1Rank = 8;
	}
	if (!is_onepair(h1) && !is_twopairs(h1) && !is_threeofakind(h1) && !is_straight(h1) && !is_flush(h1) && !is_fullhouse(h1) && !is_fourofakind(h1) && !is_straightflush(h1) && !is_royalflush(h1)) {
		h1Rank = -1;
	}

///////////////////////////////////////////////
     
   if (is_onepair(h2)) {
	    if (h1Rank == 0) { 
		   int i;
		   sort_hand(h1);
		   sort_hand(h2);
		   int card1 = h1[0].value, card2 = h2[0].value; 
		   for (i = 1; i<5; i++) {
			  if (card1 == h1[i].value)
				 break;
			  else 
				 card1 = h1[i].value;
		   }

		  for (i = 1; i < 5; i++) {
			 if (card2 == h2[i].value) 
				break;
			 else
				card2 = h2[i].value;
		  }
		 return (card2 > card1);
	    }
    	    else  h2Rank = 0;
     }

    if (is_twopairs(h2)) {
	
	if (h1Rank == 1) {
	   sort_hand(h1);
	   sort_hand(h2);
	   int i;
	   int k;
	   int h1Pair1, h1Pair2, h2Pair1, h2Pair2;
	   int highestH1, highestH2;

	   for (i = 0; i < 4; i++) {
		   if (h1[i].value == h1[i + 1].value) {
			   h1Pair1 = h1[i].value;
			   k = i + 2;
			   break;
		   }
	   }
	   for (i = k; i < 4; i++) {
		   if (h1[i].value == h1[i + 1].value) {
			   h1Pair2 = h1[i].value;
			   break;
		   }
	   }

	   for (i = 0; i < 4; i++) {
		   if (h2[i].value == h2[i + 1].value) {
			   h2Pair1 = h2[i].value;
			   k = i + 2;
			   break;
		   }
	   }
	   for (i = k; i < 4; i++) {
		   if (h2[i].value == h2[i + 1].value) {
			   h2Pair2 = h2[i].value;
			   break;
		   }
	   }

	   if (h1Pair1 > h1Pair2) {
		   highestH1 = h1Pair1;
	   }
	   else if (h1Pair2 > h1Pair1) {
		   highestH1 = h1Pair2;
	   }
	 
	   if (h2Pair1 > h2Pair2) {
		   highestH2 = h1Pair1;
	   }
	   else if (h2Pair2 > h2Pair1) {
		   highestH2 = h1Pair2;
	   }
	

	   if (highestH1 > highestH2) {
		   return 0;
	   }
	   else if (highestH2 > highestH1) {
		   return 1;
	   }
	}

     else h2Rank = 1; 
}

    if (is_threeofakind(h2)) {
	    if (h1Rank == 2) {
		    int card1 = h1[0].value, card2 = h2[0].value;
		    int i;
		    
		    for (i = 1; i < 5; i++) {
			    if (card2 == h1[i].value) 
				   break;
			    else 
				   card1 = h1[i].value;
		    }
		    for (i = 1; i < 5; i++) {
			    if (card2 == h2[i].value) 
				   break;
			    else 
				   card1 = h2[i].value;
		    }
		    return (card2 > card1);
	    }
	    else h2Rank = 2;
    }

    if (is_fullhouse(h2)) {
	    if (h1Rank == 5) {
		  int h2ThreeKindValue, h1ThreeKindValue;
		  
		  if ( (h1[0].value == h1[1].value) && (h1[1].value == h1[2].value) ) {
			   h1ThreeKindValue = h1[0].value;
		   }
		  else 
			   h1ThreeKindValue = h1[1].value;

		  if ( (h2[0].value == h2[1].value) && (h2[1].value == h2[2].value) ) {
			   h2ThreeKindValue = h2[0].value;
		   }
		  else 
			   h2ThreeKindValue = h2[1].value;

		  return (h2ThreeKindValue > h1ThreeKindValue);
	    }
	     else h2Rank = 5;
    }
    
    if (is_straight(h2) && !is_straightflush(h2)) {
	    if (h1Rank == 3) {	    
	  return compare_highcards(h1, h2);
	    }
	    else h2Rank = 3;
    }

    if (is_flush(h2)) {
	    if (h1Rank == 4) {
	   return compare_highcards(h1, h2);
	    }
	    else h2Rank = 4;
    }

    if (is_fourofakind(h2)) {
	 if (h1Rank == 6) {
	           int card1 = h1[0].value, card2 = h2[0].value;
		   int i;
		   for (i = 1; i<5; i++) {
			  if (card1 == h1[i].value)
				 break;
			  else 
				 card1 = h1[i].value;
		   }

		  for (i = 1; i < 5; i++) {
			 if (card2 == h2[i].value) 
				break;
			 else
				card2 = h2[i].value;
		  }
		 return (card2 > card1);
	    }
          else  h2Rank = 6;
   }
  
   if (is_straightflush(h2)) {
	   if (h1Rank == 7) {
    	   return compare_highcards(h1, h2);
	   }
	   else h2Rank = 7;
    }
   
   if (is_royalflush(h2)) {
	   h2Rank = 8;
    }

	if (!is_onepair(h2) && !is_twopairs(h2) && !is_threeofakind(h2) && !is_straight(h2) && !is_flush(h2) && !is_fullhouse(h2) && !is_fourofakind(h2) && !is_straightflush(h2) && !is_royalflush(h2)) {
		h2Rank = -1;
	}


/**Compares hands **/

	if (h1Rank > h2Rank) {
		return 0;
	}
        else if (h2Rank > h1Rank) {
		return 1;
	}
	else if (h2Rank == h1Rank) {
		return compare_highcards(h1, h2);
	}
}