public void Perft_Test(int depth, Board board) // Also prints information regarding the moves { Debug.Assert(BoardOperations.CheckBoard(board)); var startTime = Variables.Watch.ElapsedMilliseconds; Console.Write("\nStarting Perft Test to Depth {0}", depth); BoardOperations.PrintBoard(board); LeafNodes = 0; MoveList list = new MoveList(); MoveGen.GenerateAllMoves(board, list, false); for (int i = 0; i < list.Count; ++i) { int move = list.Moves[i].Move; if (!MakeMove.Make_Move(board, list.Moves[i].Move)) { continue; } long cumulativeNodes = LeafNodes; _Perft(depth - 1, board); MakeMove.TakeMove(board); long oldNodes = LeafNodes - cumulativeNodes; Console.Write("\nmove {0} : {1} : {2}", i + 1, Io.MoveToString(move), oldNodes); } Console.Write("\nTest Complete: {0} nodes visited in {1} miliseconds\n", LeafNodes, Variables.Watch.ElapsedMilliseconds - startTime); }
// should read "position fen" // "position startpos" // which could possibly be followed by "... moves a2a3 a3a4" etc. public void ParsePosition(string lineIn, Board board) { int stringIndex = 9; // starts at 9 cause position is length 8 int moveIndex = lineIn.IndexOf("moves"); // is there any moves to consider? if (lineIn.Length >= stringIndex + 8 && lineIn.Substring(stringIndex, 8).Equals("startpos")) { BoardOperations.ParseFen(Fens.START_FEN, board); } else // Else "position fen fenstring" { if (lineIn.Length >= stringIndex + 3 && lineIn.Substring(stringIndex, 3).Equals("fen")) { stringIndex += 4; // should be at start of fenstring now. if (moveIndex == -1) { BoardOperations.ParseFen(lineIn.Substring(stringIndex), board); } else { BoardOperations.ParseFen( lineIn.Substring(stringIndex, moveIndex - stringIndex - 1), board); } } else { BoardOperations.ParseFen(Fens.START_FEN, board); } } if (moveIndex != -1) // moves were found. { stringIndex = moveIndex + 6; // We are now at start of command moves. moves |a2a3 int move = Variables.NO_MOVE; while (stringIndex <= lineIn.Length - 1) { stringIndex += 5; if (lineIn.Length > stringIndex && lineIn[stringIndex - 1] == ' ') { move = Io.ParseMove(board, lineIn.Substring(stringIndex - 5, 4).ToCharArray()); // not a promotion move. } else if (stringIndex == lineIn.Length + 1) // if at last move { move = Io.ParseMove(board, lineIn.Substring(stringIndex - 5, 4).ToCharArray()); } else if (stringIndex == lineIn.Length) // promotion move at end of line { move = Io.ParseMove(board, lineIn.Substring(stringIndex - 5, 5).ToCharArray()); } else if (lineIn.Length >= stringIndex && lineIn[stringIndex - 1] != ' ') { move = Io.ParseMove(board, lineIn.Substring(stringIndex - 5, 5).ToCharArray()); stringIndex++; } if (move == Variables.NO_MOVE) { break; } MakeMove.Make_Move(board, move); board.Ply = 0; } } BoardOperations.PrintBoard(board); }