⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fivestoneprocess.cpp

📁 该工程是一个非常完整的,优化的五子棋源代码(VC),可以帮你学习路径选择算法和vc编程.
💻 CPP
📖 第 1 页 / 共 5 页
字号:
		
	{
		
		//还是不能防住
		
		selectqianmodel5(color,x,y,tempresult,count,true);
		
		common_info("人二阶牵制子low!",debug,cur_time);
		thinkpos = 100;
		return;
		
	}
	
	ShowInfo("has_twolevel_qianmodel_defent_low2:"+passtime(cur_time));
	thinkpos += 2;
	if (!defent_success&&has_twolevel_qianmodel(anticolor,count,tempresult))
		
	{
		
		//还是不能防住,那么只挡某一个活子即可
		
		
		selectqianmodel5(color,x,y,tempresult,count,true);
		
		common_info("人二阶牵制子2!",debug,cur_time);
		thinkpos = 100;
		return;
		
	}
	
	ShowInfo("has_twolevel_qianmodel2:"+passtime(cur_time));
	thinkpos += 2;

	//________________________________________________
	/*
	if ((countpoints()<50)&&has_threelevel_qianmodel(anticolor,count,tempresult))
		
	{
		
		selectqianmodel5(color,x,y,tempresult,count,true);
		
		common_info("人三阶牵制子!",debug,cur_time);
		
		return;
		
	}
	
	ShowInfo("has_threelevel_qianmodel2:"+passtime(cur_time));	

	*/
	/*

	if ((countpoints()<50)&&has_qiang_beat(anticolor,count,tempresult))
		
	{
		
		selectqianmodel5(color,x,y,tempresult,count,true);
		
		common_info("人强打击子!",debug,cur_time);
		
		return;
		
	}
	
	ShowInfo("has_qiang_beat2:"+passtime(cur_time));
	*/

	/*
	if (has_beatpoints_low(color,count,tempresult))
		
	{
		
		selectqianmodel5(color,x,y,tempresult,count);
		
		common_info("计算机打击子low!",debug,cur_time);
		
		return;
		
	}
	
	ShowInfo("has_beatpoints_low1:"+passtime(cur_time));
	/*

	if ((countpoints()<50)&&has_twolevel_beat_low(color,count,tempresult))
		
	{
		
		selectqianmodel5(color,x,y,tempresult,count);
		
		common_info("计算机二阶打击子low!",debug,cur_time);
		
		return;
		
	}
	
	ShowInfo("has_twolevel_beat_low1:"+passtime(cur_time));
	*/
	if ((countpoints()<50)&&has_beatpoints(anticolor,count,tempresult))
	{
		selectqianmodel5(color,x,y,tempresult,count,true);
		common_info("人打击子!",debug,cur_time);		thinkpos = 100;
		return;
	}
	ShowInfo("has_beatpoints2:"+passtime(cur_time));
	thinkpos += 2;
	/*

	if ((countpoints()<50)&&has_twolevel_beat(anticolor,count,tempresult))
		
	{
		
		selectqianmodel5(color,x,y,tempresult,count,true);
		
		common_info("人二阶打击子!",debug,cur_time);
		
		return;
		
	}
	
	ShowInfo("has_twolevel_beat2:"+passtime(cur_time));	
	*/	
	
	/*
	if (make_beatpoints(color,count,tempresult))
		
	{
		
		selectqianmodel5(color,x,y,tempresult,count);
		
		common_info("计算机制造打击子!",debug,cur_time);
		
		return;
		
	}
	
	ShowInfo("make_beatpoints:"+passtime(cur_time));
	/*

	if (make_twolevel_qianmodel(color,count,tempresult))
		
	{
		
		selectqianmodel5(color,x,y,tempresult,count);
		
		common_info("计算机制造二阶牵制子匹配!",debug,cur_time);
		
		return;
		
	}
	
	ShowInfo("make_twolevel_qianmodel:"+passtime(cur_time));

	/*
	if (make_threelevel_qianmodel(color,count,tempresult))
	{
		selectqianmodel5(color,x,y,tempresult,count);
		common_info("计算机制造三阶牵制子匹配!",debug,cur_time);
		return;
	}
	ShowInfo("make_threelevel_qianmodel:"+passtime(cur_time));	
	*/
	//也不存在二阶活子,看能否制造活子
	/*
	if (make_twolevel(color,count,tempresult))
	{
		selectqianmodel5(color,x,y,tempresult,count);
		common_info("计算机制造二阶活子!",debug,cur_time);
		return;
	}
	ShowInfo("make_twolevel:"+passtime(cur_time));
	/*
	if (make_alive(color,count,tempresult))
	{
		selectmax(color,x,y,tempresult,count);
		common_info("计算机制造一阶活子!",debug);
		return;
	}	
	if (make_alive(anticolor,count,tempresult))
	{
		selectmax(color,x,y,tempresult,count,true);
		common_info("制造人的一阶活子!",debug);
		return;
	}
	//最后前置函数都已经失败,采用赋值算法
	getclose(color,count,tempresult);
	selectqianmodel5(color,x,y,tempresult,count);
	*/
	//getmax(count,tempresult);
	//getclose(color,count,tempresult);

/*
	if (((color==1)||(countpoints()>=10))&&has_chongtwoandmakeqianmodel(color,count,tempresult))

	{
		selectqianmodel5(color,x,y,tempresult,count);
		
		common_info("计算机冲二子和制造牵制子匹配!",debug,cur_time);
		thinkpos = 100;
		return;
		
	}

	ShowInfo("has_chongtwoandmakeqianmodel:"+passtime(cur_time));
	thinkpos += 2;
	*/
	
	
	if (((color==1)||(countpoints()>=10))&&has_chongtwo(color,count,tempresult))

	{
		selectqianmodel5(color,x,y,tempresult,count);
		
		common_info("计算机冲二子!",debug,cur_time);
		thinkpos = 100;
		return;
		
	}
	ShowInfo("has_chongtwo:"+passtime(cur_time));
	thinkpos += 2;
	if (((color==1)||(countpoints()>=10))&&make_qianmodel(color,count,tempresult))
		
	{
		
		selectqianmodel5(color,x,y,tempresult,count);
		
		common_info("计算机制造牵制子匹配!",debug,cur_time);
		thinkpos = 100;
		
		return;
		
	}
	
	ShowInfo("make_qianmodel:"+passtime(cur_time));
	thinkpos += 2;
	
	if (color==1)
	{
		getclose_small(count,tempresult);
		selectmax(color,x,y,tempresult,count,true);	
	}
	
	else
	{
		getmax(count,tempresult);
		
		int tempi = random(0,count-1);
		
		x = tempresult[tempi].x;
		
		y = tempresult[tempi].y;
		
	}
	common_info("赋值算法!",debug,cur_time);	
	thinkpos = 100;
}

void FiveStoneProcess::getpoint(int &x, int &y, int color,BOOL debug)
{
	switch(m_grade)
	{
		case 1:getpoint1(x,y,color,debug);break;
		case 2:getpoint2(x,y,color,debug);break;
		case 3:getpoint3(x,y,color,debug);break;
		case 4:getpoint4(x,y,color,debug);break;
		case 5:getpoint5(x,y,color,debug);break;
	}
}

BOOL FiveStoneProcess::twolevel_alive(int x, int y, int color)
{
	if (points[x][y]!=0) return false;//已经有子了
	int model[][9]={//此数组表示各种模式,包括此子前四个和后四个子的排列
		//-1表示任意,1表示相同颜色,0表示空,2表示(x,y)所在位置
		{0,1,1,1,2,-1,-1,-1,-1},//_111*
		{1,0,1,1,2,-1,-1,-1,-1},//1_11*
		{1,1,0,1,2,-1,-1,-1,-1},//11_1*
		{1,1,1,0,2,-1,-1,-1,-1},//111_*
		{-1,1,1,1,2,0,-1,-1,-1},//111*_
		{-1,0,1,1,2,1,-1,-1,-1},//_11*1
		{-1,1,0,1,2,1,-1,-1,-1},//1_1*1
		{-1,1,1,0,2,1,-1,-1,-1},//11_*1
		{-1,-1,1,1,2,0,1,-1,-1},//11*_1
		{-1,-1,1,1,2,1,0,-1,-1},//11*1_
		{0,0,1,1,2,0,-1,-1,-1},//__11*_
		{0,1,0,1,2,0,-1,-1,-1},//_1_1*_
		{0,1,1,0,2,0,-1,-1,-1},//_11_*_
		{-1,0,1,1,2,0,0,-1,-1},//_11*__
		{-1,0,0,1,2,1,0,-1,-1},//__1*1_
		{-1,0,1,0,2,1,0,-1,-1},//_1_*1_
		{-1,-1,0,1,2,0,1,0,-1},//_1*_1_
	};//17种可以造成活子的情形
	int model_num = 17;
	int point_num = 9;
	BOOL flag;
	int count = 0;//累计有多少个方向的上有模式被匹配
	for (int i=0;i<4;i++)
	{
		//四个方向遍历		
		for (int j=0;j<model_num;j++)//model_num种模式遍历,每种模式遍历两次,正反各一次
		{
			flag = true;
			for(int k=0;k<point_num;k++)//point_num个子遍历,正遍历
			{
				if (model[j][k]==0)
				{
					if (getcolor(x,i,k-4,y)!=0)
					{
						//不匹配此模式
						flag = false;
						break;
					}
				}
				else if (model[j][k]==1)
				{
					if (getcolor(x,i,k-4,y)!=color)
					{
						//不匹配此模式
						flag = false;
						break;
					}
				}				
			}
			if (flag) 
			{
				//匹配上某种模式
				count++;
				break;//此方向就不用再累加了
			}
			flag = true;
			for(k=0;k<point_num;k++)//point_num个子遍历,反遍历
			{
				if (model[j][k]==0)
				{
					if (getcolor(x,i,4-k,y)!=0)
					{
						//不匹配此模式
						flag = false;
						break;
					}
				}
				else if (model[j][k]==1)
				{
					if (getcolor(x,i,4-k,y)!=color)
					{
						//不匹配此模式
						flag = false;
						break;
					}
				}				
			}
			if (flag) 
			{
				//匹配上某种模式
				count++;
				break;//此方向就不用再累加了
			}
		}
	}
	if (count>=2) return true;
	return false;
}

BOOL FiveStoneProcess::twolevel_alive_pure(int x, int y, int color)
{
	//与twolevel_alive不同的是,pure不包括强二阶活子
	if (points[x][y]!=0) return false;//已经有子了
	int model[][9]={//此数组表示各种模式,包括此子前四个和后四个子的排列
		//-1表示任意,1表示相同颜色,0表示空,2表示(x,y)所在位置
		{0,0,1,1,2,0,-1,-1,-1},//__11*_
		{0,1,0,1,2,0,-1,-1,-1},//_1_1*_
		{0,1,1,0,2,0,-1,-1,-1},//_11_*_
		{-1,0,1,1,2,0,0,-1,-1},//_11*__
		{-1,0,0,1,2,1,0,-1,-1},//__1*1_
		{-1,0,1,0,2,1,0,-1,-1},//_1_*1_
		{-1,-1,0,1,2,0,1,0,-1},//_1*_1_
	};//17种可以造成活子的情形
	int model_num = 7;
	int point_num = 9;
	BOOL flag;
	int count = 0;//累计有多少个方向的上有模式被匹配
	for (int i=0;i<4;i++)
	{
		//四个方向遍历		
		for (int j=0;j<model_num;j++)//model_num种模式遍历,每种模式遍历两次,正反各一次
		{
			flag = true;
			for(int k=0;k<point_num;k++)//point_num个子遍历,正遍历
			{
				if (model[j][k]==0)
				{
					if (getcolor(x,i,k-4,y)!=0)
					{
						//不匹配此模式
						flag = false;
						break;
					}
				}
				else if (model[j][k]==1)
				{
					if (getcolor(x,i,k-4,y)!=color)
					{
						//不匹配此模式
						flag = false;
						break;
					}
				}				
			}
			if (flag) 
			{
				//匹配上某种模式
				count++;
				break;//此方向就不用再累加了
			}
			flag = true;
			for(k=0;k<point_num;k++)//point_num个子遍历,反遍历
			{
				if (model[j][k]==0)
				{
					if (getcolor(x,i,4-k,y)!=0)
					{
						//不匹配此模式
						flag = false;
						break;
					}
				}
				else if (model[j][k]==1)
				{
					if (getcolor(x,i,4-k,y)!=color)
					{
						//不匹配此模式
						flag = false;
						break;
					}
				}				
			}
			if (flag) 
			{
				//匹配上某种模式
				count++;
				break;//此方向就不用再累加了
			}
		}
	}
	if (count>=2) return true;
	return false;
}

BOOL FiveStoneProcess::twolevel_alive_old(int x, int y, int color)
{
	//这是用定义直接做的判断,比较慢,因此被放弃,但仍然放在此处作为示范
	//计算有无二阶活子
	//即自己下一子后,对方不论走什么子,都会存在活子	
	if (points[x][y]!=0) return false;//已经有子了,不可能是二阶活子
	if (can_five(color)) return false;//如果已经可以连成5子,那么去掉
	if (is_alive(x,y,color)) return false;//如果是一阶活子,那么去掉
	int i;
	points[x][y] = color;//假设走了此子
	int anticolor;//对方的color
	if (color==1) anticolor = 2;
	else anticolor = 1;
	BOOL flag = true;//表明是否对方每次走子时,自己都可以存在活子
	POINT roundpoints[8];//一个子周围8个方向上离它最近的空子位置
	getroundpoints(x,y,color,roundpoints);//此处,为了避免全盘搜索,采用了近似手法,只计算它周围的8个空子即可
	for(i=0;i<8;i++)
	{
		if (roundpoints[i].x!=0)//即是有效的位置
		{
			points[roundpoints[i].x][roundpoints[i].y] = anticolor;//走对方的子
			if (!can_five(color)&&!has_alive(color)) 
			{
				//如果存在一种情况不能存在活子,也不存

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -