Skip to content

Commit

Permalink
Merge branch 'main' into perf/enpassantcapturesquares-dictionary
Browse files Browse the repository at this point in the history
  • Loading branch information
eduherminio authored Jan 4, 2024
2 parents 565535e + adba5ff commit 7806352
Show file tree
Hide file tree
Showing 7 changed files with 431 additions and 66 deletions.
41 changes: 21 additions & 20 deletions src/Lynx.Benchmark/MakeUnmakeMove_implementation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,13 @@ public struct MakeMovePosition

public BoardSquare EnPassant { get; private set; }

public int Castle { get; private set; }
public byte Castle { get; private set; }

public MakeMovePosition(string fen) : this(FENParser.ParseFEN(fen))
{
}

public MakeMovePosition((BitBoard[] PieceBitBoards, BitBoard[] OccupancyBitBoards, Side Side, int Castle, BoardSquare EnPassant,
public MakeMovePosition((BitBoard[] PieceBitBoards, BitBoard[] OccupancyBitBoards, Side Side, byte Castle, BoardSquare EnPassant,
int HalfMoveClock/*, int FullMoveCounter*/) parsedFEN)
{
PieceBitBoards = parsedFEN.PieceBitBoards;
Expand Down Expand Up @@ -325,7 +325,7 @@ public MakeMovePosition(MakeMovePosition position, Move move) : this(position)
public MakeMoveGameState MakeMove_Original(Move move)
{
int capturedPiece = -1;
int castleCopy = Castle;
var castleCopy = Castle;
BoardSquare enpassantCopy = EnPassant;

var oldSide = Side;
Expand Down Expand Up @@ -547,7 +547,7 @@ public void UnmakeMove_Original(Move move, MakeMoveGameState gameState)
public MakeMoveGameStateWithZobristKey MakeMove_WithZobristKey(Move move)
{
int capturedPiece = -1;
int castleCopy = Castle;
var castleCopy = Castle;
BoardSquare enpassantCopy = EnPassant;
long uniqueIdentifierCopy = UniqueIdentifier;

Expand Down Expand Up @@ -811,11 +811,11 @@ public readonly struct MakeMoveGameState
{
public readonly int CapturedPiece;

public readonly int Castle;
public readonly byte Castle;

public readonly BoardSquare EnPassant;

public MakeMoveGameState(int capturedPiece, int castle, BoardSquare enpassant)
public MakeMoveGameState(int capturedPiece, byte castle, BoardSquare enpassant)
{
CapturedPiece = capturedPiece;
Castle = castle;
Expand All @@ -825,15 +825,15 @@ public MakeMoveGameState(int capturedPiece, int castle, BoardSquare enpassant)

public readonly struct MakeMoveGameStateWithZobristKey
{
public readonly int CapturedPiece;
public readonly long ZobristKey;

public readonly int Castle;
public readonly int CapturedPiece;

public readonly BoardSquare EnPassant;

public readonly long ZobristKey;
public readonly byte Castle;

public MakeMoveGameStateWithZobristKey(int capturedPiece, int castle, BoardSquare enpassant, long zobristKey)
public MakeMoveGameStateWithZobristKey(int capturedPiece, byte castle, BoardSquare enpassant, long zobristKey)
{
CapturedPiece = capturedPiece;
Castle = castle;
Expand All @@ -842,7 +842,7 @@ public MakeMoveGameStateWithZobristKey(int capturedPiece, int castle, BoardSquar
}
}

#region ;(
#region

public static class MakeMoveZobristTable
{
Expand Down Expand Up @@ -887,7 +887,7 @@ public static long SideHash()
/// <param name="castle"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static long CastleHash(int castle)
public static long CastleHash(byte castle)
{
long combinedHash = 0;

Expand Down Expand Up @@ -966,8 +966,9 @@ public static long PositionHash(MakeMovePosition position)

public static class MakeMoveMoveGenerator
{
private static readonly Logger _logger = LogManager.GetCurrentClassLogger();

#if DEBUG
private static readonly NLog.Logger _logger = NLog.LogManager.GetCurrentClassLogger();
#endif
private const int TRUE = 1;

/// <summary>
Expand All @@ -978,16 +979,16 @@ public static class MakeMoveMoveGenerator
{
(int origin, BitBoard _) => MakeMoveAttacks.PawnAttacks[(int)Side.White, origin],
(int origin, BitBoard _) => MakeMoveAttacks.KnightAttacks[origin],
(int origin, BitBoard occupancy) => MakeMoveAttacks.BishopAttacks(origin, occupancy),
(int origin, BitBoard occupancy) => MakeMoveAttacks.RookAttacks(origin, occupancy),
(int origin, BitBoard occupancy) => MakeMoveAttacks.QueenAttacks(origin, occupancy),
MakeMoveAttacks.BishopAttacks,
MakeMoveAttacks.RookAttacks,
MakeMoveAttacks.QueenAttacks,
(int origin, BitBoard _) => MakeMoveAttacks.KingAttacks[origin],

(int origin, BitBoard _) => MakeMoveAttacks.PawnAttacks[(int)Side.Black, origin],
(int origin, BitBoard _) => MakeMoveAttacks.KnightAttacks[origin],
(int origin, BitBoard occupancy) => MakeMoveAttacks.BishopAttacks(origin, occupancy),
(int origin, BitBoard occupancy) => MakeMoveAttacks.RookAttacks(origin, occupancy),
(int origin, BitBoard occupancy) => MakeMoveAttacks.QueenAttacks(origin, occupancy),
MakeMoveAttacks.BishopAttacks,
MakeMoveAttacks.RookAttacks,
MakeMoveAttacks.QueenAttacks,
(int origin, BitBoard _) => MakeMoveAttacks.KingAttacks[origin],
};

Expand Down
40 changes: 21 additions & 19 deletions src/Lynx.Benchmark/MakeUnmakeMove_integration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,13 @@ public struct MakeMovePosition

public BoardSquare EnPassant { get; private set; }

public int Castle { get; private set; }
public byte Castle { get; private set; }

public MakeMovePosition(string fen) : this(FENParser.ParseFEN(fen))
{
}

public MakeMovePosition((BitBoard[] PieceBitBoards, BitBoard[] OccupancyBitBoards, Side Side, int Castle, BoardSquare EnPassant,
public MakeMovePosition((BitBoard[] PieceBitBoards, BitBoard[] OccupancyBitBoards, Side Side, byte Castle, BoardSquare EnPassant,
int HalfMoveClock/*, int FullMoveCounter*/) parsedFEN)
{
PieceBitBoards = parsedFEN.PieceBitBoards;
Expand Down Expand Up @@ -483,7 +483,7 @@ public MakeMovePosition(MakeMovePosition position, Move move) : this(position)
public MakeMoveGameState MakeMove_Original(Move move)
{
int capturedPiece = -1;
int castleCopy = Castle;
var castleCopy = Castle;
BoardSquare enpassantCopy = EnPassant;

var oldSide = Side;
Expand Down Expand Up @@ -604,7 +604,7 @@ public MakeMoveGameState MakeMove_Original(Move move)
public void MakeMove_PassOut(Move move, out MakeMoveGameState_PassOut gameState)
{
int capturedPiece = -1;
int castleCopy = Castle;
var castleCopy = Castle;
BoardSquare enpassantCopy = EnPassant;

var oldSide = Side;
Expand Down Expand Up @@ -725,7 +725,7 @@ public void MakeMove_PassOut(Move move, out MakeMoveGameState_PassOut gameState)
public void MakeMove_PassRef(Move move, ref MakeMoveGameState_PassRef gameState)
{
int capturedPiece = -1;
int castleCopy = Castle;
var castleCopy = Castle;
BoardSquare enpassantCopy = EnPassant;

var oldSide = Side;
Expand Down Expand Up @@ -1208,13 +1208,13 @@ public readonly bool WasProduceByAValidMove()

public readonly struct MakeMoveGameState
{
public readonly int CapturedPiece;
public readonly byte Castle;

public readonly int Castle;
public readonly int CapturedPiece;

public readonly BoardSquare EnPassant;

public MakeMoveGameState(int capturedPiece, int castle, BoardSquare enpassant)
public MakeMoveGameState(int capturedPiece, byte castle, BoardSquare enpassant)
{
CapturedPiece = capturedPiece;
Castle = castle;
Expand All @@ -1226,11 +1226,11 @@ public struct MakeMoveGameState_PassOut
{
public int CapturedPiece;

public int Castle;
public byte Castle;

public BoardSquare EnPassant;

public MakeMoveGameState_PassOut(int capturedPiece, int castle, BoardSquare enpassant)
public MakeMoveGameState_PassOut(int capturedPiece, byte castle, BoardSquare enpassant)
{
CapturedPiece = capturedPiece;
Castle = castle;
Expand All @@ -1243,13 +1243,13 @@ public struct MakeMoveGameState_PassRef
#pragma warning disable S1104 // Fields should not have public accessibility
public int CapturedPiece;

public int Castle;
public byte Castle;

public BoardSquare EnPassant;
#pragma warning restore S1104 // Fields should not have public accessibility
}

#region ;(
#region

public static class MakeMoveZobristTable
{
Expand Down Expand Up @@ -1373,7 +1373,9 @@ public static long PositionHash(MakeMovePosition position)

public static class MakeMoveMoveGenerator
{
private static readonly Logger _logger = LogManager.GetCurrentClassLogger();
#if DEBUG
private static readonly NLog.Logger _logger = NLog.LogManager.GetCurrentClassLogger();
#endif

private const int TRUE = 1;

Expand All @@ -1385,16 +1387,16 @@ public static class MakeMoveMoveGenerator
{
(int origin, BitBoard _) => MakeMoveAttacks.PawnAttacks[(int)Side.White, origin],
(int origin, BitBoard _) => MakeMoveAttacks.KnightAttacks[origin],
(int origin, BitBoard occupancy) => MakeMoveAttacks.BishopAttacks(origin, occupancy),
(int origin, BitBoard occupancy) => MakeMoveAttacks.RookAttacks(origin, occupancy),
(int origin, BitBoard occupancy) => MakeMoveAttacks.QueenAttacks(origin, occupancy),
MakeMoveAttacks.BishopAttacks,
MakeMoveAttacks.RookAttacks,
MakeMoveAttacks.QueenAttacks,
(int origin, BitBoard _) => MakeMoveAttacks.KingAttacks[origin],

(int origin, BitBoard _) => MakeMoveAttacks.PawnAttacks[(int)Side.Black, origin],
(int origin, BitBoard _) => MakeMoveAttacks.KnightAttacks[origin],
(int origin, BitBoard occupancy) => MakeMoveAttacks.BishopAttacks(origin, occupancy),
(int origin, BitBoard occupancy) => MakeMoveAttacks.RookAttacks(origin, occupancy),
(int origin, BitBoard occupancy) => MakeMoveAttacks.QueenAttacks(origin, occupancy),
MakeMoveAttacks.BishopAttacks,
MakeMoveAttacks.RookAttacks,
MakeMoveAttacks.QueenAttacks,
(int origin, BitBoard _) => MakeMoveAttacks.KingAttacks[origin],
};

Expand Down
Loading

0 comments on commit 7806352

Please sign in to comment.