Small cleanup
This commit is contained in:
parent
a1fdbee6ba
commit
282048c796
3 changed files with 18 additions and 15 deletions
|
@ -41,22 +41,29 @@ namespace ChessChallenge.API
|
||||||
return ((bitboard >> square.Index) & 1) != 0;
|
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)
|
public static int ClearAndGetIndexOfLSB(ref ulong bitboard)
|
||||||
{
|
{
|
||||||
return BitBoardUtility.PopLSB(ref 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)
|
public static int GetNumberOfSetBits(ulong bitboard)
|
||||||
{
|
{
|
||||||
return BitBoardUtility.PopCount(bitboard);
|
return BitBoardUtility.PopCount(bitboard);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a bitboard where each bit that is set to 1 represents a square that the given
|
/// Returns a bitboard where each bit that is set to 1 represents a square that the given piece type is
|
||||||
/// piece type is able to attack. These attacks are calculated from the given square,
|
/// able to attack. These attacks are calculated from the given square, and take the given board state into
|
||||||
/// and take the given board state into account (so queen, rook, and bishop attacks will be blocked by pieces that are in the way).
|
/// 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>
|
/// </summary>
|
||||||
public static ulong GetPieceAttacks(PieceType pieceType, Square square, Board board, bool isWhite)
|
public static ulong GetPieceAttacks(PieceType pieceType, Square square, Board board, bool isWhite)
|
||||||
{
|
{
|
||||||
|
@ -73,9 +80,10 @@ namespace ChessChallenge.API
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a bitboard where each bit that is set to 1 represents a square that the given
|
/// Returns a bitboard where each bit that is set to 1 represents a square that the given piece type is
|
||||||
/// piece type is able to attack. These attacks are calculated from the given square,
|
/// able to attack. These attacks are calculated from the given square, and take the given blockers into
|
||||||
/// and take the given board state into account (so queen, rook, and bishop attacks will be blocked by pieces that are in the way).
|
/// 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>
|
/// </summary>
|
||||||
public static ulong GetPieceAttacks(PieceType pieceType, Square square, ulong blockers, bool isWhite)
|
public static ulong GetPieceAttacks(PieceType pieceType, Square square, ulong blockers, bool isWhite)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
using Raylib_cs;
|
using Raylib_cs;
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
|
using static ChessChallenge.Application.FileHelper;
|
||||||
|
|
||||||
namespace ChessChallenge.Application
|
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;
|
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)
|
public static float Scale(float val, int referenceResolution = referenceResolution)
|
||||||
{
|
{
|
||||||
return Raylib.GetScreenWidth() / (float)referenceResolution * val;
|
return Raylib.GetScreenWidth() / (float)referenceResolution * val;
|
||||||
|
|
|
@ -421,7 +421,7 @@ namespace ChessChallenge.Application
|
||||||
void LoadPieceTexture()
|
void LoadPieceTexture()
|
||||||
{
|
{
|
||||||
// Workaround for Raylib.LoadTexture() not working when path contains non-ascii chars
|
// 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);
|
Image pieceImg = Raylib.LoadImageFromMemory(".png", pieceImgBytes);
|
||||||
piecesTexture = Raylib.LoadTextureFromImage(pieceImg);
|
piecesTexture = Raylib.LoadTextureFromImage(pieceImg);
|
||||||
Raylib.UnloadImage(pieceImg);
|
Raylib.UnloadImage(pieceImg);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue