tips for a good evaluation function! help!
Posted:
31 May 2008, 21:10
by pimidrez
hello everyone, my english is not good but please hepl me jeje
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]
Re: tips for a good evaluation function! help!
Posted:
31 May 2008, 21:28
by Onno Garms
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.
Re: tips for a good evaluation function! help!
Posted:
31 May 2008, 21:58
by pimidrez
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
Re: tips for a good evaluation function! help!
Posted:
01 Jun 2008, 02:55
by Pedro Castro
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}
Re: tips for a good evaluation function! help!
Posted:
01 Jun 2008, 04:29
by pimidrez
THANKS PEDRO CASTRO!!
really helps me your message!! (Im from argentina if youre spanish please write in spañish jejej
)
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
I aplicating right now all the "tips" you and other guys are telling me..
thanks, And I'll hear all sugestions!!! jeje
Re: tips for a good evaluation function! help!
Posted:
01 Jun 2008, 05:11
by Pedro Castro
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.
Re: tips for a good evaluation function! help!
Posted:
01 Jun 2008, 06:35
by Onno Garms
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.
Re: tips for a good evaluation function! help!
Posted:
01 Jun 2008, 20:23
by pimidrez
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..
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!!!!!!!
Re: tips for a good evaluation function! help!
Posted:
05 Jun 2008, 22:50
by Sven Schüle
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