Пример #1
0
double AiPlayer::alphaBeta(Board nodeBoard, int depth, double alpha, double beta, bool maximising) {
	if (depth == 0 || nodeBoard.hasWinner()) {
		return getStaticValue(nodeBoard)/(maxDepth_ - depth + 1);
	}
	else if (maximising) {
		double staticValue = alpha;
		int filledColumns = 0;

		for (int column = 0; column < nodeBoard.getWidth(); column++) {
			if (nodeBoard.isValidMove(column)) {
				Board childNodeBoard(nodeBoard);
				childNodeBoard.placeToken(column, false);

				staticValue = std::max(staticValue, alphaBeta(childNodeBoard, depth - 1, alpha, beta, false));

				alpha = std::max(alpha, staticValue);
				if (beta <= alpha) break;
			}
			else filledColumns += 1;
		}

		return filledColumns == 7 ? getStaticValue(nodeBoard) / (maxDepth_ - depth + 1) : staticValue;
	}
	else {
		double staticValue = beta;
		int filledColumns = 0;

		for (int column = 0; column < nodeBoard.getWidth(); column++) {
			if (nodeBoard.isValidMove(column)) {
				Board childNodeBoard(nodeBoard);
				childNodeBoard.placeToken(column, true);

				staticValue = std::min(staticValue, alphaBeta(childNodeBoard, depth - 1, alpha, beta, true));

				beta = std::min(beta, staticValue);
				if (beta <= alpha) break;
			}
			else filledColumns += 1;
		}

		return filledColumns == 7 ? getStaticValue(nodeBoard) / (maxDepth_ - depth + 1) : staticValue;
	}
}
Пример #2
0
QVariant JClass::getStaticValue(const char* name, JSignature sig) const
{
	QByteArray ba = sig.str().toLatin1();
	return getStaticValue(name, ba.data());
}