51Testing软件测试论坛
标题:
请教如何用C++编写个牌型判断的测试程序
[打印本页]
作者:
moto16017973
时间:
2004-11-25 16:51
标题:
请教如何用C++编写个牌型判断的测试程序
#ifndef _JUDGE_CARD_STATU_H_
#define _JUDGE_CARD_STATU_H_
#define TYPE_SINGLE_CARDS 0x01 //单牌
#define TYPE_PAIR_CARDS 0x20 //对子
#define TYPE_TRIAD_CARDS 0x30 //三张牌
#define TYPE_TRIAD_CARDS_SINGLE 0x31 //三带一
#define TYPE_TRIAD_CARDS_PAIR 0x32 //三带二
#define TYPE_SINGLE_SEQUENCE_CARDS 0x15 //单顺牌(5张)
#define TYPE_SINGLE_SEQUENCE_SIX 0x16 //单顺牌(6张)
#define TYPE_SINGLE_SEQUENCE_SEVEN 0x17 //单顺牌(7张)
#define TYPE_SINGLE_SEQUENCE_EIGHT 0x18 //单顺牌(8张)
#define TYPE_SINGLE_SEQUENCE_NINE 0x19 //单顺牌(9张)
#define TYPE_SINGLE_SEQUENCE_TEN 0x1A //单顺牌(10张)
#define TYPE_SINGLE_SEQUENCE_ELEVEN 0x1B //单顺牌(11张)
#define TYPE_SINGLE_SEQUENCE_TWELVE 0x1C //单顺牌(12张)
#define TYPE_PAIR_SEQUENCE_CARDS 0x23 //双顺牌(3对)
#define TYPE_PAIR_SEQUENCE_FOUR 0x24 //双顺牌(4对)
#define TYPE_PAIR_SEQUENCE_FIVE 0x25 //双顺牌(5对)
#define TYPE_PAIR_SEQUENCE_SIX 0x26 //双顺牌(6对)
#define TYPE_PAIR_SEQUENCE_SEVEN 0x27 //双顺牌(7对)
#define TYPE_PAIR_SEQUENCE_EIGHT 0x28 //双顺牌(8对)
#define TYPE_PAIR_SEQUENCE_NINE 0x29 //双顺牌(9对)
#define TYPE_PAIR_SEQUENCE_TEN 0x2A //双顺牌(10对)
#define TYPE_TRIAD_SEQUENCE_CARDS 0x3B //三顺牌(连续2个)
#define TYPE_TRIAD_SEQUENCE_THREE 0x3C //三顺牌(连续3个)
#define TYPE_TRIAD_SEQUENCE_FOUR 0x3D //三顺牌(连续4个)
#define TYPE_TRIAD_SEQUENCE_FIVE 0x3E //三顺牌(连续5个)
#define TYPE_TRIAD_SEQUENCE_SIX 0x3F //三顺牌(连续6个)
#define TYPE_FOUR_WITH_TWO 0x42 //四带二
#define TYPE_PLANE_TWO_WING_SIGLE 0x60 //飞机带翅膀(两三条带两单牌)
#define TYPE_PLANE_TWO_WING_TWO 0x61 //飞机带翅膀(两三条带两对子)
#define TYPE_PLANE_THREE_WING_SIGLE 0x62 //飞机带翅膀(三三条带三单牌)
#define TYPE_PLANE_THREE_WING_TWO 0x63 //飞机带翅膀(三三条带三对子)
#define TYPE_PLANE_FOUR_WING_SIGLE 0x64 //飞机带翅膀(四三条带四单牌)
#define TYPE_PLANE_FOUR_WING_TWO 0x65 //飞机带翅膀(四三条带四对子)
#define TYPE_PLANE_FIVE_WING_SIGLE 0x66 //飞机带翅膀(五三条带五单牌)
#define TYPE_BOMB_CARD 0x70 //炸弹
#define TYPE_ROCKET_CARD 0x71 //火箭
/*
*判断牌形,arg_num[]为存有牌的数组,arg_num为牌的张数,arg_value用来返回牌的大小,
*若牌合法,返回牌形,arg_value返回牌形中主要牌的最大一张,
*若牌不合,法否则返回-1;arg_value返回0;
*/
int JudgeCardShape(int arg_card[], int arg_num, int &arg_value)
{
#endif //_JUDGE_CARD_STATU_H_
作者:
moto16017973
时间:
2004-11-29 09:51
#include <vector>
#include <algorithm>
#include "JudgeCard.h"
using namespace std;
int MoreCard(int &arg_low, char &arg_high);
int JudgeCardShape(int arg_card[], int arg_num, int &arg_value)
{
if(arg_num <= 0)
{
arg_value = 0;
return -1;
}
vector<int>card(arg_card, arg_card+arg_num);
sort(card.begin(),card.end());
card.push_back(-1);//ネard[i]=-1ア桄セコ賽゙ナニ
int statu = 1;
char more_statu = 0;
int i=1;
int temp_count = 1;
int max_count;
while(card[i] != -1 && i < 16)
{
if(card[i] == card[i-1])
{
statu = statu|(3<<(i*2));
temp_count ++;
}
else if(card[i] == card[i-1]+1)
{
statu = statu|(2<<(i*2));
temp_count = 1;
}
else
{
statu = statu|(1<<(i*2));
temp_count = 1;
}
if(temp_count >= max_count)
{
max_count = temp_count;
arg_value = card[i];
}
i++;
}
if(i == 16)
{
while(card[i] != -1 && i < 20)
{
if(card[i] == card[i-1])
{
more_statu = more_statu|(3<<((i-16)*2));
temp_count++;
}
else if(card[i] == card[i-1]+1)
{
more_statu = more_statu|(2<<((i-16)*2));
temp_count = 1;
}
else
{
more_statu = more_statu|(1<<((i-16)*2));
temp_count = 1;
}
if(temp_count >= max_count)
{
max_count = temp_count;
arg_value = card[i];
}
i++;
}
}
if(more_statu == 0)
{
switch(statu)
{
/*****-----------------オ・ナニ-------------*****/
case 1:
return TYPE_SINGLE_CARDS;
break;
/*****-----------------サ-------------*****/
//case 9:
// if(card[0] == ミ。ケ・
// return TYPE_PAIR_CARDS;
// else
// {
// arg_value = 0;
// return -1;
// }
// break;
/*****-----------------カヤラモ-------------*****/
case 13:
return TYPE_PAIR_CARDS;
break;
/*****-----------------ネフ・------------*****/
case 61:
return TYPE_TRIAD_CARDS;
break;
/*****--------------ヒトテカ(ユィオッ)------------*****/
case 253:
return TYPE_BOMB_CARD;
break;
/*****-----------------ネエサ-------------*****/
case 125:
case 189:
case 249:
case 245:
return TYPE_TRIAD_CARDS_SINGLE;
break;
/*****-----------------ネエ-------------*****/
case 989:
case 1005:
case 957:
case 893:
return TYPE_TRIAD_CARDS_PAIR;
break;
/****----ヒウラモ(ホ袗ナモテシーメヤノマハヨオマ狠レオトオ・ナニ)----*****/
case 681: return TYPE_SINGLE_SEQUENCE_CARDS; //5ユナ
case 2729: return TYPE_SINGLE_SEQUENCE_SIX; //6ユナ
case 10921: return TYPE_SINGLE_SEQUENCE_SEVEN; //7ユナ
case 43689: return TYPE_SINGLE_SEQUENCE_EIGHT; //8ユナ
case 174761: return TYPE_SINGLE_SEQUENCE_NINE; //9ユナ
case 699049: return TYPE_SINGLE_SEQUENCE_TEN; //10ユナ
case 2796201: return TYPE_SINGLE_SEQUENCE_ELEVEN; //11ユナ
case 11184809: return TYPE_SINGLE_SEQUENCE_TWELVE; //12ユナ
//return;
break;
/****----ネヒウ(チスクーメヤノマハヨオマ狠レオトネフ・----*****/
case 4029: return TYPE_TRIAD_SEQUENCE_CARDS; //(チャミ・ク・
case 257981: return TYPE_TRIAD_SEQUENCE_THREE; //(チャミ・ク・
case 16510909: return TYPE_TRIAD_SEQUENCE_FOUR; //(チャミ・ク・
case 1056698301: return TYPE_TRIAD_SEQUENCE_FIVE; //(チャミ・ク・
//return;
break;
/****----ヒォヒウ(ネクーメヤノマハヨオマ狠レオトカヤラモ)----*****/
case 3821: return TYPE_PAIR_SEQUENCE_CARDS;//(3カヤ)
case 61165: return TYPE_PAIR_SEQUENCE_FOUR; //(3カヤ)
case 978669: return TYPE_PAIR_SEQUENCE_FIVE; //(3カヤ)
case 15658733: return TYPE_PAIR_SEQUENCE_SIX; //(3カヤ)
case 250539757: return TYPE_PAIR_SEQUENCE_SEVEN;//(3カヤ)
case -286331155: return TYPE_PAIR_SEQUENCE_EIGHT;//(3カヤ)
//return;
break;
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/)
Powered by Discuz! X3.2