Dynamic piece square tables for chess variants?

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

Moderators: hgm, Rebel, chrisw

zulban
Posts: 36
Joined: Sun Apr 08, 2018 6:23 pm

Dynamic piece square tables for chess variants?

Post by zulban »

Hello! First post here. I'm working on a smartphone interface and AI (now playable!) which allows the player to make custom board shapes and sizes, and pieces with custom move rules. One enhancement I'd like for my AI are piece square tables. However I'm facing some challenges.

Because any board/pieces can be made and immediately played by the player, I cannot massively precompute to help the AI. A new set of decent tables needs to be generated by a smartphone in a couple seconds. A doable example: knights want to be where they have lots of available moves, which on a classic board means away from edges and corners. I have found writeups like this:

http://www.chessbin.com/post/Piece-Square-Table

Which says things like "During the middle game kings are encouraged to stay in the corners, while in the end game kings are encouraged to move towards the center." However, is there some discussion somewhere of generalising these rules? What if a king could move more, or less? Or a bishop that can only move forward..? Where would those pieces want to be start, mid, and end game, and why? If a board were narrow, or L shaped, where would bishops want to be? Why?

Basically I'm looking for discussion on why the values in piece square tables are the way they are, and how they'd be different under different circumstances. I've also noted that different engines have fairly different piece square tables.

I've also seen this page, but there's a lot of random links to wade through:

https://chessprogramming.wikispaces.com ... are+Tables

Anyway, I think this is a pretty interesting problem! I have a few simple ideas in mind to start but was wondering what people here might think. Or if you could link me to any existing discussions or resources.

Cheers!
User avatar
Evert
Posts: 2929
Joined: Sat Jan 22, 2011 12:42 am
Location: NL

Re: Dynamic piece square tables for chess variants?

Post by Evert »

zulban wrote:Hello! First post here. I'm working on a smartphone interface and AI (now playable!) which allows the player to make custom board shapes and sizes, and pieces with custom move rules. One enhancement I'd like for my AI are piece square tables. However I'm facing some challenges.

Because any board/pieces can be made and immediately played by the player, I cannot massively precompute to help the AI. A new set of decent tables needs to be generated by a smartphone in a couple seconds. A doable example: knights want to be where they have lots of available moves, which on a classic board means away from edges and corners. I have found writeups like this:

http://www.chessbin.com/post/Piece-Square-Table

Which says things like "During the middle game kings are encouraged to stay in the corners, while in the end game kings are encouraged to move towards the center." However, is there some discussion somewhere of generalising these rules? What if a king could move more, or less? Or a bishop that can only move forward..? Where would those pieces want to be start, mid, and end game, and why? If a board were narrow, or L shaped, where would bishops want to be? Why?

Basically I'm looking for discussion on why the values in piece square tables are the way they are, and how they'd be different under different circumstances. I've also noted that different engines have fairly different piece square tables.

I've also seen this page, but there's a lot of random links to wade through:

https://chessprogramming.wikispaces.com ... are+Tables

Anyway, I think this is a pretty interesting problem! I have a few simple ideas in mind to start but was wondering what people here might think. Or if you could link me to any existing discussions or resources.

Cheers!
There's a recent discussion on the technical forum about piece values by HGM. That is probably the best place to start.
In Leonidas I use piece square tables based on mobility on an empty board, but that's not very good. I do something a bit more involved in SjaakII, where I also make a distinction between "leapers" and "sliders", but I've never been entirely happy with it.
User avatar
hgm
Posts: 27790
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Dynamic piece square tables for chess variants?

Post by hgm »

User avatar
Greg Strong
Posts: 388
Joined: Sun Dec 21, 2008 6:57 pm
Location: Washington, DC

Re: Dynamic piece square tables for chess variants?

Post by Greg Strong »

In ChessV, I generate the PST for each piece based on the piece's movement capabilities and some parameters that can be configured for each piece, but remain at the defaults in most cases. It uses different PSTs for midgame and endgame and interpolates between those values as the board clears out.

Here are the default parameters for PST generation:

Code: Select all

PSTMidgameInSmallCenter = 3;
PSTMidgameInLargeCenter = 3;
PSTMidgameSmallCenterAttacks = 1;
PSTMidgameLargeCenterAttacks = 1;
PSTMidgameForwardness = 0;
PSTMidgameGlobalOffset = -15;

PSTEndgameInSmallCenter = 3;
PSTEndgameInLargeCenter = 3;
PSTEndgameSmallCenterAttacks = 1;
PSTEndgameLargeCenterAttacks = 1;
PSTEndgameForwardness = 0;
PSTEndgameGlobalOffset = -15;
So the piece gets +3 for occupying the small center, another +3 for occupying the large center, +1 for each square in the small center he attacks from the current square on an empty board, +1 for each square in the large center attached, no adjustment for forwardness, and a flat -15 to balance it out.

This is used for most pieces but there are a couple of important exceptions.

King has the following changes:

Code: Select all

PSTMidgameInSmallCenter = 0;
PSTMidgameInLargeCenter = 0;
PSTMidgameSmallCenterAttacks = 0;
PSTMidgameLargeCenterAttacks = 0;
PSTMidgameForwardness = -15;

PSTEndgameForwardness = 8;
PSTEndgameInLargeCenter = 15;
Pawn has the following changes:

Code: Select all

PSTMidgameForwardness = 6;
PSTMidgameInSmallCenter = 8;

PSTEndgameForwardness = 12;
I do some other tweaks for a few pieces but it isn't all that important. This will get you something reasonable. If you install ChessV, you can see the results for any piece type on any board it uses. In a game, just right-click on a piece and select Properties and the properties dialog box has tabs for midgame and endgame PSTs.
zulban
Posts: 36
Joined: Sun Apr 08, 2018 6:23 pm

Re: Dynamic piece square tables for chess variants?

Post by zulban »

Great discussion, thanks :o
zulban
Posts: 36
Joined: Sun Apr 08, 2018 6:23 pm

Re: Dynamic piece square tables for chess variants?

Post by zulban »

Thanks for the input, and for sharing the source. Having a look now :o
User avatar
Greg Strong
Posts: 388
Joined: Sun Dec 21, 2008 6:57 pm
Location: Washington, DC

Re: Dynamic piece square tables for chess variants?

Post by Greg Strong »

zulban wrote:Thanks for the input, and for sharing the source. Having a look now :o
Of course. Please let me know if you have any questions!
zulban
Posts: 36
Joined: Sun Apr 08, 2018 6:23 pm

Re: Dynamic piece square tables for chess variants?

Post by zulban »

Hey H.G.Muller, I thought you might be interested to see that I used something similar to your equation to make this:

https://i.imgur.com/felOb4t.png

https://i.imgur.com/MW2RxWq.png

https://i.imgur.com/mweV6g8.png

Note: pieces can start on disabled tiles and enter the board. This works now for any board and any piece in my system :)

Plugging it into my smartphone-AI-game now. Should help give a lot more personality to my quiescent AB :o

I'm sure I will have more questions and thoughts for all of you soon... Still looking at Gregory source code.

Cheers
User avatar
hgm
Posts: 27790
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Dynamic piece square tables for chess variants?

Post by hgm »

Interesting. If the first image is the board, I don't understand how squares in the blue (inaccessible) zone can have a non-zero PST value, though.

Note that if you want to use this method not just for calculating the positional bonus, but the total value of an arbitrary piece, it would need some refinement over just counting the number of moves for getting the instantaneous value. It will have to award some bonus for moves to orthogonally adjacent squares in order to value the Rook properly compare to the Bishop, an the Archbishop to the Chancellor. It would also needs some non-lenearity, which can be achieved by adding not just a factor times the future value averaged over all moves, but also that totalled over all moves.
zulban
Posts: 36
Joined: Sun Apr 08, 2018 6:23 pm

Re: Dynamic piece square tables for chess variants?

Post by zulban »

Regarding inaccessible non-zero PST values, this is because my editor allows you to place a piece on a disabled tile. So for example, for classic chess if you placed a knight on J1 (which is outside the board) that has some value because a knight can hop from there to H2. This works because in another game mode the computer chooses its own pieces based on points, also assigned in the editor. The knight cannot return, but it could start there (computers choosing start pieces is not implemented yet, I want good AI first).

So if placing pieces on disabled tiles before the game starts is allowed, it would be a good idea placing a knight in the centre of a 5x5 ring. The PST should indicate that.
hgm wrote:It will have to award some bonus for moves to orthogonally adjacent squares in order to value the Rook properly compare to the Bishop, an the Archbishop to the Chancellor.
This is actually part of my challenge here. I cannot always award more points to orthogonally adjacent squares. For example:

https://i.imgur.com/qbjnNEU.png

In a board like this, I imagine that bishops are more valuable than rooks. Reducing this to some formula is a challenge though... I think I need to get the "graph diameter" for each piece type (where the bishop has a small graph diameter here, and the rook a large one). Unfortunately solving the graph diameter is O(n^3). I am considering doing an approximation.

I intend on doing a pre-compute analysis of the board in various ways (connectivity by various metrics, graph diameter for each piece) and putting that into my AI training system to discover what weights could be. Until I do training though, having the slightest sense of what the weights should start it would be helpful.

Note also that there is no "bishop" or "rook", only pieces that move like them. I could for example have a piece that only moves forward like a bishop, and only moves backwards like a rook, but captures like a knight, but cannot capture like a knight in the rear left.

Anyway, often I find I have to question or reject about half of the typical chess AI and human chess strategies as they don't apply to my system.