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


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

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


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

示例1: mainLoop

int Search::mainLoop( MoveList<RootEntry>& rootMoves, std::atomic<bool>& abortCondition) {
	int targetCutoff = rootMoves.size;
	for (int depth = 0; depth <= Depth::MAX_DEPTH; depth++) {

		// reset rootMove values
		for (int i = 0; i < rootMoves.size; i++) {
			rootMoves.entries[i]->value = -Value::INFINITE;
		}

		int alpha = -Value::INFINITE;
		int beta = Value::INFINITE;

		for (int i = 0; i < rootMoves.size; i++) {
			int move = rootMoves.entries[i]->move;
			position.makeMove(move);
			int value = -search(depth, -beta, -alpha, 1, abortCondition);
			//protocol.sendBestMove(move, Move::NOMOVE);
			position.undoMove(move);

			// If aborted we must not update the value.
			stopConditions();
			if (abort || abortCondition) {
				break;
			}

			rootMoves.entries[i]->value = value;
			rootMoves.entries[i]->pondermove = bestResponse;

			if (value > alpha) {
				alpha = value;
			}
		}
		if (abort || abortCondition) {
			break;
		}

		rootMoves.sort();

		/*
		for (int i = 0; i < rootMoves.size; i++) {
			auto rootMoveEntry = rootMoves.entries[i];
			std::cout << "move: " << MartonChess::fromMove(rootMoveEntry->move) << "score: " << rootMoveEntry->value << std::endl;
		}
*/

		targetCutoff = 0;
		int targetCutoffValue = 
			(int) (rootMoves.entries[rootMoves.size - 1]->value
					+ (rootMoves.entries[0]->value - rootMoves.entries[rootMoves.size - 1]->value)
					* cutoffRatio);
		while (rootMoves.entries[targetCutoff]->value >= targetCutoffValue) {
			targetCutoff++;
			if (targetCutoff >= rootMoves.size)
				break;
		}
	}

	return targetCutoff;
}
开发者ID:Hava842,项目名称:martonchess,代码行数:59,代码来源:Search.cpp

示例2: readGame


//.........这里部分代码省略.........
					<< "          <tr>\n"
					<< "            <td colspan=2 align=left><font face=Arial size=1>"
					<< cntmove << ".&nbsp;"
					<< Piece::getChar(piece1) << Piece::getChar(piece2)
					<< "</font></td>\n"
					<< "          </tr>\n"
					<< "          <tr>\n"
					<< "            <td align=right><font face=Arial size=1>&nbsp;</font></td>\n"
					<< "            <td align=right><font face=Arial size=1>vx</font></td>\n";

		for (int i=level; i>=preview; i--)
			wHtml << "            <td align=right><font face=Arial size=1>&nbsp;&nbsp;Level&nbsp;"
						<< i << "</font></td>\n";
					
		wHtml << "          </tr>\n";

		while (length-- > 0)
		{
			int v = rGameFile.readByte();				// # V
			int x = rGameFile.readShort();			// # X
			int y = rGameFile.readShort();			// # Y

			Move *move = moveList->getMove();
			moveList->add(v, x, y);

			for (int i=preview; i<=level; i++)	// Equity (e.g):
			{
				double equity = rGameFile.readFloat();		// L2, L3, L4

				move->setEquity(i, equity);
			}
		}

		moveList->sort();

		int movecnt = 0;
		Move *move = moveList->getFirstMove();

		int first[MAX_LEVELS+1];
		float bestEquity[MAX_LEVELS+1];

		if (move != 0)
		{
			for (int i=preview; i<=level; i++)
			{
				first[i] = 1;
				bestEquity[i] = (float)moveList->getBestEquity(i);
			}
		}

		// 2. Equity list list
		while (move != 0)
		{
			movecnt++;

			if (movecnt > height/2)
				break;

			int v = move->getV();
			int x = move->getX();
			int y = move->getY();

			wHtml << "          <tr>\n"
				    << "            <td align=right><font face=Arial size=1>"
						<< movecnt << ".</font></td>\n"
						<< "            <td align=right><font face=Arial size=1>"
开发者ID:tengstrand,项目名称:tetrisanalyzer,代码行数:67,代码来源:Game.cpp


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