handleGo method

void handleGo(
  1. List<String> parts
)

Implementation

void handleGo(List<String> parts) async {
  int moveTime = 5000;
  int movetimeIndex = parts.indexOf('movetime');
  if (movetimeIndex != -1 && movetimeIndex + 1 < parts.length) {
    moveTime = int.tryParse(parts[movetimeIndex + 1]) ?? 5000;
  }
  isSearching = true;

  if (mcts != null) {
    // Pass the time limit to the monteCarlo function
    mc.EngineResult result = await mcts!.monteCarlo(timeLimit: moveTime);
    isSearching = false;

    if (result.hasMove) {
      stdout.writeln('bestmove ${game.toAlgebraic(result.move!)}');
    }
  }
}