/// <summary> /// Saves a board to the specified file. /// </summary> /// <param name="command">The Save command.</param> private void SaveBoard(Command command) { var boardNameArgument = command.GetArgument <string>(0); var boardWriter = new BoardWriter(); var board = VisualBoard.FriendlyBoard; var path = $"Boards\\{boardNameArgument}.board"; boardWriter.Write(path, board); }
/// <summary> /// Recursive method for calculating bitboard. If depth is equal or less than zero, then /// current node is the last and next CalculateBitboard call will not be executed. /// </summary> /// <param name="color">Color of the current player.</param> /// <param name="bitboard">Currently calculated bitboard</param> /// <param name="depth">Current depth</param> /// <param name="calculateEndNodes">If true, every end node will calculate attacks and evaluation function.</param> /// <param name="verifyIntegrity">If true, every board will be checked whether incremental-updating parameters are correctly calculated.</param> /// <param name="testData">Container for test data which will be returned when test is done.</param> private void CalculateBitboard(Color color, Bitboard bitboard, int depth, bool calculateEndNodes, bool verifyIntegrity, MovesTestData testData) { if (verifyIntegrity) { bitboard.Calculate(GeneratorMode.CalculateAttacks, false); if (!bitboard.VerifyIntegrity()) { testData.Integrity = false; var boardWriter = new BoardWriter(); boardWriter.Write("Boards/error.board", new FriendlyBoard(bitboard)); } } if (depth <= 0) { if (calculateEndNodes) { bitboard.Calculate(GeneratorMode.CalculateAttacks, false); bitboard.GetEvaluation(); } testData.EndNodes++; } else { var enemyColor = ColorOperations.Invert(color); var whiteMode = GetGeneratorMode(color); var blackMode = GetGeneratorMode(enemyColor); bitboard.Calculate(whiteMode, blackMode, false); foreach (var move in bitboard.Moves) { var bitboardAfterMove = bitboard.Move(move); CalculateBitboard(enemyColor, bitboardAfterMove, depth - 1, calculateEndNodes, verifyIntegrity, testData); } } testData.TotalNodes++; }
/// <summary> /// Gets a piece type on the specified field. /// </summary> /// <param name="field">The field with piece.</param> /// <param name="pieceColor">The piece color.</param> /// <param name="bitboard">The bitboard.</param> /// <exception cref="PieceTypeNotFoundException">Thrown when there is no piece on the specified field.</exception> /// <returns>The piece type on the specified field.</returns> private PieceType GetPieceType(ulong field, Color pieceColor, Bitboard bitboard) { for (var piece = 0; piece < 6; piece++) { if ((field & bitboard.Pieces[FastArray.GetPieceIndex(pieceColor, (PieceType)piece)]) != 0) { return((PieceType)piece); } } // Temporary, there is a bug here Console.WriteLine(field); Console.WriteLine(pieceColor); Console.WriteLine(bitboard.Occupancy[0]); Console.WriteLine(bitboard.Occupancy[1]); Console.WriteLine(bitboard.AttacksSummary[0]); Console.WriteLine(bitboard.AttacksSummary[1]); Console.WriteLine(bitboard.VerifyIntegrity()); Console.WriteLine(bitboard.Pieces[0]); Console.WriteLine(bitboard.Pieces[1]); Console.WriteLine(bitboard.Pieces[2]); Console.WriteLine(bitboard.Pieces[3]); Console.WriteLine(bitboard.Pieces[4]); Console.WriteLine(bitboard.Pieces[5]); Console.WriteLine(bitboard.Pieces[6]); Console.WriteLine(bitboard.Pieces[7]); Console.WriteLine(bitboard.Pieces[8]); Console.WriteLine(bitboard.Pieces[9]); Console.WriteLine(bitboard.Pieces[10]); Console.WriteLine(bitboard.Pieces[11]); var save = new BoardWriter(); save.Write("err.board", new FriendlyBoard(bitboard)); // throw new PieceTypeNotFoundException(); }