resources on how to write an eval function?

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

cyberfish

Re: resources on how to write an eval function?

Post by cyberfish »

BTW if You wish, I might try to write an evaluation function for Your program. Mine, called Hopeless, is of Chesswar "E" strength, despite being outsearched by just about any opponent. So it means that if it has anything good inside, it's eval.
That would really be great. My engine (Brainless), as of now, has a half-decent search (alpha-beta, quie, ID, non-recursive nullmove, TT, history heuristic, simple SEE, selective extension on checks) but the eval is really brain dead. I cannot vouch for the bug-free-ness of it, but I have watched it playing quite a few games on FICS (under the handle BrainlessChess, 2112 std, 1832 blitz) and I don't see anything wrong with it (I don't usually play against it, perhaps it's because of my 1200 rating...). It has not played any tournaments yet, though I have registered it for WBEC. I use rotated bitboards (many thanks to Dr. Hyatt) for move generation but also keep a 8x8 mailbox for other purposes. One problem is though, is that the code is not pretty by any standard =) (never knew that someone but me would see it). Please let me know if you are interested.

I am more of a computer science guy than a chess guy, so I pay more attention to the search than to the eval.
cyberfish

Re: resources on how to write an eval function?

Post by cyberfish »

Thanks Mark for your suggestion, I will certainly try it sometime. Sounds like a good idea, but I am not sure if my nearly non-existent chess knowledge will serve me well...
cyberfish

Re: resources on how to write an eval function?

Post by cyberfish »

Marks ideas are very good. What I do though is to set the value of a pawn first and then adjust the other pieces accordingly. I set my pawns to worth 100 points as this makes it easier to give miscellaneous points to other features with out going to decimals. Decimals don't add as fast as whole numbers. After doing that then work on one other eval feature at a time as making to many changes can confuse the issue and make it harder to see which one gives you a positive point flow. As a second item I would suggest piece/square tables for the different pieces. Start with one at first then add others as you go alone. Remember that each new feature can have a drastic effect on all the other features in your eval.
Thanks for the reply. That is essentially where I am at right now, although I am sure the pcsq tables are nowhere near optimal.
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: 10267
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)