private void OnSearchUpdate(object sender, SearchStatistics stats) { var score = FormatScore(stats.Score); var principalVariation = FormatPrincipalVariation(stats.PrincipalVariation, stats.PrincipalVariationMovesCount); Send($"info depth {stats.Depth} seldepth {stats.SelectiveDepth} time {stats.SearchTime} " + $"score {score} nodes {stats.TotalNodes} nps {stats.TotalNodesPerSecond} pv {principalVariation}"); if (_debugMode) { var evaluationStatistics = new EvaluationStatistics(); var openingPhase = stats.Board.GetPhaseRatio(); var endingPhase = BoardConstants.PhaseResolution - openingPhase; var fieldsAttackedByWhite = 0ul; var fieldsAttackedByBlack = 0ul; var materialEvaluation = MaterialEvaluator.Evaluate(stats.Board); var castlingEvaluation = CastlingEvaluator.Evaluate(stats.Board, openingPhase, endingPhase); var positionEvaluation = PositionEvaluator.Evaluate(stats.Board, openingPhase, endingPhase); var pawnStructureEvaluation = PawnStructureEvaluator.Evaluate(stats.Board, evaluationStatistics, openingPhase, endingPhase); var mobility = MobilityEvaluator.Evaluate(stats.Board, openingPhase, endingPhase, ref fieldsAttackedByWhite, ref fieldsAttackedByBlack); var kingSafety = KingSafetyEvaluator.Evaluate(stats.Board, openingPhase, endingPhase, fieldsAttackedByWhite, fieldsAttackedByBlack); var pieces = PiecesEvaluator.Evaluate(stats.Board, openingPhase, endingPhase); var fianchetto = FianchettoEvaluator.Evaluate(stats.Board, openingPhase, endingPhase); var total = materialEvaluation + castlingEvaluation + positionEvaluation + pawnStructureEvaluation + mobility + kingSafety + pieces; Send($"info string evaluation {total} phase {openingPhase} material {materialEvaluation} castling {castlingEvaluation} " + $"position {positionEvaluation} pawns {pawnStructureEvaluation} mobility {mobility} ksafety {kingSafety} " + $"pieces {pieces} fianchetto {fianchetto} irrmoves {stats.Board.IrreversibleMovesCount}"); } }
public static int Evaluate(BoardState board, bool enableCache, EvaluationStatistics statistics) { var openingPhase = board.GetPhaseRatio(); var endingPhase = BoardConstants.PhaseResolution - openingPhase; var result = MaterialEvaluator.Evaluate(board); result += enableCache ? PawnStructureEvaluator.Evaluate(board, statistics, openingPhase, endingPhase) : PawnStructureEvaluator.EvaluateWithoutCache(board, statistics, openingPhase, endingPhase); result += PositionEvaluator.Evaluate(board, openingPhase, endingPhase); if (endingPhase != BoardConstants.PhaseResolution) { var fieldsAttackedByWhite = 0ul; var fieldsAttackedByBlack = 0ul; result += MobilityEvaluator.Evaluate(board, openingPhase, endingPhase, ref fieldsAttackedByWhite, ref fieldsAttackedByBlack); result += KingSafetyEvaluator.Evaluate(board, openingPhase, endingPhase, fieldsAttackedByWhite, fieldsAttackedByBlack); result += RookEvaluator.Evaluate(board, openingPhase, endingPhase); result += BishopEvaluator.Evaluate(board, openingPhase, endingPhase); } return(board.ColorToMove == Color.White ? result : -result); }
public QuiescenceSearch(ArtemisEngine engine, GameState gameState, PositionEvaluator evaluator, MoveEvaluator moveEvaluator) { this.engine = engine; this.gameState = gameState; this.evaluator = evaluator; this.moveEvaluator = moveEvaluator; }
public AppearNode(GameBoard board, Direction moveDirection, PositionEvaluator evaluator) { instances++; this.board = board.move(moveDirection); this.lastDirection = moveDirection; this.evaluator = evaluator; }
public ArtemisEngine(GameState gameState, IEngineConfig config, OpeningBook openingBook) { this.gameState = gameState; transpositionTable = new TranspositionTable(config); evConfig = new EvaluationConfig(); evaluator = new PositionEvaluator(gameState, evConfig); Config = config; this.openingBook = openingBook; threadMaster = new ThreadMaster(this, gameState, transpositionTable, config); }
public static int FastEvaluate(BoardState board, EvaluationStatistics statistics) { var openingPhase = board.GetPhaseRatio(); var endingPhase = BoardConstants.PhaseResolution - openingPhase; var result = MaterialEvaluator.Evaluate(board); result += PawnStructureEvaluator.Evaluate(board, statistics, openingPhase, endingPhase); result += PositionEvaluator.Evaluate(board, openingPhase, endingPhase); return(board.ColorToMove == Color.White ? result : -result); }
public SearchThread(ArtemisEngine engine, ThreadMaster master, GameState gameState, TranspositionTable transpositionTable, ConcurrentDictionary <ulong, bool> searchedNodes, IEngineConfig config) { this.master = master; this.gameState = gameState; EvaluationConfig evConfig = new EvaluationConfig(); evaluator = new PositionEvaluator(gameState, evConfig); moveEvaluator = new MoveEvaluator(evConfig); quietSearch = new QuiescenceSearch(engine, gameState, evaluator, moveEvaluator); pvSearch = new PVSearch(engine, gameState, transpositionTable, killerMoves, evaluator, moveEvaluator, quietSearch, searchedNodes, config); this.config = config; }
public PVSearch(ArtemisEngine engine, GameState gameState, TranspositionTable transpositionTable, KillerMoves killerMoves, PositionEvaluator evaluator, MoveEvaluator moveEvaluator, QuiescenceSearch quietSearch, ConcurrentDictionary <ulong, bool> searchedNodes, IEngineConfig config) { this.engine = engine; this.gameState = gameState; this.transpositionTable = transpositionTable; this.killerMoves = killerMoves; this.evaluator = evaluator; this.moveEvaluator = moveEvaluator; this.quietSearch = quietSearch; this.searchedNodes = searchedNodes; this.config = config; }
public void Run(params string[] parameters) { var fen = string.Join(' ', parameters); var boardState = FenToBoard.Parse(fen); var evaluationStatistics = new EvaluationStatistics(); var openingPhase = boardState.GetPhaseRatio(); var endingPhase = BoardConstants.PhaseResolution - openingPhase; var fieldsAttackedByWhite = 0ul; var fieldsAttackedByBlack = 0ul; var materialEvaluation = MaterialEvaluator.Evaluate(boardState); var castlingEvaluation = CastlingEvaluator.Evaluate(boardState, openingPhase, endingPhase); var positionEvaluation = PositionEvaluator.Evaluate(boardState, openingPhase, endingPhase); var pawnStructureEvaluation = PawnStructureEvaluator.Evaluate(boardState, evaluationStatistics, openingPhase, endingPhase); var mobility = MobilityEvaluator.Evaluate(boardState, openingPhase, endingPhase, ref fieldsAttackedByWhite, ref fieldsAttackedByBlack); var kingSafety = KingSafetyEvaluator.Evaluate(boardState, openingPhase, endingPhase, fieldsAttackedByWhite, fieldsAttackedByBlack); var pieces = PiecesEvaluator.Evaluate(boardState, openingPhase, endingPhase); var fianchetto = FianchettoEvaluator.Evaluate(boardState, openingPhase, endingPhase); var total = materialEvaluation + castlingEvaluation + positionEvaluation + pawnStructureEvaluation + mobility + kingSafety + pieces + fianchetto; _interactiveConsole.WriteLine($"Evaluation for board with hash {boardState.Hash} (phase {openingPhase}, " + $"{boardState.IrreversibleMovesCount} irreversible moves)"); _interactiveConsole.WriteLine($" = Material: {materialEvaluation}"); _interactiveConsole.WriteLine($" = Castling: {castlingEvaluation}"); _interactiveConsole.WriteLine($" = Position: {positionEvaluation}"); _interactiveConsole.WriteLine($" = Pawns: {pawnStructureEvaluation}"); _interactiveConsole.WriteLine($" = Mobility: {mobility}"); _interactiveConsole.WriteLine($" = King safety: {kingSafety}"); _interactiveConsole.WriteLine($" = Pieces evaluation: {pieces}"); _interactiveConsole.WriteLine($" = Fianchetto evaluation: {fianchetto}"); _interactiveConsole.WriteLine(); _interactiveConsole.WriteLine($" = Total: {total}"); }
private void OnSearchUpdate(object sender, SearchStatistics stats) { var score = FormatScore(stats.Score); var principalVariation = FormatPrincipalVariation(stats.PrincipalVariation, stats.PrincipalVariationMovesCount); Send($"info depth {stats.Depth} seldepth {stats.SelectiveDepth} time {stats.SearchTime} " + $"score {score} nodes {stats.TotalNodes} nps {stats.TotalNodesPerSecond} pv {principalVariation}"); if (_debugMode && stats.PrincipalVariationMovesCount > 0 && stats.PrincipalVariation[0] != Move.Empty) { var sign = stats.Board.ColorToMove == Color.White ? 1 : -1; stats.Board.MakeMove(stats.PrincipalVariation[0]); var evaluationStatistics = new EvaluationStatistics(); var openingPhase = stats.Board.GetPhaseRatio(); var endingPhase = BoardConstants.PhaseResolution - openingPhase; var fieldsAttackedByWhite = 0ul; var fieldsAttackedByBlack = 0ul; var materialEvaluation = sign * MaterialEvaluator.Evaluate(stats.Board); var positionEvaluation = sign * PositionEvaluator.Evaluate(stats.Board, openingPhase, endingPhase); var pawnStructureEvaluation = sign * PawnStructureEvaluator.Evaluate(stats.Board, evaluationStatistics, openingPhase, endingPhase); var mobility = sign * MobilityEvaluator.Evaluate(stats.Board, openingPhase, endingPhase, ref fieldsAttackedByWhite, ref fieldsAttackedByBlack); var kingSafety = sign * KingSafetyEvaluator.Evaluate(stats.Board, openingPhase, endingPhase, fieldsAttackedByWhite, fieldsAttackedByBlack); var rooks = sign * RookEvaluator.Evaluate(stats.Board, openingPhase, endingPhase); var bishops = sign * BishopEvaluator.Evaluate(stats.Board, openingPhase, endingPhase); var total = materialEvaluation + positionEvaluation + pawnStructureEvaluation + mobility + kingSafety; Send($"info string evaluation {total} phase {openingPhase} material {materialEvaluation} " + $"position {positionEvaluation} pawns {pawnStructureEvaluation} mobility {mobility} ksafety {kingSafety} " + $"rooks {rooks} bishops {bishops} irrmoves {stats.Board.IrreversibleMovesCount}"); stats.Board.UndoMove(stats.PrincipalVariation[0]); } }
public void Run(params string[] parameters) { var fen = string.Join(' ', parameters); var boardState = FenToBoard.Parse(fen, false); var evaluationStatistics = new EvaluationStatistics(); var openingPhase = boardState.GetPhaseRatio(); var endingPhase = BoardConstants.PhaseResolution - openingPhase; var fieldsAttackedByWhite = 0ul; var fieldsAttackedByBlack = 0ul; var materialEvaluation = MaterialEvaluator.Evaluate(boardState); var positionEvaluation = PositionEvaluator.Evaluate(boardState, openingPhase, endingPhase); var pawnStructureEvaluation = PawnStructureEvaluator.EvaluateWithoutCache(boardState, evaluationStatistics, openingPhase, endingPhase); var mobility = MobilityEvaluator.Evaluate(boardState, openingPhase, endingPhase, ref fieldsAttackedByWhite, ref fieldsAttackedByBlack); var kingSafety = KingSafetyEvaluator.Evaluate(boardState, openingPhase, endingPhase, fieldsAttackedByWhite, fieldsAttackedByBlack); var rooks = RookEvaluator.Evaluate(boardState, openingPhase, endingPhase); var bishops = BishopEvaluator.Evaluate(boardState, openingPhase, endingPhase); var total = materialEvaluation + positionEvaluation + pawnStructureEvaluation + mobility + kingSafety; _interactiveConsole.WriteLine($"Evaluation for board with hash {boardState.Hash} (phase {openingPhase}, " + $"{boardState.IrreversibleMovesCount} irreversible moves)"); _interactiveConsole.WriteLine($" = Material: {materialEvaluation}"); _interactiveConsole.WriteLine($" = Position: {positionEvaluation}"); _interactiveConsole.WriteLine($" = Pawns: {pawnStructureEvaluation}"); _interactiveConsole.WriteLine($" = Mobility: {mobility}"); _interactiveConsole.WriteLine($" = King safety: {kingSafety}"); _interactiveConsole.WriteLine($" = Rooks: {rooks}"); _interactiveConsole.WriteLine($" = Bishops: {bishops}"); _interactiveConsole.WriteLine(); _interactiveConsole.WriteLine($" = Total: {total}"); }
public static int Evaluate(BoardState board, EvaluationStatistics statistics) { var openingPhase = board.GetPhaseRatio(); var endingPhase = BoardConstants.PhaseResolution - openingPhase; var result = MaterialEvaluator.Evaluate(board); result += PositionEvaluator.Evaluate(board, openingPhase, endingPhase); result += PawnStructureEvaluator.Evaluate(board, statistics, openingPhase, endingPhase); if (endingPhase != BoardConstants.PhaseResolution) { var fieldsAttackedByWhite = 0ul; var fieldsAttackedByBlack = 0ul; result += MobilityEvaluator.Evaluate(board, openingPhase, endingPhase, ref fieldsAttackedByWhite, ref fieldsAttackedByBlack); result += KingSafetyEvaluator.Evaluate(board, openingPhase, endingPhase, fieldsAttackedByWhite, fieldsAttackedByBlack); result += CastlingEvaluator.Evaluate(board, openingPhase, endingPhase); result += FianchettoEvaluator.Evaluate(board, openingPhase, endingPhase); result += PiecesEvaluator.Evaluate(board, openingPhase, endingPhase); } return(board.ColorToMove == Color.White ? result : -result); }
public MoveNode(GameBoard board, PositionEvaluator evaluator) { instances++; this.board = board; this.evaluator = evaluator; }
public MoveNode(GameBoard board, Square square, PositionEvaluator evaluator) { instances++; this.board = board.withNewSquare(square); this.evaluator = evaluator; }
public EvaluatorStrategy(PositionEvaluator evaluator) { this.evaluator = evaluator; }
public TreeStrategy(PositionEvaluator evaluator, int moveTimeInMs) { this.evaluator = evaluator; this.moveTimeInMs = moveTimeInMs; }