 /****************************************************************************
  ****************************************************************************
  ****                                                                    **** 
  ****           Liquid Metal Battle コンピューター思考ルーチン           **** 
  ****                                                                    **** 
  ****                                                                    **** 
  ****                            <<ＭＩＮＤ>>                            **** 
  ****                                                                    **** 
  ****                   ｜    ｜  ￣  ｜    ｜ ｜￣＼                    **** 
  ****                   ｜＼／｜  ｜  ｜＼  ｜ ｜   ｜                   **** 
  ****                   ｜    ｜  ｜  ｜  ＼｜ ｜   ｜                   **** 
  ****                   ｜    ｜  ＿  ｜    ｜ ｜＿／                    **** 
  ****                                                                    **** 
  ****                                                                    **** 
  ****                                               Ver 1.2              **** 
  ****                                                                    **** 
  ****                                                                    **** 
  ****************************************************************************
  ****************************************************************************/


/*  関数のプロトタイプ宣言  */
int	mind(char *,int *,int *,int *,int *,int *,int ,int ,int);


int mind(char *work,int *boa,int *aigx,int *aigy,int *aipx,int *aipy,int pl,int mode,int vs)
{
/*	         LV1, LV2, LV3, LV4, LV5, LV6, LV7, LV8,KING	*/
/*  CPの攻撃	*/
int	at1a[]={  50, 300, 400, 500, 800, 900,1000,  10,   0},/*  攻撃する駒    */
   	at1b[]={  10,  20, 100, 200, 400, 500, 700,1000,9999},/*  攻撃される駒  */
	efe1[]={   5,  10,  20,  50,  80, 110, 150, 200, 250},/*  効果点        */
/*  人間の攻撃	*/
	at2a[]={ 100, 600, 800,1000,1600,1800,2000,  20,   0},/*  攻撃する駒    */  
	at2b[]={  40,  80, 400, 800,1600,2000,2800,4000,7000},/*  攻撃される駒  */
	efe2[]={   1,   5,  10,  20,  30,  60,  80, 100, 100},/*  効果点        */
/*  CPの攻撃	*/
	at3a[]={  15,  50,  80, 150, 200, 270, 300,   3,   0},/*  攻撃する駒    */  
	at3b[]={   3,   7,  40,  60, 120, 150, 250, 300, 310},/*  攻撃される駒  */
	efe3[]={   1,   5,  10,  20,  30,  60,  80, 100, 100};/*  効果点        */
int	at11,at12,at21,at22,at31,at32,ef1,ef2,ef3,hmat;
int	board[49],brd0[49],brd1[49],brd2[49];
int	r0,r1,r2,r3,r4,r5,rpx,rpy;
int	mx0,my0,mx1,my1,mx2,my2,mx3,my3,mx4,my4,mx5,my5;
int	ret,rdm,tt,total,can;
char	str[10],val[5];
int	stick,trig;


	_outp(0x05ec,1);
	memcpy(board,boa,49*4);
	total=-30000;
	EGB_writePage(work,1);
	EGB_writeMode(work,0);
	EGB_textSpace(work,0);
	EGB_textZoom(work,0, 8,16);
	EGB_textZoom(work,1,16,16);
	EGB_fontStyle(work,8);
	EGB_paintMode(work,0x222);
	EGB_color(work,0,15);
	EGB_color(work,1,8);

	g_print(work,256,272,"I am thinking !!");
	g_print(work,288,288,"Now ");



/*  CPの攻撃点 1	*/
	memcpy(brd0,board,49*4);
	for(r0=0;r0<49;r0++){
	  mx0=r0%7;  my0=r0/7;
	  for(r1=0;r1<49;r1++){
	    mx1=r1%7;  my1=r1/7;
	    at11=0;  at12=0;  ef1=0;
	    if((board[r0]>=pl*20+1)&&(board[r0]<=pl*20+9)){
	      ret=canmove(board,mx0,my0,mx1,my1,pl);
	      if(ret>=0){
	        if(ret==1){
	          at11=at1a[(board[r0]%20)-1];
	          at12=at1b[(board[r1]%20)-1];
	          if(board[r0]%20==9) board[r1]=board[r0];
	          else{
	            board[r1]=board[r0]+(mode==0)+(mode==1)*(board[r1]-(pl==0)*20);
	            if(board[r1]-pl*20>=9) board[r1]=8+pl*20;
	            }
	          }
	        else{
	          at11=0;  at12=0;
	          board[r1]=board[r0];
	          }
	        board[r0]=0;

/*  効果点	*/
	        memcpy(brd1,board,49*4);
	        ef1=0;
	        for(rpx=0;rpx<7;rpx++){
	          for(rpy=0;rpy<7;rpy++){
	            ret=canmove(board,mx1,my1,rpx,rpy,pl);
	            if(ret==1) ef1+=efe1[board[rpy*7+rpx]%20-1];
	            }
	          }

/*  人間の攻撃点 1	*/
	        hmat=0;
	        pl=(pl==0);
	        for(r2=0;r2<49;r2++){
	          mx2=r2%7;  my2=r2/7;
	          for(r3=0;r3<49;r3++){
	            mx3=r3%7;  my3=r3/7;
	            at21=0;  at22=0;  ef2=0;
	            if((board[r2]>=pl*20+1)&&(board[r2]<=pl*20+9)){
	              ret=canmove(board,mx2,my2,mx3,my3,pl);
	              if(ret>=0){
	                if(ret==1){
	                  at21=at2a[(board[r2]%20)-1];
	                  at22=at2b[(board[r3]%20)-1];
	                  if(board[r2]%20==9) board[r3]=board[r2];
	                  else{
	                    board[r3]=board[r2]+(mode==0)+(mode==1)*(board[r3]-(pl==0)*20);
	                    if(board[r3]-pl*20>=9) board[r3]=8+pl*20;
	                    }
	                  }
	                else{
	                  at21=0;  at22=0;
	                  board[r3]=board[r2];
	                  }
	                board[r2]=0;

/*  効果点	*/
	                ef2=0;
	                for(rpx=0;rpx<7;rpx++){
	                  for(rpy=0;rpy<7;rpy++){
	                    ret=canmove(board,mx3,my3,rpx,rpy,pl);
	                    if(ret==1) ef2+=efe2[board[rpy*7+rpx]%20-1];
	                    }
	                  }
	                if(hmat<at21+at22+ef2){
	                  hmat=at21+at22+ef2;
	                  memcpy(brd2,board,49*4);
	                  }
	                }
	              memcpy(board,brd1,49*4);
	              }
	            }
	          }
	        memcpy(board,brd2,49*4);

/*  CPの攻撃点 2  */
	        pl=(pl==0);
	        can=0;
	        for(rpx=0;rpx<49;rpx++){
	          if((board[rpx]>=pl*20+1)&&(board[rpx]<=pl*20+9)) can=1;
	          }
	        if(can==0){
	          rdm=rand()%6;
	          tt=at11+at12+ef1-hmat+rdm;
	          if(total<tt){
	            total=tt;
	            *aigx=mx0;  *aigy=my0;
	            *aipx=mx1;  *aipy=my1;
	            }
	          }
	        for(r4=0;r4<49;r4++){
	          mx4=r4%7;  my4=r4/7;
	          for(r5=0;r5<49;r5++){
	            mx5=r5%7;  my5=r5/7;
	            at31=0;  at32=0;  ef3=0;
	            if((board[r4]>=pl*20+1)&&(board[r4]<=pl*20+9)){
	              ret=canmove(board,mx4,my4,mx5,my5,pl);
	              if(ret>=0){
	                if(ret==1){
	                  at31=at3a[(board[r4]%20)-1];
	                  at32=at3b[(board[r5]%20)-1];
	                  if(board[r4]%20==9) board[r5]=board[r4];
	                  else{
	                    board[r5]=board[r4]+(mode==0)+(mode==1)*(board[r5]-(pl==0)*20);
	                    if(board[r5]-pl*20>=9) board[r5]=8+pl*20;
	                    }
	                  }
	                else{
	                  at31=0;  at32=0;
	                  board[r5]=board[r4];
	                  }
	                board[r4]=0;

/*  効果点	*/
	                ef3=0;
	                for(rpx=0;rpx<7;rpx++){
	                  for(rpy=0;rpy<7;rpy++){
	                    ret=canmove(board,mx5,my5,rpx,rpy,pl);
	                    if(ret==1) ef3+=efe3[board[rpy*7+rpx]%20-1];
	                    }
	                  }

	                rdm=rand()%6;
	                tt=at11+at12+ef1-hmat+at31+at32+ef3+rdm;
	                if(total<tt){
	                  total=tt;
	                  *aigx=mx0;  *aigy=my0;
	                  *aipx=mx1;  *aipy=my1;
	                  }
	                memcpy(board,brd2,49*4);
	                }
	              }
	            }
	          }
	        memcpy(board,brd0,49*4);
	        }
	      }
	    }
	  _itoa(r0*100/49,val,10);
	  strcpy(str,val);
	  strcat(str,"%");
	  EGB_color(work,0,0);
	  EGB_color(work,2,0);
	  g_box(work,320,272,352,290);
	  EGB_color(work,0,15);
	  EGB_color(work,1,8);
	  g_print(work,320,288,str);
	  if(vs==5){
	    pad2(0,&stick,&trig);
	    if(trig!=0) return 1;
	    }
	  }
	EGB_color(work,1,0);
	EGB_clearScreen(work);
	_outp(0x05ec,0);
	return 0;
}