resources on how to write an eval function?

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

mjlef
Posts: 1494
Joined: Thu Mar 30, 2006 2:08 pm

Re: resources on how to write an eval function?

Post by mjlef »

Hey, I bet you know more about chess that you would expect. Chess programs are very, very stupid. None that I have seem really understand how say pawns can keep a king from ever getting to the other side of the board, or that in some positions, a knight can never reach a position where it can defend a promotion square. You can at a glance.

Most programs just have:

a. reasonable values for pieces (pawn=1, knight=bishop=3, rook=5 and q=9 are good starting points)
b. Piece square tables just to encouraging occupying the center
c. "mobility" the more moves you have the better
d. some passed pawn eval
e. some king safety eval
f. pawn structure eval

Even beginning chess books cover all these things to some degree. If you look at Fruit and other strong open source programs, there are not a lot of numbers to adjust. Maybe 100. Much more and it just gets too hard to adjust. And even those 100 are based on simple rules or formulas.

Some other ideas:
a. start with linear, then tweak. For example, say you think a bishop might be stronger in the center, just try a simple linear bonus where it increases with distance for the nearest edge.
b. When adding a feature, try to keep the average the same. So if you were giving say a +10 bonus for a bishop on the center 4 squares, make the "bonus" -10 for a bishop on the edge. If you do not make it average out to zero, then you have unintentionally made the average bishop bonus bigger. If you want to keep all your bonuses positive, then subtract a little from the base piece value accordingly.
c. Watch games. You will see really dumb play and it will encourage you to finially add that "wrong color bishop and rook pawn" rule you keep meaning to get to.
d. Try to use general rules. For example lone Rook vs Lone Bishop is nealry always a draw, so most programs divide the score by something. Instead of doing that, how about the more general rule of "if you have no pawns, you have to be a rook ahead to win". This would then score RB vs R as closer to a draw too, and RRB vs RR and QRB vs QR, etc. A rule like that will a big difference.
e. When tuning, use something like OpenOffice Cal to plot the feature (say rook value) versus strength (say win percentage against another program). Your brian is then pretty good at seeing where a maximum value might be from several points.

I like chess programming since it is a way to explore. Hmm, maybe I should give a bigger penalty if a rook attacks the king? A day later, maybe you decide not, but you have found out something.

Mark
Uri Blass
Posts: 10281
Joined: Thu Mar 09, 2006 12:37 am
Location: Tel-Aviv Israel

Re: resources on how to write an eval function?

Post by Uri Blass »

cyberfish wrote:Thanks for the suggestions, found some great help in other engines' sources, as well as the discussion pointed to by the link.

For future references, I found TSCP's evaluation to be of great help. It has the simplicity which is exactly what I wanted (heavily commented, too). By the length of it (~400 lines including comments), I don't think it would be as accurate as something like crafty's, but I am not aiming to win the computer chess champion or anything like that, so it works for me.
Strelka's evaluation is also of similiar size and clearly better than tscp's evaluation.

After some modification to make it smaller by getting rid of special code for white and black strelka's evaluation is less than 500 lines of code.

Note that an obvious weakness of tscp is that it use wrong value for the pieces.

it is easy to improve tscp by increasing the knight and the bishop values from 3 pawns to 3.4 pawns so tscp is not going to make bad trades like trading bishop and knight for rook and pawn.

Uri
User avatar
Bill Rogers
Posts: 3562
Joined: Thu Mar 09, 2006 3:54 am
Location: San Jose, California

Re: resources on how to write an eval function?

Post by Bill Rogers »

Uri
I have looked all over but could not find a copy of Streka. Do you have one that you could send me?
Bill
cyberfish

Re: resources on how to write an eval function?

Post by cyberfish »

I have looked all over but could not find a copy of Streka. Do you have one that you could send me?
I found the source of Strelka here:
http://sdchess.ru/download_engines.htm

I don't understand the Russian though...
PK
Posts: 893
Joined: Mon Jan 15, 2007 11:23 am
Location: Warsza

Re: resources on how to write an eval function?

Post by PK »

I'm still interested in trying to improve Your evaluation function. Please send me Your source code to the address that can be found on the page www.koziol.home.pl/clericus - or hang it somewhere in the net.

If Your code is *that* ugly, then I'll simply ask for a couple of interface functions like isPiece(piece, square, color) etc.

regards,

Pawel Koziol
cyberfish

Re: resources on how to write an eval function?

Post by cyberfish »

email sent.

If anyone else is interested, here is the source:
http://cyberfish.wecheer.com/Brainless20080316.zip
PK
Posts: 893
Joined: Mon Jan 15, 2007 11:23 am
Location: Warsza

Re: resources on how to write an eval function?

Post by PK »

for some reason the mail didn't come across, but I have already downloaded Your source. and I'm pleased to see that there is one more engine with self-deptecating name :P (I know at least four: Brainless, Clueless, Hopeless, Mediocre)
User avatar
Andres Valverde
Posts: 557
Joined: Sun Feb 18, 2007 11:07 pm
Location: Almeria. SPAIN

Re: resources on how to write an eval function?

Post by Andres Valverde »

PK wrote:for some reason the mail didn't come across, but I have already downloaded Your source. and I'm pleased to see that there is one more engine with self-deptecating name :P (I know at least four: Brainless, Clueless, Hopeless, Mediocre)
Add DIRTY to your list :-)
Saludos, Andres
FrancoisK
Posts: 80
Joined: Tue Jul 18, 2006 10:46 pm

Re: resources on how to write an eval function?

Post by FrancoisK »

You can add Sloppy, Patzer and BugChess2 at least :D
And there are a lot more around for sure...Fruit & Cheese ?

François
cyberfish

Re: resources on how to write an eval function?

Post by cyberfish »

for some reason the mail didn't come across, but I have already downloaded Your source. and I'm pleased to see that there is one more engine with self-deptecating name Razz (I know at least four: Brainless, Clueless, Hopeless, Mediocre)
That is really strange. Check PM for the email =).