package de.nowchess.bot

import de.nowchess.api.game.GameContext
import de.nowchess.api.move.Move
import de.nowchess.rules.RuleSet
import de.nowchess.rules.sets.DefaultRules

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

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

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

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