Beispiel #1
0
void evaluate_hand(int Decks[2][5][2], int Hands[2], const char *hNames[])
{
	int i;
	for( i = 0; i < 2; i++)
	{
		if ((check_flush(Decks, i)) && (check_straight(Decks, i)))
			{
			Hands[i] = 9;
			continue;
			}
		else if (check_four(Decks, i))
			{
			Hands[i] = 8;
			continue;
			}
		else if (check_full(Decks, i))
			{
			Hands[i] = 7;
			continue;
			}
		else if (check_flush(Decks, i))
			{
			Hands[i] = 6;
			continue;	
			}
		else if (check_straight(Decks, i))
			{
			Hands[i] = 5;
			continue;
			}
		else if (check_three(Decks, i))
			{
			Hands[i] = 4;
			continue;
			}
		else if (check_two_pair(Decks, i))
			{
			Hands[i] = 3;
			continue;
			}
		else if (check_pair(Decks, i))
			{
			Hands[i] = 2;
			continue;
			}
		else
			Hands[i] = 1;	
		}
	
	if	(Hands[0] > Hands[1])
		printf("HAND 1 WINNER with %s\n ", hNames[Hands[0]-1]);
	else if (Hands[1] > Hands[0])
		printf("HAND 2 WINNER with %s\n", hNames[Hands[1]-1]);
	else if (getMax(Decks, 0) > getMax(Decks, 1))
		printf("HAND 1 WINNER with %s\n ", hNames[Hands[0]-1]);
	else if (getMax(Decks, 1) > getMax(Decks, 0))
		printf("HAND 2 WINNER with %s\n", hNames[Hands[1]-1]);
	else
		printf("Split\n");
}
Beispiel #2
0
void analyze_hand(void)
{
	int count;
	if(check_straight())
	{
		printf("STRAIGHT");
	}
	if(check_flush())
	{
		printf("FLUSH");
	}
	if(check_four_cards())
	{
		printf("FOUR CARDS");
	}

	if(check_three_cards())
	{
		printf("TRIPLE");
	}
	if((count = count_paris()))
	{
		printf("PAIR :: %d",count);
	}
	printf("\n");
}
Beispiel #3
0
// テイクによる制限をかける関数 制限する必要が無いならDEFAULT_NUM(10)を返す
int limit_take(int cg, int tk, Handcard hands[], Cards remain_card, Cards hand_card, Cards deck_card, int hd[])
{
  int t;
  int k; // 反復変数
  int flag = 0; 

  if ( tk == 0 ) {
    if ( check_straight(remain_card, hand_card) >= 1 ) { flag = 1; }
    for ( k = 0; k < 4; k++ ) { if ( hand_card.sut[k] >= 4 ) { flag = 1; } }
    if ( poker_point(hd) >= P3 ) { flag = 1; }
    if ( flag == 0 ) { return -1; }
  }

  if ( tk == 1 ) {
    for ( k = 0; k < 4; k++ ) { if ( hand_card.sut[k] >= 4 ) { flag = 1; } }
    if ( check_straight(remain_card, hand_card) >= 3 ) { flag = 1; }
    if ( poker_point(hd) >= P3 ) { flag = 1; }
    if ( flag == 0 ) { return -1; }
  }

  if ( tk == 4 && deck_card.amount <= 11 ) { return -1; }
  if ( tk == 3 && deck_card.amount <= 22 ) { return -1; }
  /* if ( tk == 2 && deck_card.amount <= 33 ) { return -1; } */

  // テイクによる交換回数の制限
  if ( tk < 3 && cg >= 4 ) {
    for ( k = 0; k < 4; k++ ) {
      if ( hand_card.sut[k] >= 4 ) {
        return flush(hands, hand_card, deck_card, cg);
      }
    }
    if ( check_straight(remain_card, hand_card) >= 1 ) {
      return straight(hands, remain_card, hand_card, deck_card, cg);
    }
    if ( poker_point(hd) >= P3 ) {
      return pair(hands, hand_card, deck_card, remain_card);
    }
    return -1;
  }
  // 最後のtakeは別関数
  if ( tk == 5 ) { return final_attack(hands, remain_card, hand_card, deck_card, cg); }
  return DEFAULT_NUM;
}
Beispiel #4
0
int straight(Handcard hd[], Cards remain_card, Cards hand_card, Cards deck_card, int cg) 
{
  int k1, k2, num;
  double exp_num[13] = {0}; // 全てのカードの確率を保持
  double prob; // 一時的に確率を保持
  int reqire_num; // 残り必要枚数
  int change_num = CHNG - cg;

  // リーチの場合
  if ( check_straight(remain_card, hand_card) ) {
    for ( k1 = 0; k1 < HNUM - 1; k1++ ) {
      for ( k2 = k1+1; k2 < HNUM; k2++ ) {
        if ( hd[k1].num == hd[k2].num ) {
          if ( hand_card.sut[hd[k1].sut] < hand_card.sut[hd[k2].sut]) { return k1; }
          else { return k2; }
        }
      }
    }
  }
  for ( k1 = 0; k1 < 10; k1++ ) {
    prob = 1;
    reqire_num = 0;
    // 確率の計算
    for ( k2 = k1; k2 < k1 + 5; k2++ ) {
      if ( k2 == 13 ) { num = 0; }
      else { num = k2; }
      if ( hand_card.num[num] == 0 ) {
        prob *= ((double)deck_card.num[num] / deck_card.amount);
        reqire_num++;
      }
    }
    if ( reqire_num > change_num ) { prob = 0; }
    // 確率の格納
    for ( k2 = k1; k2 < k1 + 5; k2++ ) {
      if ( k2 == 13 ) { num = 0; }
      else { num = k2; }
      exp_num[num] += prob;
    }
  }
  for ( k1 = 0; k1 < HNUM; k1++ ) {
    hd[k1].exp[STRAIGHT] += (exp_num[hd[k1].num] * P4);
  }
  bubble_sort_role(hd, HNUM, STRAIGHT);
  return hd[0].pos;
}
Beispiel #5
0
int strategy(const int hd[], const int fd[], int cg, int tk, const int ud[], int us)
{
  int disc_num;  // 捨てるカードの番号(-1:捨てない)
  int t;
  int k, k1, k2; // 反復変数
  Handcard hands[5]; // 手札を保管
  Cards hand_card, deck_card, remain_card;

  // 手札の情報を格納
  for (k1 = 0; k1 < HNUM; k1++ ) {
    hands[k1].num_val = hd[k1];
    hands[k1].num     = hd[k1] % 13;
    hands[k1].sut     = hd[k1] / 13;
    hands[k1].pos     = k1;
    for ( k2 = 0; k2 < 11; k2++ ) { hands[k1].exp[k2] = 0; }
  }
  calc_card(hands, &remain_card, &deck_card, &hand_card, ud, us);
  //フルハウス以上は確定
  if ( tk != 5 && poker_point(hd) >= P6 ) { return -1; }

  disc_num = limit_take(cg, tk, hands, remain_card, hand_card, deck_card, hd);  if ( disc_num != DEFAULT_NUM ) { return disc_num; }
  // ストレートリーチならストレートを狙う
  if ( check_straight(remain_card, hand_card) >= 1 ) {
    return straight(hands, remain_card, hand_card, deck_card, cg);
  }
  // フラッシュリーチならフラッシュを狙う
  for (k1 = 0; k1 < HNUM; k1++ ) {
    if ( hand_card.sut[k1] >= 4 && deck_card.sut[k1] >= 2 ) {
      return flush(hands, hand_card, deck_card, cg);
    }
  }
  /* // 3カード以上ならペア系を狙う */
  if ( poker_point_pair(hand_card.num) == P3 ) {
    return pair(hands, hand_card, deck_card, remain_card);
  }
  return decide_discard(hands, remain_card, hand_card, deck_card, cg, tk);
}