tips for a good evaluation function! help!

Programming Topics (Computer Chess) and technical aspects as test techniques, book building, program tuning etc

Moderator: Andres Valverde

tips for a good evaluation function! help!

Postby pimidrez » 31 May 2008, 21:10

hello everyone, my english is not good but please hepl me jeje :wink:

Im writing a chess engine in Basic, but i dont know why he still playing bad...

Features:
he only can play at 3 PLY (i know is a low level, but the most of the programs can play a good game at this deep)

the evaluation function analyzes:
*Material Balance
*Mobility of the pieces (one point for each cell that can move)
*Center control with pawns
*Doubled Pawns (-4 points if exist double pawns)
*Passed Pawns (5 points if exist a passed pawn)
*Connected Rooks (5 points if exist a connection)
*Position of pieces in certain parts of the board

it also give a bonus for keeping the two towers, the two knights, the queen...
I know that is a lazy evaluation, but I dont find more things to evaluate...
please someone tell me something to make my program stronger

thanks to all!![/list]
pimidrez
 
Posts: 46
Joined: 31 May 2008, 20:47

Re: tips for a good evaluation function! help!

Postby Onno Garms » 31 May 2008, 21:28

If your engine can search only three plies, most likely an improvement of the search efficiency will pay off much better then tuning of the evaluation function.

You might want to add more PST then just center control by pawns. Or is that what you mean by "position of pieces in certain parts of the board"? PST cheap in terms of implementation time as well as in terms of runtime.

Your doubled malus and passed bonus seems to be very small (if it's centipawns).

I don't think that connected rooks are good in general. Having both rooks or both knights is definitely not a reason for a bonus, but having two bishops is.

King safety is missing, but I would go for the search efficiency first.
User avatar
Onno Garms
 
Posts: 128
Joined: 17 Feb 2007, 11:17
Location: Bonn, Germany

Re: tips for a good evaluation function! help!

Postby pimidrez » 31 May 2008, 21:58

HI Onno Garms!

I am somewhat concerned about the scores that I apply at each point of the evaluation...
In dont work with centi-pawns cause i dont know how its works.

the scores are in numbers without decimals, or hundredths (like: 5, 1, 10, -3)...

for keeping both bishops the bonus is of 40 points (maybe is too much).

the material socores is:
Queen: 8, Knigt: 2.5, rook: 4, bishop: 3, pawn: 1.

I also give 10 points for having a pawn on center (e4,e5,d4,d5)

I penalized for having a knight or bishop on first rank with: -5 points

should I count the connection of friendly pieces like protection of the team or its depend of each piece??

thanks
pimidrez
 
Posts: 46
Joined: 31 May 2008, 20:47

Re: tips for a good evaluation function! help!

Postby Pedro Castro » 01 Jun 2008, 02:55

If you want to connect your engine to a GUI, you need a protocol, xboard or uci.

To send information of the evaluation to GUI, you have to do in centipawns, this is simply multiplied by 100.

So the values of material you have to take are:

Queen: 800, Knigt: 250, rook: 400, bishop: 300, pawn: 100

Now if it makes sense to eval the bishops pair with 40, as otherwise this is worth more than all the material together.

Build for each type of piece a table of positions PST, even for each piece can take 2 boards, one for the opening-midlegame and one for the endgame. The best thing in the middle game is that the king is castled and in the endgame the best thing is that the king go to the middle of the board.

int king_pcsq[64] = {
-30,-30,-30,-30,-30,-30,-30,-30,
-30,-30,-30,-30,-30,-30,-30,-30,
-30,-30,-30,-30,-30,-30,-30,-30,
-30,-30,-30,-30,-30,-30,-30,-30,
-30,-30,-30,-30,-30,-30,-30,-30,
-30,-30,-30,-30,-30,-30,-30,-30,
-3, -2, -5,-10,-10, -5, -2, -3,
-5, 20, 40, -5, -5, 0, 40, -5
};

int king_endgame_pcsq[64] = {
-5, 0, 0, 1, 1, 0, 0, -5,
-4, 7, 10, 10, 10, 10, 7, -4,
0, 10, 15, 20, 20, 15, 10, 0,
1, 10, 20, 30, 30, 20, 10, 1,
1, 10, 20, 30, 30, 20, 10, 1,
0, 10, 15, 20, 20, 15, 10, 0,
-4, 7, 10, 10, 10, 10, 7, -4,
-5, 0, 0, 1, 1, 0, 0, -5
};

The connection of the rooks has its importance in the seventh and eighth rows (maybe here too queen and rook). Other pieces not.

Passed pawns are very dangers and more as they are closer to the seventh row, rate more, you can make an eval by rows, for example passedpawn[] = {0, 0, 0, 20, 40, 70, 110, 0}
Best wishes,

Pedro Castro
User avatar
Pedro Castro
 
Posts: 180
Joined: 28 Jan 2005, 01:09
Location: Pays Basque (Spain)

Re: tips for a good evaluation function! help!

Postby pimidrez » 01 Jun 2008, 04:29

THANKS PEDRO CASTRO!!

really helps me your message!! (Im from argentina if youre spanish please write in spañish jejej 8-) )

Now I want to know how can I control that my engine make stupid movements...like move a knight to a dangerous and unprotected cell...

I play my engine against others engines at 1ply...but my engine still losing terrible games jejej

definitely my evaluation function is not good...jeje...im newbiee :mrgreen:

I aplicating right now all the "tips" you and other guys are telling me..

thanks, And I'll hear all sugestions!!! jeje
pimidrez
 
Posts: 46
Joined: 31 May 2008, 20:47

Re: tips for a good evaluation function! help!

Postby Pedro Castro » 01 Jun 2008, 05:11

Hola,

Desconozco en que fase de programación está tu programa. Como dices que estás jugando ya contra otros motores entiendo entonces que el generador de movimientos ya lo tienes completo. También tendrás una búsqueda y una evaluación.

Como te han sugerido anteriormente, de momento olvida un poco la evaluación, centrate en la búsqueda. Para la evaluación utiliza solo el material de cada pieza.

Si mueven blancas haces: score = score_blancas - score_negras
Si mueven negras entonces la evaluación será -score

score_blancas es la suma de material para las blancas y lo mismo para score_negro.

Para la búsqueda hoy en día todo el mundo utiliza un algoritmo llamado alphabeta, es algo más evolucionado que el mini-max y el negamax, de estos 3 algoritmos tienes buena explicación en la página de Bruce Moreland. Simplemente con el más sencillo de ellos deberías tener profundidas de 4 plys bastante rápido.

http://web.archive.org/web/200707070125 ... /index.htm

Si juegas en 1 ply y tu programa pierde piezas, entonces tienes un problema que se llama efecto horizonte. Por ejemplo tu dama quizás se come un peón del contrario y no se da cuenta el programa que está defendido.

Para evitar el efecto horizonte, cuando tu haces una búsqueda en profundidad 1 para ver cual es el mejor movimiento, cuando reduces la profundidad y te quedas en 0, en ese momento se llama a una función que se suele denominar quiescent search, en lugar de llamar a la evaluación, esa función comprueba si en la posición final hay posibles capturas y promociones, por lo que los motores en lugar de tener un generador de movimientos, tienen 2, uno para generar todos los movimientos y otro que solo genera capturas y promociones utilizado en la qsearch.

Para que el algoritmo alphabeta sea eficiente, hay que ordenar los movimientos de la lista de mejor a peor, primero se utiliza el movimiento de la tabla hash, aunque de momento supongo que no estás utilizando dichas tablas, luego puedes colocar el movimiento de la variante principal en su profundidad anterior, luego se suelen colocar las capturas, movimientos killers, etc.

Cuando mejore la profundidad de la búsqueda entonces ya puedes quizás pensar en mejorar la evaluación.

Recomendable que estudies un poco el código de algún programa; Firstchess, TSCP...

Tienes también otra buena página de programación basada en el programa Rebel.

http://www.top-5000.nl/authors/rebel/chess840.htm

Bueno, ya irás indicando tus progresos.
Best wishes,

Pedro Castro
User avatar
Pedro Castro
 
Posts: 180
Joined: 28 Jan 2005, 01:09
Location: Pays Basque (Spain)

Re: tips for a good evaluation function! help!

Postby Onno Garms » 01 Jun 2008, 06:35

I don't understand your scores. A queen value of 8 obviously does not fit a bishop pair value of 40.

Your piece values are inadequate. A knight is definitely worth more than 2.5 pawns, a rook more then a bishop and a pawn. A knight and a bishop have the same value unless the bishop comes in a pair. Try to start with knight=bishop=3.25, rook=5, queen=9.75

I cannot read the Spanish messages.
User avatar
Onno Garms
 
Posts: 128
Joined: 17 Feb 2007, 11:17
Location: Bonn, Germany

Re: tips for a good evaluation function! help!

Postby Harald Johnsen » 01 Jun 2008, 14:36

pimidrez wrote:Now I want to know how can I control that my engine make stupid movements...like move a knight to a dangerous and unprotected cell...

I play my engine against others engines at 1ply...but my engine still losing terrible games jejej

definitely my evaluation function is not good...jeje...im newbiee :mrgreen:



Do you have a quiescent search in your engine ? If not this is a must have and will give a boost to your engine.

And, the obvious, but it's allways good to say, check that you don't have bugs in your search. If you are searching only at 3 plies then you can dump your search tree to a text file (the current variant, the score, the alpha/beta bounds) to verify that it's correct.

HJ.
User avatar
Harald Johnsen
 
Posts: 43
Joined: 20 Aug 2007, 17:01
Location: France

Re: tips for a good evaluation function! help!

Postby pimidrez » 01 Jun 2008, 20:23

hello everyone!!
thanks for the help!!

Now I leave only the material balance evaluation.

Onno Garms Im already applying the scores you gave me for pieces!

I have alpha-beta pruning...and I order first the killer moves and then all the others...That gave me more speed compared to before...
but anyway takes more than 30 seconds to anlyse all the moves.. :shock:

I don't have quiescent search in my engine... :(
so..
quiescent search means to verify if in the final position (3ply) are possible captures and promotions??
...and if exist a possible capture of an unprotected bishop with a pawn for example...do I have to penalise this position? or eliminate this posible move?
or what to do?

one more question:
whats the "bonus" for a position with check??

thanks to all!!!!!!!
pimidrez
 
Posts: 46
Joined: 31 May 2008, 20:47

Re: tips for a good evaluation function! help!

Postby Sven Schüle » 03 Jun 2008, 18:12

Hi, pimidrez,

I suggest that you have a look at http://web.archive.org/web/20070707012511/http://www.brucemo.com/compchess/programming/index.htm which might give you a lot of help. It also explains the quiescence search, beneath many other chess programming topics.

Sven
User avatar
Sven Schüle
 
Posts: 240
Joined: 26 Sep 2004, 20:19
Location: Berlin, Germany

Re: tips for a good evaluation function! help!

Postby Sven Schüle » 03 Jun 2008, 18:16

pimidrez wrote:whats the "bonus" for a position with check??

Usually you don't evaluate a position where the side to move is in check. Instead you extend the full search by one ply at such a node.

Sven
User avatar
Sven Schüle
 
Posts: 240
Joined: 26 Sep 2004, 20:19
Location: Berlin, Germany

Re: tips for a good evaluation function! help!

Postby pimidrez » 03 Jun 2008, 18:21

hi Sven!

with:
whats the "bonus" for a position with check??

I try to say that the side to move is not the one in check...

so..
In case that the side to move is making check to the oponent..whats the bonus for that position??

thanks to everyone!!
my engine is getting better!! :mrgreen:
pimidrez
 
Posts: 46
Joined: 31 May 2008, 20:47

Re: tips for a good evaluation function! help!

Postby Sven Schüle » 03 Jun 2008, 20:48

pimidrez wrote:I try to say that the side to move is not the one in check...
Hm, sounds confusing because this would be an illegal position.

Side to move in check => usually extend one ply => usually no eval and no "bonus"

Opponent in check => Side to move can capture the king => Opponent's previous move was illegal => definitely no eval and no "bonus"

Sven
User avatar
Sven Schüle
 
Posts: 240
Joined: 26 Sep 2004, 20:19
Location: Berlin, Germany

Re: tips for a good evaluation function! help!

Postby pimidrez » 04 Jun 2008, 02:40

Hello sven...maybe you dont understand my doubt, or maybe Im saying something wrong jeje

what im trying to say is:
if the side to move finds a position that leaves the Opponent's Kings in check...
whats the "bonus" for the side to move for leaving the opponent in check??
pimidrez
 
Posts: 46
Joined: 31 May 2008, 20:47

Re: tips for a good evaluation function! help!

Postby Pedro Castro » 04 Jun 2008, 14:38

pimidrez wrote:Hello sven...maybe you dont understand my doubt, or maybe Im saying something wrong jeje

what im trying to say is:
if the side to move finds a position that leaves the Opponent's Kings in check...
whats the "bonus" for the side to move for leaving the opponent in check??


Most programs do not give a bonus to give check, but if that is usual in these cases extend deep into 1.

if check depth ++;

DanaSah if that proves to give half pawn bonus, it seems that some mate are faster.
Best wishes,

Pedro Castro
User avatar
Pedro Castro
 
Posts: 180
Joined: 28 Jan 2005, 01:09
Location: Pays Basque (Spain)

Re: tips for a good evaluation function! help!

Postby Sven Schüle » 05 Jun 2008, 22:50

pimidrez wrote:if the side to move finds a position that leaves the Opponent's Kings in check...
whats the "bonus" for the side to move for leaving the opponent in check??

I expect that you do not intend to give a bonus in case the side to move has the _opportunity_ to give check with at least one of his legal moves (which would be very unusual).

So the only thing I can imagine is that you think about evaluating the position _after_ having made a checking move. Now "side to move" has changed to the former "opponent", and he is now in check. That's what I meant in my previous postings. If this is what you mean then my advice remains the same: do not assign any bonus for it. A proper search algorithm will detect "in check" nodes as non-leaves anyway, so most probably there will be no evaluation at all.

If you still have something different in mind then I kindly ask you to give an example.

Sven
User avatar
Sven Schüle
 
Posts: 240
Joined: 26 Sep 2004, 20:19
Location: Berlin, Germany


Return to Programming and Technical Discussions

Who is online

Users browsing this forum: No registered users and 41 guests