ok, here is my new makeMove method. Which works more or less as follows: I trust it is familiar enough that comments are not required.
1. This method first makes a call to possibleMoves(), which is a non-recursive method that returns a list of all possible legal moves.
2. alpha and beta are initialized
3. we loop through the possible moves list, eveluating each move recursively by passing the position after the move to the search function.
4. At each iteration, alpha is updated if necessary to reflect the "best Move so far".
5. Notice I stop searching altogether if a mating line is found. The ply -= 2; line is placed to ensure that the engine "finds" the same forcing line, or one equally as fast, at the next turn, which I suppose is my concession to a lack of a hash table at this point.
OK a few comments...
Q1: it is not clear to me if I should be doing anything with beta in this method. I don't think so.
Q2: I believe earlier "confusion" about my stop condition on the search originates here. Perhaps since my initial "possibleMoves" is non recursive, perhaps it would be more in line with convention if I passed ply-1 at this stage, which would indeed result in a stop condition of ply=0 instead of ply=1 in my search function.
Q3: Since my initial ply is non-recursive, I believe it is correct to pass -beta, -alpha at this initial call to search. In my actual search method siginature, these values will be accepted as alpha, beta.
OK, once I get this method nailed down, I move on to my recursive search method.
Sound good to you?
regards.
Fred.
Code: Select all
public Move makeMove( String pStr ) {
if( diagnostics ) output.setText("");
think = true;
CMove[] list1 = possibleMoves(pStr);
if( list1.length == 0 ) {
if( inCheck( pStr ) ) return new Move( "Checkmate", false );
else return new Move("Stalemate", false );
}
int alpha = -10000;
int beta = 10000;
for( CMove cm : list1 ) {
cm.eval = search( cm.pStr, ply, -beta, -alpha );
if( cm1.eval > alpha ) alpha = cm1.eval;
// if a mating line is found, stop searching
if( cm.eval == 10000 ) {
ply -=2;
return new Move( pStr.charAt(cm1.i), cm1, "forced mate");
}
}
// code here to select the move with the maximum eval
return bestMove;
}