Beispiel #1
0
/*思路 
 为每一个点调用try_chess找出一种结果 
*/ 
int main(int argc, char *argv[]) 
{   
 chess_board main_board; 
 for(int i=0; i<4; i++) 
     for(int j=0; j<8; j++) 
     { 
         init_chess_board(&main_board); 
         put_chess(&main_board, i, j); 
         try_chess(&main_board, i,j); 
     } 

     printf("共有%d种情况", count); 
return 0; 
} 
Beispiel #2
0
static int think(int race)
{
  int i,j,k=0;
  int da_x=0,da_y,da_v=0,tmp;
  int haha[442][3];
  haha[0][0]=0;
  for(i=1;i<22;i++)
    for(j=1;j<22;j++)
    {
      /* enemy's situation */
      tmp=value(i,j,abs(race-2)+1);
      if(tmp>da_v) {da_x=i; da_y=j; da_v=tmp;}
      /* mine */
      tmp=value(i,j,race);
      if(tmp>haha[k][0])
      {
        k=0;
        haha[0][0]=tmp;
        haha[0][1]=i; haha[0][2]=j;
      }
      else if(tmp==haha[k][0])
      {
        k++;
        haha[k][0]=tmp;
        haha[k][1]=i; 
        haha[k][2]=j;
      }
    }

  i=random()%(k+1);
  gotoxy(63,15);
  if(haha[i][0]>7) bell();

  m=haha[i][1];
  n=haha[i][2];

  if((da_v>haha[i][0])||(da_v==haha[i][0]&&!attack[race]))
   {m=da_x; n=da_y;}

  put_box(mm,nn,0);
  put_box(m,n,race);
  mm=m; nn=n;
  gotoxy(48,15); prints("目前位置(%2d,%2d)",m,n);

  return put_chess(m,n,race);
}
Beispiel #3
0
int try_chess(chess_board * ptr_board, int row, int col) 
{ 
 chess_board temp; 
 for(int i=0; i<BOARD_ROWS; i++) 
     for(int j=0; j<BOARD_COLS; j++) 
         if(ptr_board->board_array[i][j] == 0)  //只有等于0的点才能放子 
         { 
             memcpy(&temp, ptr_board, sizeof(chess_board)); 
             put_chess(ptr_board, i, j); 
             if( 8 == ptr_board->chess_number ) 
             { 
                 print_result(ptr_board); 
               count++; 
               return 1; 
             } 
             if(try_chess(ptr_board, i, j)) 
                 return 1; 
             memcpy(ptr_board, &temp, sizeof(chess_board)); 
         } 

  
 return  0; 
} 
Beispiel #4
0
static int fplayer(int race)
{
  int l;
    while(-1)
    {
      gotoxy(48,15); prints("目前位置(%2d,%2d)",m,n);
      put_box(mm,nn,0);
      put_box(m,n,race);
      mm=m; nn=n;
      l=igetkey();
      switch(l)
      {
//      case '1':
        case '2':
         if(role[l-'1']==1)
         {
           role[l-'1']=2; 
           attack[l-'1']=0;
         }
         else if(attack[l-'1']==0)
           attack[l-'1']=1;
         else
           role[l-'1']=1;

         who(l-'1');
         break;
        case 'q': return 2;
        case 'r': return 1;
        case 'b':
         if(sum>2)
         {
           int i;
           for(i=0;i<2;i++)
           {
             int x=repent[sum-1][1],y=repent[sum-1][2];
             put_chess(x,y,0);
             move(y+1,x*2); outs("┼");
             sum-=2;
           }
           for(i=sum;i>=sum-5;i--)
           {
             gotoxy(48,i-sum+13);
             if(i>0)
               prints("第%d步: %s (%2d,%2d)  ",i,(repent[i-1][0]==1)?"●":"○",
                 repent[i-1][1],repent[i-1][2]);
             else
               outs("                  ");
           }
         }
         break;
        case ' ':
         if(!chess[m-1][n-1])
         {
           int hk=put_chess(m,n,race);
           if(hk)
           {
             int dk = show_win(hk);
             if(dk=='n'||dk=='q') return 2;
             return 1;
           }
           return 0;
         }
         break;
        case KEY_DOWN:  //down
          if(legal(m,n+1)) n++; 
          break; 
        case KEY_UP:	//up
          if(legal(m,n-1)) n--; 
          break;
        case KEY_RIGHT:	//right
          if(legal(m+1,n)) m++; 
          break;
        case KEY_LEFT:	//left
          if(legal(m-1,n)) m--; 
          break;
      }
    }
}