Sorting moves during move ordering

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
Ronald
Posts: 160
Joined: Tue Jan 23, 2018 10:18 am
Location: Rotterdam
Full name: Ronald Friederich

Re: Sorting moves during move ordering

Post by Ronald »

I tested the difference a long time ago, and at that time the difference was significant, although I don't remember how much...

Testing it now is not so easy, because I calculate the historyscore on the fly and I don't have space to store the values.
User avatar
Desperado
Posts: 879
Joined: Mon Dec 15, 2008 11:45 am

Re: Sorting moves during move ordering

Post by Desperado »

Ronald wrote: Thu Feb 04, 2021 6:57 pm If you are using some sort of historyscore for the sorting of quiet moves, the historyscore of moves change while searching the current quiet move. If you presort the quiet moves, you don't use the changes in historyscore for the still to search quiet moves which can lead to a different order of those moves.
That is true. But you can choose to assign the sorting values once per stage, so it would not matter if they change.
On the other hand it might be an improvement to use updated history counters. In the end you only have the choice in the "pick next best" model.

At least that can be a very different (good) reason beside the technical speedup to choose this technique.
User avatar
xr_a_y
Posts: 1871
Joined: Sat Nov 25, 2017 2:28 pm
Location: France

Re: Sorting moves during move ordering

Post by xr_a_y »

Ronald wrote: Thu Feb 04, 2021 6:57 pm If you are using some sort of historyscore for the sorting of quiet moves, the historyscore of moves change while searching the current quiet move. If you presort the quiet moves, you don't use the changes in historyscore for the still to search quiet moves which can lead to a different order of those moves.
Clever !
nionita
Posts: 175
Joined: Fri Oct 22, 2010 9:47 pm
Location: Austria

Re: Sorting moves during move ordering

Post by nionita »

Ronald wrote: Thu Feb 04, 2021 7:28 pm I tested the difference a long time ago, and at that time the difference was significant, although I don't remember how much...

Testing it now is not so easy, because I calculate the historyscore on the fly and I don't have space to store the values.
In Barbarossa I got a few ELo with this, don't remember how much, but it was significant. I took the idea from Crafty, I think. Or maybe from a comment from Bob.
User avatar
silentshark
Posts: 327
Joined: Sat Mar 27, 2010 7:15 pm

Re: Sorting moves during move ordering

Post by silentshark »

xr_a_y wrote: Thu Feb 04, 2021 7:52 pm
Ronald wrote: Thu Feb 04, 2021 6:57 pm If you are using some sort of historyscore for the sorting of quiet moves, the historyscore of moves change while searching the current quiet move. If you presort the quiet moves, you don't use the changes in historyscore for the still to search quiet moves which can lead to a different order of those moves.
Clever !
Yes, I'd not thought of this. My 'pick the next highest scoring' algorithm doesn't lend itself easily to this, but I will give this a whirl.

On a related note, have people experimented with putting more effort into sorting moves which are a long way from the leaves? For example, might it be worth trying other tricks to better sort moves at, say, depth > 8 (or whatever)?
User avatar
hgm
Posts: 27788
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Sorting moves during move ordering

Post by hgm »

Indeed, speed is only important near the leaves. And using the updated history counts for every new move only makes a difference if there is sufficient updating going on, i.e. when the tree hanging from the node is large. So it seems likely that the entire positive effect of doing this comes from the nodes close to the roots, and is partly offset by it requiring a more expensive sorting method near the leaves. So it does make sense to adapt the algorithm to the remaining depth.

On another note, I am still dissatisfied by the performance of killer + history. Killer is too local, and only helps to get the first move of a refutation for the later moves of the node (where the first move still has to find it the hard way). While history is too global: it suggests the same moves everywhere.

What I would like is a kind of 'killer tree', which suggests not just the first move of the refutation to a sibbling node, but acts as a 'template' for the entire sibbling sub-tree. Come to think of it, it might not be too difficult to do that. But I will discuss it in a topic of its own.
Ras
Posts: 2487
Joined: Tue Aug 30, 2016 8:19 pm
Full name: Rasmus Althoff

Re: Sorting moves during move ordering

Post by Ras »

niel5946 wrote: Thu Feb 04, 2021 10:12 amIs it better to sort all moves in advance or should the highest ordered move just be found at each iteration instead?
I'm doing a hybrid approach: I loop through the move list and note the "best" move via static move ranking (such as PV move, hash table move, threat move, MVV-LVA, killer moves, history scores).

This first move gets swapped to the top of the list and tried. In about 50% of the cases, that leads already to a cut-off so that the rest of the move list is never tried. If the first move is from the hash table, that's even 90%. However, if the first move hasn't cut, and if I have more than two moves overall, I sort the remaining move list using a Shellsort with the Ciura sequence up to 57. With the typical short move list lengths in chess, Shellsort performs better than Quicksort.
Rasmus Althoff
https://www.ct800.net