Advertisement
Guest User

Untitled

a guest
Apr 29th, 2024
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.72 KB | None | 0 0
  1. public class Engine
  2. {
  3.     public static int search(int depth, int alpha, int beta, Board board, int ply)
  4.     {
  5.         if (board.isMated())
  6.         {
  7.             return -100000 + ply;
  8.         }
  9.  
  10.         if (board.isDraw())
  11.         {
  12.             return 0;
  13.         }
  14.  
  15.         if (depth <= 0)
  16.         {
  17.             return qsearch(alpha, beta, board, ply);
  18.         }
  19.  
  20.         int bestValue = Integer.MIN_VALUE;
  21.  
  22.         for (Move move : board.legalMoves())
  23.         {
  24.             board.doMove(move);
  25.  
  26.             nodes++;
  27.             int thisMoveValue = -search(depth - 1, -beta, -alpha, board, ply + 1);
  28.  
  29.             board.undoMove();
  30.  
  31.             bestValue = Math.max(thisMoveValue, bestValue);
  32.  
  33.             if (bestValue > alpha)
  34.             {
  35.                 if (bestValue > beta)
  36.                 {
  37.                     return bestValue;
  38.                 }
  39.  
  40.                 alpha = bestValue;
  41.             }
  42.         }
  43.  
  44.         return bestValue;
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement