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


C++ MoveList::isLegal方法代码示例

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


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

示例1: Eval

/*this function returns a board score for the given board for the player
  indicated.  well.. actually it just randomly generates a number 
  and returns that right now.  You will need to make it better.*/
int Cathy::Eval(int board[][NUMSQUARES],int player,  MoveList p1, MoveList p2){
  /*int p1score;
  int p2score;
  int score;*/
	int result = 0;

	int tempBoard[NUMSQUARES][NUMSQUARES] = {0};
	copyBoard(tempBoard, board);
	
	int potentialMob = 0;
	int corner = 0;

	// First, we begin with taking mobility of a given player into consideration.
	// It will be a starting point for determining how good the situation is right now.
	// It is calculated from the difference between a given player and its opponent.

	// Pottential mobility should be found out. Potential mobility is a number of
	// empty squares that are adjacent to opponents pieces. 


	if(player == 1){
		

		for(int i = 0;i < NUMSQUARES; i++){             //go through each row
			for(int j = 0; j < NUMSQUARES; j++){        //go through every column in a row
				
				if( tempBoard[i][j] == -1 ){            //if field is occupied by an opponent



					for(int k = -1;  k!= 1; k++){       //loop for local row
						if( i == 0 ) k = 0;             //if row is 0, then don't check the -1 row
						for(int l = -1; l!= 1; l++){    //loop for local column
							if( j == 0 ) l = 0;         //if column is 0, then don't check for -1 column

							if(tempBoard[i+k][j+l] == 0){
								potentialMob++;
								tempBoard[i+l][j+l] = 3;
							}

							if( j == NUMSQUARES && l == 0) l++; //if column is 8, then don't check for +1 column
						}
						if( i == NUMSQUARES && k == 0) k++;  // if row is 8, then don't check +1 row
					}
				}
			}
		}

		if(p1.isLegal(0,0) != -1 || p1.isLegal(0,NUMSQUARES) != -1 ||
		   p1.isLegal(NUMSQUARES,0) != -1 || p1.isLegal(NUMSQUARES,NUMSQUARES) != -1)
		   corner++;

		result = p1.numMoves() - p2.numMoves() + potentialMob + corner;
	}
	else{
		
		for(int i = 0;i < NUMSQUARES; i++){             //go through each row
			for(int j = 0; j < NUMSQUARES; j++){        //go through every column in a row
				
				if( tempBoard[i][j] == -1 ){            //if field is occupied by an opponent



					for(int k = -1;  k!= 1; k++){       //loop for local row
						if( i == 0 ) k = 0;             //if row is 0, then don't check the -1 row
						for(int l = -1; l!= 1; l++){    //loop for local column
							if( j == 0 ) l = 0;         //if column is 0, then don't check for -1 column

							if(tempBoard[i+k][j+l] == 0){
								potentialMob++;
								tempBoard[i+l][j+l] = 3;
							}

							if( j == NUMSQUARES && l == 0) l++; //if column is 8, then don't check for +1 column
						}
						if( i == NUMSQUARES && k == 0) k++;  // if row is 8, then don't check +1 row
					}
				}
			}
		}

		if(p2.isLegal(0,0) != -1 || p2.isLegal(0,NUMSQUARES) != -1 ||
		   p2.isLegal(NUMSQUARES,0) != -1 || p2.isLegal(NUMSQUARES,NUMSQUARES) != -1)
		   corner++;

		result = p2.numMoves() - p1.numMoves() + potentialMob + corner;
	}



  // mobility 
  /*getScores(board,p1score,p2score);
  if(player==1){
	  score=p1score-p2score;
  }
  else{
	  score=p2score-p1score;
//.........这里部分代码省略.........
开发者ID:Arcanfel,项目名称:OthelloAI,代码行数:101,代码来源:ashinkevich.cpp


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