Skip to content

Commit

Permalink
minor cleanups after .net 8 upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
rudzen committed Nov 14, 2023
1 parent aee0b20 commit 2910a65
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 53 deletions.
1 change: 1 addition & 0 deletions src/Rudzoft.ChessLib.Perft/Rudzoft.ChessLib.Perft.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<Nullable>enable</Nullable>
<PublishAot>true</PublishAot>
</PropertyGroup>

<ItemGroup>
Expand Down
10 changes: 7 additions & 3 deletions src/Rudzoft.ChessLib/Board.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,13 @@ public Board()
_pieceList = new Square[Types.Square.Count][];
for (var i = 0; i < _pieceList.Length; i++)
{
var arr = new Square[Piece.Count];
arr.Fill(Types.Square.None);
_pieceList[i] = arr;
_pieceList[i] = new[]
{
Types.Square.None, Types.Square.None, Types.Square.None, Types.Square.None,
Types.Square.None, Types.Square.None, Types.Square.None, Types.Square.None,
Types.Square.None, Types.Square.None, Types.Square.None, Types.Square.None,
Types.Square.None, Types.Square.None, Types.Square.None, Types.Square.None
};
}

_index = new int[Types.Square.Count];
Expand Down
5 changes: 0 additions & 5 deletions src/Rudzoft.ChessLib/Extensions/MathExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ public static class MathExtensions
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsBetween(this uint v, int min, int max) => v - (uint)min <= (uint)max - (uint)min;

#if !NET7_0_OR_GREATER
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsAsciiDigit(this char c) => IsBetween(c, '0', '9');
#endif

/// <summary>
/// Converts a bool to a byte (0 or 1)
///
Expand Down
1 change: 0 additions & 1 deletion src/Rudzoft.ChessLib/Rudzoft.ChessLib.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<LangVersion>default</LangVersion>
<Platforms>AnyCPU</Platforms>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
Expand Down
51 changes: 9 additions & 42 deletions src/Rudzoft.ChessLib/State.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ public sealed class State : IEquatable<State>

public int NullPly { get; set; }

public CastleRight CastlelingRights { get; set; }
public CastleRight CastlelingRights { get; set; } = CastleRight.None;

[Description("En-passant -> 'in-passing' square")]
public Square EnPassantSquare { get; set; }
public Square EnPassantSquare { get; set; } = Square.None;

// -----------------------------
// Properties below this point are not copied from other state
Expand All @@ -60,58 +60,25 @@ public sealed class State : IEquatable<State>
/// <summary>
/// Represents checked squares for side to move
/// </summary>
public BitBoard Checkers { get; set; }
public BitBoard Checkers { get; set; } = BitBoard.Empty;

public BitBoard[] BlockersForKing { get; }
public BitBoard[] BlockersForKing { get; } = { BitBoard.Empty, BitBoard.Empty };

public BitBoard[] Pinners { get; }
public BitBoard[] Pinners { get; } = { BitBoard.Empty, BitBoard.Empty };

public BitBoard[] CheckedSquares { get; private set; }
public BitBoard[] CheckedSquares { get; private set; } = new BitBoard[PieceTypes.PieceTypeNb.AsInt()];

public PieceTypes CapturedPiece { get; set; }
public PieceTypes CapturedPiece { get; set; } = PieceTypes.NoPieceType;

public Move LastMove { get; set; }
public Move LastMove { get; set; } = Move.EmptyMove;

public int Repetition { get; set; }

public State Previous { get; private set; }

/// <summary>
/// Partial copy from existing state The properties not copied are re-calculated
/// </summary>
/// <param name="other">The current state</param>
public State(State other)
{
PawnKey = other.PawnKey;
MaterialKey = other.MaterialKey;
CastlelingRights = other.CastlelingRights;
ClockPly = other.ClockPly;
NullPly = other.NullPly;
EnPassantSquare = other.EnPassantSquare;
Previous = other;

Checkers = BitBoard.Empty;
BlockersForKing = new[] { BitBoard.Empty, BitBoard.Empty };
Pinners = new[] { BitBoard.Empty, BitBoard.Empty };
CheckedSquares = new BitBoard[PieceTypes.PieceTypeNb.AsInt()];
CapturedPiece = PieceTypes.NoPieceType;
}

public State()
{
LastMove = Move.EmptyMove;
CastlelingRights = CastleRight.None;
EnPassantSquare = Square.None;
Checkers = BitBoard.Empty;
CheckedSquares = new BitBoard[PieceTypes.PieceTypeNb.AsInt()];
Pinners = new[] { BitBoard.Empty, BitBoard.Empty };
BlockersForKing = new[] { BitBoard.Empty, BitBoard.Empty };
CapturedPiece = PieceTypes.NoPieceType;
}

public State CopyTo(State other)
{
other ??= new State();
other ??= new();

// copy over preserved values
other.MaterialKey = MaterialKey;
Expand Down
5 changes: 4 additions & 1 deletion src/Rudzoft.ChessLib/Types/Piece.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

#if NET7_0_OR_GREATER
using System.Numerics;
#endif
using System.Runtime.CompilerServices;
using Rudzoft.ChessLib.Extensions;

Expand Down Expand Up @@ -80,7 +83,7 @@ public static bool InBetween(this PieceTypes v, PieceTypes min, PieceTypes max)
/// Piece. Contains the piece type which indicate what type and color the piece is
/// </summary>
public readonly record struct Piece(Pieces Value)
#if net7_0
#if NET7_0_OR_GREATER
: IMinMaxValue<Piece>
#endif
{
Expand Down
2 changes: 1 addition & 1 deletion src/Rudzoft.ChessLib/Types/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public enum PlayerTypes
}

public readonly record struct Player(byte Side) : ISpanFormattable
#if NET7_0
#if NET7_0_OR_GREATER
, IMinMaxValue<Player>
#endif
{
Expand Down

0 comments on commit 2910a65

Please sign in to comment.