Beispiel #1
0
int Kyokumen::Mate(Teban teban, int maxDepth, Te &te)
{
//	Te teBuf[MAX_TE_IN_KYOKUMEN * MAX_MATE_DEPTH];	// 深さ30程度までなら十分すぎる大きさ.
	Te teBuf[MAX_TE_IN_KYOKUMEN * MAX_DEPTH];	// 深さ30程度までなら十分すぎる大きさ.
	
	TsumeHash::Clear();
	
	TsumeVal *p = TsumeHash::Find(m_KyokumenHashVal, m_HandHashVal, m_Hand+teban);
	if (p != nullptr) {
		if (p->mate == 1) {
			te = p->te;
		}
//#if defined(DEBUG_PRINT)
//	printf("Mate(0x%02x, %d, 0x%02x) return[1] [%d]\n", teban, maxDepth, te.GetKoma(), p->mate);
//#endif // defined(DEBUG_PRINT).
		return p->mate;
	}
	
	int ret = 0;
	for (int i=1; i <= maxDepth; i+=2) {
		ret = CheckMate(teban, 0, i, teBuf, te);
		if (ret != 0) {
			break;
		}
	}
	//  0:不明.
	//  1:詰んだ.
	// -1:不詰み.
//#if defined(DEBUG_PRINT)
//	printf("Mate(0x%02x, %d, 0x%02x) return[2] [%d]\n", teban, maxDepth, te.GetKoma(), ret);
//#endif // defined(DEBUG_PRINT).
	return ret;
}
Beispiel #2
0
//heuristicX's goal is to get a score as close to 0 as possible
int Heuristics::heuristicX(LegalMoves moves, CurrentBoard board){

	//get initial score from escape routes
	hScore = EscapeRoutesForY(moves);

	//check if Y is currently in checkmate or stalemate
	if (hScore == 0) {
		if (CheckMate(board, moves)) {
			return hScore; //Checkmate can be reached, end now
		}
		else {
			hScore += 5; //Avoid stalemate if possible
		} 
	}
	hScore = hScore + AvoidRookTaken(moves, board);
	hScore = hScore + MoveYToEdge(moves, board);

	return hScore;
}