package de.nowchess.bot

import de.nowchess.api.board.{Board, Color, File, Piece, PieceType, Rank, Square}
import de.nowchess.api.game.GameContext
import de.nowchess.api.board.Board
import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers

class EvaluationTest extends AnyFunSuite with Matchers:

  test("initial position evaluates to tempo bonus"):
    val eval = Evaluation.evaluate(GameContext.initial)
    eval should equal(10)  // TEMPO_BONUS only

  test("remove white queen gives negative evaluation"):
    val initial = GameContext.initial
    val board = initial.board
    val emptySquare = Square(File.D, Rank.R1)
    val boardWithoutQueen = board.pieces.filter((sq, _) => sq != emptySquare)
    val newContext = initial.withBoard(Board(boardWithoutQueen))
    val eval = Evaluation.evaluate(newContext)
    eval should be < 0

  test("remove black queen gives positive evaluation"):
    val initial = GameContext.initial
    val board = initial.board
    val emptySquare = Square(File.D, Rank.R8)
    val boardWithoutQueen = board.pieces.filter((sq, _) => sq != emptySquare)
    val newContext = initial.withBoard(Board(boardWithoutQueen))
    val eval = Evaluation.evaluate(newContext)
    eval should be > 0

  test("different piece-square bonuses are applied"):
    // Knight on d4 (center) vs knight on a1 (corner) - center should be better
    val knightD4Board = Board(Map(Square(File.D, Rank.R4) -> Piece.WhiteKnight))
    val knightA1Board = Board(Map(Square(File.A, Rank.R1) -> Piece.WhiteKnight))
    val knightD4 = GameContext.initial.withBoard(knightD4Board)
    val knightA1 = GameContext.initial.withBoard(knightA1Board)

    val eval1 = Evaluation.evaluate(knightD4)
    val eval2 = Evaluation.evaluate(knightA1)
    eval1 should be > eval2  // d4 (center) is better than a1 (corner) for knight

  test("all piece types are in material map"):
    PieceType.values.length should be > 0
    // Just verify evaluate works with all piece types
    val eval = Evaluation.evaluate(GameContext.initial)
    eval should not be (Evaluation.CHECKMATE_SCORE)

  test("CHECKMATE_SCORE and DRAW_SCORE are accessible"):
    Evaluation.CHECKMATE_SCORE should equal(10_000_000)
    Evaluation.DRAW_SCORE should equal(0)
