◣我重发~~~◥:人机对战扑克游戏,详情请进

到百度贴吧首页
新闻   网页   贴吧   知道   MP3   图片   视频   百科
    吧内搜索 | 帮助

◣我重发~~~◥:人机对战扑克游戏,详情请进

2楼

/**********************13cards.c开始******************/
/*将以下代码保存为 13cards.c*/
#include "showcrds.c"
#include "pokerAI.c"
#include "menu.c"
#include <graphics.h>
#include <stdlib.h>

typedef struct{
  unsigned char num;
  unsigned char style;
}Poker;
typedef struct{
  unsigned char num;
  unsigned char style;
  unsigned char status;
}PokerPL;

Poker allPoker[53]={{3,1},{4,1},{5,1},{6,1},{7,1},{8,1},{9,1},
        {10,1},{11,1},{12,1},{13,1},{14,1},{15,1},
        {3,2},{4,2},{5,2},{6,2},{7,2},{8,2},{9,2},
        {10,2},{11,2},{12,2},{13,2},{14,2},{15,2},
        {3,3},{4,3},{5,3},{6,3},{7,3},{8,3},{9,3},
        {10,3},{11,3},{12,3},{13,3},{14,3},{15,3},
        {3,4},{4,4},{5,4},{6,4},{7,4},{8,4},{9,4},
        {10,4},{11,4},{12,4},{13,4},{14,4},{15,4},{0,0}};

Poker deskTopPoker[53];
Poker cpuPoker[3][14];
PokerPL playerPoker[14];
Poker currentPokers[14];

void pokerToStr(Poker *p,unsigned char *str);
void drawCurrent(int player);
void washPokers(int flag);
void devide4(void);
void initGrphErrExit(void);
void updateCpus(int index);
void updatePlayer(int flag,int current);
void updateCrntPoker(void);
void updateDsktpPk(void);
void addTodeskTop(Poker p);
int game(int player);
void drawCurrent(int player);
int turnToCpus(int index,int *flag);
int getPeriod(int playerIndex);
int turnToPlayer(int *flag);
void pokerToStr(Poker p[],unsigned char *str);
int getCountP(Poker p[]);
int getCountPL(void);
void msg(int winner);
void main(void);

void washPokers(int flag){
  Poker washTmp;
  int i;
  int m,n;
  if(flag==0) randomize();
  for(i=0;i<5000;i++){
    m=random(52);
    n=random(52);
    washTmp=allPoker[m];
    allPoker[m]=allPoker[n];
    allPoker[n]=washTmp;
  }
  currentPokers[0].num=0;
  for(i=0;i<52;i++)
    deskTopPoker[i].num=0;
  cpuPoker[2][0].num=0;
  cpuPoker[1][0].num=0;
  cpuPoker[0][0].num=0;
  playerPoker[0].num=0;
}

void devide4(void){
  int i,tmp,j;
  PokerPL swapTmp;
  int pa=0,pb[3]={0,0,0};
  for(i=0;i<52;i++){
    if(i%4==0){
      playerPoker[pa].num=allPoker[i].num;

3楼

      playerPoker[pa].style=allPoker[i].style;
      playerPoker[pa].status=0;
      pa++;
    }
    else{
      tmp=(i%4)-1;
      cpuPoker[tmp][pb[tmp]]=allPoker[i];
      pb[tmp]++;
    }
  }
  playerPoker[13].num=0;
  playerPoker[13].status=0;
  cpuPoker[0][13].num=0;
  cpuPoker[1][13].num=0;
  cpuPoker[2][13].num=0;
  currentPokers[0].num=0;
  deskTopPoker[0].num=0;
  for(j=0;j<13;j++){
    for(i=0;i<12-j;i++){
      if(playerPoker[i].num>playerPoker[i+1].num){
        swapTmp=playerPoker[i];
        playerPoker[i]=playerPoker[i+1];
        playerPoker[i+1]=swapTmp;
      }
    }
  }
}


void initGrphErrExit(void){
  int gd=VGA,gm=VGAHI,errorcode;

  /*registerbgidriver(EGAVGA_driver);*/
  initgraph(&gd,&gm,"");
  errorcode=graphresult();
  if (errorcode != grOk)
  {
    printf("\nGraphics error: %s\n",grapherrormsg(errorcode));
    printf("\nI am sorry that an error occurred(in initgraph).\n\n");
    printf("\t\tPress any key to exit...");
    getch();
    exit(0);
  }
}

void updateCpus(int index){
  int i;
  switch(index){
    case 0:
      setfillstyle(SOLID_FILL,GREEN);
      bar(560,50,636,412);
      setcolor(LIGHTBLUE);
      outtextxy(565,50,"Bill");
      for(i=0;cpuPoker[index][i].num != 0;i++)
        showCard(563,i*21+60,0,0);
      break;
    case 1:
      setfillstyle(SOLID_FILL,GREEN);
      bar(140,0 ,482,100);
      setcolor(RED);
      outtextxy(55,4,"Wen Xichang");
      for(i=0;cpuPoker[index][i].num != 0;i++)
        showCard(i*22+144,2,0,0);
      break;
    case 2:
      setfillstyle(SOLID_FILL,GREEN);
      bar(2,50,76,412);

4楼

      setcolor(YELLOW);
      outtextxy(5,50,"Computer");
      for(i=0;cpuPoker[index][i].num != 0;i++)
        showCard(5,i*21+60,0,0);
      break;
  }
}
void updatePlayer(int flag,int current){
  static old=20;
  int i;
  int x,y;
  if(old==20){
    setfillstyle(SOLID_FILL,GREEN);
    for(i=0;i<13;i++) bar(149+i*22,462,167+i*22,477);
  }
  else{
    setfillstyle(SOLID_FILL,GREEN);
    bar(149+old*22,462,167+old*22,477);
  }

  logo(149+current*22,462,48,COPY_PUT);
  old=current;
  if(flag != 0){
    setfillstyle(SOLID_FILL,GREEN);
    bar(147,342,481,363);
    bar(147,439,481,460);
    for(i=0;i<13;i++){
      if(playerPoker[i].num != 0){
        if(playerPoker[i].status==0)
          showCard(147+i*22,364,playerPoker[i].num,playerPoker[i].style);
        else
          showCard(147+i*22,342,playerPoker[i].num,playerPoker[i].style);
      }
      else {
        setfillstyle(SOLID_FILL,GREEN);
        bar(196+i*22,342,481,460);
        break;
      }
    }
  }
}

void updateCrntPoker(void){
  int i;
  setfillstyle(SOLID_FILL,GREEN);
  bar(226,231,512,330);
  for(i=0;currentPokers[i].num != 0;i++)
    showCard(229+i*15,232,currentPokers[i].num,currentPokers[i].style);
}

void updateDsktpPk(void){
  int i;
  setfillstyle(SOLID_FILL,GREEN);
  bar(140,102,512,230);
  for(i=0;deskTopPoker[i].num != 0;i++){
    if(i<26) showCard(141+i*12,103,deskTopPoker[i].num,deskTopPoker[i].style);
    else showCard(141+(i-26)*12,133,deskTopPoker[i].num,deskTopPoker[i].style);
  }
}

void addTodeskTop(Poker p){
  int i=0;
  for(;;){
    if(deskTopPoker[i].num==0) break;
    i++;
  }
  deskTopPoker[i]=p;
  if(i<26) showCard(141+i*12,103,deskTopPoker[i].num,deskTopPoker[i].style);
  else showCard(141+(i-26)*12,133,deskTopPoker[i].num,deskTopPoker[i].style);

5楼

}

int game(int player){
  int tmp=0,i;
  int playerTurn;
  unsigned char tmp1[14];
  unsigned char tmp2[14];
  int jump;
  
  setfillstyle(SOLID_FILL,GREEN);
  bar(0,0,639,479);
  
  washPokers(1);
  devide4();
  updateCpus(0);
  updateCpus(1);
  updateCpus(2);
  updatePlayer(1,0);
  
  playerTurn=player;
  jump=player;
  
  for(;;){
    switch(jump){
      case 3:
        AAAA:
        drawCurrent(3);
        tmp=turnToPlayer(&playerTurn);
        switch(tmp){
          case 20:
            switch(inMenu(3)){
              case 2:
                return 4;
              case 1:
              case 0:
                updateDsktpPk();
                updateCrntPoker();
                goto AAAA;
              case 3:
                closegraph();
                exit(0);
            }
            break;
          case 10:
            return 3;
        }
        if(tmp != 0){
          sleep(1);
          for(i=0;currentPokers[i].num != 0;i++)
            addTodeskTop(currentPokers[i]);
        }
        jump=0;
        break;

6楼

      case 0:  
        drawCurrent(0);
        tmp=turnToCpus(0,&playerTurn);
        if(tmp != 0){
          sleep(1);
          for(i=0;currentPokers[i].num != 0;i++)
            addTodeskTop(currentPokers[i]);
        }
        if(tmp==10)
          return 0;
        jump++;  
        break;  
        case 1:
        drawCurrent(1);
        tmp=turnToCpus(1,&playerTurn);
        if(tmp != 0){
          sleep(1);
          for(i=0;currentPokers[i].num != 0;i++)
            addTodeskTop(currentPokers[i]);
        }
        if(tmp==10)
          return 1;
        
        jump++;
        break;  
      case 2:  
        drawCurrent(2);
        tmp=turnToCpus(2,&playerTurn);
        
        if(tmp != 0){
          sleep(1);
          for(i=0;currentPokers[i].num != 0;i++)
            addTodeskTop(currentPokers[i]);
        }
          
        if(tmp==10)
          return 2;
        jump++;
        break;
    }
  }
}

void drawCurrent(int player){
  setcolor(GREEN);
  line(20,23,52,23);
  line(20,23,36,44);
  line(36,44,52,23);
  
  line(112,34,133,50);
  line(112,34,112,66);

7楼

  line(133,50,112,66);

  line(578,19,610,19);
  line(578,19,594,40);
  line(610,19,594,40);
  
  line(107,398,107,430);
  line(107,398,128,414);
  line(107,430,128,414);
  
  line(144,101,478,101);
  line(559,55,559,403);
  line(79,55,79,403);
  setcolor(YELLOW);
  switch(player){
    case 0:
      line(578,19,610,19);
      line(578,19,594,40);
      line(610,19,594,40);
      line(559,55,559,403);
      break;
    case 1:
      line(112,34,133,50);
      line(112,34,112,66);
      line(133,50,112,66);
      line(144,101,478,101);
      break;
    case 2:
      line(20,23,52,23);
      line(20,23,36,44);
      line(36,44,52,23);
      line(79,55,79,403);
      break;
    case 3:
      line(107,398,107,430);
      line(107,398,128,414);
      line(107,430,128,414);
  }
}
    

int turnToCpus(int index,int *flag){
  unsigned char tmp1[14],ind[14],tmp2[14];
  int i,j;

  if(*flag==index){
    pokerToStr(cpuPoker[index],tmp1);
    AIout(tmp1,ind,getPeriod(index));
    for(i=0;i<14;i++){
      if(ind[i]==255) break;
      currentPokers[i]=cpuPoker[index][ind[i]];
      cpuPoker[index][ind[i]].num=0;
      cpuPoker[index][ind[i]].style=0;
    }
    currentPokers[i].num=0;
    *flag=index;
    for(i=0;i<14;i++){
      if(cpuPoker[index][i].num==0){
        for(j=i+1;j<14;j++){
          if(cpuPoker[index][j].num != 0){
            cpuPoker[index][i]=cpuPoker[index][j];
            cpuPoker[index][j].num=0;
            cpuPoker[index][j].style=0;
            break;
          }

8楼

        }
      }
    }
    updateCpus(index);
    updateCrntPoker();
    if(getCountP(cpuPoker[index])==0) return 10;
    return 1;
  }
  else{
    pokerToStr(cpuPoker[index],tmp1);
    pokerToStr(currentPokers,tmp2);
      if(getType(tmp2)==0)
        printf("!!!!");
    if(AIeat(tmp1,tmp2,ind,getPeriod(index)) != 0){
      for(i=0; i<14;i++){
        if(ind[i]==255) break;
        currentPokers[i]=cpuPoker[index][ind[i]];
        cpuPoker[index][ind[i]].num=0;
        cpuPoker[index][ind[i]].style=0;
      }
      currentPokers[i].num=0;
      *flag=index;
      for(i=0;i<14;i++){
        if(cpuPoker[index][i].num==0){
          for(j=i+1;j<14;j++){
            if(cpuPoker[index][j].num != 0){
              cpuPoker[index][i]=cpuPoker[index][j];
              cpuPoker[index][j].num=0;
              cpuPoker[index][j].style=0;
              break;
            }
          }
        }
      }
      updateCpus(index);
      updateCrntPoker();
      if(getCountP(cpuPoker[index])==0) return 10;
      return 1;
    }
    return 0;
  }
}

int getPeriod(int playerIndex){
  int num[4],sum;
  num[0]=getCountP(cpuPoker[0]);
  num[1]=getCountP(cpuPoker[1]);
  num[2]=getCountP(cpuPoker[2]);
  num[3]=getCountPL();
  if(num[playerIndex+1]<2||num[playerIndex]<3) return 4;
  sum=num[0]+num[1]+num[2]+num[3];
  if(sum>40) return 1;
  if(sum>26) return 2;
  return 3;
}


int turnToPlayer(int *flag){

9楼

  int key=0;
  int i,j,t;
  static int hand=0;
  unsigned char tmp1[14],tmp2[14],tmp3[14],tmp4[14];
  Poker tmpP[14],tmpQ[14];
  for(;;){
    if (bioskey(1))
      key=bioskey(0);
    else
      key=0;

    switch(key){
      case LEFT:
        hand=((hand<1)?(getCountPL()-1): (hand-1));
        updatePlayer(0,hand);
        break;
      case RIGHT:
        hand=((hand >= (getCountPL()-1))?0 : (hand+1));
        updatePlayer(0,hand);
        break;
      case UP:
        if(playerPoker[hand].num>2&&playerPoker[hand].num<16){
          playerPoker[hand].status=1;
          updatePlayer(1,hand);
        }
        break;
      case DOWN:
        playerPoker[hand].status=0;
        updatePlayer(1,hand);
        break;
      case ENTER:
      case SPACE:
        i=0;
        for(j=0;j<14;j++){
          if(playerPoker[j].status==1){
            tmpP[i].num=playerPoker[j].num;
            tmpP[i].style=playerPoker[j].style;
            playerPoker[j].status=0;
            i++;
          }
        }
        tmpP[i].num=0;
        pokerToStr(tmpP,tmp1);

        if(*flag != 3){
          pokerToStr(currentPokers,tmp2);
          for(i=0;i<14;i++)
            tmpQ[i].num=playerPoker[i].num;

          pokerToStr(tmpQ,tmp3);

10楼

          if(AIeat(tmp3,tmp2,tmp4,1)==0) return 0;
          t=getType(tmp1);
          if(t!=4){
            if((getType(tmp2) != t)||(t==0)|| \
              (getSmall(tmp2)>=getSmall(tmp1))){
              updatePlayer(1,hand);
              break;
            }
          }
          else{
            if((getType(tmp2) == 4)&& \
              (getSmall(tmp2)>=getSmall(tmp1))){
              updatePlayer(1,hand);
              break;
            }
          }
        }
        else{
          if(getType(tmp1)==0){
            updatePlayer(1,hand);
            break;
          }
        }

        for(i=0;tmpP[i].num != 0;i++){
          for(j=0;j<14;j++){
            if(tmpP[i].num==playerPoker[j].num&& \
              tmpP[i].style==playerPoker[j].style){
              playerPoker[j].num=0;
              playerPoker[j].style=0;
              currentPokers[i]=tmpP[i];
            }
          }
        }
        currentPokers[i].num=0;
        for(i=0;i<14;i++){
          if(playerPoker[i].num==0){

11楼

            for(j=i+1;j<14;j++){
              if(playerPoker[j].num != 0){
                playerPoker[i]=playerPoker[j];
                playerPoker[j].num=0;
                playerPoker[j].style=0;
                break;
              }
            }
          }
        }
        hand=0;
        updatePlayer(1,hand);
        updateCrntPoker();
        *flag=3;
        if(getCountPL()==0) return 10;
        return 1;
      case ESC:
        return 20;
    }
  }
}


void pokerToStr(Poker p[],unsigned char *str){
  int i,j=0;
  for(i=0;i<14;i++){
    if(p[i].num != 0){
      *(str+j)=(char)(p[i].num);
      j++;
    }
    else break;
  }
  *(str+j)=0;
}

int getCountP(Poker p[]){
  int i=0;
  for(;;){
    if(p[i].num==0) break;
    i++;
  }
  return i;
}

int getCountPL(void){
  int i=0;
  for(;;){
    if(playerPoker[i].num==0) break;
    i++;
  }
  return i;
}

void msg(int winner){
  setfillstyle(SOLID_FILL,9);
  bar(204,152,427,285);
  dBorder(204,152,427,285);
  paintLogo(4);
  setcolor(WHITE);
  outtextxy(246,189,"WINNER:");
  setcolor(BLUE);
  settextstyle(0,0,2);
  switch(winner){
    case 0:
      outtextxy(230,211,"Bill Gates");
      break;
    case 1:
      outtextxy(230,211,"Wen Xichang");
      break;
    case 2:
      outtextxy(230,211,"Computer");
      break;
    default:
      outtextxy(230,211,"YOU !!!");
  }
  settextstyle(0,0,0);
  setcolor(GREEN);
  outtextxy(260,257,"Press <ENTER> ...");
  
  while(getch() != 13);
  setfillstyle(SOLID_FILL,GREEN);
  bar(204,152,427,285);
}

void main(void){
  int key;
  int winner=3;
  
  initGrphErrExit();
  inMenu(1);
  washPokers(0);
  for(;;){
    winner=game(winner);
    if(winner==4){
      inMenu(1);
      winner=3;
    }
    else
      msg(winner);
  }
}
/**********************13cards.c结束******************/

12楼

/***********************logo.h开始***********************/
/*将以下代码保存为logo.h*/
#include <graphics.h>

char logoBmp1[]={8,0,8,0,255,128,255,128,247,128,247,128,255,128,255,128,227,
128,227,128,255,128,255,128,193,128,193,128,255,128,
255,128,128,128,128,128,255,128,255,128,0,0,0,0,255,128,
255,128,128,128,128,128,255,128,255,128,193,128,193,128,
255,128,255,128,227,128,227,128,255,128,255,128,247,128,247,128};

char logoBmp2[]={8,0,8,0,227,128,227,128,227,128,227,128,193,128,193,128,193,128,
193,128,193,128,193,128,193,128,193,128,162,128,162,128,162,128,162,
128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,148,128,148,128,148,128,148,128,
247,128,247,128,247,128,247,128,227,128,227,128,227,128,227,128};

char logoBmp3[]={8,0,8,0,255,128,255,128,156,128,156,128,255,128,255,128,8,0,8,0,
255,128,255,128,0,0,0,0,255,128,255,128,0,0,0,0,255,128,255,128,0,
0,0,0,255,128,255,128,128,128,128,128,255,128,255,128,193,128,193,128,
255,128,255,128,227,128,227,128,255,128,255,128,247,128,247,128};

char logoBmp4[]={8,0,8,0,247,128,247,128,247,128,247,128,227,128,227,128,227,128,
227,128,193,128,193,128,193,128,193,128,128,128,128,128,128,128,128,
128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,148,128,148,128,148,128,148,128,
247,128,247,128,247,128,247,128,227,128,227,128,227,128,227,128};

char logoBmp5[]={14,0,14,0,255,254,255,254,254,254,254,254,255,254,255,254,252,126,
252,126,255,254,255,254,248,62,248,62,255,254,255,254,240,30,
240,30,255,254,255,254,224,14,224,14,255,254,255,254,192,6,192,6,
255,254,255,254,128,2,128,2,255,254,255,254,0,0,0,0,255,254,255,
254,128,2,128,2,255,254,255,254,192,6,192,6,255,254,255,254,224,14,
224,14,255,254,255,254,240,30,240,30,255,254,255,254,248,62,248,62,
255,254,255,254,252,126,252,126,255,254,255,254,254,254,254,254};

char logoBmp6[]={14,0,14,0,252,126,252,126,252,126,252,126,248,62,248,62,248,62,
248,62,240,30,240,30,240,30,240,30,240,30,240,30,240,30,240,30,
240,30,240,30,240,30,240,30,248,62,248,62,248,62,248,62,196,70,
196,70,196,70,196,70,128,2,128,2,128,2,128,2,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,130,130,130,130,130,130,130,130,198,198,
198,198,198,198,198,198,252,126,252,126,252,126,252,126,248,62,248,62,
248,62,248,62};

char logoBmp7[]={14,0,14,0,255,254,255,254,195,134,195,134,255,254,255,254,129,2,
129,2,255,254,255,254,1,0,1,0,255,254,255,254,0,0,0,0,255,254,255,
254,0,0,0,0,255,254,255,254,0,0,0,0,255,254,255,254,0,0,0,0,
255,254,255,254,128,2,128,2,255,254,255,254,128,2,128,2,255,254,
255,254,192,6,192,6,255,254,255,254,224,14,224,14,255,254,255,254,
240,30,240,30,255,254,255,254,248,62,248,62,255,254,255,254,252,
126,252,126,255,254,255,254,254,254,254,254};

char logoBmp8[]={14,0,14,0,254,254,254,254,254,254,254,254,252,126,252,126,252,
126,252,126,248,62,248,62,248,62,248,62,240,30,240,30,240,30,240,
30,224,14,224,14,224,14,224,14,192,6,192,6,192,6,192,6,128,2,128,
2,128,2,128,2,128,2,128,2,128,2,128,2,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,2,128,2,128,2,128,2,128,134,194,134,194,134,

13楼

194,134,194,252,126,252,126,252,126,252,126,248,62,248,62,248,62,
248,62};

char logoBmp9[]={38,0,38,0,255,255,239,255,254,255,255,239,255,254,255,255,239,
255,254,255,255,239,255,254,255,255,199,255,254,255,255,199,255,
254,255,255,199,255,254,255,255,199,255,254,255,255,131,255,254,
255,255,131,255,254,255,255,131,255,254,255,255,131,255,254,255,
255,1,255,254,255,255,1,255,254,255,255,1,255,254,255,255,1,255,
254,255,254,16,255,254,255,254,16,255,254,255,254,16,255,254,255,
254,16,255,254,255,252,40,127,254,255,252,40,127,254,255,252,40,
127,254,255,252,40,127,254,255,248,68,63,254,255,248,68,63,254,255,
248,68,63,254,255,248,68,63,254,255,240,130,31,254,255,
240,130,31,254,255,240,130,31,254,255,240,130,31,254,
255,225,1,15,254,255,225,1,15,254,255,225,1,15,254,255,
225,1,15,254,255,194,16,135,254,255,194,16,135,254,255,
194,16,135,254,255,194,16,135,254,255,132,40,67,254,255,
132,40,67,254,255,132,40,67,254,255,132,40,67,254,255,8,
68,33,254,255,8,68,33,254,255,8,68,33,254,255,
8,68,33,254,254,16,146,16,254,254,16,146,16,254,254,16,
146,16,254,254,16,146,16,254,252,33,41,8,126,252,
33,41,8,126,252,33,41,8,126,252,33,41,8,126,248,66,68,
132,62,248,66,68,132,62,248,66,68,132,62,248,
66,68,132,62,240,132,68,66,30,240,132,68,66,30,240,132,
68,66,30,240,132,68,66,30,225,8,40,33,14,225,
8,40,33,14,225,8,40,33,14,225,8,40,33,14,194,4,16,64,
134,194,4,16,64,134,194,4,16,64,134,194,
4,16,64,134,196,2,40,128,70,196,2,40,128,70,196,2,40,
128,70,196,2,40,128,70,132,65,69,4,66,132,
65,69,4,66,132,65,69,4,66,132,65,69,4,66,136,36,146,
72,34,136,36,146,72,34,136,36,146,72,34,136,
36,146,72,34,136,33,69,8,34,136,33,69,8,34,136,33,69,
8,34,136,33,69,8,34,16,194,40,134,16,16,
194,40,134,16,16,194,40,134,16,16,194,40,134,16,17,4,
16,65,16,17,4,16,65,16,17,4,16,65,16,17,
4,16,65,16,17,8,0,33,16,17,8,0,33,16,17,8,0,33,16,17,
8,0,33,16,17,16,68,17,16,17,
16,68,17,16,17,16,68,17,16,17,16,68,17,16,16,224,170,
14,16,16,224,170,14,16,16,224,170,14,16,16,
224,170,14,16,16,1,17,0,16,16,1,17,0,16,16,1,17,0,
16,16,1,17,0,16,16,2,0,128,16,16,
2,0,128,16,16,2,0,128,16,16,2,0,128,16,8,4,0,64,32,
8,4,0,64,32,8,4,0,64,32,8,4,0,64,32,140,24,68,48,98,
140,24,68,48,98,140,24,68,48,98,140,24,68,48,98,131,224,198,
15,130,131,224,198,15,130,131,224,198,15,130,131,224,198,15,130,
192,1,199,0,6,192,1,199,0,6,192,1,199,0,6,192,1,199,0,6,224,3,
131,128,14,224,3,131,128,14,224,3,131,128,14,224,3,131,128,14,
248,15,131,224,62,248,15,131,224,62,248,15,131,224,62,248,15,
131,224,62,255,255,1,255,254,255,255,1,255,254,255,255,1,255,254,255,
255,1,255,254,255,255,1,255,254,255,255,1,255,254,255,255,1,
255,254,255,255,1,255,254,255,254,0,255,254,255,254,0,255,254,
255,254,0,255,254,255,254,0,255,254,255,252,0,127,254,255,252,
0,127,254,255,252,0,127,254,255,252,0,127,254};

char logoBmp22[]={6,0,11,0,254,254,0,0,254,254,0,0,254,254,50,50,254,254,230,230,
254,254,206,206,254,254,130,130,254,254,128,128,254,254,248,248,
254,254,248,248,254,254,56,56,254,254,0,0,254,254,130,130};

char logoBmp23[]={8,0,11,0,255,128,255,128,249,128,249,128,255,128,255,128,241,

14楼

128,241,128,255,128,255,128,225,128,225,128,255,128,
255,128,193,128,193,128,255,128,255,128,137,128,137,128,255,
128,255,128,25,128,25,128,255,128,255,128,0,0,0,0,
255,128,255,128,0,0,0,0,255,128,255,128,249,128,249,128,255,
128,255,128,249,128,249,128,255,128,255,128,240,128,
240,128,255,128,255,128,240,128,240,128};

char logoBmp24[]={6,0,11,0,254,254,0,0,254,254,0,0,254,254,62,
62,254,254,62,62,254,254,2,2,254,254,0,0,254,254,
248,248,254,254,248,248,254,254,56,56,254,254,56,56,254,254,0,
0,254,254,130,130};

char logoBmp25[]={6,0,11,0,254,254,194,194,254,254,130,130,254,254,30,30,254,
254,62,62,254,254,2,2,254,254,0,0,254,254,56,56,254,254,56,
56,254,254,56,56,254,254,56,56,254,254,0,0,254,254,130,130};

char logoBmp26[]={6,0,11,0,254,254,0,0,254,254,0,0,254,254,56,56,254,254,242,242,254,
254,242,242,254,254,230,230,254,254,230,230,254,254,230,230,254,254,
206,206,254,254,206,206,254,254,206,206,254,254,206,206};

char logoBmp27[]={6,0,11,0,254,254,130,130,254,254,0,0,254,254,56,56,254,254,56,56,
254,254,56,56,254,254,130,130,254,254,0,0,254,254,56,56,254,254,56,
56,254,254,56,56,254,254,0,0,254,254,130,130};

char logoBmp28[]={6,0,11,0,254,254,130,130,254,254,0,0,254,254,56,56,254,254,56,
56,254,254,56,56,254,254,56,56,254,254,0,0,254,254,128,128,254,
254,248,248,254,254,240,240,254,254,130,130,254,254,134,134};

char logoBmp29[]={8,0,11,0,255,128,255,128,48,128,48,128,255,128,255,128,32,0,
32,0,255,128,255,128,38,0,38,0,255,128,255,128,38,0,38,0,255,
128,255,128,38,0,38,0,255,128,255,128,38,0,38,0,255,128,255,
128,38,0,38,0,255,128,255,128,38,0,38,0,255,128,255,128,38,0,
38,0,255,128,255,128,38,0,38,0,255,128,255,128,32,0,
32,0,255,128,255,128,48,128,48,128};

char logoBmp30[]={6,0,11,0,254,254,224,224,254,254,224,224,254,254,242,242,
254,254,242,242,254,254,242,242,254,254,242,242,254,254,
242,242,254,254,242,242,254,254,50,50,254,254,50,50,254,
254,2,2,254,254,134,134};

char logoBmp31[]={6,0,13,0,254,254,130,130,254,254,0,0,254,254,56,56,254,
254,56,56,254,254,56,56,254,254,56,56,254,254,
56,56,254,254,56,56,254,254,56,56,254,254,56,56,254,254,
0,0,254,254,130,130,254,254,240,240,254,254,248,248};

char logoBmp32[]={8,0,11,0,255,128,255,128,8,0,8,0,255,128,255,128,8,0,8,0,
255,128,255,128,153,128,153,128,255,128,255,128,147,128,147,128,
255,128,255,128,135,128,135,128,255,128,255,128,143,128,143,
128,255,128,255,128,135,128,135,128,255,128,255,128,147,128,147,
128,255,128,255,128,153,128,153,128,255,128,255,128,156,128,156,
128,255,128,255,128,8,0,8,0,255,128,255,128,8,0,8,0};

char logoBmp33[]={10,0,11,0,255,224,255,224,251,224,251,224,255,224,255,224,251,
224,251,224,255,224,255,224,241,224,241,224,255,224,
255,224,241,224,241,224,255,224,255,224,228,224,228,224,255,224,
255,224,228,224,228,224,255,224,255,224,206,96,206,96,
255,224,255,224,192,96,192,96,255,224,255,224,128,32,128,32,255,
224,255,224,159,32,159,32,255,224,255,224,14,0,
14,0,255,224,255,224,14,0,14,0};

char logoBmp34[]={6,0,11,0,254,254,130,130,254,254,0,0,254,254,56,56,254,254,248,

15楼

248,254,254,240,240,254,254,226,226,254,254,
198,198,254,254,142,142,254,254,24,24,254,254,56,56,254,254,0,0,
254,254,0,0};

char logoBmp35[]={6,0,11,0,0,0,0,0,0,0,0,0,50,50,50,50,230,230,230,
230,206,206,206,206,130,130,130,130,128,128,
128,128,248,248,248,248,248,248,248,248,56,56,56,56,0,0,0,0,130,
130,130,130};

char logoBmp36[]={8,0,11,0,249,128,249,128,249,128,249,128,241,128,241,128,241,
128,241,128,225,128,225,128,225,128,225,128,193,128,
193,128,193,128,193,128,137,128,137,128,137,128,137,128,25,128,
25,128,25,128,25,128,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,249,128,249,128,249,128,249,128,249,128,249,128,
249,128,249,128,240,128,240,128,240,128,
240,128,240,128,240,128,240,128,240,128};

char logoBmp37[]={6,0,11,0,0,0,0,0,0,0,0,0,62,62,62,62,62,62,
62,62,2,2,2,2,0,0,0,0,248,248,248,248,248,248,248,248,56,56,
56,56,56,56,56,56,0,0,0,0,130,130,130,130};

char logoBmp38[]={6,0,11,0,194,194,194,194,130,130,130,130,30,
30,30,30,62,62,62,62,2,2,2,2,0,0,0,0,56,56,
56,56,56,56,56,56,56,56,56,56,56,56,56,56,0,0,0,0,130,130,130,130};

char logoBmp39[]={6,0,11,0,0,0,0,0,0,0,0,0,56,56,56,56,242,242,
242,242,242,242,242,242,230,230,230,230,230,230,230,230,230,230,230,
230,206,206,206,206,206,206,206,206,206,206,206,206,206,206,206,206};

char logoBmp40[]={6,0,11,0,130,130,130,130,0,0,0,0,56,56,56,56,56,
56,56,56,56,56,56,56,130,130,130,130,0,0,
0,0,56,56,56,56,56,56,56,56,56,56,56,56,0,0,0,0,130,130,130,130};

char logoBmp41[]={6,0,11,0,130,130,130,130,0,0,0,0,56,56,56,56,
56,56,56,56,56,56,56,56,56,56,56,56,0,0,0,0,128,128,128,128,248,248,
248,248,240,240,240,240,130,130,130,130,134,134,134,134};

char logoBmp42[]={8,0,11,0,48,128,48,128,48,128,48,128,32,0,32,0,32,
0,32,0,38,0,38,0,38,0,38,0,38,0,
38,0,38,0,38,0,38,0,38,0,38,0,38,0,38,0,38,0,38,0,38,0,38,0,38,0,38,
0,38,0,38,0,38,0,38,0,38,0,38,0,38,0,38,0,38,0,38,0,38,0,38,0,38,0,
32,0,32,0,32,0,32,0,48,128,48,128,48,128,48,128};

char logoBmp43[]={6,0,11,0,224,224,224,224,224,224,224,224,242,242,242,242,242,242,
242,242,242,242,242,242,242,242,242,242,242,242,242,242,242,242,242,
242,50,50,50,50,50,50,50,50,2,2,2,2,134,134,134,134};

char logoBmp44[]={6,0,13,0,130,130,130,130,0,0,0,0,56,56,56,56,56,
56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,
56,56,56,56,56,0,0,0,0,130,130,130,130,240,240,240,240,248,248,248,248};

char logoBmp45[]={8,0,11,0,8,0,8,0,8,0,8,0,8,0,8,0,8,0,8,0,153,128,
153,128,153,128,153,128,147,128,147,128,147,128,147,128,135,128,135,
128,135,128,135,128,143,128,143,128,143,128,143,128,135,128,135,128,
135,128,135,128,147,128,147,128,147,128,147,128,153,128,153,128,153,
128,153,128,156,128,156,128,156,128,156,128,8,0,8,0,8,0,
8,0,8,0,8,0,8,0,8,0};

char logoBmp46[]={10,0,11,0,251,224,251,224,251,224,251,224,251,224,251,224,251,224,
251,224,241,224,241,224,241,224,241,224,241,224,
241,224,241,224,241,224,228,224,228,224,228,224,228,224,228,224,228,
224,228,224,228,224,206,96,206,96,206,96,206,96,
192,96,192,96,192,96,192,96,128,32,128,32,128,32,128,32,159,32,159,

16楼

32,159,32,159,32,14,0,14,0,14,0,14,0,14,0,14,0,14,0,14,0};

char logoBmp47[]={6,0,11,0,130,130,130,130,0,0,0,0,56,56,56,56,248,248,248,248,240,
240,240,240,226,226,226,226,198,198,198,198,142,142,142,142,24,24,
24,24,56,56,56,56,0,0,0,0,0,0,0,0};

char logoBmp48[]={18,0,15,0,0,0,0,1,128,0,255,255,224,1,128,0,1,
128,0,3,0,0,255,63,224,3,0,0,1,128,0,3,0,0,255,63,224,3,0,0,1,128,
0,3,0,0,255,63,224,3,0,0,1,128,0,3,0,0,255,63,
224,3,0,0,1,128,0,3,48,0,255,63,224,3,48,0,1,176,0,3,38,0,255,39,
224,3,38,0,1,182,0,3,36,0,255,36,224,3,36,0,1,182,0,3,36,192,255,
36,224,3,36,192,1,182,192,195,36,128,223,36,128,195,36,128,97,182,
192,195,252,128,207,252,128,195,252,128,49,254,192,99,255,128,231,
255,128,99,255,128,57,255,192,113,255,128,241,255,128,113,255,128,
31,255,192,57,255,128,249,255,128,57,255,128,31,255,192,63,255,128,
255,255,128,63,255,128,15,255,192,31,255,128,255,255,128,31,255,128};

int logo(int x,int y,unsigned char index,int method);

int logo(int x,int y,unsigned char index,int method){
  switch(index){
    case 1:
      putimage(x,y,logoBmp1,method);
      break;
    case 2:
      putimage(x,y,logoBmp2,method);
      break;
    case 3:
      putimage(x,y,logoBmp3,method);
      break;
    case 4:
      putimage(x,y,logoBmp4,method);
      break;
    case 5:
      putimage(x,y,logoBmp5,method);
      break;
    case 6:
      putimage(x,y,logoBmp6,method);
      break;
    case 7:
      putimage(x,y,logoBmp7,method);
      break;
    case 8:
      putimage(x,y,logoBmp8,method);
      break;
    case 9:
      putimage(x,y,logoBmp9,method);
      break;
    case 22:
      putimage(x,y,logoBmp22,method);
      break;
    case 23:
      putimage(x,y,logoBmp23,method);
      break;
    case 24:
      putimage(x,y,logoBmp24,method);
      break;
    case 25:
      putimage(x,y,logoBmp25,method);
      break;

17楼

    case 26:
      putimage(x,y,logoBmp26,method);
      break;
    case 27:
      putimage(x,y,logoBmp27,method);
      break;
    case 28:
      putimage(x,y,logoBmp28,method);
      break;
    case 29:
      putimage(x,y,logoBmp29,method);
      break;
    case 30:
      putimage(x,y,logoBmp30,method);
      break;
    case 31:
      putimage(x,y,logoBmp31,method);
      break;
    case 32:
      putimage(x,y,logoBmp32,method);
      break;
    case 33:
      putimage(x,y,logoBmp33,method);
      break;
    case 34:
      putimage(x,y,logoBmp34,method);
      break;
    case 35:
      putimage(x,y,logoBmp35,method);
      break;
    case 36:
      putimage(x,y,logoBmp36,method);
      break;
    case 37:
      putimage(x,y,logoBmp37,method);
      break;
    case 38:
      putimage(x,y,logoBmp38,method);
      break;
    case 39:
      putimage(x,y,logoBmp39,method);
      break;
    case 40:
      putimage(x,y,logoBmp40,method);
      break;
    case 41:
      putimage(x,y,logoBmp41,method);
      break;
    case 42:
      putimage(x,y,logoBmp42,method);
      break;
    case 43:
      putimage(x,y,logoBmp43,method);
      break;
    case 44:
      putimage(x,y,logoBmp44,method);
      break;
    case 45:
      putimage(x,y,logoBmp45,method);
      break;
    case 46:
      putimage(x,y,logoBmp46,method);
      break;
    case 47:
      putimage(x,y,logoBmp47,method);
      break;
    case 48:
      putimage(x,y,logoBmp48,method);
      break;
  }
}
/***********************logo.h结束***********************/

18楼

/******************menu.c开始************************/
/*将以下代码保存为menu.c*/
#define UP 0x4800
#define DOWN 0x5000
#define LEFT 0x4b00
#define RIGHT 0x4d00
#define ENTER 0x1c0d
#define SPACE 0x3920
#define F1 0x3b00
#define ESC 0x11b

#include <stdlib.h>

char *strMain[4]={" ","PLAY","ABOUT","QUIT"};
char *strGaming[4]={" ","CONTINUE","MAIN MENU...","QUIT"};

int showCard(int x,int y,unsigned char num,unsigned char style);
void updateMenu(char *str[],int num,int crnt,int x,int y);
void dBorder(int x1,int y1,int x2,int y2);
void paintLogo(int index);
int inMenu(int mnIndex);

int inMenu(int mnIndex){
  int current=1;
  int key;
  
  switch(mnIndex){
    case 1:
      cleardevice();
      
      updateMenu(strMain,4,current,290,300);
      paintLogo(1);
      for(;;){
        if (bioskey(1))
          key=bioskey(0);
        else
          key=0;

        switch(key){
        case UP:
          current=(current <= 1?3 : current-1);
          updateMenu(strMain,4,current,290,300);
          break;
        case DOWN:
          current=(current >= 3?1 : current+1);
          updateMenu(strMain,4,current,290,300);
          break;
        case ENTER:
          if (current==1){
            cleardevice();
            return 0;
          }
          else if (current==2) inMenu(2);
          else if (current==3) {
            closegraph();
            exit(1);
          }

19楼

          updateMenu(strMain,4,current,290,300);
          paintLogo(1);
          break;
        }
      }
    case 2:
      setfillstyle(SOLID_FILL,BLUE);
      bar(128,84,512,344);
      dBorder(128,84,512,344);
      paintLogo(2);
      while(getch() != 13);
      setfillstyle(SOLID_FILL,0);
      bar(128,84,512,344);
      return 0;
    case 3:
      setfillstyle(SOLID_FILL,BLUE);
      bar(190,140,450,320);
      dBorder(190,140,450,320);
      paintLogo(3);
      updateMenu(strGaming,4,current,260,220);
      
      for(;;){
        if (bioskey(1))
          key=bioskey(0);
        else
          key=0;
      
        switch(key){
        case UP:
          current=(current <= 1?3 : current-1);
          updateMenu(strGaming,4,current,260,220);
          break;
        case DOWN:  
          current=(current >= 3?1 : current+1);
          updateMenu(strGaming,4,current,260,220);
          break;
        case ESC:
          setfillstyle(SOLID_FILL,GREEN);
          bar(190,140,450,320);
          return 0;
        case ENTER:
          setfillstyle(SOLID_FILL,GREEN);
          bar(190,140,450,320);
          return current;
        }

20楼

      }
    }
}
      
  
void updateMenu(char *str[],int num,int crnt,int x,int y){
  int i;
  
  settextstyle(0,0,0);
  for(i=1;i<num;i++){
    if (i==crnt){
      setcolor(BLUE);
      outtextxy(x-12,y+20*i,"\4");
      setcolor(WHITE);
      outtextxy(x,y+20*i,str[i]);
    }
    else{
      setcolor(8);
      outtextxy(x-12,y+20*i,"\4");
      setcolor(GREEN);
      outtextxy(x,y+20*i,str[i]);
    }
  }    
}

void dBorder(int x1,int y1,int x2,int y2){
  setfillstyle(SOLID_FILL,8);
  bar(x1,y1,x2,y2);
  
   setcolor(0);
   line(x1+1,y1+11,x1+1,y2-11);
   line(x1+1,y1+11,x1+11,y1+1);
   line(x1+11,y1+1,x2-11,y1+1);
   setcolor(7);
   line(x2-11,y1+1,x2-1,y1+11);
   line(x1+1,y2-11,x1+11,y2-1);
   setcolor(15);
   line(x1+11,y2-1,x2-11,y2-1);
   line(x2-11,y2-1,x2-1,y2-11);
   line(x2-1,y2-11,x2-1,y1+11);
   
   setcolor(15);
   line(x1+15,y1+5,x2-15,y1+5);
   line(x1+5,y1+15,x1+15,y1+5);
   line(x1+5,y2-15,x1+5,y1+15);
   setcolor(7);
   line(x1+15,y2-5,x1+5,y2-15);
   line(x2-15,y1+5,x2-5,y1+15);
   setcolor(0);
   line(x2-5,y1+15,x2-5,y2-15);
   line(x2-5,y2-15,x2-15,y2-5);
   line(x2-15,y2-5,x1+15,y2-5);
}
void paintLogo(int index){
  int i,j;
  switch(index){
    case 1:  
      showCard(240,140,12,3);
      showCard(380,150,8,2);
      showCard(290,119,10,1);
      showCard(220,100,13,4);
      showCard(350,15,14,4);
      showCard(195,110,15,2);
      settextstyle(0,0,5);
      dBorder(180,40,290,104);
      setcolor(BLUE);
      outtextxy(200,49,"1");
      setcolor(CYAN);
      outtextxy(235,49,"3");
      settextstyle(0,0,7);
      dBorder(225,89,515,179);

21楼

      setcolor(RED);
      outtextxy(245,109,"C");
      setcolor(LIGHTBLUE);
      outtextxy(295,109,"A");
      setcolor(RED);
      outtextxy(345,109,"R");
      setcolor(YELLOW);
      outtextxy(395,109,"D");
      setcolor(BLUE);
      outtextxy(445,109,"S");
      settextstyle(0,0,0);
      break;
    case 2:
      setcolor(WHITE);
      outtextxy(155,103,"13 Cards");
      setcolor(LIGHTBLUE);
      outtextxy(155,131,"VER 1.0");
      setcolor(RED);
      outtextxy(155,155,"PROGRAMMER");
      outtextxy(155,175,"WEN XICHANG");
      outtextxy(155,191,"GDUFS");
      setcolor(BLUE);
      outtextxy(155,215,"SOFTWARE (2)");
      setcolor(LIGHTBLUE);
      outtextxy(400,322,"2005.2.20");
      
      showCard(420,128,5,2);
      showCard(411,150,13,3);
      showCard(393,170,14,2);
      showCard(380,98,8,1);
      showCard(295,177,14,4);
      showCard(318,140,12,1);
      setcolor(15);
      line(155,285,411,285);
      line(155,285,155,316);
      setcolor(0);
      line(155,316,411,316);
      line(411,285,411,316);
      setcolor(YELLOW);
      outtextxy(160,290,"QQ:375020128");
      outtextxy(160,300,"E-mail:xichang.wen@yahoo.com.cn");
      break;
    case 3:
      setcolor(GREEN);
      rectangle(240,162,325,188);
      setcolor(LIGHTBLUE);
      rectangle(277,155,305,166);
      setcolor(CYAN);
      rectangle(313,177,357,207);
      setcolor(1);
      rectangle(348,162,370,185);
      setcolor(YELLOW);
      rectangle(362,172,426,195);
      
      setcolor(YELLOW);
      outtextxy(250,171,"13 CARDS");
      break;
    }
}
/******************menu.c结束************************/

22楼

/******************pokerAI.c开始******************/
/*将以下代码存为pokerAI.c*/
#include <string.h>

typedef struct{
  unsigned char pOut[14];
  int pLng;
  int pSng;
  unsigned char pSml;
}OutCase;

OutCase outCase[80];

unsigned char getSmall(unsigned char *p);
int AIout(unsigned char *have,unsigned char *out,unsigned char flag);
int AIeat(unsigned char *have,unsigned char *in,unsigned char *out,int flag);
int getCount(unsigned char *p);
int getType(unsigned char *in);
unsigned char getSmall(unsigned char *p);
int getSingle(unsigned char *p);
int haveThe(unsigned char *p,unsigned char num);
int addToOutCase(int index,unsigned char *str,unsigned char lng,unsigned char sng,unsigned char sml);
int ifUsed(unsigned char num,int flag);
int virtualPull(unsigned char *in,unsigned char *pul,unsigned char *result);
int isSingle(unsigned char *p,unsigned char a);

int AIout(unsigned char *have,unsigned char *out,unsigned char flag){
  int vlSml,vlFew,vlLng;
  int i,n,m;
  unsigned char tmp1[14]={0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  unsigned char tmp2[14]={0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  unsigned char caseIndex=0;
  int maxVl,maxIdx;
  switch(flag){
    case 1:
      vlSml=12;
      vlFew=60;
      vlLng=23;
      break;
    case 2:
      vlSml=6;
      vlFew=64;
      vlLng=30;
      break;
    case 3:
      vlSml=3;
      vlFew=45;
      vlLng=60;
      break;
    case 4:
      vlSml=-1;
      vlFew=30;
      vlLng=50;
      break;
    default:
      vlSml=10;
      vlFew=60;
      vlLng=25;
      break;
  }

  for(i=0;i<80;i++) outCase[i].pOut[0]=0;
  ifUsed(0,0);

  for(i=0;i<getCount(have);i++){
    if(ifUsed(*(have+i),1)) continue;
    else{

23楼

      tmp1[0]=*(have+i);
      tmp1[1]=0;
      if(virtualPull(have,tmp1,tmp2)){
        addToOutCase(caseIndex,tmp1,getCount(tmp1),getSingle(tmp2),getSmall(tmp1));
        caseIndex++;
      }
      else printf("An Error!\n");

      if(haveThe(have,*(have+i)) >= 2){
        tmp1[0]=tmp1[1]=*(have+i);
        tmp1[2]=0;
        if(virtualPull(have,tmp1,tmp2)){
          addToOutCase(caseIndex,tmp1,getCount(tmp1),getSingle(tmp2),getSmall(tmp1));
          caseIndex++;
        }
        else printf("An Error!\n");

        for(m=1;m<6;m++){
          if(haveThe(have,*(have+i)+m)==2){
            for(n=0;n<2*m+2;n++){
              tmp1[n]=*(have+i)+n/2;
            }
            tmp1[n]=0;
            if(virtualPull(have,tmp1,tmp2)){
              addToOutCase(caseIndex,tmp1,getCount(tmp1),getSingle(tmp2),getSmall(tmp1));
              caseIndex++;
            }
            else printf("An Error!\n");
          }
          else break;
        }
      }

      if(haveThe(have,*(have+i)) >= 3){
        tmp1[0]=tmp1[1]=tmp1[2]=*(have+i);
        tmp1[3]=0;
        if(virtualPull(have,tmp1,tmp2)){
          if(getSingle(tmp2)>1){
            for(m=3,n=3;n<16;n++){
              if(haveThe(tmp2,n)&&isSingle(tmp2,n)){
                tmp1[m]=n;

24楼

                m++;
                if(m>4) break;
              }
            }
            tmp1[5]=0;
          }
          else tmp1[3]=0;
          if(virtualPull(have,tmp1,tmp2)){
            addToOutCase(caseIndex,tmp1,getCount(tmp1),getSingle(tmp2),getSmall(tmp1));
            caseIndex++;
          }
          else printf("An Error!\n");
        }
        else printf("An Error!\n");
      }

      if(haveThe(have,*(have+i)+1)){
        for(m=2;m<13;m++){
          if(haveThe(have,*(have+i)+m)){
            for(n=0;n<m+1;n++){
              tmp1[n]=*(have+i)+n;
            }
            tmp1[n]=0;
            if(virtualPull(have,tmp1,tmp2)){
              addToOutCase(caseIndex,tmp1,getCount(tmp1),getSingle(tmp2),getSmall(tmp1));
              caseIndex++;
            }
            else printf("An Error!\n");
          }
          else break;
        }
      }
    }
  }
  maxVl=outCase[0].pLng*vlLng-outCase[0].pSml*vlSml-outCase[0].pSng*vlFew;
  maxIdx=0;
  for(i=1;i<80;i++){
    if(outCase[i].pOut[0] != 0){
      if(maxVl<(outCase[i].pLng*vlLng-outCase[i].pSml*vlSml-outCase[i].pSng*vlFew)){
        maxVl=(outCase[i].pLng*vlLng-outCase[i].pSml*vlSml-outCase[i].pSng*vlFew);

25楼

        maxIdx=i;
      }
    }
  }
  ifUsed(0,0);
  n=0;
  for(i=0;outCase[maxIdx].pOut[i] != 0;i++){
    for(m=0;*(have+m) != 0;m++){
      if(*(have+m)==outCase[maxIdx].pOut[i]){
        if(!ifUsed(m ,1)){
          *(out+n)=m;
          n++;
          break;
        }
      }
    }
  }
  *(out+n)=255;
  if(*out==*(out+1))
    return 1;
  return 1;
}

int AIeat(unsigned char *have,unsigned char *in,unsigned char *out,int flag){
  int vlSml,vlFew;
  unsigned char typeIn,min;
  int i,m,n;
  unsigned char caseIndex=0;
  unsigned char tmp1[14]={0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  unsigned char tmp2[14]={0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  int maxVl,maxIdx;

  switch(flag){
    case 1:
      vlSml=3;
      vlFew=60;
      break;
    case 2:
      vlSml=2;
      vlFew=64;
      break;
    case 3:
      vlSml=1;
      vlFew=45;
      break;
    case 4:
      vlSml=-1;
      vlFew=5;
      break;
    default:
      vlSml=10;
      vlFew=60;
      break;
  }
  typeIn=getType(in);
  if(typeIn==0)
  printf("An Error!\n");

  for(i=0;i<80;i++) outCase[i].pOut[0]=0;

  min=getSmall(in);
  switch(typeIn){
    case 1:
      for(i=0;i<getCount(have);i++){
        if(*(have+i)>min){
          tmp1[0]=*(have+i);
          tmp1[1]=0;
          if(virtualPull(have,tmp1,tmp2)){
            addToOutCase(caseIndex,tmp1,0,getSingle(tmp2),getSmall(tmp1));

26楼

            caseIndex++;
          }
          else printf("An Error!\n");
        }
      }break;
    case 2:
      for(i=0;i<getCount(have);i++){
        if((*(have+i)>min)&&(haveThe(have,*(have+i)) >= 2)){
          tmp1[0]=tmp1[1]=*(have+i);
          tmp1[2]=0;
          if(virtualPull(have,tmp1,tmp2)){
            addToOutCase(caseIndex,tmp1,0,getSingle(tmp2),getSmall(tmp1));
            caseIndex++;
          }
          else printf("An Error!\n");
        }
      }break;
    case 3:
      for(i=0;i<getCount(have);i++){
        if((*(have+i)>min)&&haveThe(have,*(have+i))==3){
          tmp1[0]=tmp1[1]=tmp1[2]=*(have+i);
          tmp1[3]=0;
          if(getCount(in) != 3){
            if(virtualPull(have,tmp1,tmp2)){
              for(m=3,n=3;n<16;n++){
                if(haveThe(tmp2,n)&&isSingle(tmp2,n)){
                  tmp1[m]=n;
                  m++;
                  if(m>4) break;
                }
              }
              if(m==3){
                tmp1[3]=tmp2[1];
                tmp1[4]=tmp2[0];
              }
              if(m==4) tmp1[4]=tmp2[0];

27楼

            }
            else printf("An Error!\n");
            tmp1[5]=0;
          }
          else tmp1[3]=0;

          if(virtualPull(have,tmp1,tmp2)){
            addToOutCase(caseIndex,tmp1,0,getSingle(tmp2),getSmall(tmp1));
            caseIndex++;
          }
          else printf("An Error!\n");
        }
      }break;
    case 4:
      for(i=0;i<getCount(have);i++){
        if((*(have+i)>min)&&haveThe(have,*(have+i))==4){
          tmp1[0]=tmp1[1]=tmp1[2]=tmp1[3]=*(have+i);
          tmp1[4]=0;
          if(virtualPull(have,tmp1,tmp2)){
            addToOutCase(caseIndex,tmp1,0,getSingle(tmp2),getSmall(tmp1));
            caseIndex++;
          }
          else printf("An Error!\n");
        }
      }break;
    default:
      if(typeIn<20){
        for(i=0;i<getCount(have);i++){
          if(*(have+i)>min){
            n=1;
            for(m=1;m<typeIn-5;m++) n=(n&&haveThe(have,*(have+i)+m));
            if(n != 0){
              tmp1[0]=*(have+i);
              for(m=1;m<typeIn-5;m++)
                tmp1[m]=*(have+i)+m;
              tmp1[m]=0;
              if(virtualPull(have,tmp1,tmp2)){
                addToOutCase(caseIndex,tmp1,0,getSingle(tmp2),getSmall(tmp1));

28楼

                caseIndex++;
              }
              else printf("An Error!\n");
            }
          }
        }
      }
      else{
        for(i=0;i<getCount(have);i++){
          if((*(have+i)>min )&&(haveThe(have,*(have+i)) >= 2)){
            n=1;
            for(m=1;m<typeIn-20;m++) n=(n&&(haveThe(have,*(have+i)+m) >= 2));
            if(n != 0){
              tmp1[0]=tmp1[1]=*(have+i);
              for(m=1;m<typeIn-20;m++){
                tmp1[2*m]=*(have+i)+m;
                tmp1[2*m+1]=*(have+i)+m;
              }
              tmp1[2*m]=0;
              if(virtualPull(have,tmp1,tmp2)){
                addToOutCase(caseIndex,tmp1,0,getSingle(tmp2),getSmall(tmp1));
                caseIndex++;
              }
              else printf("An Error!\n");
            }
          }
        }
      }
  }
  
  for(i=0;i<getCount(have);i++){
    if((typeIn != 4)&&haveThe(have,*(have+i))==4){
      tmp1[0]=tmp1[1]=tmp1[2]=tmp1[3]=*(have+i);
      tmp1[4]=0;
      if(virtualPull(have,tmp1,tmp2)){
        addToOutCase(caseIndex,tmp1,0,(getSingle(tmp2)+3),getSmall(tmp1));

29楼

        caseIndex++;
      }
      else printf("An Error!\n");
    }
  }
  
  if(outCase[0].pOut[0]==0){
    *out=255;
    return 0;
  }
  maxVl=1-outCase[0].pSml*vlSml-outCase[0].pSng*vlFew;
  maxIdx=0;
  for(i=1;i<80;i++){
    if(outCase[i].pOut[0] != 0){
      if(maxVl<(1-outCase[i].pSml*vlSml-outCase[i].pSng*vlFew)){
        maxVl=(1-outCase[i].pSml*vlSml-outCase[i].pSng*vlFew);
        maxIdx=i;
      }
    }
  }
  ifUsed(0,0);
  n=0;
  for(i=0;outCase[maxIdx].pOut[i] != 0;i++){
    for(m=0;*(have+m) != 0;m++){
      if(*(have+m)==outCase[maxIdx].pOut[i]){
        if(!ifUsed(m ,1)){
          *(out+n)=m;
          n++;
          break;
        }
      }
    }
  }
  *(out+n)=255;
  if(*out==*(out+1))
    return 1;
  return 1;
}




int getCount(unsigned char *p){
  return strlen(p);
}

int getType(unsigned char *in){
  unsigned char tmp;
  unsigned char i,ret=1;
  int n;
  switch(getCount(in)){
    case 0:
      return 0;
    case 1:
      return 1;
    case 2:
      if(*in != *(in+1)) return 0;
      else return 2;
    case 3:
      if(haveThe(in,*in)==3) return 3;
      else{
        tmp=getSmall(in);
        if(haveThe(in,tmp+1)&&haveThe(in,tmp+2))
          return 8;
        else return 0;
      }
    case 4:
      if(haveThe(in,*in)==4) return 4;
      else if(haveThe(in,*in)==2){
        tmp=getSmall(in);

30楼

        if((haveThe(in,tmp)==2)&&(haveThe(in,tmp+1)))
          return 22;
        else return 0;
      }
      else{
        tmp=getSmall(in);
        if(haveThe(in,tmp+1)&&haveThe(in,tmp+2)&&haveThe(in,tmp+3))
          return 9;
        else return 0;
      }
    case 5:
      tmp=getSmall(in);
      if(haveThe(in,tmp)==4) return 4;
      if(haveThe(in,tmp)==3) return 3;
      else{
        for(i=1;i<4;i++)
          ret=(ret&&haveThe(in,tmp+i));
        if(ret) return 10;
        else return 0;
      }
  }

  n=getCount(in);
  if(n%2==0){
    tmp=getSmall(in);
    ret=(haveThe(in,tmp)==2);
    for(i=1;i<n/2;i++)
      ret=(ret&&(haveThe(in,tmp+i)==2));
    if(ret) return (20+n/2);
  }
  tmp=getSmall(in);
  ret=1;
  for(i=1;i<n;i++)
    ret=(ret&&haveThe(in,tmp+i));
  if(ret) return (5+n);
  return 0;
}

unsigned char getSmall(unsigned char *p){
  int i;
  unsigned char min;
  min=*p;
  for(i=0;*(p+i) != 0;i++){
    min=(*(p+i)<min)?(*(p+i)) : min;
    if(haveThe(p,*(p+i))>2){
      min=*(p+i);
      return min;
    }
  }
  return min;
}

int getSingle(unsigned char *p){
  unsigned char c,i,sC=0;
  c=getCount(p);
  
  for(i=0;i<c;i++){
    if((*(p+i)<3)||(*(p+i)>15)) continue;
    if(haveThe(p,*(p+i)) >= 2) continue;
    if((haveThe(p,*(p+i)+1) >= 1)&&(haveThe(p,*(p+i)+2) >= 1)) continue;
    if((haveThe(p,*(p+i)-1) >= 1)&&(haveThe(p,*(p+i)-2) >= 1)) continue;
    if((haveThe(p,*(p+i)-1) >= 1)&&(haveThe(p,*(p+i)+1) >= 1)) continue;

31楼

    sC++;
  }
  return sC;
}

int haveThe(unsigned char *p,unsigned char num){
  int c,i,ret=0;
  c=getCount(p);
  
  if((num<3)||(num>15)) return 0;
  for(i=0;i<c;i++)
    if(*(p+i)==num) ret++;
  
  return ret;
}

int addToOutCase(int index,unsigned char *str,unsigned char lng,unsigned char sng,unsigned char sml){
  int i;
  
  if(index<0||index>79) return 0;
  for(i=0;*(str+i) != 0;i++)
    outCase[index].pOut[i]=*(str+i);
  outCase[index].pOut[i]=0;
  outCase[index].pLng=lng;
  outCase[index].pSng=sng;
  outCase[index].pSml=sml;
  return 1;
}

int ifUsed(unsigned char num,int flag){
  static unsigned char usedNum[14]={255,255,255,255,255,255,255,255,255,255,255,255,255,255};
  static int index=0;
  int i;

  if(flag==0){
    for(i=0;i<14;i++){
      usedNum[i]=255;
    }
    index=0;
    return 0;
  }

  for(i=0;i<14;i++){
    if(num==usedNum[i]) return 1;
  }

  usedNum[index]=num;
  index++;
  return 0;
}

int virtualPull(unsigned char *in,unsigned char *pul,unsigned char *result){
  int i,j,k;
  unsigned char tmp[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  
  if(getCount(in)>13||getCount(pul)>getCount(in)) return 0;
  for(i=0;*(pul+i) != 0;i++)
    if(haveThe(pul,*(pul+i))>haveThe(in,*(pul+i))) return 0;
    
  for(i=0;*(pul+i) != 0;i++){
    for(j=0;j<14;j++){
      if((*(in+j)==*(pul+i))&&(tmp[j]==0)){
        tmp[j]=1;
        break;
      }
    }
  }
  
  for(i=0,j=0;i<13;i++){
    if(!tmp[i]){
      *(result+j)=*(in+i);
      j++;
    }
  }
  *(result+j)=0;
  return 1;
}
int isSingle(unsigned char *p,unsigned char a){
  int i;
  
  if(haveThe(p,a)>1) return 0;
  if(haveThe(p,a+1)&&haveThe(p,a+2)) return 0;
  if(haveThe(p,a-1)&&haveThe(p,a+1)) return 0;
  if(haveThe(p,a-2)&&haveThe(p,a-1)) return 0;
  return 1;  
}
/******************pokerAI.c结束******************/

发表回复

内 容:
用户名:
  
©2010 Baidu 贴吧协议  意见反馈