private static void PerformanceTesting(string fen, int perftDepth, TimeSpan timespan) { var position = BoardParsing.PositionFromFen(fen); Debugging.Dump(position); var moveGen = new MoveGenerator(); var perft = new Perft(moveGen); Stopwatch overallStopwatch = new Stopwatch(); overallStopwatch.Start(); while (true) { int perftNum = perftDepth; Console.Write($"Perft {perftNum}: "); Stopwatch sw = new Stopwatch(); sw.Start(); int perftResults = perft.GoPerft(position, perftNum); sw.Stop(); double knps = ((double)perftResults) / sw.ElapsedMilliseconds; // it just works out Console.WriteLine($"{perftResults} ({knps:F2} knps)"); if (overallStopwatch.Elapsed > timespan) { break; } } //perft.GoPerft(position, perftDepth); }
public SimpleUci(IMoveGenerator moveGenerator, ISearch search, TextReader input, TextWriter output) { _position = BoardParsing.PositionFromFen(InitialFen); _moveGenerator = moveGenerator; _search = search; _timeStrategy = new DefaultTimeStrategy(); _input = input; _output = output; _searchWorkerThread = new SearchWorkerThread(); }
public void Setup() { var moveGen = new MoveGenerator(); _perft = new Perft(moveGen); _openingPosition = BoardParsing.PositionFromFen(OpeningFen); _midgamePosition = BoardParsing.PositionFromFen(MidgameFen); _endgamePosition = BoardParsing.PositionFromFen(EndgameFen); }
private static void Bench() { var moveGen = new MoveGenerator(); var evaluator = new Evaluator(); var promotionMvvLvaMoveOrderer = new CompositeMoveOrderer(new IMoveOrderer[] { new PromotionsOrderer(), new MvvLvaOrderer() }); var qSearch = new SimpleQSearch(evaluator, moveGen, promotionMvvLvaMoveOrderer, CompositeMoveOrderer.NullMoveOrderer); var search = new SimpleAlphaBetaSearch(moveGen, evaluator, qSearch); var timeStrategy = new TimePerMoveStrategy(TimeSpan.FromSeconds(10)); search.Search(BoardParsing.PositionFromFen(MidgameFen), timeStrategy, s => { }); }
public static void DumpEvalsForEachPosition() { var evaluator = new Evaluator(); foreach (var(fen, _) in GetPerftCasesEnumerator()) { var position = BoardParsing.PositionFromFen(fen); Console.WriteLine($"{fen} {evaluator.Evaluate(position)}"); } }
private static void DivideTesting(string fen, int depth, params string[] moves) { var position = BoardParsing.PositionFromFen(fen); Debugging.Dump(position); var moveGen = new MoveGenerator(); var perft = new Perft(moveGen); foreach (var moveStr in moves) { Move move = BoardParsing.GetMoveFromCoordinateString(moveGen, position, moveStr); position = Position.MakeMove(new Position(), move, position); Debugging.Dump(position); } GoDivide(moveGen, perft, position, depth - moves.Length); }
private void SetPosition(string optionsStr) { var options = optionsStr.Split(' ', StringSplitOptions.RemoveEmptyEntries).ToList(); if (options[0] == "startpos") { _position = BoardParsing.PositionFromFen(InitialFen); options.RemoveAt(0); } else if (options[0] == "fen") { string fen = ""; options.RemoveAt(0); while (options.Count > 0 && options[0] != "moves") { fen += $"{options[0]} "; options.RemoveAt(0); } _position = BoardParsing.PositionFromFen(fen); } else { throw new Exception($"Invalid option: {options[0]}"); } if (!_position.IsValid()) { throw new Exception("Invalid position"); } if (options.Any() && options[0] == "moves") { options.RemoveAt(0); foreach (var moveStr in options) { Move move = BoardParsing.GetMoveFromCoordinateString(_moveGenerator, _position, moveStr); _position = Position.MakeMove(new Position(), move, _position); } } }
private static void IncrementalPerft(string fen, int maxDepth) { var position = BoardParsing.PositionFromFen(fen); Debugging.Dump(position); var moveGen = new MoveGenerator(); var perft = new Perft(moveGen); for (int i = 1; i <= maxDepth; i++) { Console.Write($"Perft {i}: "); Stopwatch sw = new Stopwatch(); sw.Start(); int perftResults = perft.GoPerft(position, i); sw.Stop(); double knps = ((double)perftResults) / sw.ElapsedMilliseconds; // it just works out Console.WriteLine($"{perftResults} ({knps:F2} knps)"); } }
private static void GoDivide(MoveGenerator moveGenerator, Perft perft, Position position, int depth) { if (depth <= 0) { Console.WriteLine($"##### No moves generated at depth {depth}"); return; } var total = 0; List <Move> moves = new List <Move>(); moveGenerator.Generate(moves, position); var movesDict = new SortedDictionary <string, Move>(); foreach (var move in moves) { movesDict.Add(BoardParsing.CoordinateStringFromMove(move), move); } foreach (var(moveStr, move) in movesDict) { var nextBoard = Position.MakeMove(new Position(), move, position); // check move legality if using a pseudolegal move generator if (!moveGenerator.OnlyLegalMoves && nextBoard.MovedIntoCheck()) { continue; } Console.Write($"{moveStr}: "); int count = perft.GoPerft(nextBoard, depth - 1); Console.WriteLine(count); total += count; } Console.WriteLine($"##### Total moves: {total}"); }
public void BitboardSquaresTest(string fen, int depth) { var position = BoardParsing.PositionFromFen(fen); BitboardSquaresTestHelper(position, depth); }
public override string ToString() { return(BoardParsing.NaiveSanStringFromMove(this)); }
public void ZobristTest(string fen, int depth) { var position = BoardParsing.PositionFromFen(fen); ZobristTestHelper(position, depth); }
public string FenTest(string fen) { var position = BoardParsing.PositionFromFen(fen); return(BoardParsing.FenStringFromBoard(position)); }
public override string ToString() { return(BoardParsing.FenStringFromBoard(this)); }
private void PrintBestMove(Move bestMove) { _output.WriteLine($"bestmove {BoardParsing.CoordinateStringFromMove(bestMove)}"); }
public int PerftWithHashingTest(string fen, int depth) { var position = BoardParsing.PositionFromFen(fen); return(_perftWithHashing.GoPerft(position, depth)); }