Skip to content

Commit

Permalink
Simplify by removing InitialIncrementalStaticEvaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
eduherminio committed Jan 10, 2025
1 parent deb9f53 commit 840092a
Showing 1 changed file with 1 addition and 55 deletions.
56 changes: 1 addition & 55 deletions src/Lynx/Model/Position.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ public Position((BitBoard[] PieceBitBoards, BitBoard[] OccupancyBitBoards, int[]
UniqueIdentifier = ZobristTable.PositionHash(this);
#pragma warning restore S3366 // "this" should not be exposed from constructors

_isIncrementalEval = true;
_incrementalEvalAccumulator = InitialIncrementalStaticEvaluation();
_isIncrementalEval = false;
}

/// <summary>
Expand Down Expand Up @@ -536,59 +535,6 @@ public bool WasProduceByAValidMove()

#region Evaluation

/// <summary>
/// Base incremental evaluation for the position.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int InitialIncrementalStaticEvaluation()
{
int packedScore = 0;

var whiteKing = PieceBitBoards[(int)Piece.K].GetLS1BIndex();
var blackKing = PieceBitBoards[(int)Piece.k].GetLS1BIndex();

var whiteBucket = PSQTBucketLayout[whiteKing];
var blackBucket = PSQTBucketLayout[blackKing ^ 56];

// White pieces PSQTs, except king
for (int pieceIndex = (int)Piece.P; pieceIndex < (int)Piece.K; ++pieceIndex)
{
var bitboard = PieceBitBoards[pieceIndex];

while (bitboard != default)
{
var pieceSquareIndex = bitboard.GetLS1BIndex();
bitboard.ResetLS1B();

packedScore += PSQT(0, whiteBucket, pieceIndex, pieceSquareIndex)
+ PSQT(1, blackBucket, pieceIndex, pieceSquareIndex);
}
}

// Black pieces PSQTs, except king
for (int pieceIndex = (int)Piece.p; pieceIndex < (int)Piece.k; ++pieceIndex)
{
var bitboard = PieceBitBoards[pieceIndex];

while (bitboard != default)
{
var pieceSquareIndex = bitboard.GetLS1BIndex();
bitboard.ResetLS1B();

packedScore += PSQT(0, blackBucket, pieceIndex, pieceSquareIndex)
+ PSQT(1, whiteBucket, pieceIndex, pieceSquareIndex);
}
}

// Kings
packedScore += PSQT(0, whiteBucket, (int)Piece.K, whiteKing)
+ PSQT(0, blackBucket, (int)Piece.k, blackKing)
+ PSQT(1, blackBucket, (int)Piece.K, whiteKing)
+ PSQT(1, whiteBucket, (int)Piece.k, blackKing);

return packedScore;
}

/// <summary>
/// Evaluates material and position in a NegaMax style.
/// That is, positive scores always favour playing <see cref="Side"/>.
Expand Down

0 comments on commit 840092a

Please sign in to comment.