Beispiel #1
0
	bool operator()(move a, move b)
	{
		if (base.moveGains(a) > base.moveGains(b))
			return true;
		if (base.moveGains(a) < base.moveGains(b))
			return false;
		return b < a;
	}
Beispiel #2
0
	bool operator()(pair<int, move> a, pair<int, move> b)
	{
		if (a.first > b.first)
			return true;
		if (a.first < b.first)
			return false;
		if (base.moveGains(a.second) > base.moveGains(b.second))
			return true;
		if (base.moveGains(a.second) < base.moveGains(b.second))
			return false;
		return b.second < a.second;
	}
Beispiel #3
0
int quiesence(board b, int alpha, int beta, bool hasPass)
{
	if (b.inCheck().first || b.inCheck().second)
		return minimax(1, b, alpha, beta, 0);
	
	lookupResult res;
	bool haveHit = queryTable(b, res);
	
	int bestSoFar;
	if (hasPass)
	{
		alpha = max(b.eval(), alpha);
		if (alpha >= beta)
			return alpha;
		if (haveHit)
		{
			if (res.type == SCORE_LOWERBOUND)
			{
				if (res.evaluation >= beta)
					return -res.evaluation;
				else
					alpha = max(alpha, res.evaluation);
			}
			if (res.type == SCORE_UPPERBOUND)
			{
				if (res.evaluation <= alpha)
					return -alpha;
				else
					beta = min(beta, res.evaluation);
			}
			if (res.type == SCORE_EXACT)
				return -max(alpha, res.evaluation);
		}
	
		bestSoFar = alpha;
	}
	else
	{
		if (haveHit)
		{
			if (res.type == SCORE_LOWERBOUND)
			{
				if (res.evaluation >= beta)
					return -res.evaluation;
				else
					alpha = max(alpha, res.evaluation);
			}
			if (res.type == SCORE_UPPERBOUND)
			{
				if (res.evaluation <= alpha)
					return -res.evaluation;
				else
					beta = min(beta, res.evaluation);
			}
			if (res.type == SCORE_EXACT)
				return -res.evaluation;
		}
		b.flipToMove();
		bestSoFar = quiesence(b, -beta, -alpha, true);
		b.flipToMove();
	}
	
	vector<move> moves = b.genMoves();
	moveOrderer order(b);
	sort(moves.begin(), moves.end(), order);
	int besti = 0;
	for (int i=0; i<moves.size(); i++)
	{
		if (b.moveGains(moves[i]) < 300)
			break;
		board temp = b;
		temp.executeMove(moves[i]);
		int curScore = quiesence(temp, -beta, -max(alpha, bestSoFar), false);
		if (curScore > bestSoFar)
		{
			bestSoFar = curScore;
			besti = i;
		}
		if (bestSoFar >= beta)
			break;
	}
	
	putTable(b, 0, bestSoFar, moves[besti], alpha, beta);
	
	return -bestSoFar;
}