Help writing simple evaluation function please.

Code, algorithms, languages, construction...
Post Reply
delta67
Posts: 5
Joined: Sat Mar 04, 2017 9:47 am

Help writing simple evaluation function please.

Post by delta67 » Sat Mar 04, 2017 10:03 am

Hi,
Inspired by SARGON I'm trying to write a simple chess program.
For the moment the program (DOS terminal) plays random legal simple moves (No castling, en passant, promotion, 50 rule....).
I need ur help please to add the simplest possible evaluation function to choose the best move among generated array of moves.
I don't know the efficient way to use piece square tables and pieces values.
Next step will be the search algorithm (negamax or alpha-beta).
Many thanks in advance.

BrianR
Posts: 17
Joined: Thu Jun 10, 2010 4:48 am

Re: Help writing simple evaluation function please.

Post by BrianR » Sat Mar 04, 2017 4:58 pm


delta67
Posts: 5
Joined: Sat Mar 04, 2017 9:47 am

Re: Help writing simple evaluation function please.

Post by delta67 » Sun Mar 05, 2017 11:38 am

Thanks BrianR for the link.
Of course, I've already visited this page. What I need is a simple practical example, even in pseudo code, which can play acceptable moves.

H.G.Muller
Posts: 190
Joined: Sun Jul 14, 2013 10:00 am
Real Name: H.G. Muller

Re: Help writing simple evaluation function please.

Post by H.G.Muller » Mon Mar 06, 2017 9:02 am

What exactly is your goal? I understand that you don't have a search yet. Or perhaps just a 1-ply search that tries all moves and plays the one with the best evaluation. But you cannot expect such a design to play 'acceptable moves', unless your evaluation would deal with tactics. Because what are reasonable moves and what are gross blunders is totally dominated by shallow tactics, in Chess. Static evaluation, however, is a very cumbersome and inefficient way to find tactically acceptable moves; search would be far more accurate and cheaper. So no strong Chess program tries to pay attention to tactics in its evaluation. With as a consequence that if you would use the evaluation of the strongest programs in the world to play the move that leads to the best evaluation, you would get a program that cannot wait to sacrifice his Queen for a Pawn, and then his Rooks, etc.

If you want to make a program that plays reasonable Chess, first make it search, and in particular, make it search for quiet positions, without paying any attention to evaluation, other than material (through the classical P=1, N=B=3, R=5, Q=9 rule). Only if it can do that you can expect any benefit from evaluating more subtle positional effects, such as centralization or Pawn structure.

A practical example of an engine that plays without search is N.E.G. ( http://home.hccnet.nl/h.g.muller/dwnldpage.html ). An example of a simple engine that searches with a rudimentary evaluation is micro-Max (for a readable source code of an old version, see http://home.hccnet.nl/h.g.muller/maximax.txt ); an even simpler version (without castling and e.p., and somewhat cryptical variable names) can be found at http://home.hccnet.nl/h.g.muller/max1.html .

delta67
Posts: 5
Joined: Sat Mar 04, 2017 9:47 am

Re: Help writing simple evaluation function please.

Post by delta67 » Mon Mar 06, 2017 11:11 am

Many thanks H.G.Muller for ur reply.
Yes, I've just a 1-ply search and I need an evaluation function to choose the best move.
I'm programming just for fun and I don't want a strong program just a simple one which will be, perhaps, a starting point for another person.
I'll take a look at the links u've given.

H.G.Muller
Posts: 190
Joined: Sun Jul 14, 2013 10:00 am
Real Name: H.G. Muller

Re: Help writing simple evaluation function please.

Post by H.G.Muller » Mon Mar 06, 2017 2:03 pm

Well, remember that solving tactical problems by search is far easier to achieve than solving them by evaluation. N.E.G. uses a heuristic that counts the number of attackers and protectors of each square, and together with the value of the piece there and the lowest protector decides if it is safe to go there. Plus that it applies the same judgement to its own pieces, to decide how important it is (in terms of material loss) to move something away. But this leaves it completely naive to anything but the most stupid tactics. E.g. it does not recognize the merit of moves that protect a hanging piece, block the attack on it. And it does not recognize that piece are soft-pinned. To solve all that by dedicated evaluation code would be at least 10 times more effort than writing a simple search (which then would solve all tactics 8 ply deep).

delta67
Posts: 5
Joined: Sat Mar 04, 2017 9:47 am

Re: Help writing simple evaluation function please.

Post by delta67 » Wed Mar 08, 2017 11:59 am

OK, many thanks again H.G.Muller for ur very interesting advises.
In fact I'm a very beginner in chess programing. Ur ideas will help me very much.
Thanks

lucasart
Posts: 201
Joined: Mon Dec 17, 2012 1:09 pm
Contact:

Re: Help writing simple evaluation function please.

Post by lucasart » Sun Mar 12, 2017 10:31 am

delta67 wrote:Hi,
Inspired by SARGON I'm trying to write a simple chess program.
For the moment the program (DOS terminal) plays random legal simple moves (No castling, en passant, promotion, 50 rule....).
I need ur help please to add the simplest possible evaluation function to choose the best move among generated array of moves.
I don't know the efficient way to use piece square tables and pieces values.
Next step will be the search algorithm (negamax or alpha-beta).
Many thanks in advance.
You don't have a search and you want to write an eval ?

You're putting the carriage in front of the horse here.

Follow this order:
step 1: test your board management code is correct (with perft).
step 2: write a simple material count evaluation (nothing more). test it.
step 3: understand how alpha-beta works.
step 4: write a qsearch. test it.
step 5: write a search. test it.
step 6: understand how SEE works, and write an SEE. test it.
step 7: use SEE to sort captures, and prune losing captures at shallow depth. test it.

Don't even think about writing an eval before you reach that point.
"Talk is cheap. Show me the code." -- Linus Torvalds.

delta67
Posts: 5
Joined: Sat Mar 04, 2017 9:47 am

Re: Help writing simple evaluation function please.

Post by delta67 » Mon Mar 13, 2017 11:43 am

lucasart wrote: You don't have a search and you want to write an eval ?
Thanks lucasart for your proposed steps to write a chess program.
What I meant is your step2.
I've written a very basic material count evaluation function based on these articles:
https://chessprogramming.wikispaces.com/Evaluation
https://chessprogramming.wikispaces.com ... n+function
Now I can try different search algorithms, It's very very fun , I'm enjoying this!!!!!
Many Thanks for all people who shared their knowledge on the web.
P.S: If some one needs my humble code (C), let me know (PM), I'll upload it and put the link here.

lucasart
Posts: 201
Joined: Mon Dec 17, 2012 1:09 pm
Contact:

Re: Help writing simple evaluation function please.

Post by lucasart » Tue Mar 14, 2017 6:37 am

delta67 wrote:
lucasart wrote: You don't have a search and you want to write an eval ?
Thanks lucasart for your proposed steps to write a chess program.
What I meant is your step2.
I've written a very basic material count evaluation function based on these articles:
https://chessprogramming.wikispaces.com/Evaluation
https://chessprogramming.wikispaces.com ... n+function
Now I can try different search algorithms, It's very very fun , I'm enjoying this!!!!!
Many Thanks for all people who shared their knowledge on the web.
P.S: If some one needs my humble code (C), let me know (PM), I'll upload it and put the link here.
I thought it was obvious…

You count material, with pawn=1, minor=3, rook=5, queen=10. Do that for both sides, and calculate the difference, expressed from the side to move's pov (for negamax).

But you should first read about, and understand, how negamax and alpha beta work, before writing any more code.
"Talk is cheap. Show me the code." -- Linus Torvalds.

Post Reply