user-0 提问: 求帮助（极小极大算法的问题，感兴趣的帮忙看下码！谢谢！）

回复:
user: user-1
content: 这么搞没人会理你的

user: user-0
content: QP changedQi(int x,int y)/*判断棋盘的变化*/ { 	int i,j,k,kk,ii,jj; 	   QI qi_temp; 	   QP pTail; 	   QP qi_store = (QP) malloc(sizeof(QPNODE)); 	   qi_store->QPnext = 0; 	   pTail = qi_store;         i=(x-120)/40; /*计算数组元素的行下标*/        j=(y-120)/40; /*计算数组元素的列下标*/ 	           if(j<6)/*往右边*/        { 		   for(k=j+1;k<8;k++) 			   if(a[i][k]==a[i][j]||a[i][k]==0)/*遇到自己的棋子或空格结束*/ 				   break; 			   if(a[i][k]!=0&&k<8) 			   { 				   for(kk=j+1;kk<k&&k<8;kk++)/*判断下边*/ 				   { 					   QP qi_new = (QP) malloc(sizeof(QPNODE)); 					   a[i][kk]=a[i][j]; /*改变棋子颜色*/ 					   qi_temp.x = i*40+120; 					   qi_temp.y = kk*40+120; 					   qi_new->qi_position = qi_temp;	 					   qi_new->QPnext = NULL; 					   pTail->QPnext = qi_new; 					   pTail = qi_new; 				   }    			   }        }        if(j>1)/*判断上边*/        { 		   for(k=j-1;k>=0;k--) 			   if(a[i][k]==a[i][j]||!a[i][k]) 				   break; 			   if(a[i][k]!=0&&k>=0) 			   { 				   for(kk=j-1;kk>k&&k>=0;kk--) 				   { 					    					   QP qi_new = (QP) malloc(sizeof(QPNODE)); 					   a[i][kk]=a[i][j]; /*改变棋子颜色*/ 					   qi_temp.x = i*40+120; 					   qi_temp.y = kk*40+120; 					   qi_new->qi_position = qi_temp;	 					   qi_new->QPnext = NULL; 					   pTail->QPnext = qi_new; 					   pTail = qi_new; 				   } 				    			   }        }        if(i<6)/*判断右边*/        { 		   for(k=i+1;k<8;k++) 			   if(a[k][j]==a[i][j]||!a[k][j]) 				   break; 			   if(a[k][j]!=0&&k<8) 			   { 				   for(kk=i+1;kk<k&&k<8;kk++) 				   { 					    					   QP qi_new = (QP) malloc(sizeof(QPNODE)); 					   a[kk][j]=a[i][j]; /*改变棋子颜色*/ 					   qi_temp.x = kk*40+120; 					   qi_temp.y = j*40+120; 					   qi_new->qi_position = qi_temp;	 					   qi_new->QPnext = NULL; 					   pTail->QPnext = qi_new; 					   pTail = qi_new; 				   } 				    			   }        }        if(i>1)/*判断左边*/        { 		   for(k=i-1;k>=0;k--) 			   if(a[k][j]==a[i][j]||!a[k][j]) 				   break; 			   if(a[k][j]!=0&&k>=0) 			   { 				   for(kk=i-1;kk>k&&k>=0;kk--) 				   { 					   QP qi_new = (QP) malloc(sizeof(QPNODE)); 					   a[kk][j]=a[i][j]; /*改变棋子颜色*/ 					   qi_temp.x = kk*40+120; 					   qi_temp.y = j*40+120; 					   qi_new->qi_position = qi_temp;	 					   qi_new->QPnext = NULL; 					   pTail->QPnext = qi_new; 					   pTail = qi_new; 				   } 				    			   }        }        if(i>1&&j<6)/*左下*/        { 		   for(k=i-1,kk=j+1;k>=0&&kk<8;k--,kk++) 			   if(a[k][kk]==a[i][j]||!a[k][kk]) 				   break; 			   if(a[k][kk]&&k>=0&&kk<8) 			   { 				   for(ii=i-1,jj=j+1;ii>k&&k>=0;ii--,jj++) 				   { 					    					   QP qi_new = (QP) malloc(sizeof(QPNODE)); 					   a[ii][jj]=a[i][j]; /*改变棋子颜色*/ 					   qi_temp.x = ii*40+120; 					   qi_temp.y = jj*40+120; 					   qi_new->qi_position = qi_temp;	 					   qi_new->QPnext = NULL; 					   pTail->QPnext = qi_new; 					   pTail = qi_new; 				   } 			   }        }        if(i<6&&j>1)/*右上*/        { 		   for(k=i+1,kk=j-1;k<8&&kk>=0;k++,kk--) 			   if(a[k][kk]==a[i][j]||!a[k][kk]) 				   break; 			   if(a[k][kk]!=0&&k<8&&kk>=0) 			   { 				   for(ii=i+1,jj=j-1;ii<k&&k<8;ii++,jj--) 				   { 					   QP qi_new = (QP) malloc(sizeof(QPNODE)); 					   a[ii][jj]=a[i][j]; /*改变棋子颜色*/ 					   qi_temp.x = ii*40+120; 					   qi_temp.y = jj*40+120; 					   qi_new->qi_position = qi_temp;	 					   qi_new->QPnext = NULL; 					   pTail->QPnext = qi_new; 					   pTail = qi_new; 				   }  			   }        }        if(i>1&&j>1)/*左上*/        { 		   for(k=i-1,kk=j-1;k>=0&&kk>=0;k--,kk--) 			   if(a[k][kk]==a[i][j]||!a[k][kk]) 				   break; 			   if(a[k][kk]!=0&&k>=0&&kk>=0) 			   { 				   for(ii=i-1,jj=j-1;ii>k&&k>=0;ii--,jj--) 				   { 					   QP qi_new = (QP) malloc(sizeof(QPNODE)); 					   a[ii][jj]=a[i][j]; /*改变棋子颜色*/ 					   qi_temp.x = ii*40+120; 					   qi_temp.y = jj*40+120; 					   qi_new->qi_position = qi_temp;	 					   qi_new->QPnext = NULL; 					   pTail->QPnext = qi_new; 					   pTail = qi_new; 				   } 				    			   }        }        if(i<6&&j<6)/* 右下*/        { 		   for(k=i+1,kk=j+1;kk<8&&kk<8;k++,kk++) 			   if(a[k][kk]==a[i][j]||!a[k][kk]) 				   break; 			   if(a[k][kk]!=0&&kk<8&&k<8) 			   { 				   for(ii=i+1,jj=j+1;ii<k&&k<8;ii++,jj++) 				   { 					   QP qi_new = (QP) malloc(sizeof(QPNODE)); 					   a[ii][jj]=a[i][j]; /*改变棋子颜色*/ 					   qi_temp.x = ii*40+120; 					   qi_temp.y = jj*40+120; 					   qi_new->qi_position = qi_temp;	 					   qi_new->QPnext = NULL; 					   pTail->QPnext = qi_new; 					   pTail = qi_new;  				   } 			   }        }        return qi_store;     }      void DoScore()/*处理分数*/     { 		int i,j; 		score1=score2=0;/*重新开始计分数*/ 		for(i=0;i<8;i++) 			for(j=0;j<8;j++) 				if(a[i][j]==1)/*分别统计两个人的分数*/ 					score1++; 				else 					if(a[i][j]==2) 						score2++;     }     void PrintScore(int playnum)/*输出成绩*/     { 		if(playnum==1)/*清除以前的成绩*/ 		{ 			setfillstyle(SOLID_FILL,BLUE); 			bar(550,100,640,400); 		} 		setcolor(RED); 		settextstyle(0,0,4);/*设置文本输出样式*/ 		if(playnum==1)/*判断输出哪个棋手的分,在不同的位置输出*/ 		{ 			sprintf(playone,"%d",score1); 			outtextxy(550,200,playone); 		} 		else 		{ 			sprintf(playtwo,"%d",score2); 			outtextxy(550,300,playtwo); 		} 		setcolor(0);     }     void playWin()/*输出最后的胜利者结果*/     { 		settextstyle(0,0,4); 		setcolor(12); 		if(score2>score1)/*开始判断最后的结果*/ 			outtextxy(100,50,"black win!"); 		else 			if(score2<score1) 				outtextxy(100,50,"white win!"); 			else 				outtextxy(60,50,"you all win!");     }

user: user-0
content: QI MinMax(int depth) { 	FILE *fp; 	int x,y; 	QI qi; 	QP qp; 	QI best_qi;  best_qi.val = -1000; 	qp = canTakeboard(2); 	 fp = fopen("\\output\\minmax.txt","a"); 	fprintf(fp,"\n");	 	while(qp->QPnext) 	{ 		QP qp_temp; 		qp = qp->QPnext; 		qi = qp->qi_position; 		x = qi.x; 		y = qi.y; 		qp_temp = MakeMove(2,x,y); 		qi.val = Min(depth-1); 		UnMakeMove(2,x,y,qp_temp); 		if(qi.val > best_qi.val) 		{ 			best_qi = qi;	 		}  	fprintf(fp,"(%d,%d) ",(x-120)/40,(y-120)/40); 	 	}   	fclose(fp); 	return best_qi; }  QP MakeMove(int t,int x,int y) { 	QP qp; 	a[(x-120)/40][(y-120)/40] = t; 	qp = changedQi(x,y); 	return qp; }  void UnMakeMove(int t,int x,int y,QP qp) { 	FILE *fp; 	int xx=0,yy=0; 	QI qi; 	a[(x-120)/40][(y-120)/40] = 0; 	fp = fopen("\\output\\unmakemove.txt","a"); 	fprintf(fp,"\n");	 	while(qp->QPnext) 	{ 		qp = qp->QPnext; 		qi = qp->qi_position; 		xx = qi.x; 		yy = qi.y; 		a[(xx-120)/40][(yy-120)/40] = t%2+1; 		fprintf(fp,"(%d,%d)",(xx-120)/40,(yy-120)/40); 	     	}	fclose(fp);	 }  int Max(int depth) { 	int max = -1000; 	int val = 0; 	int x,y; 	QI qi; 	QP qp; 	qp = canTakeboard(2); 	 	if(depth<=0) 		return evaluate(); 	if(mobility(2)==0) 	{ 		if(mobility(1)==0) 			return evaluate(); 		return Min(depth); 	} 	while(qp->QPnext) 	{ 		QP qp_temp; 		qp = qp->QPnext; 		qi = qp->qi_position; 		x = qi.x; 		y = qi.y; 		qp_temp = MakeMove(2,x,y); 		val = Max(depth-1); 		UnMakeMove(2,x,y,qp_temp); 		if(val>max) max = val; 	} 	return max;	 }  int Min(int depth) { 	FILE *fp; 	 	int min = 1000; 	int val = 0; 	int x,y; 	QI qi; 	QP qp; 	qp = canTakeboard(1); 	fp = fopen("\\output\\min.txt","a"); 	fprintf(fp,"\n");	 	if (depth<=0) 		return evaluate(); 	if(mobility(1)==0) 	{ 		if(mobility(2)==0) 			return evaluate(); 		return Max(depth); 	} 	while(qp->QPnext) 	{ 		QP qp_temp; 		qp = qp->QPnext; 		qi = qp->qi_position; 		x = qi.x; 		y = qi.y; 		qp_temp = MakeMove(1,x,y); 		val = Max(depth-1); 		UnMakeMove(1,x,y,qp_temp); 		if(val<min) min = val; 		fprintf(fp,"(%d,%d) ",(x-120)/40,(y-120)/40);  	} 	fclose(fp); 	return min; }     void SetPlayColor(int t)/*设置棋子颜色*/ { 	if(t%2==1) 		setfillstyle(SOLID_FILL,15);/*白色*/ 	else 		setfillstyle(SOLID_FILL,8);/*灰色*/ } void MoveColor(int x,int y)/*走了一步后恢复原来格子的状态*/ { 	if(y<100)/*如果是从起点出发就恢复蓝色*/ 		setfillstyle(SOLID_FILL,BLUE); 	else/*其他情况如果是1就恢复白色棋子,2恢复黑色棋子,或恢复蓝色棋盘*/ 		switch(a[(x-120)/40][(y-120)/40]) 	{ 		 case 1: 			 setfillstyle(SOLID_FILL,15);break; /*白色*/ 		 case 2: 			 setfillstyle(SOLID_FILL,8);break; /*黑色*/ 		 default: 			 setfillstyle(SOLID_FILL,BLUE); /*蓝色*/ 	} }  int QpChange(int sign,int x,int y,int t)/*判断棋盘的变化*/ { 	int i,j,k,kk,ii,jj,yes; 	yes=0; 	i=(x-120)/40; /*计算数组元素的行下标*/ 	j=(y-120)/40; /*计算数组元素的列下标*/ 	if(sign == 1) SetPlayColor(t);/*设置棋子变化的颜色*/ 	/*开始往8个方向判断变化*/ 	if(j<6)/*往右边*/ 	{ 		for(k=j+1;k<8;k++) 			if(a[i][k]==a[i][j]||a[i][k]==0)/*遇到自己的棋子或空格结束*/ 				break; 			if(a[i][k]!=0&&k<8) 			{ 				for(kk=j+1;kk<k&&k<8;kk++)/*判断右边*/ 				{ 					if(sign == 1) 					{ 					a[i][kk]=a[i][j]; /*改变棋子颜色*/ 					fillellipse(120+i*40,120+kk*40,15,15); 					}  				} 				if(kk!=j+1) /*条件成立则有棋子改变过颜色*/ 					yes=1; 			} 	} 	if(j>1)/*判断左边*/ 	{ 		for(k=j-1;k>=0;k--) 			if(a[i][k]==a[i][j]||!a[i][k]) 				break; 			if(a[i][k]!=0&&k>=0) 			{ 				for(kk=j-1;kk>k&&k>=0;kk--) 				{ 					if(sign == 1) 					{ 					a[i][kk]=a[i][j]; 					fillellipse(120+i*40,120+kk*40,15,15); 					} 				} 				if(kk!=j-1) 					yes=1; 			} 	} 	if(i<6)/*判断下边*/ 	{ 		for(k=i+1;k<8;k++) 			if(a[k][j]==a[i][j]||!a[k][j]) 				break; 			if(a[k][j]!=0&&k<8) 			{ 				for(kk=i+1;kk<k&&k<8;kk++) 				{ 					if(sign == 1) 					{ 					a[kk][j]=a[i][j]; 					fillellipse(120+kk*40,120+j*40,15,15); 					} 				} 				if(kk!=i+1) 					yes=1; 			} 	} 	if(i>1)/*判断上边*/ 	{ 		for(k=i-1;k>=0;k--) 			if(a[k][j]==a[i][j]||!a[k][j]) 				break; 			if(a[k][j]!=0&&k>=0) 			{ 				for(kk=i-1;kk>k&&k>=0;kk--) 				{ 					if(sign == 1) 					{ 					a[kk][j]=a[i][j]; 					fillellipse(120+kk*40,120+j*40,15,15); 					} 				} 				if(kk!=i-1) 					yes=1; 			} 	} 	if(i>1&&j<6)/*右上*/ 	{ 		for(k=i-1,kk=j+1;k>=0&&kk<8;k--,kk++) 			if(a[k][kk]==a[i][j]||!a[k][kk]) 				break; 			if(a[k][kk]&&k>=0&&kk<8) 			{ 				for(ii=i-1,jj=j+1;ii>k&&k>=0;ii--,jj++) 				{ 					if(sign == 1) 					{ 					a[ii][jj]=a[i][j]; 					fillellipse(120+ii*40,120+jj*40,15,15); 					} 				} 				if(ii!=i-1) 					yes=1; 			} 	} 	if(i<6&&j>1)/*左下*/ 	{ 		for(k=i+1,kk=j-1;k<8&&kk>=0;k++,kk--) 			if(a[k][kk]==a[i][j]||!a[k][kk]) 				break; 			if(a[k][kk]!=0&&k<8&&kk>=0) 			{ 				for(ii=i+1,jj=j-1;ii<k&&k<8;ii++,jj--) 				{ 					if(sign == 1) 					{ 					a[ii][jj]=a[i][j]; 					fillellipse(120+ii*40,120+jj*40,15,15); 					} 				} 				if(ii!=i+1) 					yes=1; 			} 	} 	if(i>1&&j>1)/*左上*/ 	{ 		for(k=i-1,kk=j-1;k>=0&&kk>=0;k--,kk--) 			if(a[k][kk]==a[i][j]||!a[k][kk]) 				break; 			if(a[k][kk]!=0&&k>=0&&kk>=0) 			{ 				for(ii=i-1,jj=j-1;ii>k&&k>=0;ii--,jj--) 				{ 					if(sign == 1) 					{ 					a[ii][jj]=a[i][j]; 					fillellipse(120+ii*40,120+jj*40,15,15); 					} 				} 				if(ii!=i-1) 					yes=1; 			} 	} 	if(i<6&&j<6)/* 右下*/ 	{ 		for(k=i+1,kk=j+1;kk<8&&kk<8;k++,kk++) 			if(a[k][kk]==a[i][j]||!a[k][kk]) 				break; 			if(a[k][kk]!=0&&kk<8&&k<8) 			{ 				for(ii=i+1,jj=j+1;ii<k&&k<8;ii++,jj++) 				{ 					if(sign == 1) 					{ 					a[ii][jj]=a[i][j]; 					fillellipse(120+ii*40,120+jj*40,15,15); 					} 				} 				if(ii!=i+1) 					yes=1; 			} 	} 	return yes;/*返回是否改变过棋子颜色的标记*/ }