Piece square tables

Discussion of chess software programming and technical issues.

Moderators: hgm, Dann Corbit, Harvey Williamson

Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
Pio
Posts: 252
Joined: Sat Feb 25, 2012 9:42 pm
Location: Stockholm
Contact:

Re: Piece square tables

Post by Pio » Sat Jan 09, 2021 3:40 pm

maksimKorzh wrote:
Sat Jan 09, 2021 3:11 pm
Pio wrote:
Sat Jan 09, 2021 12:14 am
maksimKorzh wrote:
Fri Jan 08, 2021 11:59 pm
Pio wrote:
Fri Jan 08, 2021 11:25 pm
Something I haven’t tried but might be very good is giving the piece that moved two plies before a bonus for all its moves or even better you can generalise this giving a bonus for all new moves you got in this position compared to the moves two plies before.
No, I tried only toSquare.
Interesting idea. Maybe I'll try it when get done with tuning.
If you take toSquare minus fromSquare you will get an improvement.
Hi Pio

Actually I'm getting more nodes traversed instead, here's the code:

Code: Select all

function addMove(moveList, move) {
    let moveScore = 0;
    
    let piece = board[getMoveSource(move)]
    
    if (getMoveCapture(move)) {
      moveScore = mvvLva[board[getMoveSource(move)] * 13 + board[getMoveTarget(move)]];
      moveScore += 10000;
    } else {
      if (killerMoves[searchPly] == move) moveScore = 9000;
      else if (killerMoves[maxPly + searchPly] == move) moveScore = 8000;
      else {
        moveScore = historyMoves[board[getMoveSource(move)] * 128 + getMoveTarget(move)];
        //let delta = (piece < 7) ? 1: 7;
        //moveScore += 3 * (pst[opening][piece - delta][getMoveTarget(move)] - pst[opening][piece - delta][getMoveSource(move)])
      }
    }

    moveList.push({
      move: move,
      score: moveScore
    });
  }
output (no PST ordering)

Code: Select all

info score cp 26 depth 1 nodes 50 time 19 pv g1f3 
wukong.js:1682 info score cp -22 depth 2 nodes 151 time 63 pv g1f3 g8f6 
wukong.js:1682 info score cp 22 depth 3 nodes 775 time 181 pv g1f3 g8f6 b1c3 
wukong.js:1682 info score cp -22 depth 4 nodes 1852 time 413 pv g1f3 g8f6 b1c3 b8c6 
wukong.js:1682 info score cp 14 depth 5 nodes 6097 time 534 pv g1f3 g8f6 b1c3 b8c6 e2e4 
wukong.js:1682 info score cp -22 depth 6 nodes 25513 time 1268 pv g1f3 g8f6 d2d4 b8c6 d4d5 c6b4 
wukong.js:1694 bestmove g1f3
output (PST ordering)

Code: Select all

info score cp 26 depth 1 nodes 40 time 18 pv g1f3 
wukong.js:1682 info score cp -22 depth 2 nodes 120 time 58 pv g1f3 g8f6 
wukong.js:1682 info score cp 22 depth 3 nodes 726 time 189 pv g1f3 g8f6 b1c3 
wukong.js:1682 info score cp -22 depth 4 nodes 1753 time 441 pv g1f3 g8f6 b1c3 b8c6 
wukong.js:1682 info score cp 14 depth 5 nodes 5843 time 604 pv g1f3 g8f6 b1c3 b8c6 e2e4 
wukong.js:1682 info score cp -22 depth 6 nodes 27827 time 1276 pv g1f3 g8f6 d2d4 b8c6 d4d5 c6b4 
wukong.js:1694 bestmove g1f3
Did I do something wrong?

EDIT:
changed (fromSq - toSq) to abs(fromSq - toSq)
now in starting position have only a few more nodes with PST ordering and in position with lots of captures
have a slight improvement:

no PST ordering

Code: Select all

info score cp 36 depth 1 nodes 2960 time 277 pv e2a6 b4c3 
wukong.js:1682 info score cp 36 depth 2 nodes 6033 time 432 pv e2a6 b4c3 
wukong.js:1682 info score cp 22 depth 3 nodes 10262 time 501 pv e2a6 b4c3 d2c3 h3g2 f3g2 e6d5 
wukong.js:1682 info score cp 22 depth 4 nodes 16621 time 615 pv e2a6 b4c3 d2c3 h3g2 f3g2 e6d5 
wukong.js:1682 info score cp 9 depth 5 nodes 34325 time 898 pv e2a6 b4c3 d2c3 e6d5 e4d5 h3g2 f3g2 b6d5 
wukong.js:1682 info score cp 9 depth 6 nodes 78751 time 1299 pv e2a6 b4c3 d2c3 e6d5 e4d5 h3g2 f3g2 b6d5 
wukong.js:1694 bestmove e2a6
PST ordering

Code: Select all

info score cp 36 depth 1 nodes 2957 time 293 pv e2a6 b4c3 
wukong.js:1682 info score cp 36 depth 2 nodes 6137 time 480 pv e2a6 b4c3 
wukong.js:1682 info score cp 22 depth 3 nodes 10418 time 562 pv e2a6 b4c3 d2c3 h3g2 f3g2 e6d5 
wukong.js:1682 info score cp 22 depth 4 nodes 16845 time 682 pv e2a6 b4c3 d2c3 h3g2 f3g2 e6d5 
wukong.js:1682 info score cp 9 depth 5 nodes 34951 time 981 pv e2a6 b4c3 d2c3 e6d5 e4d5 h3g2 f3g2 b6d5 
wukong.js:1682 info score cp 9 depth 6 nodes 78385 time 1427 pv e2a6 b4c3 d2c3 e6d5 e4d5 h3g2 f3g2 b6d5 
wukong.js:1694 bestmove e2a6
Try PST[pieceType][toSquare] - PST[pieceType][fromSquare]

The logic is simple. If you would only have PST evaluation in your engine the move scoring would perfectly sort the moves in the last level. Make sure it is toSquare - fromSquare and not the opposite.

You will also have to order the moves in descending order taking the moves with highest scores first.

Pio
Posts: 252
Joined: Sat Feb 25, 2012 9:42 pm
Location: Stockholm
Contact:

Re: Piece square tables

Post by Pio » Sat Jan 09, 2021 3:49 pm

You should test your code against maybe 50 positions to be sure

Daniel Anulliero
Posts: 726
Joined: Fri Jan 04, 2013 3:55 pm
Location: Nice

Re: Piece square tables

Post by Daniel Anulliero » Sat Jan 09, 2021 5:12 pm

Hi
Interresting topic , as I'm working on Isa's psqt from time to time.

I've tested to order the moves by psqt , but leaved this idea because it confused me a little bit , as I'm using two tables (middle and endgame) with tappered eval .
You can't use always the MG or EG tables to order moves because of tappered eval , right ?

how do you avoid this problem ? or use only the MG tables ?

Pio
Posts: 252
Joined: Sat Feb 25, 2012 9:42 pm
Location: Stockholm
Contact:

Re: Piece square tables

Post by Pio » Sat Jan 09, 2021 5:18 pm

Daniel Anulliero wrote:
Sat Jan 09, 2021 5:12 pm
Hi
Interresting topic , as I'm working on Isa's psqt from time to time.

I've tested to order the moves by psqt , but leaved this idea because it confused me a little bit , as I'm using two tables (middle and endgame) with tappered eval .
You can't use always the MG or EG tables to order moves because of tappered eval , right ?

how do you avoid this problem ? or use only the MG tables ?
I use the tapered PST values, that is the linear interpolation between the MG- and EG-PST.

User avatar
Desperado
Posts: 708
Joined: Mon Dec 15, 2008 10:45 am

Re: Piece square tables

Post by Desperado » Tue Jan 12, 2021 10:00 am

eligolf wrote:
Fri Jan 08, 2021 10:09 am
I have lately read lot on piece square tables, both here, on Chesswiki and at the internet in general. There seems to be incredibly different opinions and even wether to use them at all. My base questions is, is there a "standard" way peice square tables are used?

...
Hello eligolf,

i think there are basically two concepts you can follow when building your piece square tables.

1. PST as evaluation shortcut

The first one is about the simple idea to save time by recalculating terms in the standard evaluation.

For example you can have evaluation terms like

* development for piece on first rank
* center control
* bad mobility for pawn a/h file
* danger zone for king
* many more...

Of course you can define eval parameters and compute them again and again, but putting
the precomputed value into a table and look it up is faster of course. Such a table may look
very simple because if you only put in one term like "center" they will be very symetric.

2. PST as blackbox evaluation

Using this idea, you don't care what is behind a score. You try to complement your main evaluation,
the score replaces not defined evaluation paramters in your main evaluation. The extreme would be,
that you only have a perfect PST but nothing else you evaluate.

Conclusion

Recently i switched to type 1. It gives me freedom to know what the table represents.
You might end up with a handful of parmeters per table you can easily tune later.
You dont need to tune several hundred scores...

Finally concentrate on the king table. It is essential.
The knight table is useful too. The other tables will be less important.

Regards.

User avatar
maksimKorzh
Posts: 525
Joined: Sat Sep 08, 2018 3:37 pm
Location: Ukraine
Full name: Maksim Korzh
Contact:

Re: Piece square tables

Post by maksimKorzh » Tue Jan 12, 2021 12:09 pm

Desperado wrote:
Tue Jan 12, 2021 10:00 am
eligolf wrote:
Fri Jan 08, 2021 10:09 am
I have lately read lot on piece square tables, both here, on Chesswiki and at the internet in general. There seems to be incredibly different opinions and even wether to use them at all. My base questions is, is there a "standard" way peice square tables are used?

...
Hello eligolf,

i think there are basically two concepts you can follow when building your piece square tables.

1. PST as evaluation shortcut

The first one is about the simple idea to save time by recalculating terms in the standard evaluation.

For example you can have evaluation terms like

* development for piece on first rank
* center control
* bad mobility for pawn a/h file
* danger zone for king
* many more...

Of course you can define eval parameters and compute them again and again, but putting
the precomputed value into a table and look it up is faster of course. Such a table may look
very simple because if you only put in one term like "center" they will be very symetric.

2. PST as blackbox evaluation

Using this idea, you don't care what is behind a score. You try to complement your main evaluation,
the score replaces not defined evaluation paramters in your main evaluation. The extreme would be,
that you only have a perfect PST but nothing else you evaluate.

Conclusion

Recently i switched to type 1. It gives me freedom to know what the table represents.
You might end up with a handful of parmeters per table you can easily tune later.
You dont need to tune several hundred scores...

Finally concentrate on the king table. It is essential.
The knight table is useful too. The other tables will be less important.

Regards.
A very useful insights, thanks!
JavaScript chess engine with UCI support, own GUI and public API:
https://github.com/maksimKorzh/wukongJS

Chess programming YouTube channel:
https://www.youtube.com/channel/UCB9-pr ... KKqDgXhsMQ

Post Reply