diff --git a/Chess-Challenge/src/API/BitboardHelper.cs b/Chess-Challenge/src/API/BitboardHelper.cs index 5a07a8e..ae10397 100644 --- a/Chess-Challenge/src/API/BitboardHelper.cs +++ b/Chess-Challenge/src/API/BitboardHelper.cs @@ -41,22 +41,29 @@ namespace ChessChallenge.API return ((bitboard >> square.Index) & 1) != 0; } + + /// + /// Returns index of the first bit that is set to 1. The bit will also be cleared to zero. + /// This can be useful for efficiently iterating over all the set squares in a bitboard. + /// public static int ClearAndGetIndexOfLSB(ref ulong bitboard) { return BitBoardUtility.PopLSB(ref bitboard); } + /// + /// Returns the number of bits that set to 1 in the given bitboard. + /// public static int GetNumberOfSetBits(ulong bitboard) { return BitBoardUtility.PopCount(bitboard); } - - /// - /// Returns a bitboard where each bit that is set to 1 represents a square that the given - /// piece type is able to attack. These attacks are calculated from the given square, - /// and take the given board state into account (so queen, rook, and bishop attacks will be blocked by pieces that are in the way). + /// Returns a bitboard where each bit that is set to 1 represents a square that the given piece type is + /// able to attack. These attacks are calculated from the given square, and take the given board state into + /// account (so queen, rook, and bishop attacks will be blocked by pieces that are in the way). + /// The isWhite parameter determines the direction of pawn captures. /// public static ulong GetPieceAttacks(PieceType pieceType, Square square, Board board, bool isWhite) { @@ -73,9 +80,10 @@ namespace ChessChallenge.API } /// - /// Returns a bitboard where each bit that is set to 1 represents a square that the given - /// piece type is able to attack. These attacks are calculated from the given square, - /// and take the given board state into account (so queen, rook, and bishop attacks will be blocked by pieces that are in the way). + /// Returns a bitboard where each bit that is set to 1 represents a square that the given piece type is + /// able to attack. These attacks are calculated from the given square, and take the given blockers into + /// account (so queen, rook, and bishop attacks will be blocked by pieces that are in the way). + /// The isWhite parameter determines the direction of pawn captures. /// public static ulong GetPieceAttacks(PieceType pieceType, Square square, ulong blockers, bool isWhite) { diff --git a/Chess-Challenge/src/Framework/Application/Helpers/UIHelper.cs b/Chess-Challenge/src/Framework/Application/Helpers/UIHelper.cs index 950f247..d83ce4a 100644 --- a/Chess-Challenge/src/Framework/Application/Helpers/UIHelper.cs +++ b/Chess-Challenge/src/Framework/Application/Helpers/UIHelper.cs @@ -1,7 +1,7 @@ using Raylib_cs; using System; -using System.IO; using System.Numerics; +using static ChessChallenge.Application.FileHelper; namespace ChessChallenge.Application { @@ -104,11 +104,6 @@ namespace ChessChallenge.Application return mousePos.X >= rec.x && mousePos.Y >= rec.y && mousePos.X <= rec.x + rec.width && mousePos.Y <= rec.y + rec.height; } - public static string GetResourcePath(params string[] localPath) - { - return Path.Combine(Directory.GetCurrentDirectory(), "resources", Path.Combine(localPath)); - } - public static float Scale(float val, int referenceResolution = referenceResolution) { return Raylib.GetScreenWidth() / (float)referenceResolution * val; diff --git a/Chess-Challenge/src/Framework/Application/UI/BoardUI.cs b/Chess-Challenge/src/Framework/Application/UI/BoardUI.cs index 288a767..9ca8b04 100644 --- a/Chess-Challenge/src/Framework/Application/UI/BoardUI.cs +++ b/Chess-Challenge/src/Framework/Application/UI/BoardUI.cs @@ -421,7 +421,7 @@ namespace ChessChallenge.Application void LoadPieceTexture() { // Workaround for Raylib.LoadTexture() not working when path contains non-ascii chars - byte[] pieceImgBytes = File.ReadAllBytes(GetResourcePath("Pieces.png")); + byte[] pieceImgBytes = File.ReadAllBytes(FileHelper.GetResourcePath("Pieces.png")); Image pieceImg = Raylib.LoadImageFromMemory(".png", pieceImgBytes); piecesTexture = Raylib.LoadTextureFromImage(pieceImg); Raylib.UnloadImage(pieceImg);