Page 1 of 1

Simple quiet move sorting

Posted: Sat Jan 13, 2018 9:55 am
by AndrewGrant
So my current (not for long) method of sorting quietsis the following

Code: Select all

value =  getHistoryScore(*mp->history, move, board->turn, 512);
value += abs(PSQTMidgame[board->squares[MoveFrom(move)]][MoveTo(move)  ]);
value -= abs(PSQTMidgame[board->squares[MoveFrom(move)]][MoveFrom(move)]);
Basically just take the history score and add a little more/less based on PSQT


I've just got the following method to pass instead. It's almost like PSQT just for sorting, but much simpler.

Code: Select all

// Pawn, Knight, Bishop, Rook, Queen, King
static const int SortingTypes[KING+1] = {10, 8, 8, 4, 3, 1};

static const int SortingTable[SQUARE_NB] = {
    0, 0, 0, 0, 0, 0, 0, 0,
    1, 2, 2, 2, 2, 2, 2, 1,
    1, 2, 4, 4, 4, 4, 2, 1,
    1, 2, 4, 6, 6, 4, 2, 1,
    1, 2, 4, 6, 6, 4, 2, 1,
    1, 2, 4, 4, 4, 4, 2, 1,
    1, 2, 2, 2, 2, 2, 2, 1,
    0, 0, 0, 0, 0, 0, 0, 0,
};

value =  getHistoryScore(*mp->history, move, board->turn, 256);
value += SortingTypes[PieceType(board->squares[MoveFrom(move)])] * SortingTable[MoveTo(move)  ];
value -= SortingTypes[PieceType(board->squares[MoveFrom(move)])] * SortingTable[MoveFrom(move)];
Seems to beworth 7-10 elo @ 20+.02s. And I would say this is a method you could recommend to people just starting to do quiet move sorting. I'm sure this is not some new knowledge for sorting, but I have not seen this method on the forms or CPW.

Re: Simple quiet move sorting

Posted: Sat Jan 13, 2018 10:37 am
by Sven
Just one question: in both your old and new methods you combine
... MoveFrom ... MoveTo ...
... MoveFrom ... MoveFrom ...

Is this done by intent, or a copy&paste bug which should be corrected into
... MoveTo ... MoveTo ...
... MoveFrom ... MoveFrom ...
?

Re: Simple quiet move sorting

Posted: Sat Jan 13, 2018 11:06 am
by AndrewGrant
Done by intent. first MoveFrom in each line is getting the piece type we are moving. The following MoveTo/MoveFrom is getting to to and from square, so we can see the difference in the SortingTables.

Re: Simple quiet move sorting

Posted: Sat Jan 13, 2018 10:12 pm
by Greg Strong
In the old code, I don't understand the use of absolute values. Looks like if you have any negative PST entries, you'll actually wind up doing the opposite of what you want (rewarding moving to a square with a value that is more negative.) Perhaps your new code is performing better because it doesn't have this bug?

Re: Simple quiet move sorting

Posted: Sat Jan 13, 2018 10:15 pm
by AndrewGrant
Material values are also in the PSQT so I can update midgame/endgame eval with make/unmake move. So no, none of those numbers are negative, unless they are black. In which case, they all are. Hence the abs.

Re: Simple quiet move sorting

Posted: Sun Jan 14, 2018 12:25 am
by Greg Strong
Got it. Makes sense.

Re: Simple quiet move sorting

Posted: Sun Jan 14, 2018 12:55 am
by lucasart
AndrewGrant wrote:So my current (not for long) method of sorting quietsis the following

Code: Select all

value =  getHistoryScore(*mp->history, move, board->turn, 512);
value += abs(PSQTMidgame[board->squares[MoveFrom(move)]][MoveTo(move)  ]);
value -= abs(PSQTMidgame[board->squares[MoveFrom(move)]][MoveFrom(move)]);
Basically just take the history score and add a little more/less based on PSQT


I've just got the following method to pass instead. It's almost like PSQT just for sorting, but much simpler.

Code: Select all

// Pawn, Knight, Bishop, Rook, Queen, King
static const int SortingTypes[KING+1] = {10, 8, 8, 4, 3, 1};

static const int SortingTable[SQUARE_NB] = {
    0, 0, 0, 0, 0, 0, 0, 0,
    1, 2, 2, 2, 2, 2, 2, 1,
    1, 2, 4, 4, 4, 4, 2, 1,
    1, 2, 4, 6, 6, 4, 2, 1,
    1, 2, 4, 6, 6, 4, 2, 1,
    1, 2, 4, 4, 4, 4, 2, 1,
    1, 2, 2, 2, 2, 2, 2, 1,
    0, 0, 0, 0, 0, 0, 0, 0,
};

value =  getHistoryScore(*mp->history, move, board->turn, 256);
value += SortingTypes[PieceType(board->squares[MoveFrom(move)])] * SortingTable[MoveTo(move)  ];
value -= SortingTypes[PieceType(board->squares[MoveFrom(move)])] * SortingTable[MoveFrom(move)];
Seems to beworth 7-10 elo @ 20+.02s. And I would say this is a method you could recommend to people just starting to do quiet move sorting. I'm sure this is not some new knowledge for sorting, but I have not seen this method on the forms or CPW.
Interesting idea, but I wonder if this is really valuable in itself, or works like a placebo.

What if you revert this patch, and instead increase HistoryMax ?

I find it surprising that a static method like that would somehow improve on history, which is extremely strong and scalable in my experience.