Page 3 of 3

Re: Bug in my engine

Posted: Mon Dec 23, 2019 1:56 pm
by JimmyRustles
Guenther, if you do more tests with Raven, could you please use the 0.70 release which I've just released.

https://github.com/sgriffin53/raven/releases/tag/0.70

The bugfix version I gave you has a bug with illegal PVs, this should be fixed in 0.70. I'm pretty sure both of these bugs are fixed now which is why I released 0.70 but let me know if you do find any problems. Thanks.

Re: Bug in my engine

Posted: Mon Dec 23, 2019 5:24 pm
by elcabesa
You solved the bug by not saving the mate scores in hash tables. Looking at your code I saw that you managed TT values in a wrong way in your code. I don't know if it's the real bug, or if there are some other bugs in the code.

mate score are relative to ply ( mate in 11 ply from here, so when you save and retrieve scores for mate positions you have to transform them from mate values from root position, to mate score from this ply. in Vajolet I use those to functions:

Code: Select all


// value_to_tt() adjusts a mate score from "plies to mate from the root" to
	// "plies to mate from the current position". Non-mate scores are unchanged.
	// The function is called before storing a value to the transposition table.
	static Score scoreToTT(Score v, int ply)
	{
		assert(v<=SCORE_MATE);
		assert(v>=SCORE_MATED);
		assert(ply>=0);
		assert(v+ply<=SCORE_MATE);
		assert(v-ply>=SCORE_MATED);
		assert(v != SCORE_NONE);
		return  v >= SCORE_MATE_IN_MAX_PLY  ? v + ply
				: v <= SCORE_MATED_IN_MAX_PLY ? v - ply : v;
	}


	// value_from_tt() is the inverse of value_to_tt(): It adjusts a mate score
	// from the transposition table (where refers to the plies to mate/be mated
	// from current position) to "plies to mate/be mated from the root".
	static Score scoreFromTT(Score v, int ply)
	{

		assert(ply>=0);
		assert(v-ply<SCORE_MATE || v == SCORE_NONE);
		assert(v+ply>SCORE_MATED);
		assert(v>=SCORE_MATED);
		assert(v<=SCORE_MATE || v == SCORE_NONE);
		return  v == SCORE_NONE ? SCORE_NONE
				: v >= SCORE_MATE_IN_MAX_PLY  ? v - ply
				: v <= SCORE_MATED_IN_MAX_PLY ? v + ply : v;
	}

you can find similar code in stockfish too, or in any strong engine. I don't know if this could solve all your problems with mate endgames :)

Re: Bug in my engine

Posted: Mon Dec 23, 2019 6:03 pm
by JimmyRustles
I've got mate_in() and mated_in() functions which change the mate score based on ply. It should be the same way that Stockfish does it.
elcabesa wrote: Mon Dec 23, 2019 5:24 pm You solved the bug by not saving the mate scores in hash tables. Looking at your code I saw that you managed TT values in a wrong way in your code. I don't know if it's the real bug, or if there are some other bugs in the code.

mate score are relative to ply ( mate in 11 ply from here, so when you save and retrieve scores for mate positions you have to transform them from mate values from root position, to mate score from this ply. in Vajolet I use those to functions:

Code: Select all


// value_to_tt() adjusts a mate score from "plies to mate from the root" to
	// "plies to mate from the current position". Non-mate scores are unchanged.
	// The function is called before storing a value to the transposition table.
	static Score scoreToTT(Score v, int ply)
	{
		assert(v<=SCORE_MATE);
		assert(v>=SCORE_MATED);
		assert(ply>=0);
		assert(v+ply<=SCORE_MATE);
		assert(v-ply>=SCORE_MATED);
		assert(v != SCORE_NONE);
		return  v >= SCORE_MATE_IN_MAX_PLY  ? v + ply
				: v <= SCORE_MATED_IN_MAX_PLY ? v - ply : v;
	}


	// value_from_tt() is the inverse of value_to_tt(): It adjusts a mate score
	// from the transposition table (where refers to the plies to mate/be mated
	// from current position) to "plies to mate/be mated from the root".
	static Score scoreFromTT(Score v, int ply)
	{

		assert(ply>=0);
		assert(v-ply<SCORE_MATE || v == SCORE_NONE);
		assert(v+ply>SCORE_MATED);
		assert(v>=SCORE_MATED);
		assert(v<=SCORE_MATE || v == SCORE_NONE);
		return  v == SCORE_NONE ? SCORE_NONE
				: v >= SCORE_MATE_IN_MAX_PLY  ? v - ply
				: v <= SCORE_MATED_IN_MAX_PLY ? v + ply : v;
	}

you can find similar code in stockfish too, or in any strong engine. I don't know if this could solve all your problems with mate endgames :)

Re: Bug in my engine

Posted: Mon Dec 23, 2019 6:18 pm
by elcabesa
no, change mate score when saving and retrieving from TT. look at stockfish code :)

line 1375 of search.cpp, take a look at value_from_tt

Code: Select all

posKey = pos.key();
    tte = TT.probe(posKey, ttHit);
**************    ttValue = ttHit ? value_from_tt(tte->value(), ss->ply, pos.rule50_count()) : VALUE_NONE;********
    ttMove = ttHit ? tte->move() : MOVE_NONE;
    pvHit = ttHit && tte->is_pv();


Re: Bug in my engine

Posted: Mon Dec 23, 2019 6:56 pm
by JimmyRustles
Ok, thanks. I'll try that at some point. Right now it seems to be okay just not storing the TT mate scores. I'm sure I'll get an improvement if I can readd made scores to the TT properly again.