If this node is in check, then all moves are generated, so if no moves are generated here, a checkmate score is returned.
If this node is not in check, then just captures on the last TO square are considered, if there are non, then I use the score from the static evaluation..
Code: Select all
int QS(int ALPHA, int BETA, int DEPTH, int LAST_TO)
{
staticEval=getEval();
if(NOT_IN_CHECK && SIDE_TO_MOVE_HAS_MORE_THAN_2_PIECES)
{
if(staticEval >= BETA ) return BETA
}
if(IN_CHECK)
{
MOVES=generateAllMoves()
if(MOVES is not empty)
{
for(each MOVE in MOVES)
{
MakeMove(MOVE)
val = -QS(-BETA,-ALPHA, DEPTH-1, MOVE.TO)
UndoMove(MOVE)
if(val>=BETA) return BETA;
if(val>ALPHA) ALPHA=val;
}
}
else // NO MOVES GENERATED
{
return MateScore(DEPTH)
}
}
if(NOT_IN_CHECK)
{
MOVES=generateAllCapturesOnLastTO_Square(LAST_TO)
if(MOVES is not empty)
{
for(each MOVE in MOVES)
{
MakeMove(MOVE)
val = -QS(-BETA,-ALPHA, DEPTH-1, MOVE.TO)
UndoMove(MOVE)
if(val>=BETA) return BETA;
if(val>ALPHA) ALPHA=val;
}
}
else // NO MOVES GENERATED
{
val=staticEval;
if(val>ALPHA) ALPHA=val;
if(val>=BETA) return BETA;
}
}
return ALPHA
}
I realize I'm overlooking many captures, but I'm trying to avoid an explosion in the tree size.
Is it a good idea to handle positions in check with a full move generation, and to return a mate score when no moves are available(when position is in check)?
Thanks for any advice.