public List <EpdPositionData> Load(string epdPath) { var positions = new List <EpdPositionData>(); using (var streamReader = new StreamReader(epdPath)) { while (!streamReader.EndOfStream) { var line = streamReader.ReadLine(); var trimmedLine = line.Trim(';'); var chunks = trimmedLine.Split(' '); var result = chunks.Last(); if (string.IsNullOrWhiteSpace(result)) { continue; } positions.Add(new EpdPositionData { BoardState = FenToBoard.Parse(trimmedLine, false), Result = GetGameResult(result) }); } } return(positions); }
public void SimplePerft_EndGameBoard(int depth, ulong expectedLeafsCount) { var boardState = FenToBoard.Parse("7r/8/2k3P1/1p1p2Kp/1P6/2P5/7r/Q7 w - - 0 1"); var result = SimplePerft.Run(boardState, depth); Assert.Equal(expectedLeafsCount, result.LeafsCount); }
public void SimplePerft_MidGameBoard(int depth, ulong expectedLeafsCount) { var boardState = FenToBoard.Parse("r2qr1k1/p2n1p2/1pb3pp/2ppN1P1/1R1PpP2/BQP1n1PB/P4N1P/1R4K1 w - - 0 21"); var result = SimplePerft.Run(boardState, depth); Assert.Equal(expectedLeafsCount, result.LeafsCount); }
public void VerificationPerft_EndGameBoard() { var boardState = FenToBoard.Parse("7r/8/2k3P1/1p1p2Kp/1P6/2P5/7r/Q7 w - - 0 1"); var result = VerificationPerft.Run(boardState, 6); Assert.True(result.VerificationSuccess); }
public void VerificationPerft_MidGameBoard() { var boardState = FenToBoard.Parse("r2qr1k1/p2n1p2/1pb3pp/2ppN1P1/1R1PpP2/BQP1n1PB/P4N1P/1R4K1 w - - 0 21"); var result = VerificationPerft.Run(boardState, 5); Assert.True(result.VerificationSuccess); }
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}"); }
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}"); }
private void TestEndGame() { var boardState = FenToBoard.Parse("7r/8/2k3P1/1p1p2Kp/1P6/2P5/7r/Q7 w - - 0 1"); Test(boardState, "Endgame", 17); }
private void TestMidGame() { var boardState = FenToBoard.Parse("r2qr1k1/p2n1p2/1pb3pp/2ppN1P1/1R1PpP2/BQP1n1PB/P4N1P/1R4K1 w - - 0 21"); Test(boardState, "Midgame", 12); }
private void ParseFen(string fen, List <string> moves) { _uciClient.BoardState = FenToBoard.Parse(fen); ParseMoves(moves); }
public void DividedPerft_DefaultBoard(string fen) { var boardFromFen = FenToBoard.Parse(fen); Assert.Equal(fen, boardFromFen.ToString()); }