コード例 #1
0
ファイル: position.c プロジェクト: dsteuer/laska
int Position::evaluateTowers() const {
	int v = 0;

	// std::cerr << " #  tower  value" << std::endl;
	// std::cerr << "----------------" << std::endl;
	for (unsigned int b = bitb.bits[ turn]; b; b &= (b - 1)){
		unsigned int at = __builtin_ffs(b) - 1;
		// std::cerr << std::setw(2) << at << std::setw(7) << tower[at].toString() << std::setw(7) << tower[at].getValue() << std::endl;
		v += tower[at].getValue(); 
	}

	for (unsigned int b = bitb.bits[!turn]; b; b &= (b - 1)){
		unsigned int at = __builtin_ffs(b) - 1;
		// std::cerr << std::setw(2) << at << std::setw(7) << tower[at].toString() << std::setw(7) << -tower[at].getValue() << std::endl;
		v -= tower[at].getValue();
	}
	// std::cerr << "----------------" << std::endl;
	// std::cerr << "         " << std::setw(7) << v << std::endl;

	v += evaluateSquares();

	return(v);
}
コード例 #2
0
void bestMove(binaryTreePtr tree)
/* This procedure will determine the best move available
 * by using a minmax method to either compute the value (on a leaf)
 * or sending it one level up where will be decided if the minimum or the maximum value will be used
 * Pre-condition:none
 * Post-condition: the root of the tree now has the minmax value needed
*/
{
	infoPtr gameInfo,temp;
	treeNodePtr current;
	//retrieve the current node's info
	gameInfo = retrieveNodeElm(tree);

	//is this a leaf?
	if ((existNode(tree,TOLEFT)== -1) )
	{
		//then compute the value of this square
		gameInfo->eval = evaluateSquares(gameInfo);
	}else
	{
		//go down a level, to first node
		nextNode(tree, TOLEFT);
		//get the current node in tree
		current = getCurrentNode(tree);

		//get the info for this node
		temp = retrieveNodeElm(tree);

		//call this procedure again, this will send up a value
		bestMove(tree);

		//go back to first node on the level
		setCurrentNode(tree, current);
		//set the parent level's value to this node's
		gameInfo->eval = temp->eval;

		//is there a next node on this level?
		while (existNode(tree,TORIGHT) == 1)
		{
			//then go to the next node
			nextNode(tree, TORIGHT);

			//set this as the current node on this level
			current = getCurrentNode(tree);

			//get the info for this node
			temp = retrieveNodeElm(tree);

			//call this procedure again, this will send up a value
			bestMove(tree);

			//go back to node on this level we're working on
			setCurrentNode(tree, current);
			//who's turn was it last
			if (gameInfo->turn == COMPUTER)
			{
				//if temp->eval is smaller
				if (gameInfo->eval > temp->eval)
				{
					//this is the new minimum value
					gameInfo->eval = temp->eval;
				}
			}else
			{
				//if temp->eval is bigger
				if (gameInfo->eval < temp->eval)
				{
					//this is the new maximum value
					gameInfo->eval = temp->eval;
				}
			}
		}
	}
}