Small cleanup

This commit is contained in:
Sebastian Lague 2023-07-29 11:20:45 +02:00
parent a1fdbee6ba
commit 282048c796
3 changed files with 18 additions and 15 deletions

View file

@ -41,22 +41,29 @@ namespace ChessChallenge.API
return ((bitboard >> square.Index) & 1) != 0;
}
/// <summary>
/// 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.
/// </summary>
public static int ClearAndGetIndexOfLSB(ref ulong bitboard)
{
return BitBoardUtility.PopLSB(ref bitboard);
}
/// <summary>
/// Returns the number of bits that set to 1 in the given bitboard.
/// </summary>
public static int GetNumberOfSetBits(ulong bitboard)
{
return BitBoardUtility.PopCount(bitboard);
}
/// <summary>
/// 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.
/// </summary>
public static ulong GetPieceAttacks(PieceType pieceType, Square square, Board board, bool isWhite)
{
@ -73,9 +80,10 @@ namespace ChessChallenge.API
}
/// <summary>
/// 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.
/// </summary>
public static ulong GetPieceAttacks(PieceType pieceType, Square square, ulong blockers, bool isWhite)
{

View file

@ -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;

View file

@ -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);