Go into their discord and look it up - or ask them.Sopel wrote: ↑Fri Oct 22, 2021 12:09 amThis number is wrong by about an order of magnitudedangi12012 wrote: ↑Fri Oct 22, 2021 12:04 am Maybe stockfish will use my approach according to their discord since its faster - and they currently use 30% of time for the movegeneration.
Move structure and hash tables
Moderator: Ras
-
dangi12012
- Posts: 1062
- Joined: Tue Apr 28, 2020 10:03 pm
- Full name: Daniel Infuehr
Re: Move structure and hash tables
Worlds-fastest-Bitboard-Chess-Movegenerator
Daniel Inführ - Software Developer
Daniel Inführ - Software Developer
-
Ras
- Posts: 2727
- Joined: Tue Aug 30, 2016 8:19 pm
- Full name: Rasmus Althoff
Re: Move structure and hash tables
Yes, I'm doing that because in my microcontroller version with 8192 entries in total, that saves 16kB, which is a lot. I'm also using that compressed move format e.g. for tracking PVs in positions because that saves stack.
Rather not. I store from and to which are 6 bits each for a 0-63 board index. Actually, I'm using a 10x12 mailbox board, but have conversion tables from and to 8x8 notation. That leaves 4 bits free which I'm using to indicate piece or pawn move, or promotion piece (implying a pawn move). I could encode that more efficiently, e.g. I store black and white promotion pieces as separate numbers. I could get away with only 3 bits here, but that one free bit wouldn't help me so that I rather went for quicker table-based conversion that doesn't need the board state to convert the move.But then you need special functions to determine, with the board state, whether a move is castling (although this one may be as simple as abs(orig - dest) == 2), en passant, capturing, promotion piece, etc.
The main thing I lose from my usual 32 bit move format is the MVV-LVA info, but that's no big deal because when retrieving the hash move, that gets a fixed MVV-LVA override anyway. Castling and EP don't need to be stored in the hash table because that is already in the board state, provided that the move is legal - I'm checking for pseudo-legality when looking up a hash move and discard the hash hit if the hash move fails that check.
I don't think this is actually worth Elo if you're not in such a tight memory sitiuation where you fight for mere kilobytes because it doesn't allow hash tables with more entries unless you allow non-powers of two in terms of entries.
Rasmus Althoff
https://www.ct800.net
https://www.ct800.net
-
hgm
- Posts: 28440
- Joined: Fri Mar 10, 2006 10:06 am
- Location: Amsterdam
- Full name: H G Muller
Re: Move structure and hash tables
That would make decoding very slow, as you would have to generate the entire move list to do it.dangi12012 wrote: ↑Fri Oct 22, 2021 12:04 am Extracting a special move takes no amount of time if its a C++ template. Also any move can be encoded in 8 bits - as the offset in the movelist.
Not sure what you mean by 'extracting a move'. We were talking about extracting data required for updating the game state from a move as one of the possible ways for obtaining that data.
-
Ras
- Posts: 2727
- Joined: Tue Aug 30, 2016 8:19 pm
- Full name: Rasmus Althoff
Re: Move structure and hash tables
The drawback is that this requires you to have a movelist at that point - so you can't try the hash move and only generate the movelist if the hash move doesn't lead to a beta cut. If you have a hash move, you have like 90% probability of a beta cut.dangi12012 wrote: ↑Thu Oct 21, 2021 12:31 amJust the move can be done in 8 bits as the offset in your movelist from any position.
Rasmus Althoff
https://www.ct800.net
https://www.ct800.net
-
Karlo Bala
- Posts: 373
- Joined: Wed Mar 22, 2006 10:17 am
- Location: Novi Sad, Serbia
- Full name: Karlo Balla
Re: Move structure and hash tables
Don't bother, just use as many bits as you need. The size of a move structure is probably the last thing you want to optimize in the engine.gaard wrote: ↑Wed Oct 20, 2021 9:24 pm I see a lot of effort going towards packing a move in 16 bits to save space in the hash table or even for general use. But then you need special functions to determine, with the board state, whether a move is castling (although this one may be as simple as abs(orig - dest) == 2), en passant, capturing, promotion piece, etc. I suppose some of those can be encoded in the remaining 4 bits of a 16-bit move, but usually not all of them. An extra 16 bits also leaves room for flags like direct check, reveal check, etc. Has anyone every measured performance between the two schemes, that is, 16-bit move versus 32-bit. Is there any reason to believe the difference is worth more than a couple of Elo?
Best Regards,
Karlo Balla Jr.
Karlo Balla Jr.
-
Daniel Shawul
- Posts: 4186
- Joined: Tue Mar 14, 2006 11:34 am
- Location: Ethiopia
Re: Move structure and hash tables
I use 32-bit move representation because that is more convenient. But when size really matters, such as in an MCTS search where the tree is stored in RAM, I encode and decode the move into 16 bit representation. For the hashtable, if you need that extra space to double your hash size it may matter but probably not worth a lot of elo.gaard wrote: ↑Wed Oct 20, 2021 9:24 pm I see a lot of effort going towards packing a move in 16 bits to save space in the hash table or even for general use. But then you need special functions to determine, with the board state, whether a move is castling (although this one may be as simple as abs(orig - dest) == 2), en passant, capturing, promotion piece, etc. I suppose some of those can be encoded in the remaining 4 bits of a 16-bit move, but usually not all of them. An extra 16 bits also leaves room for flags like direct check, reveal check, etc. Has anyone every measured performance between the two schemes, that is, 16-bit move versus 32-bit. Is there any reason to believe the difference is worth more than a couple of Elo?
-
Henk
- Posts: 7251
- Joined: Mon May 27, 2013 10:31 am
Re: Move structure and hash tables
Yes I regret storing move in 16 bits. Just make debugging as easy as possible. At least annoying.
Why all these tricks for a few elo. If you can't invent something better than just resign.
Why all these tricks for a few elo. If you can't invent something better than just resign.
-
Sopel
- Posts: 392
- Joined: Tue Oct 08, 2019 11:39 pm
- Full name: Tomasz Sobczyk
Re: Move structure and hash tables
You once again have nothing to back up your claims. Your number is for perft, which no one cares about. You're not better than a troll at this point, I hope moderation takes some action.dangi12012 wrote: ↑Fri Oct 22, 2021 12:14 amGo into their discord and look it up - or ask them.Sopel wrote: ↑Fri Oct 22, 2021 12:09 amThis number is wrong by about an order of magnitudedangi12012 wrote: ↑Fri Oct 22, 2021 12:04 am Maybe stockfish will use my approach according to their discord since its faster - and they currently use 30% of time for the movegeneration.
dangi12012 wrote:No one wants to touch anything you have posted. That proves you now have negative reputations since everyone knows already you are a forum troll.
Maybe you copied your stockfish commits from someone else too?
I will look into that.
-
hgm
- Posts: 28440
- Joined: Fri Mar 10, 2006 10:06 am
- Location: Amsterdam
- Full name: H G Muller
Re: Move structure and hash tables
You mean like warning people who call posters names just because these have an opinion they don't agree with?
-
chrisw
- Posts: 4764
- Joined: Tue Apr 03, 2012 4:28 pm
- Location: Midi-Pyrénées
- Full name: Christopher Whittington
Re: Move structure and hash tables
It makes little difference to performance.gaard wrote: ↑Wed Oct 20, 2021 9:24 pm I see a lot of effort going towards packing a move in 16 bits to save space in the hash table or even for general use. But then you need special functions to determine, with the board state, whether a move is castling (although this one may be as simple as abs(orig - dest) == 2), en passant, capturing, promotion piece, etc. I suppose some of those can be encoded in the remaining 4 bits of a 16-bit move, but usually not all of them. An extra 16 bits also leaves room for flags like direct check, reveal check, etc. Has anyone every measured performance between the two schemes, that is, 16-bit move versus 32-bit. Is there any reason to believe the difference is worth more than a couple of Elo?
Another disadvantage of 16-bit, apart from having to write more fiddly code for determining the characteristics of the move, is that you also start running into problems between finding move character before MakeMove() and after it, because you’re dependent on board state (after MakeMove, the moving piece type had to be got from sq-to, not sq-from and so on and so on). Or maybe for example you need to know something about the move at nply-1, or nply-2, well, you’ll also need a boardstate history, not just a move history.
For an engine in development where you probably can’t predict all possible move informations you might need, then 32 bit with OTT info would seem desirable. After the engine is fully complete, then think about cutting back to 16-bit, but I’ld predict it would by way down the list of important things to try and optimize.