当前位置: 首页>>代码示例>>C++>>正文


C++ board::checkGameState方法代码示例

本文整理汇总了C++中board::checkGameState方法的典型用法代码示例。如果您正苦于以下问题:C++ board::checkGameState方法的具体用法?C++ board::checkGameState怎么用?C++ board::checkGameState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在board的用法示例。


在下文中一共展示了board::checkGameState方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: mini

result player::mini( pos& p , board& b )
{
	if(b.checkGameState()==WIN)
		return WIN;
	else
	{
		result finalResult=WIN;
			/*	This Function will simulate Human moves and try to reduce the score
				Human will go for the move by which he can win*/
		for ( int i=0  ;i<3 ; i++)
		{
			for ( int j=0 ; j<3 ; j++)
			{
				board tempBoard=b; 
				if(tempBoard.mMatrix[i][j]==NONE)
				{
					tempBoard.mMatrix[i][j]=CROSS;
					
					result res=max(p ,tempBoard);
					if(res<finalResult)
						{
							finalResult=res; 

						}
				}
			}
		}
		return finalResult;
	}
}
开发者ID:anshulbahukhandi,项目名称:TicTacToe-Artificial-Intelligence,代码行数:30,代码来源:player.cpp

示例2: max

result  player::max(pos& p , board& b)
{
	if(b.checkGameState()==LOSS)
		{	
		return LOSS;
		}
	/* This function will play KNOT or AI's moves */
	if(b.getLevel()==9)
		{
			return DRAW;
		}
	else 
	{
		/* if found winning move in next step . Prune everything else
           It stops the process of finding the suitable move as soon 
           as the winning move is found.
		*/ 
		bool flag=false;
		/* Saves the current best coordinate/Box in the current state*/
		int *coord=new int[2];

		result finalResult = LOSS;
		for ( int i=0 ; i<3 ; i++)
			{
				for ( int j=0 ; j<3 ; j++)
				{	
					if(b.mMatrix[i][j]==NONE)
					{

						board tempBoard=b;
						tempBoard.mMatrix[i][j]=KNOT;
						result res=mini(p ,tempBoard);
						if(res>=finalResult)
						{
							coord[0]=i;
							coord[1]=j;
							finalResult=res;
							
							if(res==WIN)
							{
								flag=true;
								break;
							}
						}
					}
				}
				if(flag==true)
					break;
			}

		p.r=coord[0];
		p.c=coord[1];	

	return finalResult;
	}
}
开发者ID:anshulbahukhandi,项目名称:TicTacToe-Artificial-Intelligence,代码行数:56,代码来源:player.cpp


注:本文中的board::checkGameState方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。