Fguy64 wrote:OK, it has been suggested that my current method of making sure the king is not exposed to check is very inefficient. In my current setup, the last thing that moveGen does with every candidate move, before it is searched, is run an issquareAttacked method on the king in the resulting position.
So I've been thinking this over, and it occurs to me that all I need to do is remove this check check

from MoveGen, and add a line at the beginning of alphaBeta() that determines whether or not the side to move in the current node has a king. If the answer is no, then return an appropriately extreme value. Sound ok?
Anyways, it's a simple idea, I could just try it, but I thought I'd bounce it off the board, such questions usually generate interesting discussion. The idea is intuitive enough that if it is correct, then I imagine it is probably de rigeur.
I assume you are talking about your implementation of legality check. I think your current solution is not really bad but can be slightly improved. What you are doing is not uncommon: after making a move on the board within the search, you check whether this move left your own king in check. So in fact you are not performing this check during move generation but within search, so you avoid to do unnecessary legality checks for many moves that will never be made on the board due to cutoffs. And it's fine this way.
An optional, small (or perhaps medium) improvement is possible if you restrict the expensive "enemy king in check" test to only those moves which may have any potential to be illegal. A pseudo-legal move is illegal if it either puts the own king into a check that was not present before, or if it does not escape from a check that was given. So you can write a test function that decides whether the move that thas just been made on the board may have been illegal at all, and return "true" if either
- in the previous position, your king had been in check (this requires an "in check" flag per historical position), or
- your move is a king move (with special care about castling), or
- you are moving a pinned piece,
otherwise "false". You probably won't save a lot but it should be measureable.
Your other proposal is not really new, this would turn your engine into something that is well known as "king capture engine". It is possible to do it that way but today most programmers seem to agree that other methods of legality checking are more efficient than "king capture". I skip the details here; to my knowledge one of the key points is that in positions where the king of the moving side is in check, "king capture" is quite inefficient since there are many illegal moves.
Sven