package de.nowchess.bot.bots

import de.nowchess.api.game.GameContext
import de.nowchess.api.move.Move
import de.nowchess.bot.bots.nnue.EvaluationNNUE
import de.nowchess.bot.logic.AlphaBetaSearch
import de.nowchess.bot.util.PolyglotBook
import de.nowchess.bot.{Bot, BotDifficulty}
import de.nowchess.rules.RuleSet
import de.nowchess.rules.sets.DefaultRules

final class NNUEBot(
  difficulty: BotDifficulty,
  rules: RuleSet = DefaultRules,
  book: Option[PolyglotBook] = None
) extends Bot:

  private val search: AlphaBetaSearch = AlphaBetaSearch(rules, weights = EvaluationNNUE)
  private val TIME_BUDGET_MS = 1000L

  override val name: String = s"NNUEBot(${difficulty.toString})"

  override def nextMove(context: GameContext): Option[Move] =
    book.flatMap(_.probe(context))
      .orElse(search.bestMoveWithTime(context, TIME_BUDGET_MS))
