Problems with TT, sometimes makes blunder moves

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

tttony
Posts: 268
Joined: Sun Apr 24, 2011 12:33 am

Problems with TT, sometimes makes blunder moves

Post by tttony »

I've added TT to my engine that has vanilla alphabeta search and eval it's only PST from CPW (https://chessprogramming.wikispaces.com ... e%20Tables), very very basic

Now in the tests it's not winning games because makes blunder moves, like in this position:

[d] r3r1k1/B1p1qpp1/2b1p2p/1p1pP3/8/1P2P2P/P1P1QPP1/3RR1K1 w - - 1 19

In the pv switch to: Rd3 or Qd2 or Bd4

I think that the problem is obviously the TT here is the hash.c code: https://pastebin.com/ma77xzwj

I think that the problem is that always replace the entry, in the hash_entry it has an age member that I don't know how to implement the age, I have read engines source code but all of them has their own way, I was thinking in doing it like Bruce Moreland in GERBIL, with a int seq variable that increment each time it search
Dann Corbit
Posts: 12537
Joined: Wed Mar 08, 2006 8:57 pm
Location: Redmond, WA USA

Re: Problems with TT, sometimes makes blunder moves

Post by Dann Corbit »

What are your definitions for the missing header file?
I guess something like this:

Code: Select all


typedef struct hash_entry_s {
	uint64_t key;
	int32_t move;
	uint8_t depth;
	uint32_t flags;
	int32_t score;
	int16_t age;
} hash_entry_s;

typedef struct stats_struct
{
	unsigned hits;
	unsigned newEntry;
	unsigned overEntry;
} stats_struct;

typedef struct hash_s {
	hash_entry_s *entry;
	size_t size;
	stats_struct stats;
} hash_s;

typedef  unsigned char bool;

extern void  tt_init(struct hash_s *hash, unsigned int size);
extern void  tt_clear(struct hash_s *hash);
extern void  tt_save(uint64_t key, unsigned char ply, struct hash_s *hash, int score, int move, unsigned char depth, unsigned int flags, short age);
extern int  tt_move(uint64_t key, struct hash_s *hash);
extern void  tt_free(struct hash_s *hash);
having the exact definitions will make it much easier to understand your code.
Taking ideas is not a vice, it is a virtue. We have another word for this. It is called learning.
But sharing ideas is an even greater virtue. We have another word for this. It is called teaching.
tttony
Posts: 268
Joined: Sun Apr 24, 2011 12:33 am

Re: Problems with TT, sometimes makes blunder moves

Post by tttony »

You right, sorry for not posting all the info

Excelent! Your code was not a guess, it's almost the copy, here are the defs:

Code: Select all

#include <inttypes.h>
#include <stdbool.h>

//...

typedef struct &#123;
	uint32_t newEntry;
	uint32_t overEntry;
	uint32_t hits;
	uint32_t cuts;
&#125; hash_stats_s;

typedef struct &#123;
	uint64_t key;
	int32_t move;
	int32_t score;
	uint8_t depth;
	uint32_t flags;
	int16_t age;
	uint64_t nodes; // only for perft
&#125; hash_entry_s;

typedef struct &#123;
	hash_entry_s *entry;
	uint64_t size;
	hash_stats_s stats&#91;1&#93;;
&#125; hash_s;
I have all the prototype in a single header file, it's a mess, I should refactor the code in multiples header files
lauriet
Posts: 199
Joined: Sun Nov 03, 2013 9:32 am

Re: Problems with TT, sometimes makes blunder moves

Post by lauriet »

I had similar problems.

Make sure you test for a valid move before using it.
tttony
Posts: 268
Joined: Sun Apr 24, 2011 12:33 am

Re: Problems with TT, sometimes makes blunder moves

Post by tttony »

I did some tests checking if the move exists, right now I'm testing more games to see if that's the problem, do you check if the move is in the move lists?
lauriet
Posts: 199
Joined: Sun Nov 03, 2013 9:32 am

Re: Problems with TT, sometimes makes blunder moves

Post by lauriet »

I have a separate routine that checks for a legal move so I do something like:

If TTmoveAvailable AND ItsLegal then........
PK
Posts: 893
Joined: Mon Jan 15, 2007 11:23 am
Location: Warsza

Re: Problems with TT, sometimes makes blunder moves

Post by PK »

Another classic way to break transposition table is to save moves and scores when search is already timed-out.

If the error disappears when you run your engine in fixed depth mode, then this is the reason.
Henk
Posts: 7216
Joined: Mon May 27, 2013 10:31 am

Re: Problems with TT, sometimes makes blunder moves

Post by Henk »

If your engine assumes that information stored in TT cannot be fully trusted then there can never be a problem. Might be that this assumption costs ELO.
User avatar
hgm
Posts: 27787
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Problems with TT, sometimes makes blunder moves

Post by hgm »

It is best to test the TT on a simple position with very many transpositions. Like the KPK ending or Fine #70. If it doesn't work perfectly, it would almost certainly show up there. E.g. can you find the promotion in

[d]4k3/8/8/8/8/8/4P3/4K3 w

If not, let it print the relevant part of the tree and look where it goes wrong. I always put infra-structure in my engines to print debug info along a selected path, labeled with ply, depth (and possibly IID iteration depth), so that you know which node is printing. Most useful is to print move, score, bestScore immediately after UnMake, and the hash key at the point where you take a hash cutoff. Then you can see which move has the wrong score, add that to the print path, and zoom in on the error. This never fails, although it sometimes is tedious.

BTW, why 32 bits for flags? What flags can you possibly have? I never used more than 3: upper bound, lower bound and in check.
flok

Re: Problems with TT, sometimes makes blunder moves

Post by flok »

At what minimum search depth should it find the promotion? 11?

Because I think there then indeed may be something fishy with my program:

Code: Select all

14&#58;14&#58;31 folkert@belle&#58;~/Projects/QueenBee/tags/v0.9.1_2205/trunk trunk&#40;18&#41; 11s ‡ ./Embla -H 4096 -p initial_fen='4k3/8/8/8/8/8/4P3/4K3 w - - 0 0'
go
info depth 1 seldepth 1 score cp 155 time 1 nodes 7 pv e2e4
info depth 2 seldepth 2 score cp 148 time 1 nodes 25 pv e2e4 e8d7
info depth 3 seldepth 3 score cp 179 ebf 2.17 time 1 nodes 58 pv e2e4 e8d7 e4e5
info depth 4 seldepth 4 score cp 172 ebf 1.78 time 1 nodes 115 pv e2e4 e8d7 e4e5 d7e6
info depth 5 seldepth 6 score cp 155 ebf 2.35 time 1 nodes 297 pv e2e4 e8d7 e1d2 d7e6 d2d3
info depth 6 seldepth 6 score cp 152 ebf 2.28 time 2 nodes 594 pv e2e4 e8d7 e1d2 d7e6 d2d3 e6e5
info depth 7 seldepth 8 score cp 152 ebf 1.68 time 2 nodes 1106 pv e2e4 e8d7 e1d2 d7e6 d2d3 e6e5 d3e3
info depth 8 seldepth 8 score cp 155 ebf 1.61 time 4 nodes 1879 pv e2e4 e8d7 e1d2 d7e6 d2d3 e6e5 d3e3 e5d6
info depth 9 seldepth 10 score cp 157 ebf 1.35 time 6 nodes 2806 pv e2e4 e8d7 e1d2 d7e6 d2d3 e6e5 d3e3 e5d6 e3d4
info depth 10 seldepth 10 score cp 157 ebf 1.12 time 8 nodes 3776 pv e2e4 e8d7 e1d2 d7e6 d2d3 e6e5 d3e3 e5d6
info depth 11 seldepth 12 score cp 188 ebf 1.73 time 13 nodes 6536 pv e2e4 e8d7 e1d2 d7e6 d2d3 e6e5 d3e3 e5d6 e3d4 d6e6 e4e5
info depth 12 seldepth 13 score cp 188 ebf 2.49 time 19 nodes 12531 pv e1d2 e8d7 d2d3 d7e6 d3d4 e6d6 e2e4 d6e6 e4e5 e6f5 d4d5 f5f4
info depth 13 seldepth 14 score cp 196 ebf 1.53 time 25 nodes 18986 pv e1d2 e8d7 d2d3 d7d6 d3d4 d6c6 e2e4 c6c7 e4e5 c7c6 d4e4
info depth 14 seldepth 15 score cp 240 ebf 1.07 time 31 nodes 25793 pv e1d2 e8d7 d2d3 d7d6 d3d4 d6c6 e2e4 c6b5 d4d5 b5b4 e4e5 b4c3 e5e6 c3d3
info depth 15 seldepth 16 score cp 240 ebf 1.02 time 36 nodes 32491 pv e1d2 e8d7 d2d3 d7d6 d3d4 d6c6 e2e4 c6d6 e4e5 d6e6 d4e4 e6f7 e4d5 f7g6
info depth 16 seldepth 17 score cp 240 ebf 1.08 time 40 nodes 40396 pv e1d2 e8d7 d2d3 d7d6 d3d4 d6c6 e2e4 c6d6 e4e5 d6e6 d4e4 e6f7 e4d5 f7g6 e5e6 g6f6 d5d6
info depth 17 seldepth 18 score cp 240 ebf 1.31 time 47 nodes 51975 pv e1d2 e8d7 d2d3 d7d6 d3d4 d6c6 e2e4 c6d6 e4e5 d6e6 d4e4 e6f7 e4d5 f7g6 d5d4 g6f5
info depth 18 seldepth 20 score cp 183 ebf 2.01 time 66 nodes 83886 pv e1d2 e8d7 d2d3 d7d6 d3d4 d6c6 e2e4 c6d6 d4d3 d6c5 d3e3 c5d6 e3f4 d6e6 e4e5 e6d5 f4f5 d5d4
info depth 19 seldepth 20 score cp 260 ebf 2.32 time 105 nodes 146466 pv e1d2
info depth 19 seldepth 19 score cp 255 ebf 0.40 time 108 nodes 151543 pv e1d2
info depth 20 seldepth 22 score cp 330 ebf 0.87 time 140 nodes 199023 pv e1d2
info depth 20 seldepth 20 score cp 330 ebf 1.18 time 144 nodes 206097 pv e1d2
info depth 21 seldepth 23 score cp 327 ebf 1.32 time 193 nodes 288475 pv e1d2 e8d7 d2e3 d7c6 e3f4 c6d6 f4e4 d6c7 e4d5 c7b6 d5d6 b6b7 e2e4 b7c8 e4e5 c8d8 d6d5
info depth 22 seldepth 24 score cp 317 ebf 3.13 time 232 nodes 357975 pv e1d2 e8d7 d2e3 d7c6 e3f4 c6d6 f4e4 d6c7 e4d5 c7d7 d5e5 d7d8
info depth 23 seldepth 24 score cp 317 ebf 0.91 time 270 nodes 425860 pv e1d2 e8d7 d2e3 d7c6 e3f4 c6d6 f4e4 d6c7 e4d5
info depth 24 seldepth 26 score cp 317 ebf 1.31 time 338 nodes 545759 pv e1d2 e8d7 d2e3 d7c6 e3f4 c6d6 f4e4 d6e6 e4d4 e6d7
info depth 25 seldepth 27 score cp 317 ebf 1.45 time 416 nodes 688536 pv e1d2 e8d7 d2e3 d7c6 e3f4 c6d6 f4e4 d6e6 e4d4 e6d7
info depth 26 seldepth 28 score cp 317 ebf 1.35 time 536 nodes 906370 pv e1d2 e8d7 d2e3 d7c6 e3f4 c6d6 f4e4 d6e6 e4d4 e6d7 d4d5 d7e8 d5e5 e8f7 e5d4 f7e7
info depth 27 seldepth 29 score cp 317 ebf 1.36 time 681 nodes 1171123 pv e1d2 e8d7 d2e3 d7c6 e3f4 c6d6 f4e4 d6e6 e4d4 e6d7
info depth 28 seldepth 30 score cp 260 ebf 1.60 time 991 nodes 1728156 pv e1d2 e8d7 d2e3 d7c6 e3f4 c6d6 f4e4 d6e6 e4d4 e6d6 e2e3 d6e6 e3e4 e6d6 d4e3
info depth 29 seldepth 30 score cp 260 ebf 1.35 time 1255 nodes 2211080 pv e1d2 e8d7 d2e3 d7c6 e3f4 c6d6 f4e4 d6e6 e4d4 e6d6 e2e3 d6e6 e3e4 e6d6 d4e3
info depth 30 seldepth 32 score cp 260 ebf 1.07 time 1596 nodes 2845067 pv e1d2 e8d7 d2e3 d7c6 e3f4 c6d6 f4e4 d6e6 e4d4 e6d6 e2e3 d6e6 e3e4 e6d6 d4e3
info depth 31 seldepth 33 score cp 260 ebf 1.34 time 2068 nodes 3708316 pv e1d2 e8d7 d2e3 d7c6 e3f4 c6d6 f4e4 d6e6 e4d4 e6d6 e2e3 d6e6 e3e4 e6d6 d4e3
info depth 32 seldepth 34 score cp 260 ebf 1.66 time 3013 nodes 5447405 pv e1d2 e8d7 d2e3 d7c6 e3f4 c6d6 f4e4 d6e6 e4d4 e6d6 e2e3 d6e6 d4e4 e6d6
info depth 33 seldepth 35 score cp 312 ebf 1.25 time 3754 nodes 6791971 pv e1d2 e8d7 d2e3 d7c6 e3f4 c6d6 f4e4 d6e6 e4d4 e6d6 e2e3 d6e6 d4e4 e6d6 e4f5
info depth 34 seldepth 36 score cp 310 ebf 1.13 time 4977 nodes 9023402 pv e1d2 e8d7 d2e3 d7e6 e3d4 e6d6 e2e3 d6e6 d4e4 e6d6 e4f5 d6e7 f5e5 e7f7
info depth 35 seldepth 36 score cp 310 ebf 1.23 time 6140 nodes 11069652 pv e1d2 e8d7 d2e3 d7e6 e3d4 e6d6 e2e3 d6e6 d4e4 e6d6 e4f5 d6e7 f5e5 e7f7 e3e4 f7e7 e5d5
info depth 36 seldepth 37 score cp 310 ebf 1.18 time 7830 nodes 14166696 pv e1d2 e8d7 d2e3 d7e6 e3d4 e6d6 e2e3 d6e6 d4e4 e6d6 e4f5 d6e7 f5e5 e7f7 e3e4 f7e7 e5d5
info depth 37 seldepth 39 score cp 310 ebf 1.49 time 10335 nodes 18730510 pv e1d2 e8d7 d2e3 d7e6 e3d4 e6d6 e2e3 d6e6 d4e4 e6d6 e4f5 d6e7 f5e5 e7f7 e3e4 f7e7 e5d5
info depth 38 seldepth 40 score cp 310 ebf 1.48 time 14054 nodes 25481083 pv e1d2 e8d7 d2e3 d7e6 e3d4 e6d6 e2e3 d6e6 d4e4 e6d6 e4f5 d6e7 f5e5 e7f7 e3e4 f7e7
info depth 39 seldepth 41 score cp 505 ebf 1.12 time 17215 nodes 31186369 pv e1d2
info depth 39 seldepth 41 score cp 505 ebf 2.98 time 61784 nodes 91299844 pv e1d2
info depth 40 seldepth 42 score cp 957 ebf 0.98 time 64792 nodes 96741544 pv e1d2
info depth 40 seldepth 42 score cp 957 ebf 1.71 time 201822 nodes 271889546 pv e1d2
info depth 41 seldepth 43 score cp 540 ebf 2.27 time 217866 nodes 299841369 pv e1d2
info score cp 540
bestmove e1d2
Last edited by flok on Thu Apr 13, 2017 2:19 pm, edited 1 time in total.