```
Introduce UCI engine and improve codebase functionality
- Add `CreateMoveUCI` function in `board/move.go` for parsing UCI strings into moves with error handling for invalid inputs.
- Refactor `main.go` to use the `uci` package for implementing a chess engine, replacing legacy functionality and optimizing input handling with `bufio`.
- Add a new `Engine` interface implementation in `uci/engine.go` for handling UCI interactions, including methods for engine initialization, copy protection, and position parsing.
- Add `.vscode` to the `.gitignore` file to exclude editor-specific configurations.
- Add unit tests in `uci/engine_test.go` and `main_test.go` for verifying the UCI engine and main module functionality.
```
[board/move.go]
- Added a new function `CreateMoveUCI` for creating a move using the Universal Chess Interface (UCI) string format.
- The function constructs move coordinates and handles promotion if included in the UCI string.
- Error handling added for invalid promotion piece inputs, with a panic in case of an error.
[main.go]
- Replaced usage of the `fmt` package with `bufio` for input handling.
- Removed logic related to chess board initialization and move generation.
- Introduced new usage of the `uci` package to create and manage a chess engine.
- Implemented a loop to continuously read commands from `stdin`.
- Removed legacy functionality, including FEN parsing, move generation, and `Perft` calculations.
- Added a goroutine to asynchronously handle and process commands using the UCI engine.
[main_test.go]
- Added a new test file for the main package.
[uci/engine.go]
- Added a new implementation of an `Engine` interface for handling UCI (Universal Chess Interface) interactions.
- Defined the `MyEngine` struct with fields for reader, writer, a chess game object, and a debug flag.
- Implemented `Engine` interface methods:
- `CopyProtection`: Responds with a "copyprotection ok" message.
- `Init`: Outputs engine metadata such as name and author and indicates UCI readiness.
- `Debug`: Toggles debug mode.
- `SetOption`: Stub method added but not yet implemented.
- `Position`: Parses a FEN string to initialize a chess game and handles errors in debug mode.
- Introduced utility methods for printing through the engine's output stream.
- Provided a constructor function `NewEngine` to initialize a `MyEngine` instance.
[.gitignore]
- Added `.vscode` to the ignored files list.
[uci/engine_test.go]
- Added a test file with unit tests for the UCI engine.
- Implemented a `base` helper function to initialize the engine and establish pipe connections.
- Added a test case `TestInit` to validate the engine's initialization:
- Ensures that initialization output is read from the pipe.
- Checks for errors during read operations.
- Verifies the output matches the expected initialization string.
- Update `main.go` to enhance configurability:
- Change the initial board setup FEN string to reflect a new game state.
- Adjust default search depth to 1 and allow depth customization via command-line arguments.
- Print command-line arguments for debugging purposes and update output to include depth value.
- Add new test cases in `board/move_test.go` for "Kiwipete - Checked" and "Kiwipete - Minimized" scenarios.
- Improve castling logic and code clarity in `board/move.go`:
- Fix naming inconsistencies and enhance castle legality checks for scenarios like being in check or under threat.
- Simplify knight move generation using helper methods, and refine castle edge case handling.
- Add comments to improve readability around critical logic.
[main.go]
- Changed the initial board setup FEN string to a new game state.
- Adjusted the default search depth from 5 to 1.
- Added code to print the command-line arguments using `os.Args`.
- Introduced logic to accept depth from the command line, validating and parsing it as an integer.
- Commented out a debug print statement for depth.
- Updated the final output format to include the depth value in addition to the total moves.
[board/move_test.go]
- Added two new test cases, "Kiwipete - Checked" and "Kiwipete - Minimized," each with unique FEN strings and corresponding known performance data.
[board/move.go]
- Fixed variable naming inconsistency in `createMoveFromDisambiguatedRow` function, ensuring column and row variables are more descriptive and avoid shadowing.
- Adjusted the loop in `GetMoves` to include castle legality checks:
- Added logic to prevent castling while in check or castling into check.
- Enhanced enemy move processing during pseudo-move validation.
- Simplified `getKnightMoves` by replacing manual coordinate creation with the `Add` helper method for knight move offsets.
- Introduced additional logic in `getCastleMoves` to account for edge cases:
- Added a check to prevent castling if certain pawn threats exist.
- Updated conditions for both king-side and queen-side castling legality.
- Improved code readability and added comments in critical areas like handling castling edge cases.
- Increase search depth from 2 to 5 in `main.go` and refine move count display format by removing the word "moves."
- Optimize `Perft` function in `board/board.go` by introducing a global `perftCache` to avoid redundant calculations.
- Implement FEN-based cache keys with depth information in `board/board.go` to uniquely identify results and enhance caching.
- Add logic in `board/board.go` to utilize cached results and store computed node counts for performance improvement.
[main.go]
- The depth value for the search has been increased from 2 to 5.
- Adjusted the format of the printed output to remove the word "moves" from the move count display.
[board/board.go]
- Added a global cache `perftCache` to optimize the `Perft` function and improve performance by avoiding redundant calculations.
- Initialized `perftCache` as a map when first used in the `Perft` method.
- Constructed a compact FEN key, combining depth information, for uniquely identifying cached results.
- Implemented a check to return cached values if a matching FEN key exists.
- Stored computed node counts in the cache after calculating moves.
```
Refactor and enhance board logic, move handling, and test cases
- Refactor `board/board.go`:
- Rename move fields to uppercase for consistent capitalization (`From`, `To`, `Piece`, etc.).
- Add handling for castling restrictions when a rook is captured.
- Refactor en passant and promotion logic to align with updated field names.
- Introduce a new `Perft` function for move generation debugging.
- Refactor `board/move.go`:
- Standardize field capitalizations and update corresponding usage in methods (`IsCastle`, `String`, `GetAlgebra`, etc.).
- Ensure consistency in pawn moves, sliding moves, and enemy/ally filtering.
- Update `board/move_test.go`:
- Replace field references (`from`, `to`, etc.) with updated capitalized counterparts.
- Update test cases to reflect new naming conventions and improve error readability.
- Update `board/board_test.go`:
- Adjust test logic and variable references to match capitalized field naming.
- Ensure test consistency with updated function and variable naming.
- Update `main.go`:
- Integrate `Perft` function for move depth evaluation and replace existing logic.
- Modify initial FEN string and improve output formatting for perft count.
```
[board/board.go]
- **Refactored move field names**:
- Renamed lowercase fields (e.g., `from`, `to`, `piece`, `capture`, `promotionTo`) to uppercase (`From`, `To`, `Piece`, `Capture`, `PromotionTo`) to align with Go's convention for exported fields.
- **Added handling for castling restrictions**:
- Added logic to update the opponent's castling ability when a rook is captured.
- **Adjusted en passant logic**:
- Refactored en passant related field usage to match updated naming (`move.To`, `move.From`, etc.).
- Maintained correct behavior for capture during en passant and validation scenarios.
- **Updated UndoMove method**:
- Updated field references to use uppercase names for `move` attributes.
- Refactored en passant and castling restoration logic.
- **Introduced a new `Perft` function**:
- Added the `Perft(depth int)` method to calculate the number of legal positions at a given search depth for move generation debugging purposes.
- **Improved consistency**:
- Standardized field usage across functions (e.g., `Captured` instead of `captured`).
- Applied uniform conventions for accessing all attributes across the codebase.
- **Enhanced promotion logic**:
- Updated the piece promotion logic to reference the refactored field names.
- **Refactored applyCastle method**:
- Updated logic to use renamed fields (`move.To`, `move.Piece`, `move.Capture`).
[board/move.go]
- Standardized field capitalizations, modifying `from`, `to`, `piece`, and `capture` to `From`, `To`, `Piece`, and `Capture`.
- Updated method calls and assignments to match the new field capitalizations throughout the file.
- Adjusted logic in functions related to moves (`IsCastle`, `String`, `GetAlgebra`, etc.) to use updated field names.
- Ensured filtering logic for captures and allies checks matches the new field naming conventions.
- Made associated updates in pawn move generation, sliding moves, and enemy/ally filtering functions to reference `Capture` instead of `capture`.
- Introduced minor layout consistency improvements without altering functionality.
[board/move_test.go]
- Replaced `move.from`, `move.to`, `move.piece`, and `move.capture` with `move.From`, `move.To`, `move.Piece`, and `move.Capture` for consistent capitalization throughout the file.
- Updated method call `perft` to `Perft` in accordance with naming convention changes.
- Removed the `perft` function from the file, likely moved somewhere else or made redundant.
- Adjusted test cases to reflect changes in attribute and method naming conventions (e.g., `from` to `From`, `to` to `To`, `piece` to `Piece`, `capture` to `Capture`).
- Improved error messages in test cases to align with updated attribute names.
[board/board_test.go]
- Variable case corrections for `move.to` and `move.from` to `move.To` and `move.From` respectively.
- Adjusted references of function arguments to match updated casing in various test cases.
- Aligned test logic to maintain consistency with adjusted variable naming conventions.
- No functional logic changes, only updates for adherence to a particular naming style.
[main.go]
- Updated the initial board position by changing the FEN string to a new scenario.
- Added a new variable `depth` set to 2 for evaluating moves to a specific depth.
- Introduced tracking of the total perft count with a new `total` variable.
- Replaced the retrieval of new moves with the use of the `Perft` function to calculate possible moves.
- Modified the output to print the algebraic notation of moves along with their perft count.
- Simplified the final output to display the total count instead of listing all moves.
- Enhance `testdata/integration_test.go` with improved logging and subtest naming for better clarity.
- Refine castle move legality checks in `board/move.go` to ensure accurate column-based validation.
[testdata/integration_test.go]
- Updated log statement in `testData` function to include both the description and FEN string.
- Modified subtest naming to replace slashes in the FEN string with periods.
[board/move.go]
- Adjusted conditional logic for castle-related moves to check for different column coordinates when determining legality.
- No functional changes outside of castle move handling.
- Comment out the main function implementation in `main.go` to disable functionality for now.
- Remove the "indirect" comment from the dependency declaration in `go.mod`.
- Add tests for the `testdata` directory.
[main.go]
- Commented out the entire main function implementation, including code for initializing the board, retrieving moves, iterating over moves, and printing outputs.
- No functional code remains active in the main function.
[go.mod]
- Removed the "indirect" comment from the dependency declaration.
[.github/workflows/go.yml]
- Updated the "Set up Go environment" step to specify Go version 1.22.8.
- Added an additional command to run tests specifically on the `testdata` directory.
- Ensured consistency and expanded test coverage in the workflow.
[board/board_test.go]
- Removed an unnecessary log statement from an En Passant test case.
- Tests verify UndoMove behavior:
- Active player correctly switches between turns.
- Original board position is restored after undoing moves.
- Castling rights are properly updated upon undoing moves.
- Improved En Passant test cases:
- Validation that pawn restoration works after an undo.
- Correctly marks and restores En Passant availability from moves and FEN configurations.
- Verifies board state integrity after multiple moves and undos involving En Passant captures.
- Simplify move string representation by removing intermediate coordinates
- Filter out pseudo moves where the capturing piece is a King
- Format checks for rook captures during castling correctly
- Improve readability and maintainability of the GetMoves function
- Refactor applyEnPassant function for clarity
- Store destination move coordinates in two variables
- Introduce checks for en passant conditions and capture logic
- Reset board.EnPassant appropriately
- Refactor main function to include board operations based on FEN notation
- Add error handling for board initialization
- Implement logic to generate and display moves from the chess board
- Print count of moves after each execution and provide a list of new moves
- Add a test for en passant pawn removal
- Validate en passant pawn restoration upon undo
- Ensure accurate board state reversion after a move
- Update castling state checks after undo
- Enable parallel execution for performance tests
- Update known performance values for specific tests
- Add a new test case for a chess position named Gaviota