public void SetUp() { Initializer.AllInit(); var dir = new DirectoryInfo(Path.GetDirectoryName( Assembly.GetExecutingAssembly().Location)); while (dir.Name != "bin") { dir = dir.Parent; } dir = dir.Parent; var path = Path.Combine(dir.FullName, "perftsuite.epd"); var file = ""; try { file = File.ReadAllText(path); } catch (Exception e) { throw new FileNotFoundException("Invalid file path"); } perftSuite = file.Split( new[] { Environment.NewLine }, StringSplitOptions.None ); perft = new Perft(); board = new Board(); moveList = new MoveList(); }
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); }
/// <summary> /// Counts all moves from the given position to the required ply count, and returns the actual number of move paths found /// </summary> /// <param name="pos"></param> /// <returns></returns> public static PerftTestResult TestPosition(Position pos) { ulong expectedCount = pos.ExpectedCount; var x = Notation.ReadFEN(pos.FEN); var b = Helpers.ManagedBoardToNative(x); var start = DateTime.Now; var results = Perft.Search(b, pos.Depth); var seconds = (DateTime.Now - start).TotalSeconds; Console.WriteLine("Perft(" + pos.Depth + "): " + (results->Total) + ", Time: " + String.Format("{0:0.000}", seconds)); Console.WriteLine("NPS: " + String.Format("{0:0} kNodes/sec", (results->Total / seconds / 1000))); Console.WriteLine(""); if (EnableDebugOutput) { for (int i = 0; i < results->EntryCount; i++) { int from = results->Entries[i].From; int to = results->Entries[i].To; ulong count = results->Entries[i].Count; string sfrom = Chess.Base.Notation.TileToText(from); string sto = Chess.Base.Notation.TileToText(to); Console.WriteLine(sfrom + " " + sto + " : " + count); } } Board.Delete(b); return(new PerftTestResult { Count = results->Total, TimeMillis = seconds * 1000.0 }); }
public void Setup() { var moveGen = new MoveGenerator(); _perft = new Perft(moveGen); _openingPosition = BoardParsing.PositionFromFen(OpeningFen); _midgamePosition = BoardParsing.PositionFromFen(MidgameFen); _endgamePosition = BoardParsing.PositionFromFen(EndgameFen); }
static void Main(string[] args) { using (var stream = new StreamReader(new FileStream("../../perfsuite.epd", FileMode.Open))) { string fen; int count; int depth; string perftEntry; Stopwatch timer = new Stopwatch(); while ((perftEntry = stream.ReadLine()) != null) { depth = 3; var entries = perftEntry.Split(';'); fen = entries[0]; while (depth <= 5) { if (entries.Length < depth) { Console.WriteLine("Invalid PERFT string"); return; } int.TryParse(entries[depth].Split(' ')[1], out count); timer.Start(); Console.WriteLine("Running with Fen {0} at depth {1}", fen, depth); var board = new Board(); board.ParseFen(fen); var perft = new Perft(board, new ConsoleReporter()); perft.Run(depth); timer.Stop(); if (count == perft.LeafNodes) { Console.WriteLine("expected {0}, returned {1} in {2}", count, perft.LeafNodes, timer.Elapsed); } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("expected {0}, returned {1} in {2}", count, perft.LeafNodes, timer.Elapsed); Console.ForegroundColor = ConsoleColor.White; } Console.WriteLine("============================================================="); depth++; if (Trace) { break; } } if (Trace) { break; } } } }
public void PerftFull() { foreach (var perftPosition in Positions) { var perft = new Perft(Positions.Length); perft.AddPosition(perftPosition); var expected = perft.GetPositionCount(0, Positions.Length); var actual = perft.DoPerft(); Assert.Equal(expected, actual); } }
public void PerftMedium() { foreach (var perftPosition in Positions) { var perft = new Perft(MediumCount); perft.AddPosition(perftPosition); var expected = perft.GetPositionCount(0, MediumCount); var actual = perft.DoPerft(); Assert.Equal(expected, actual); } }
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 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 Setup() { _perft = new Perft(N); _perft.AddStartPosition(); }
public void Setup() { _moveGenerator = new MoveGenerator(); _perftWithHashing = new Perft(_moveGenerator, 1_000_000); }
public void Setup() { _moveGenerator = new MoveGenerator(); _perft = new Perft(_moveGenerator); }