by crystalclear » 29 Oct 2011, 04:06
There are various places in a chess program that you can test for checkmate, or ways of doing it.
example 1.
When a move is made, the program might mark check positions with a flag or something and for check positions might further analyse them to see if they are checkmate.
example 2.
Another way of doing things is to use the count of the number of moves created by the move generator when doing the search and if it is zero then the position is mate: checkmate or stalemate. If it is some kind of mate, then you can see whether the position has a check or not to distinguish the two case.
=
In example 1, the first time an iterative deepening search encounters the position, it see that it is checkmate, scores it as such and return an extreme score value. The program will find a mate in 3 with a depth 3 search.
In example 2, depth 2 searches don't come across the checkmate position for a mate in 3. A depth 3 search will see the position, but just score it on its material value etc. And then iterative deepening looking at depth 4, will try all the moves from that position, find there are none, realise that the position is mate: checkmate, since there is a check, and return the extreme value that would finish a mate search, but only at depth 4 for a mate in 3.
Since a lot of extra searching is potentially done, I don't think many engines work like example 2, at least after some initial testing and improvements.
===
There is a potential recusion problem with the method of example 1: if makeing a move tests for mate, if testing for mate consists of counting moves from the move generator, and if the moves generator tests moves for legality by making them and verifying the mover has not left himself in check.
To avoid that, I think some chess engines have a full blown make-move and a lazy or quick make-move.
=
Incidentally, I have just started looking at mate searches and I had the idea of having a mate search specific evaluation function that pretty much ignoresthe value of the material on the board and instead scores positons by rewarding mate related ideas like checks, removal of flight squares etc. (Is that spelling right? Flight from the verb flee, not flight from fly!)
Is there anything written anywhere that could guide me in writing a good mate-search-specific evaluation function?
Also, if I don't find mate in 3 (5 ply search), the next possible mate (if I am not looking also for mated!) is mate in 4, ie (7 ply).
Are there any tricks I should know with regard to treating the odd and even plys differently?
====
A final note: most of the recent posts are mine. If I am writing too much and should shut up, please say. Really, I thought this forum would be more busy when I registered and I am starting to feel I am talking to myself most of the time!