Determining values for piece-square tables.

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
Don
Posts: 5106
Joined: Tue Apr 29, 2008 4:27 pm

Re: Determining values for piece-square tables.

Post by Don »

xsadar wrote:Thanks for all the thoughts Don. When I've tried before to make piece-square tables, I figured I could just follow the general rules, but I really know very few of the general rules. I know you should try to control the center. I know to keep knights away from the edges. I know to move the king more toward the center in the end game, but of course keep it safely tucked away behind some pawns in the corner before that.
So that leads to the question, where can I find more information on general rules that are more pertinent to piece-square tables? Of course I know there are millions of chess books out there, but I'm looking for something most pertinent to the task at hand. On the web would be ideal (and as I remember there is at least some on CPW), but I'm not completely opposed to buying a book if it's worth the cost.
Also, I just realized, I don't have to put everything I want it to know into the tables at once, but I can build them up gradually over time. I can start by figuring in one simple rule, and test that, then figure in another rule, and test that, and so on. That would definitely work best if I generate them on the fly as you suggest. The difficult part of course will be figuring the range of values.
Unfortunately, even strong players will disagree on many aspects of this, especially when it comes to what the values should be in a chess program.

I think you may want to start it with rules to build the table, instead of just trying to hand-code each square - that way you can experiement freely. You can auto-test each change if you don't know much about chess, but it's generally better to watch it play games and then back this up with auto-testing.

For you, I think you definitely need to get into serious self-testing even if it's at shallow depths. You can get a reasonable evaluation function from shallow depth games.

I know that Franz Morsch used to use 1 ply games as a sanity check. He once told me that it must play reasonable looking moves on 1 ply or the evaluation is no good.

Also, look at the 2nd, 3rd, 4th choice etc. Are those moves in reasonable order? It may play the correct move, but if it's second favorite move is h4 from the opening position you have a problem. Of course for this check you should make sure that the alpha beta window will score these moves correctly.
Gian-Carlo Pascutto
Posts: 1243
Joined: Sat Dec 13, 2008 7:00 pm

Re: Determining values for piece-square tables.

Post by Gian-Carlo Pascutto »

Don wrote:
Sergei Markoff wrote:
mclane wrote:make an array /table for each piece.

take grandmaster games.
bring each movement into the array with 1 point.
run through the database and you will get
data that is sensible because it came out of good human games.

IMO this way you would get good piece-square tables with a realistic value.
It will not work because for example Nb1-c3 is more frequent than Nc3-e4 and so on.
I'm not saying this will work, but it's possible to use the Bradley Terry model and assign scores to moves. This has been done in GO for patterns. The bradley terry model essential assigned ELO ratings to moves and this could be done by looking at high level games.

So in your example, it doesn't matter how often Nc3 is played, what matters is how it does in competition with other moves. So if a move is played a very high percentage of the time when it's possible to play it, then this would indicate that the move is a very good move.

If I were to do this, I would at least perform see() on each move and only consider non-losing moves as part of the Bradley Terry model. So if half the moves were losing moves, I would not consider "rating" them using the Bradley Terry model.
I know the original suggestion doesn't work because I've tried it. But I've tried your suggestion as well :) (about 1.5 year ago)

I factored in the rest of the evaluation in the BT model as well. The resulting piece square tables looked very good, but they were not better than the manually tuned black magic tables.
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Determining values for piece-square tables.

Post by bob »

xsadar wrote:For a long time I've had piece-square tables in my engine that I had "temporarily" borrowed from other engines. This has prevented me from releasing my engine, because I want to release an engine that's entirely my own work (and definitely avoid releasing an engine that infringes on other people's copyrights).
I've begun a complete rewrite from the ground up, and have no intention of borrowing tables again, so my question is: how do people come up with these values in the first place?

I'm pretty mediocre at chess myself, and have very little book knowledge about chess, so any guesstimates I make will most likely be way off, and I would imagine that even a Grand Master's estimates would be off by a fair amount. So are there any suggestions on how I can go about determining those values? Or information I might be able to use in the process? Testing my values will be quite a task since I don't have a cluster like Bob's -- I'll just have to run tests while I'm at work or sleeping -- so, obviously, the closer I can get my initial estimates, the better.
I just make reasonable assumptions, and then test them by playing games and looking at what happens. If a knight ends up on the edge of the board, out of play, and that costs you a game, you probably don't have the values tuned very well yet...
Antonio Torrecillas
Posts: 90
Joined: Sun Nov 02, 2008 4:43 pm
Location: Barcelona

Re: Determining values for piece-square tables.

Post by Antonio Torrecillas »

In my effort to revive PB* I am replacing the UFO evaluation of Rocinante.
This is the method I use, just in case...

First I create a test epd (aprox 10^6 positions) as follow.
- I play a pgn file and for each position I do a Perft(1), (engines avoid carefully to get some position!!!)
- for each leaf node I do a PVS(depth=3) and record the resulting move as bm in the tune.epd file.

Now I define parameterized rules for the value of each square
for example:

Code: Select all

const int centralv[8] = {-3,-1,1,3,3,1,-1,-3};

void CentralX(CDiagrama &Board,int piece,int Value)
{
	int j;
	for&#40;j = 0; j < 64;j++)
	&#123;
		Board.Pst&#91;piece&#93;&#91;blanco&#93;&#91;j&#93; += Value * centralv&#91;FILE&#40;j&#41;&#93;; 
		Board.Pst&#91;piece&#93;&#91;negro&#93;&#91;j&#93; += -Value  * centralv&#91;FILE&#40;j&#41;&#93;; 
	&#125;
&#125;
I evaluate the score of the engine for each parameter value(+1,-1,+2,-2...) and rule with a fixed_depth=1 of the tune.epd.

Not perfect, but for a first aproximation...to not depends on the evaluation of another engine,
to get acceptable values, to don't need to guess...
User avatar
Don
Posts: 5106
Joined: Tue Apr 29, 2008 4:27 pm

Re: Determining values for piece-square tables.

Post by Don »

Gian-Carlo Pascutto wrote:
Don wrote:
Sergei Markoff wrote:
mclane wrote:make an array /table for each piece.

take grandmaster games.
bring each movement into the array with 1 point.
run through the database and you will get
data that is sensible because it came out of good human games.

IMO this way you would get good piece-square tables with a realistic value.
It will not work because for example Nb1-c3 is more frequent than Nc3-e4 and so on.
I'm not saying this will work, but it's possible to use the Bradley Terry model and assign scores to moves. This has been done in GO for patterns. The bradley terry model essential assigned ELO ratings to moves and this could be done by looking at high level games.

So in your example, it doesn't matter how often Nc3 is played, what matters is how it does in competition with other moves. So if a move is played a very high percentage of the time when it's possible to play it, then this would indicate that the move is a very good move.

If I were to do this, I would at least perform see() on each move and only consider non-losing moves as part of the Bradley Terry model. So if half the moves were losing moves, I would not consider "rating" them using the Bradley Terry model.
I know the original suggestion doesn't work because I've tried it. But I've tried your suggestion as well :) (about 1.5 year ago)

I factored in the rest of the evaluation in the BT model as well. The resulting piece square tables looked very good, but they were not better than the manually tuned black magic tables.
Yes, I think you are right. No matter how good it may sound it usually doesn't work out in practice! There are many issues to grapple with - how do you convert an ELO rating for a move to values for a pieces square table? How do you deal with the problem of quies, such when a move from a good square to a bad is played because it is attacked? Or capture moves doesn't fit cleanly into the scheme. I guess for much of this you can just assume things will average out.
Mincho Georgiev
Posts: 454
Joined: Sat Apr 04, 2009 6:44 pm
Location: Bulgaria

Re: Determining values for piece-square tables.

Post by Mincho Georgiev »

I think the more important question here is not about the exact values.
Following the basic principles in chess you could easily determine what should avoid and what should you focus on. Like center control reasonable bonuses, end of the board again reasonable lower scores, e.t.c...
What really matters though is the weights of your psq tables, meaning the interaction between them and the rest of the evaluation score members. Unfortunately you can only determine the balance using the "trial-error" approach.
Gian-Carlo Pascutto
Posts: 1243
Joined: Sat Dec 13, 2008 7:00 pm

Re: Determining values for piece-square tables.

Post by Gian-Carlo Pascutto »

Don wrote: There are many issues to grapple with - how do you convert an ELO rating for a move to values for a pieces square table?
I consider each game a series of matches (=the positions) between two teams of players, with a known result. The teams of players are the evaluation features.

With the Bradley-Terry model, you can calculate the ratings for each individual player, i.e. you directly get the evaluation weights for each feature.

It's a direct application of Remi Couloms result for go to chess. The method is insanely powerful.
Rein Halbersma
Posts: 741
Joined: Tue May 22, 2007 11:13 am

Re: Determining values for piece-square tables.

Post by Rein Halbersma »

Gian-Carlo Pascutto wrote:
Don wrote: There are many issues to grapple with - how do you convert an ELO rating for a move to values for a pieces square table?
I consider each game a series of matches (=the positions) between two teams of players, with a known result. The teams of players are the evaluation features.

With the Bradley-Terry model, you can calculate the ratings for each individual player, i.e. you directly get the evaluation weights for each feature.

It's a direct application of Remi Couloms result for go to chess. The method is insanely powerful.
Michael Buro did the same in Othello with his GLEM methode.
gingell

Re: Determining values for piece-square tables.

Post by gingell »

I've experimented with the the idea of using Bayes Law to estimate the weights for different evaluation features, like piece/location pairs. The approach is similar to spam filtering: if you can train a filter to measure "spaminess", then maybe it can be used to measure the "goodness" of a chess position.

I had pretty mixed results but my model was very simple. I think there's more potential here.

Here's what I wrote up at the time:

https://sourceforge.net/apps/wordpress/ ... eneration/

https://sourceforge.net/apps/wordpress/ ... are-tables
User avatar
Don
Posts: 5106
Joined: Tue Apr 29, 2008 4:27 pm

Re: Determining values for piece-square tables.

Post by Don »

Gian-Carlo Pascutto wrote:
Don wrote: There are many issues to grapple with - how do you convert an ELO rating for a move to values for a pieces square table?
I consider each game a series of matches (=the positions) between two teams of players, with a known result. The teams of players are the evaluation features.

With the Bradley-Terry model, you can calculate the ratings for each individual player, i.e. you directly get the evaluation weights for each feature.

It's a direct application of Remi Couloms result for go to chess. The method is insanely powerful.
Ok, lets's say you have a match (the position) and the competition is between all the legal moves, right? So if you view an individual as the state change between the from and to squares, how do you assign credit for this? Do you view vacating one square and occupying another as a "team of 2" players?

- Don