src/Hexxagon/HexxagonAIPlayer.cpp
/*
 * analyse given stone and return best possible move
 * @param iIndex offset of the current stone in vector
 * @param vecStones vector of HexxagonStone*
 * @return HexxagonMove with the best rating
 * ===================================================================== */
analyse given stone and return best possible move
@param iIndex offset of the current stone in vector
@param vecStones vector of HexxagonStone
@return HexxagonMove with the best rating
analyse given stone and return best possible move @param iIndex offset of the current stone in vector @param vecStones vector of HexxagonStone @return HexxagonMove with the best rating
HexxagonMove HexxagonAIPlayer::analyze(int iIndex, vector<HexxagonStone*> vecStones)
{
	HexxagonMove ratedMove = HexxagonMove(vecStones[iIndex]->getColor(),iIndex,-1,-1,-1);
	for (int x=0; x<HEX_NUM_STONE_NEIGHBOURS+HEX_NUM_STONE_DISTANT_NEIGHBOURS;x++) {
		int iNeighbour = vecStones[iIndex]->getNeighbour(x);
		if (iNeighbour >= 0 && vecStones[iNeighbour]->getColor()==0) {
			int iRate = (x<HEX_NUM_STONE_NEIGHBOURS)?2:1;
			for (int y=0; y<HEX_NUM_STONE_NEIGHBOURS;y++) {
				int iSubNeighbour = vecStones[iNeighbour]->getNeighbour(y);
				if ( iSubNeighbour>=0
					&& (vecStones[iSubNeighbour]->getColor() != iCurrentPlayer)
					&& (vecStones[iSubNeighbour]->getColor() != 0))
					iRate++;
			}
			if ( iRate > ratedMove.rate ) {
				ratedMove.to			 = iNeighbour;
				ratedMove.rate		 = iRate;
				ratedMove.moveType = (x<HEX_NUM_STONE_NEIGHBOURS)?2:1;
			}
		}
	}
	return ratedMove;
}
HexxagonMove HexxagonAIPlayer :: analyze ( int iIndex , vector < HexxagonStone * > vecStones ) { HexxagonMove ratedMove = HexxagonMove ( vecStones [ iIndex ] -> getColor ( ) , iIndex , -1 , -1 , -1 ) ; for ( int x = 0 ; x < HEX_NUM_STONE_NEIGHBOURS + HEX_NUM_STONE_DISTANT_NEIGHBOURS ; x ++ ) { int iNeighbour = vecStones [ iIndex ] -> getNeighbour ( x ) ; if ( iNeighbour >= 0 && vecStones [ iNeighbour ] -> getColor ( ) == 0 ) { int iRate = ( x < HEX_NUM_STONE_NEIGHBOURS ) ? 2 : 1 ; for ( int y = 0 ; y < HEX_NUM_STONE_NEIGHBOURS ; y ++ ) { int iSubNeighbour = vecStones [ iNeighbour ] -> getNeighbour ( y ) ; if ( iSubNeighbour >= 0 && ( vecStones [ iSubNeighbour ] -> getColor ( ) != iCurrentPlayer ) && ( vecStones [ iSubNeighbour ] -> getColor ( ) != 0 ) ) iRate ++ ; } if ( iRate > ratedMove . rate ) { ratedMove . to = iNeighbour ; ratedMove . rate = iRate ; ratedMove . moveType = ( x < HEX_NUM_STONE_NEIGHBOURS ) ? 2 : 1 ; } } } return ratedMove ; }
analyse given stone and return best possible move
 @param iIndex offset of the current stone in vector
 @param vecStones vector of HexxagonStone
 @return HexxagonMove with the best rating
analyse given stone and return best possible move @param iIndex offset of the current stone in vector @param vecStones vector of HexxagonStone @return HexxagonMove with the best rating
// create new move and set to color and given index
 // check all neighbouring stones
 // get neighbour from current stone
 // if we have a neighbour and it is an empty field
 // rate depending on move type
 // check close neighbours of neighbours
 // get close neighbour if it is valid
 // increment rate if field is sourrounded by enemy stones
 // compare rate with rate of last best rated move
 // copy rest of move attributes
 // pass best possible move back
