Advertisement

good chess hueristics

Started by October 09, 2004 12:27 PM
14 comments, last by Nice Coder 20 years, 1 month ago
Try to have a bonus for protection of pieces (like a bishop-pawn combo).

You hsould also have a bonus for thnigs like attacking 2 or more pieces (bonus++ if they are pawns). Same goes for squares. Controlling the *other side* of the board is also quite nice to do (things like get a rook on 8, it makes things so much easier.)

Maybe some sort of "checkmate solver" could come in handy. Every time on of the marked pieces moves (or the king moves), the board is resolved, to figure out which pieces to kill to cause a checkmate.

It would be more advanced then that, maybe looking at which squares are vonrable and which squares (which may or may not be occupied) should be taken to cut down on the possible moves of the king (for eg. if you were to take pawn p5, then you would get ahead.

p1|p2|p3|p4|p5
..|..|.K|..|..

p1|p2|p3|p4|b1
..|.K|..|..|..

You have now trapped the king, another bishop on p4 would also be nice. a rook on p4 could prove fatal for your opponant. What yo uneed is some sort of coefficient to figure out how good that square is, compared to the effort of getting there.

Now if, in order to take that square (if it was a really good square, like the one right on top of the king, or a row which cannot be blocked by a piece (eg. you have one rook, and your opponant has none).),
you had to take a piece, you would do hte same thing with that piece, look for the vectores needed to take it.
check all avalible pieces, and compute the reward/effort coefficient in taking that piece. you would then multiply it with how much that piece is worth.
if in order to take that piece, you need to take another piece, repeat.

This might make a nice little side-project.

From,
Nice coder
Click here to patch the mozilla IDN exploit, or click Here then type in Network.enableidn and set its value to false. Restart the browser for the patches to work.
great thanks for the input guys! now i've implemented some of the rules u mentioned but when its near the end of the game the ai has a problem with sticking with a plan. For instance when only the white king is left and a black king, queen and rook are left, it's fighting between several different check mates (its selecting a different move seqence every time it makes a move (cause the white king shits positions at each move). any ideas? thanks
Advertisement
How are you handling checkmates score? Make 'nearer' checkmates (checkmates that happen in fewer moves) more valuable than checkmates that happen in more moves.

This way it sould always stick to the same path to mate.

Will
------------------http://www.nentari.com
Perhaps have some sort of inersea, and distance to completion, change the persieved havue of a plan. the inersia would stop it from wanting to try a different plan every turn.

from,
Nice coder
Click here to patch the mozilla IDN exploit, or click Here then type in Network.enableidn and set its value to false. Restart the browser for the patches to work.
I had never coded any chess engine so far, but from my expirience as a chess player, where I tried to do lots of chess training, I would like to add some hints for your engine:

In middle and end games there is a rules that tells that healty games have ALL pieces moving from time to time. This rule is not meant to be used exactly, excludes pawns (mostly), but tells a lot about game quality. If only few pieces are moving within any time windows (# of plys), famous games show generally that there is already an advantage or poor play in progress. So if you have that situation and there is no advantage for any side, you might look more for other pieces first that could make usefull moves, than for the few pieces that have already moved a lot. In endgames there should not be any ONLY MOVING piece as long as there is not only the king left, or there is a great advantage (forced moves) for one side and this for perhaps no winning possiblility any more, because of lack of tempi.

Try to weight material dynamically. Pieces that moved in the very past have some temporary higher value and a lower exchange value (the might gain for piece exchange).

If there is only one bishop left for one side, DO NOT count it equal to a knight, since one knight can go any square, but a bishop only half the squares on the board for the rest of the game. Single bishops are often overestimated from chess engines at this point and lead to strategic fail. If material values is equal but one side has 2 bishops and the other only one, there is an potential advantage for the two bishops even with closed diagonal lines, since the opponent might open them for gaining the advantage in reality.

Do not forget to do not cut to early for pieces that have moved at the latest plys. They have a large dynimic value and might even exchange pieces with much less value (sacrifice) to gain advantage. So you should look more into deepth for all possible moves for them.
Below is a chess game played via email, where I had expected my oponent to use a chess engine (what was not forbidden at all). The oponents engine did not expect a queens sacrifice and for this did not search deep enough into this variant. I had checked this for the most common chess engines (fritz7/8, shredder6, nimzo, hiarcs8) and they all failed for expecting 18...Qd1+ in the 17. move and for realizing the resulting disadvantage from the kings little space left and the following forced moves.
This game shows very well the typical weakness of todays chess engines, ignoring dynamic value of a lately moved pieces:

[Event "CC-2003-0-00054"]
[Site "IECG"]
[Date "2003.01.26"]
[Round "1"]
[White "Delooz, Philippe"]
[Black "Gruber, Sebastian Andreas"]
[Result "0-1"]

1.e4 d5 2.exd5 Qxd5 3.Nc3 Qa5 4.d4 Nf6 5.Nf3 Bf5 6.Bc4 e6 7.Bd2 c6 8.Ne4 Qc7 9.Nxf6+ gxf6 10.Nh4 Bg6 11.f4 f5 12.Qf3 Nd7 13.Qc3 Be7 14.Nf3 Bh5 15.Ne5 0-0-0 16.Qh3 Nxe5 17.dxe5 Qd7 18.Bc3 Qd1+ 19.Rxd1 Rxd1+ 20.Kf2 Bc5+ 21.Kg3 Rg8+ 22.Kh4 Rxh1 23.Kxh5 Bg1 24.Kh6 Rxh2 25.Bf1 Rxh3+ 26.gxh3 Be3 27.Kxh7 Rg1 28.Be2 Bxf4 29.h4 Bxe5 30.Bxe5 Re1 31.Bc4 Rxe5 32.h5 f4 33.h6 Rg5 34.Bd3 f3 0-1

By the way, most engines rate the white play with little advantage, while white mostly moves repetitive 1 knight and the queen most the time... which is absolte crap!

But you should have a sacrifices search anyway, no matter of piece was moved or not...!!!

You might also have dynamic values for squares related to be being moved at or from within some time window (plys). Mostly those squares are very important for the upcoming moves, especially when located on the oponents side of the board of course. So all pieces that can claim such squares are becoming more important and should be searched heavier (deeper). This is much more important than simply building sums over controlled squares, because lots of them are unimportant to the strategic and tactic aspects of a game.

All in all the dynamic part of games is not solved very well even with the right now strongest chess engines. Even an average human player, like me, with support of a analytic chess engine, will always win against any of the so called strongest chess engines right now. And static evaluation functions will prevent from loosing pieces for nothing, but the make no good game play at all since chess is all about dynamic. ;-)

I also would advice you to play correspondence chess (where engines allowed and welcome for analysing) and check your engine development against playing such games... this might help a lot for enhancing your chess engines quality.

I'd advice to remember that an engine equal with other engines and world class players simply knows to prevent bad moves, but the good moves are still created only by human brain... ;-))

In this sense it is usefull to have good searching technic, but the most important is what you actually look for when searching

[Edited by - Sebastian Gruber on October 23, 2004 3:51:57 PM]
-----------------------------I found some tools that grant me 30% less development time and also about 30% less computation usage. Well, I was curious and started making use of more of them and guess what? I found myself cutting down a 5 year development process with only 20 tools down to less than a day granting me a little more than 190 times computation speed.I thought, "Jesus! It's not first of april right now!" But I know there is a next 1st of april going to come for certain and perhaps I might gain all those advantages promised then?! One never knows...
Maybe you could try a multi-level gameplan?

You have a few levels (2,5,?)

on level1 you have your normal gamebord

Then for each level above that, you summerize the board at that level.

This would mean that you can search at heigher levels, and see very far into the future, because the amount of board states would be smaller. (and as such the amount of nodes which would be searched would also be much smaller).

HTH.
From,
Nice coder.
Click here to patch the mozilla IDN exploit, or click Here then type in Network.enableidn and set its value to false. Restart the browser for the patches to work.

This topic is closed to new replies.

Advertisement