Move Ordering idea

Discussion of anything and everything relating to chess playing software and machines.

Moderator: Ras

LeviGibson
Posts: 11
Joined: Sat Aug 07, 2021 3:41 pm
Full name: Levi Gibson

Move Ordering idea

Post by LeviGibson »

I had a move ordering idea that worked out pretty well when implemented. I'm not sure if it has been thought of before, so let me know.
The idea is to look at the most common responses to moves. For example, when the move "exd4" happens, a common response is "Nxd4" or "Qxd4" or "Cxb4".
[d]r1bqkb1r/pppp1ppp/2n2n2/8/3pP3/2P2N2/PP3PPP/RNBQKB1R w KQkq - 0 5
My idea was to take this data from games played by humans, and use it for move ordering. Here's the implementation I went for:

The table that holds the data. the indexes are the previous move's source square, the previous move's target square, and the current move's target square.

Code: Select all

int table [64][64][64]
Here's the function to get information out of it

Code: Select all

int get_move_score(Move prevmove, Move move){
    return commonMoveTable[get_move_source(prevmove)][get_move_target(prevmove)][get_move_target(move)];
}
This managed to lower the nodes of my mediocre engine down from 102k nodes to 88k nodes in combination with MVV-LVA and Killer heuristics.

Let me know any suggestions or comments. This is my first post here so let me know if there is some sort of etiquette I am not following also.
User avatar
Ras
Posts: 2727
Joined: Tue Aug 30, 2016 8:19 pm
Full name: Rasmus Althoff

Re: Move Ordering idea

Post by Ras »

LeviGibson wrote: Sat Aug 07, 2021 10:50 pmThe idea is to look at the most common responses to moves.
That only makes sense for frequent positions, which only arise early in the game - and that's where you'd use an opening book.
Rasmus Althoff
https://www.ct800.net
LeviGibson
Posts: 11
Joined: Sat Aug 07, 2021 3:41 pm
Full name: Levi Gibson

Re: Move Ordering idea

Post by LeviGibson »

Hi and thanks for your reply.
My idea was to do lookups with only the source and target square, not the rest of the position. Like in my example, after the move pawn takes pawn in any position, it's pretty common to capture that pawn back with a knight.
do you still think this could be of use outside the opening?
User avatar
Ras
Posts: 2727
Joined: Tue Aug 30, 2016 8:19 pm
Full name: Rasmus Althoff

Re: Move Ordering idea

Post by Ras »

Any time you capture something, it's a common move to recapture (or first capture something else). MVV-LVA does a good job here. In your example position, MVV-LVA would rank c3xd4 as first move to try, followed by Nf3xd4.

Your table based approach sounds like a "countermove heuristic": https://www.chessprogramming.org/Countermove_Heuristic
Rasmus Althoff
https://www.ct800.net
User avatar
Rebel
Posts: 7466
Joined: Thu Aug 18, 2011 12:04 pm
Full name: Ed Schröder

Re: Move Ordering idea

Post by Rebel »

Sounds like the counter move, you can do it also like this:

int counter_move[12][64][12][64];
12 = piece type
64 = square

Using 188,000 Stockfish games I get -

Image
90% of coding is debugging, the other 10% is writing bugs.
LeviGibson
Posts: 11
Joined: Sat Aug 07, 2021 3:41 pm
Full name: Levi Gibson

Re: Move Ordering idea

Post by LeviGibson »

Wow! Looks a lot more efficient than the method I used. Thanks!