Beispiel #1
0
void posDraw(const Pos *pos) {
	// Header.
	uciWrite("Position:\n");

	// Board with pieces.
	int file, rank;
	for(rank=Rank8;rank>=Rank1;--rank) {
		uciWrite("%i|", (rank+8)-Rank8);
		for(file=FileA;file<=FileH;++file)
			uciWrite(" %c", pieceToChar(posGetPieceOnSq(pos, sqMake(file,rank))));
		uciWrite("\n");
	}
	uciWrite("   ----------------\n");
	uciWrite("  ");
	for(file=FileA;file<=FileH;++file)
		uciWrite(" %c", (file+'a')-FileA);
	uciWrite("\n");

	// Other information.
	uciWrite("STM: %s\n", colourToStr(posGetSTM(pos)));
	uciWrite("Castling rights: %s\n", posCastRightsToStr(posGetCastRights(pos)));
	if (pos->data->epSq!=SqInvalid)
		uciWrite("EP-sq: %c%c\n", fileToChar(sqFile(pos->data->epSq)), rankToChar(sqRank(pos->data->epSq)));
	else
		uciWrite("EP-sq: -\n");
	uciWrite("Half move number: %u\n", pos->data->halfMoveNumber);
	uciWrite("Full move number: %u\n", pos->fullMoveNumber);
	uciWrite("Base hash key: %016"PRIxKey"\n", posGetKey(pos));
	uciWrite("Pawn hash key: %016"PRIxKey"\n", posGetPawnKey(pos));
	uciWrite("Material hash key: %016"PRIxKey"\n", posGetMatKey(pos));
}
Beispiel #2
0
void ttWrite(const Pos *pos, Depth ply, Depth depth, Move move, Score score, Bound bound) {
	// Sanity checks.
	assert(depthIsValid(ply));
	assert(depthIsValid(depth));
	assert(moveIsValid(move) || move==MoveNone);
	assert(scoreIsValid(score));
	assert(bound!=BoundNone);

	uint64_t key=posGetKey(pos);

	// Grab cluster.
	HTableKey hTableKey=ttHTableKeyFromPos(pos);
	TTCluster *cluster=htableGrab(tt, hTableKey);

	// Find entry to overwrite.
	TTEntry *entry, *replace=cluster->entries;
	unsigned int i, replaceScore=0; // Worst possible score.
	for(i=0,entry=cluster->entries;i<ttClusterSize;++i,++entry) {
		// If we find an exact match, simply reuse this entry.
		// We can also be certain that if this entry is unused, we will not find an
		// exact match in a later entry (otherwise said later entry would have
		// instead been written to this unused entry).
		if (ttEntryMatch(pos, entry) || ttEntryUnused(entry)) {
			// Set key (in case entry was previously unused).
			entry->keyUpper=(key>>48);

			// Update entry date (to reset age to 0).
			entry->date=searchGetDate();

			// Update move if we have one and it is from a deeper search (or no move already stored).
			if (!moveIsValid(entry->move) || (moveIsValid(move) && depth>=entry->depth))
				entry->move=move;

			// Update score, depth and bound if search was at least as deep as the entry depth.
			if (depth>=entry->depth) {
				entry->score=ttScoreIn(score, ply);
				entry->depth=depth;
				entry->bound=bound;
			}

			htableRelease(tt, hTableKey);
			return;
		}

		// Otherwise check if entry is better to use than replace.
		unsigned int entryScore=ttEntryFitness(searchDateToAge(entry->date), entry->depth, entry->bound==BoundExact);
		if (entryScore>replaceScore) {
			replace=entry;
			replaceScore=entryScore;
		}
	}
Beispiel #3
0
/// if ret == 0 task1 is equal to task2 else no
int compareTasks(Task *task1, Task *task2){
	int ret = 0;

	ret = taskIdListCompare(task1->myDeps, task2->myDeps);
	if (ret != 0) return 1;

	
	if (task1->dependsOnMe == NULL) {
		if (task2->dependsOnMe != NULL) {
			if (0 != taskIdListGetSize(task2->dependsOnMe)) {
				return -1;
			}
		}
	} else {
		if (task2->dependsOnMe == NULL) {
			if (0 != taskIdListGetSize(task1->dependsOnMe)) {
				return 1;
			}
		} else {
			ret = taskIdListCompare(task1->dependsOnMe, task2->dependsOnMe);
			if (ret != 0) return ret;
		}
	}

	if (task1->id != task2->id) {
		return 1;
	}

	if(task1->endedTasks != task2->endedTasks || task1->metaSize != task2->metaSize || task1->state != task2->state){
		return 1;
	}

	if(memcmp(task1->metadata, task2->metadata, task1->metaSize)) return 1;


	// Vereify if task2->children has 
	HashIntVoidIterator *it1 = createHashIntVoidIterator(task1->children, 0);
	PosHandlerIntVoid pos1 = hashIntVoidIteratorNext(it1, task1->children);
	while (pos1!=NULL) {
		Task *child1 = posGetValue(pos1);
		PosHandlerIntVoid pos2 = hashIntVoidGet(task2->children, posGetKey(pos1));
		Task *child2 = posGetValue(pos2);
		
		ret = compareTasks(child1, child2);
		if (ret != 0) return ret;
		
		pos1 = hashIntVoidIteratorNext(it1, task1->children);
	}
	
	HashIntVoidIterator *it2 = createHashIntVoidIterator(task2->children, 0);
	PosHandlerIntVoid pos2 = hashIntVoidIteratorNext(it2, task2->children);
	while (pos2!=NULL) {
		Task *child2 = posGetValue(pos2);
		pos1 = hashIntVoidGet(task1->children, posGetKey(pos2));
		Task *child1 = posGetValue(pos1);
		
		ret = compareTasks(child1, child2);
		if (ret != 0) return ret;
		
		pos2 = hashIntVoidIteratorNext(it2, task2->children);
	}
	return 0;
}