Skip to content

Commit

Permalink
feat: improve perf and uci notation (#26)
Browse files Browse the repository at this point in the history
* feat: optimize UCI notation handling and improve castling move conversion

* feat: remove unused castleMap variable to streamline code

* feat: enhance hex string parsing and FEN validation in Zobrist hashing to reduce allocs and improve performances by 200%

* feat: optimize XOR operations in Zobrist hashing for improved performance and reduced allocations

* feat: improve efficiency of hex string conversion and optimize Polyglot hash retrieval

* feat: rename addTag method to AddTag for consistency with Go naming conventions

* feat: update addTag method calls to AddTag for consistency with Go naming conventions

* feat: add unit tests for UCI notation decoding and enhance Move.AddTag documentation

* feat: add error handling for hex string decoding in polyglot hash initialization

* feat: add bounds checking to GetPolyglotHashBytes for safer access
  • Loading branch information
CorentinGS authored Feb 5, 2025
1 parent 52609c6 commit 85f540d
Show file tree
Hide file tree
Showing 10 changed files with 1,072 additions and 900 deletions.
16 changes: 8 additions & 8 deletions engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,20 +176,20 @@ func standardMoves(pos *Position, first bool) []Move {
func addTags(m *Move, pos *Position) {
p := pos.board.Piece(m.s1)
if pos.board.isOccupied(m.s2) {
m.addTag(Capture)
m.AddTag(Capture)
} else if m.s2 == pos.enPassantSquare && p.Type() == Pawn {
m.addTag(EnPassant)
m.AddTag(EnPassant)
}
// determine if in check after move (makes move invalid)
cp := pos.copy()
cp.board.update(m)
if isInCheck(cp) {
m.addTag(inCheck)
m.AddTag(inCheck)
}
// determine if opponent in check after move
cp.turn = cp.turn.Other()
if isInCheck(cp) {
m.addTag(Check)
m.AddTag(Check)
}
}

Expand Down Expand Up @@ -327,7 +327,7 @@ func castleMoves(pos *Position) []Move {
!squaresAreAttacked(pos, F1, G1) &&
!pos.inCheck {
m := Move{s1: E1, s2: G1}
m.addTag(KingSideCastle)
m.AddTag(KingSideCastle)
addTags(&m, pos)
moves[count] = m
count++
Expand All @@ -339,7 +339,7 @@ func castleMoves(pos *Position) []Move {
!squaresAreAttacked(pos, C1, D1) &&
!pos.inCheck {
m := Move{s1: E1, s2: C1}
m.addTag(QueenSideCastle)
m.AddTag(QueenSideCastle)
addTags(&m, pos)
moves[count] = m
count++
Expand All @@ -351,7 +351,7 @@ func castleMoves(pos *Position) []Move {
!squaresAreAttacked(pos, F8, G8) &&
!pos.inCheck {
m := Move{s1: E8, s2: G8}
m.addTag(KingSideCastle)
m.AddTag(KingSideCastle)
addTags(&m, pos)
moves[count] = m
count++
Expand All @@ -363,7 +363,7 @@ func castleMoves(pos *Position) []Move {
!squaresAreAttacked(pos, C8, D8) &&
!pos.inCheck {
m := Move{s1: E8, s2: C8}
m.addTag(QueenSideCastle)
m.AddTag(QueenSideCastle)
addTags(&m, pos)
moves[count] = m
count++
Expand Down
Loading

0 comments on commit 85f540d

Please sign in to comment.