Bug in my engine

Discussion of chess software programming and technical issues.

Moderators: Harvey Williamson, Dann Corbit, hgm

Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
User avatar
JimmyRustles
Posts: 22
Joined: Sun May 05, 2019 9:24 pm
Full name: Steven Griffin

Re: Bug in my engine

Post by JimmyRustles » Mon Dec 23, 2019 12:56 pm

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.

elcabesa
Posts: 848
Joined: Sun May 23, 2010 11:32 am
Contact:

Re: Bug in my engine

Post by elcabesa » Mon Dec 23, 2019 4: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 :)

User avatar
JimmyRustles
Posts: 22
Joined: Sun May 05, 2019 9:24 pm
Full name: Steven Griffin

Re: Bug in my engine

Post by JimmyRustles » Mon Dec 23, 2019 5:03 pm

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 4: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 :)

elcabesa
Posts: 848
Joined: Sun May 23, 2010 11:32 am
Contact:

Re: Bug in my engine

Post by elcabesa » Mon Dec 23, 2019 5:18 pm

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();


User avatar
JimmyRustles
Posts: 22
Joined: Sun May 05, 2019 9:24 pm
Full name: Steven Griffin

Re: Bug in my engine

Post by JimmyRustles » Mon Dec 23, 2019 5:56 pm

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.

Post Reply