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

📄 fivestoneprocess.cpp

📁 java程序五子棋源代码。 java程序五子棋源代码。
💻 CPP
📖 第 1 页 / 共 5 页
字号:
			if (is_chongtwo(color,closepoints[i].x,closepoints[i].y)) 
				
			{
				
				tempresult[counter].x = closepoints[i].x;
				
				tempresult[counter].y = closepoints[i].y;
				
				counter++;
				
				flag = true;
				
			}
			
		}
		
	}
	
	return flag;
	
	
	
}

BOOL FiveStoneProcess::has_defent_point(int color,int &counter,POINT tempresult[])

{
	
	//判断一个棋盘有没有阻挡子
	
	//counter为候选结果的计数,tempresult为候选结果集
	
	counter = 0;
	
	BOOL flag = false;	//返回值
	
	POINT closepoints[225];
	
	int count = 0;
	
	getclose(color,count,closepoints);			
	
	for(int i=0;i<count;i++)
		
	{
		
		if (closepoints[i].x!=0)
			
		{
			
			if (is_defent_point(color,closepoints[i].x,closepoints[i].y)) 
				
			{
				
				tempresult[counter].x = closepoints[i].x;
				
				tempresult[counter].y = closepoints[i].y;
				
				counter++;
				
				flag = true;
				
			}
			
		}
		
	}
	
	return flag;
	
	
	
}



BOOL FiveStoneProcess::has_twoqianmodel(int color,int &counter,POINT tempresult[])

{

	//判断一个棋盘有没有两个牵制子连在一起的情况

	//counter为候选结果的计数,tempresult为候选结果集

	counter = 0;

	int count;

	POINT local_tempresult[225];

	BOOL flag = false;

	if (has_qian(color,count,local_tempresult))

	{

		for (int i=0;i<count;i++)

		{

			if (is_twoqianmodel(color,local_tempresult[i].x,local_tempresult[i].y,local_tempresult,count))

			{

				tempresult[counter].x = local_tempresult[i].x;

				tempresult[counter].y = local_tempresult[i].y;

				counter++;

				flag = true;

			}

		}		

	}

	return flag;

	

}



BOOL FiveStoneProcess::has_alive(int color)

{

	//判断一个棋盘有没有活子

	//if (can_five(color)) return false;//已经存在可以连5的子,不必再判断一阶活子

	POINT closepoints[225];

	int count = 0;

	getclose(color,count,closepoints);	

	for(int i=0;i<count;i++)

	{

		if (closepoints[i].x!=0)

		{

			if (is_alive(closepoints[i].x,closepoints[i].y,color)) 

			{

				return true;

			}

		}

	}

	return false;

	

}

void FiveStoneProcess::getpoint1(int &x, int &y, int color,BOOL debug)

{
	//一共有6个算法,每个算法16%,即每个算法算完thinkpos都可以长16
	//如果return,那么一下置为100

	thinkpos = 0;

	POINT tempresult[225];

	int count=0;	

	int anticolor;//对方的color

	if (color==1) anticolor = 2;

	else anticolor = 1;

	x=0;y=0;

	if (has_five(1)||has_five(2)) {
		thinkpos = 100;
		return;//已经连成5子,什么都不做了
	}
	thinkpos+=16;
	int cur_time = GetCurrentTime();

	if (can_five(color,x,y)) 

	{

		common_info("计算机可以连成5子!",debug,cur_time);
		thinkpos = 100;
		return;//如果能连成5子,那么返回

	}

	ShowInfo("can_five1:"+passtime(cur_time));
	thinkpos+=16;
	if (can_five(anticolor,x,y)) 

	{

		common_info("人可以连成5子!",debug,cur_time);
		thinkpos = 100;
		return;//看对方能否连成5子

	}

	ShowInfo("can_five2:"+passtime(cur_time));
	thinkpos+=16;
	if (has_alive(color,count,tempresult))

	{

		//存在活子,直接输出活子(应从结果集中random选取)

		int tempi = random(0,count-1);

		x = tempresult[tempi].x;

		y = tempresult[tempi].y;		

		common_info("计算机找到一阶活子!",debug,cur_time);
		thinkpos = 100;
		return;

	}

	ShowInfo("has_alive:"+passtime(cur_time));
	thinkpos+=16;
	if (has_alive(anticolor,count,tempresult))

	{

		//看对方是否存在活子

		int tempi = random(0,count-1);

		x = tempresult[tempi].x;

		y = tempresult[tempi].y;

		common_info("找到人的一阶活子!",debug,cur_time);
		thinkpos = 100;
		return;

	}

	ShowInfo("has_alive2:"+passtime(cur_time));
	thinkpos+=16;
	getclose_small(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::getpoint2(int &x, int &y, int color,BOOL debug)

{

	//一共有10个算法,每个算法10%,即每个算法算完thinkpos都可以长10
	//如果return,那么一下置为100
	
	thinkpos = 0;

	//在grade3的基础上,再减少一些功能,比如,将qianmodel算法全部去掉

	//采用随机算法

	POINT tempresult[225];

	int count=0;	

	int anticolor;//对方的color

	if (color==1) anticolor = 2;

	else anticolor = 1;

	x=0;y=0;

	if (has_five(1)||has_five(2)) 
	{
		thinkpos = 100;
		return;//已经连成5子,什么都不做了
	}
	thinkpos+=10;

	int cur_time = GetCurrentTime();

	if (can_five(color,x,y)) 

	{

		common_info("计算机可以连成5子!",debug,cur_time);
		thinkpos = 100;
		return;//如果能连成5子,那么返回

	}

	ShowInfo("can_five1:"+passtime(cur_time));
	thinkpos+=10;
	if (can_five(anticolor,x,y)) 

	{

		common_info("人可以连成5子!",debug,cur_time);
		thinkpos = 100;
		return;//看对方能否连成5子

	}

	ShowInfo("can_five2:"+passtime(cur_time));
	thinkpos+=10;
	if (has_alive(color,count,tempresult))

	{

		//存在活子,直接输出活子(应从结果集中random选取)

		int tempi = random(0,count-1);
		
		x = tempresult[tempi].x;
		
		y = tempresult[tempi].y;

		common_info("计算机找到一阶活子!",debug,cur_time);
		thinkpos = 100;
		return;

	}

	ShowInfo("has_alive:"+passtime(cur_time));
	thinkpos+=10;
	if (has_twolevel_four(color,count,tempresult))

	{

		//存在一个存在四子的二阶活子

		int tempi = random(0,count-1);
		
		x = tempresult[tempi].x;
		
		y = tempresult[tempi].y;

		common_info("计算机找到强二阶活子!",debug,cur_time);
		thinkpos = 100;
		return;

	}

	ShowInfo("has_twolevel_four:"+passtime(cur_time));
	thinkpos+=10;
	//1_____________________________________

	if (has_alive(anticolor,count,tempresult))

	{

		//看对方是否存在活子

		int tempi = random(0,count-1);
		
		x = tempresult[tempi].x;
		
		y = tempresult[tempi].y;

		common_info("找到人的一阶活子!",debug,cur_time);
		thinkpos = 100;
		return;

	}

	ShowInfo("has_alive:"+passtime(cur_time));	
	thinkpos+=10;
	//2_____________________________________

	if (has_twolevel_four(anticolor,count,tempresult))

	{

		//存在一个存在四子的二阶活子

		int tempi = random(0,count-1);
		
		x = tempresult[tempi].x;
		
		y = tempresult[tempi].y;

		common_info("找到人的强二阶活子!",debug,cur_time);
		thinkpos = 100;
		return;

	}

	ShowInfo("has_twolevel_four:"+passtime(cur_time));	
	thinkpos+=10;
	//____________________________________________

	//不存在一阶活子,考察是否存在二阶活子

	if (has_twolevel_pure(color,count,tempresult))

	{

		//存在二阶活子,直接输出二阶活子(应从结果集中random选取)

		int tempi = random(0,count-1);
		
		x = tempresult[tempi].x;
		
		y = tempresult[tempi].y;

		common_info("计算机找到二阶活子!",debug,cur_time);
		thinkpos = 100;
		return;

	}

	ShowInfo("has_twolevel:"+passtime(cur_time));
	thinkpos+=10;
	//3___________________________

	if (has_twolevel(anticolor,count,tempresult))

	{

		//看对方是否存在二阶活子

		int tempi = random(0,count-1);
		
		x = tempresult[tempi].x;
		
		y = tempresult[tempi].y;

		common_info("找到人的二阶活子!",debug,cur_time);
		thinkpos = 100;
		return;

	}	

	ShowInfo("has_twolevel:"+passtime(cur_time));	
	thinkpos+=10;
	getclose_small(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::getpoint3(int &x, int &y, int color,BOOL debug)

{

	//一共有12个算法,每个算法8%,即每个算法算完thinkpos都可以长8
	//如果return,那么一下置为100
	
	thinkpos = 0;
	//认为这时候还不能看出来二阶牵制子,所以所有与二阶牵制子相关的函数都去掉了

	//也不使用make和defent算法

	//同时只能辨别纯牵制子匹配,即如果你有掺杂牵制子匹配,那么就可胜利

	POINT tempresult[225];

	int count=0;	

	int anticolor;//对方的color

	if (color==1) anticolor = 2;

	else anticolor = 1;

	x=0;y=0;

	if (has_five(1)||has_five(2)) 
	{
		thinkpos = 100;
		return;//已经连成5子,什么都不做了
	}
	thinkpos += 8;
	int cur_time = GetCurrentTime();

	if (can_five(color,x,y)) 

	{

		common_info("计算机可以连成5子!",debug,cur_time);
		thinkpos = 100;
		return;//如果能连成5子,那么返回

	}

	ShowInfo("can_five1:"+passtime(cur_time));
	thinkpos += 8;
	if (can_five(anticolor,x,y)) 

	{

		common_info("人可以连成5子!",debug,cur_time);
		thinkpos = 100;
		return;//看对方能否连成5子

	}

	ShowInfo("can_five2:"+passtime(cur_time));
	thinkpos += 8;
	if (has_alive(color,count,tempresult))

	{

		//存在活子,直接输出活子(应从结果集中random选取)

		selectqianmodel3(color,x,y,tempresult,count);		

		common_info("计算机找到一阶活子!",debug,cur_time);
		thinkpos = 100;
		return;

	}

	ShowInfo("has_alive:"+passtime(cur_time));
	thinkpos += 8;
	if (has_twolevel_four(color,count,tempresult))

	{

		//存在一个存在四子的二阶活子

		selectqianmodel3(color,x,y,tempresult,count);

		common_info("计算机找到强二阶活子!",debug,cur_time);
		thinkpos = 100;
		return;

	}

	ShowInfo("has_twolevel_four:"+passtime(cur_time));
	thinkpos += 8;
	//1_____________________________________

	if (has_alive(anticolor,count,tempresult))

	{

		//看对方是否存在活子

		selectqianmodel3(color,x,y,tempresult,count);

		common_info("找到人的一阶活子!",debug,cur_time);
		thinkpos = 100;
		return;

	}

	ShowInfo("has_alive:"+passtime(cur_time));	
	thinkpos += 8;
	//2_____________________________________

	if (has_twolevel_four(anticolor,count,tempresult))

	{

		//存在一个存在四子的二阶活子

		selectqianmodel3(color,x,y,tempresult,count);

		common_info("找到人的强二阶活子!",debug,cur_time);
		thinkpos = 100;
		return;

	}

	ShowInfo("has_twolevel_four:"+passtime(cur_time));	
	thinkpos += 8;
	//____________________________________________

	//不存在一阶活子,考察是否存在二阶活子

	if (has_twolevel_pure(color,count,tempresult))

	{

		//存在二阶活子,直接输出二阶活子(应从结果集中random选取)

		selectqianmodel3(color,x,y,tempresult,count);

		common_info("计算机找到二阶活子!",debug,cur_time);
		thinkpos = 100;
		return;

	}

	ShowInfo("has_twolevel:"+passtime(cur_time));
	thinkpos += 8;
	if (has_qianmodel(color,count,tempresult))

	{

		selectqianmodel3(color,x,y,tempresult,count);

		common_info("计算机三个牵制子匹配!",debug,cur_time);
		thinkpos = 100;
		return;

	}

	ShowInfo("has_qianmodel:"+passtime(cur_time));
	thinkpos += 8;
	//3___________________________

	if (has_twolevel(anticolor,count,tempresult))

	{

		//看对方是否存在二阶活子

		selectqianmodel3(color,x,y,tempresult,count);

		common_info("找到人的二阶活子!",debug,cur_time);
		thinkpos = 100;
		return;	

	}	

	ShowInfo("has_twolevel:"+passtime(cur_time));	
	thinkpos += 8;
	//4_________________________________

	if (has_qianmodel(anticolor,count,tempresult))

	{

		selectqianmodel3(color,x,y,tempresult,count);

		common_info("人三个牵制子匹配!",debug,cur_time);
		thinkpos = 100;
		return;

	}

	ShowInfo("has_qianmodel2:"+passtime(cur_time));
	thinkpos += 8;
	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::getpoint4(int &x, int &y, int color,BOOL debug)

{
	//一共有26个算法,每个算法4%,即每个算法算完thinkpos都可以长4
	//如果return,那么一下置为100
	
	thinkpos = 0;

	POINT tempresult[225];

	int count=0;	

	int anticolor;//对方的color

	if (color==1) anticolor = 2;

	else anticolor = 1;

	x=0;y=0;

	if (has_five(1)||has_five(2)) 
	{
		thinkpos = 100;
		return;//已经连成5子,什么都不做了
	}
	thinkpos += 4;
	int cur_time = GetCurrentTime();

	if (can_five(color,x,y)) 

	{

		common_info("计算机可以连成5子!",debug,cur_time);
		thinkpos = 100;
		return;//如果能连成5子,那么返回

	}

	ShowInfo("can_five1:"+passtime(cur_time));
	thinkpos += 4;
	if (can_five(anticolor,x,y)) 

	{

		common_info("人可以连成5子!",debug,cur_time);

⌨️ 快捷键说明

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