76 Commits

Author SHA1 Message Date
Isaac
65e11f3abc Create LICENSE (#8) 2025-03-25 05:12:11 +00:00
Isaac
bbaf785ef8 Apply GoLand formatting (#7) v0.1.0 2025-03-25 04:52:59 +00:00
dependabot[bot]
da9ce7b698 build(deps): Bump github.com/google/go-cmp from 0.6.0 to 0.7.0 (#6)
Bumps [github.com/google/go-cmp](https://github.com/google/go-cmp) from 0.6.0 to 0.7.0.
- [Release notes](https://github.com/google/go-cmp/releases)
- [Commits](https://github.com/google/go-cmp/compare/v0.6.0...v0.7.0)

---
updated-dependencies:
- dependency-name: github.com/google/go-cmp
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-03-25 00:58:26 +00:00
Isaac
6726754cfe Feat/static check (#5)
* ci: Add and update CI workflows; refine build and test steps

- Add new "Static" GitHub Actions workflow for running `staticcheck`
- Rename `go.yml` to `buildtest.yml` and update workflows
  - Add build and test jobs with caching, coverage, and result publishing
- Update `.gitignore` to exclude `.vscode` files

[.github/workflows/static.yml]
- Added a new GitHub Actions workflow named "Static".
- Configured the workflow to trigger on push and pull request events.
- Defined a CI job running on `ubuntu-latest`.
- Included steps for checking out the repository and running the `staticcheck` tool using a specific version (`2022.1.1`).
[.github/workflows/go.yml]
- Renamed the GitHub Actions workflow file from `go.yml` to `buildtest.yml`.
- Updated the file paths in the `push` trigger to reflect the new filename.
- Renamed the `unit_tests` job to `build` and added a "Build" step to run `go build -v ./...`.
- Introduced a cache setup step in the `build` job for Golang caches, improving build performance.
- Added a new `test` job that runs after the `build` job (with `needs: build` dependency).
   - `test` job includes permissions configuration for checks and pull requests.
   - Installs dependencies, runs tests with coverage, generates JUnit reports, and publishes test results.
- Removed unused permissions settings in the `build` job.
[.gitignore]
- Added `.vscode` to the ignored files in the `.gitignore` file.

* ci: Update checkout action to version 4 in workflow

* ci: Update staticcheck action to version 1.3.1

* ci: Update staticcheck action to use the latest version

* Fix/static errors (#4)

* refactor: Refactor piece enums to prioritize color over type

- Update piece composition order to prioritize color before piece type across relevant files (`Color | Piece` instead of `Piece | Color`)
- Remove `filterEnemies` method from `board/move.go`
- Update test cases and helper functions in `board/fen_test.go` to reflect the new composition order
- Adjust piece constant definitions in `board/pieces_test.go` for consistency with new composition order

[board/pieces_test.go]
- Updated the order of composition for piece constants to prioritize color before piece type (e.g., White | King instead of King | White).
[board/move.go]
- Removed the `filterEnemies` method, which filtered moves based on whether the captured piece was an enemy.
- No other changes to the file.
[board/fen_test.go]
- Reordered enum composition for clarity and consistency, changing the order from `Piece | Color` to `Color | Piece`.
- Updated test cases in `TestGenerateRow` to reflect the new order of enum composition.
  - Modified piece definitions in scenarios including "All Pawns", "Rooks Only", "Alternating Pawns", "Many Kings".
- Adjusted the helper function `getTestBoard` to match the new enum composition order in all board row definitions.

* ci: Refactor workflows by merging test into build job

- Update `.github/workflows/buildtest.yml` to merge "Test" job into "Build" job
- Add explicit permissions for checks and pull-requests in the "Build" job
- Integrate testing, coverage reporting, JUnit report generation, and result publishing into the "Build" job

[.github/workflows/buildtest.yml]
- Added explicit permissions for checks and pull-requests in the "Build" job.
- Removed the "Test" job and merged its steps into the "Build" job.
- Integrated testing, coverage reporting, JUnit report generation, and result publishing directly into the "Build" job.

* ci: Specify read permissions in CI job configuration
2025-03-24 19:51:38 +00:00
Isaac
1b3df458a6 Revert "feat: Implement UCI engine with command processing loop" (#2)
* Revert "feat: Implement UCI engine with command processing loop"

This reverts commit f83f9dd036.

* Run CodeQL
2025-03-24 19:18:30 +00:00
Isaac
612be866b2 Create dependabot.yml (#3)
* Create dependabot.yml

* Run CodeQL
2025-03-24 19:15:52 +00:00
MSWS
f83f9dd036 feat: Implement UCI engine with command processing loop
```
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.
2025-03-24 12:03:23 -07:00
MSWS
a5d5032c3a Merge branches 'dev' and 'main' of github.com:MSWS/GoChess2 2025-03-23 17:26:43 -07:00
Isaac
0e02ec4457 test: Expand test coverage and refine CI workflow paths (#1)
* test: Expand test coverage and refine CI workflow paths

- Update GitHub Actions workflow to allow broader branch triggers and include "testdata/*.json" in paths
- Expand test coverage and performance data validation in `board/move_test.go`

[.github/workflows/go.yml]
- Removed restriction on specific branches for push events.
- Added "testdata/*.json" to the paths triggering the workflow.
[board/move_test.go]
- Updated `knownPerfs` arrays for several test cases to include additional performance data across various depths.
- Expanded test coverage for positions like "Nf3 g5," "a4 a5," "Kiwipete," "Kiwipete - Passant," "Kiwipete - Checked," "Kiwipete - Minimized," "3 g3+," and "Gaviota."
- Improved the granularity of performance test data for better validation at deeper levels.

* test: Refactor move tests with subtests and simpler handling

Simplify error handling and improve test structure in move_test.go

- Remove `defer` and `recover` block, streamlining error handling.
- Refactor `t.Log` calls into subtests using `t.Run` for better granularity.
- Organize tests into isolated subtests for clearer execution and reporting.

[board/move_test.go]
- Removed the `defer` and `recover` block for error recovery, simplifying error handling.
- Changed the `t.Log` for each ply into a subtest using `t.Run`.
- Improved test structure by adding isolated subtests for each ply using `t.Run`, providing better granularity for test execution and reporting.

* feat: Adjust board traversal logic for active player direction

- Update board traversal logic to handle direction based on active player
  Introduce `startRow` and `rowDir` for flexible iteration, adjusting row iteration logic to vary starting points and directions based on whether the active player is Black.

[board/move.go]
- Added logic to handle board traversal direction based on the active player, introducing `startRow` and `rowDir` for flexible iteration.
- Adjusted the row iteration logic to account for varying starting points and directions, depending on whether the active player is Black.
- No changes were made to the underlying move generation or legality checks.

* test: Refactor move tests for readability and early exit

- Add conditional early exit on unsuccessful `t.Run` for a ply in `board/move_test.go`
2025-03-24 00:26:27 +00:00
MSWS
a08bddbc6b test: Refactor move tests for readability and early exit
- Add conditional early exit on unsuccessful `t.Run` for a ply in `board/move_test.go`
2025-03-23 17:23:07 -07:00
MSWS
6ce23992ae feat: Adjust board traversal logic for active player direction
- Update board traversal logic to handle direction based on active player
  Introduce `startRow` and `rowDir` for flexible iteration, adjusting row iteration logic to vary starting points and directions based on whether the active player is Black.

[board/move.go]
- Added logic to handle board traversal direction based on the active player, introducing `startRow` and `rowDir` for flexible iteration.
- Adjusted the row iteration logic to account for varying starting points and directions, depending on whether the active player is Black.
- No changes were made to the underlying move generation or legality checks.
2025-03-23 17:20:15 -07:00
MSWS
3739104149 test: Refactor move tests with subtests and simpler handling
Simplify error handling and improve test structure in move_test.go

- Remove `defer` and `recover` block, streamlining error handling.
- Refactor `t.Log` calls into subtests using `t.Run` for better granularity.
- Organize tests into isolated subtests for clearer execution and reporting.

[board/move_test.go]
- Removed the `defer` and `recover` block for error recovery, simplifying error handling.
- Changed the `t.Log` for each ply into a subtest using `t.Run`.
- Improved test structure by adding isolated subtests for each ply using `t.Run`, providing better granularity for test execution and reporting.
2025-03-23 17:10:02 -07:00
MSWS
a7cb54819c test: Expand test coverage and refine CI workflow paths
- Update GitHub Actions workflow to allow broader branch triggers and include "testdata/*.json" in paths
- Expand test coverage and performance data validation in `board/move_test.go`

[.github/workflows/go.yml]
- Removed restriction on specific branches for push events.
- Added "testdata/*.json" to the paths triggering the workflow.
[board/move_test.go]
- Updated `knownPerfs` arrays for several test cases to include additional performance data across various depths.
- Expanded test coverage for positions like "Nf3 g5," "a4 a5," "Kiwipete," "Kiwipete - Passant," "Kiwipete - Checked," "Kiwipete - Minimized," "3 g3+," and "Gaviota."
- Improved the granularity of performance test data for better validation at deeper levels.
2025-03-23 17:04:07 -07:00
MSWS
cd463aed80 feat: Revise board setup, depth, and move generation logic
- 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.
2025-03-23 16:52:24 -07:00
MSWS
eab479658f refactor: Refactor perftCache to use thread-safe sync.Map
- Refactor `perftCache` to use `sync.Map` for thread-safe operations.
- Remove manual initialization logic for `perftCache` as `sync.Map` handles it natively.
- Update `fen` string manipulation to utilize `string(rune(depth))` for cleaner type conversion.

[board/board.go]
- Added the `sync` package import for thread-safe operations.
- Replaced the `map`-based implementation of `perftCache` with the thread-safe `sync.Map`.
- Removed the manual initialization check for `perftCache` since `sync.Map` does not require explicit initialization.
- Adjusted the `fen` string manipulation to use `string(rune(depth))` for improved type conversion.
- Updated all `perftCache` read and write operations to use `sync.Map`'s `Load` and `Store` methods for thread-safe access.
2025-03-23 15:58:46 -07:00
MSWS
76b6d55ff5 perf: Optimize Perft with caching and update search behavior
- 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.
2025-03-23 15:52:11 -07:00
MSWS
40326d03b0 refactor: Refactor field naming and integrate Perft evaluation
```
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.
2025-03-23 15:15:44 -07:00
MSWS
f0746ceac4 fix: Ensure applyEnPassant is always executed for moves
- Ensure `board.applyEnPassant(&move)` is always executed for a move by moving the method call outside the Pawn conditional block

[board/board.go]
- Moved the `board.applyEnPassant(&move)` method call outside the conditional block for Pawns, making it always executed for a move.
2025-03-23 14:31:17 -07:00
MSWS
ce6de427e0 feat: Add En Passant tests and improve move algebra handling
- Add subtest for "En Passant" in `TestCreateMoveAlgebra` within `board_test.go`
  - Test verifies move "dxe6" using FEN notation and includes error handling.
- Introduce `GetAlgebra` method in `Move` struct to generate algebraic notations, with handling for various piece moves and captures.
- Update `CreateMoveAlgebra` in `move.go` to sanitize input using regex and default to `Pawn` piece type for unknown inputs.

[board/board_test.go]
- Added a new subtest for testing "En Passant" moves within the "Pawn" section of the `TestCreateMoveAlgebra` test.
- The "En Passant" test initializes a board using FEN notation and verifies the "from" and "to" coordinates for the move "dxe6".
- Includes error handling for board creation and validation of expected results for the test case.
[board/move.go]
- Added a `regexp` package import to support regex operations.
- Introduced a new method `GetAlgebra` for the `Move` struct to generate algebraic notations for moves, including handling cases for different piece types, pawn moves, castling, and captures.
  - TODO for adding checks and mates to the algebraic notation.
- Modified the `CreateMoveAlgebra` function to sanitize the input algebraic notation by removing characters like "x", "+", and "#" using regex.
- Updated the piece parsing logic in `CreateMoveAlgebra` to default to `Pawn` instead of throwing an error if the input doesn't match a known piece type.
2025-03-23 14:21:06 -07:00
MSWS
b49bbd0aae feat: Add castling and disambiguation support for moves
- Implement castling logic and support for double-disambiguated algebraic notation in `board/move.go`
- Add helper functions for move generation and improve move source coordinate identification
- Enhance error handling for invalid moves in `board/move.go`
- Expand test coverage for pawn moves and refine test structure in `board/board_test.go`

[board/move.go]
- Added logic to handle castling moves based on input algebra.
- Introduced support for double-disambiguated algebraic notation (e.g., specifying exact `from -> to` square).
- Added capability to identify the piece type (e.g., Knight, Bishop, Rook, Queen, King) from algebraic notation.
- Implemented a new helper function `createMoveFromTarget` to deduce moves based on target square and piece type.
  - Handles disambiguation by row or column when applicable.
- Added methods `createMoveFromDisambiguatedCol` and `createMoveFromDisambiguatedRow` to support move generation from specific row or column disambiguations.
- Introduced `getSourceCoord` function to locate the source coordinate of a piece based on filters, enhancing move determination logic.
- Improved error handling and validation for invalid moves or unknown piece types in algebraic notation.
[board/board_test.go]
- Added a new test case to verify handling of pawn moves in the `TestCreateMoveAlgebra` function.
- Removed unnecessary `defer` blocks that attempted to recover from panics in the `TestCreateMoveAlgebra` test.
- Slightly adjusted some test structures and white space.
- No significant changes were made to logic within core tests, primarily focused on improving test structure and expanding coverage.
2025-03-23 13:56:28 -07:00
MSWS
22a50662c8 fix: Fix piece handling and error messages in board tests
- Correct error message in castling tests to indicate the correct king placement square (`g1` instead of `f1`)
- Fix order of bitwise OR operation for board initialization to ensure consistent piece representation (`White | Pawn` instead of `Pawn | White`)
- Modify `markRowColor` function to use `GetType()` for accurate piece type and color combination

[board/board_test.go]
- Corrected an error message in castling tests to indicate the proper square for the white king placement (`g1` instead of `f1`).
- Fixed the order of bitwise OR operation in board initialization to ensure consistency (`White | Pawn` instead of `Pawn | White`).
- Modified `markRowColor` function to correctly combine piece type with color using `GetType()` method.
- No structural changes in the implementations but improved clarity and correctness of piece manipulation and test cases.
2025-03-23 13:21:40 -07:00
MSWS
0b518ed6f3 ci: Add always() condition to publish test results
- Add `if: always()` condition to "Publish Test Results" step in GitHub Actions workflow
- Apply minor formatting adjustments in `go.yml`

[.github/workflows/go.yml]
- Added a condition `if: always()` to the "Publish Test Results" step.
- No other notable changes except for formatting adjustments.
2025-03-23 13:10:52 -07:00
MSWS
df0a15242f ci: Refactor JUnit and Test Results step conditions
- Add `if: always()` condition to "Generate JUnit report" step in CI workflow
- Remove `if: always()` condition from "Publish Test Results" step in CI workflow

[.github/workflows/go.yml]
- Added an explicit condition `if: always()` to the "Generate JUnit report" step.
- Removed the `if: always()` condition from the "Publish Test Results" step.
2025-03-23 13:09:13 -07:00
MSWS
c25416305e ci: Refactor Go workflow to update test steps and formats
- Update `.github/workflows/go.yml` to improve test workflow by installing `go-junit-report`, splitting test steps, and switching test results to XML format

[.github/workflows/go.yml]
- Updated the workflow to install dependencies using `go-junit-report`.
- Replaced the "Run Tests with Coverage" step with separate steps for running tests, generating a JUnit report, and handling test results.
- Test result format changed from JSON to XML for publishing.
2025-03-23 13:07:03 -07:00
MSWS
31f49138f0 ci: Update Go version and test result handling in CI
Update Go workflow configuration

- Modify test command to store output in `test-results.json`
- Adjust publishing step to reference `test-results.json` directly
2025-03-23 13:00:12 -07:00
MSWS
e1c42edf96 ci: Update Go CI workflow with coverage and test publishing
- Add `permissions` section with write access for `checks` and `pull-requests` in GitHub Actions workflow
2025-03-23 12:56:11 -07:00
MSWS
b5bf1cb555 ci: Streamline CI workflow and update test data.
- Update test performance data in `board/move_test.go` with additional and higher depth analysis results for specific positions, ensuring no changes to test logic or structure.
- Simplify `.github/workflows/go.yml` by removing PR-specific actions, upgrading to Go 1.23, streamlining test result handling, and integrating `EnricoMi/publish-unit-test-result-action`.

[board/move_test.go]
- Added additional known performance data to specific test cases.
- Un-commented performance data values for select board positions.
- Adjusted data for positions like "Starting Position," "Kiwipete," and "6" by adding higher depth analysis results.
- No changes to test logic or structure, only updates to performance-related test data.
[.github/workflows/go.yml]
- Removed handling of pull requests and kept only push events triggering the workflow.
- Updated Go version from `^1.22` to `^1.23`.
- Consolidated steps for archiving and processing test results into a streamlined approach.
- Eliminated jobs for code coverage report and test summary.
- Integrated the `EnricoMi/publish-unit-test-result-action` for publishing test results.
- Reduced complexity by removing custom test summaries and PR comment posting logic.
- Simplified logic for handling test failures directly within the unit test step.
2025-03-23 12:54:08 -07:00
MSWS
48400eeac8 ci: Update Go workflow with refined test handling logic
- Refactor test processing by enhancing `jq` filters and splitting summary handling for `push` events
- Improve conditional logic for event-specific actions in workflow

[.github/workflows/go.yml]
- Updated Go version setup to use `^1.22`.
- Changed how test results are processed, modifying `jq` filters for counting passed and failed tests.
- Split test summary functionality:
  - Added a dedicated step to output test summaries specifically for `push` events in the GitHub Actions summary.
  - Refined pull request comment posting for test summaries.
- Improved conditional logic to differentiate actions based on the event type (`push` vs `pull_request`).
2025-03-23 12:27:17 -07:00
MSWS
9126c962bb ci: Update Go workflow to include testdata package
- Update test command in GitHub Actions workflow to include the `./testdata` package

[.github/workflows/go.yml]
- Updated the command for running tests to include the `./testdata` package.
2025-03-22 19:56:10 -07:00
MSWS
91b8eff72c ci: Make test workflows robust and handle test failures
- Update "Run Tests with Coverage" to allow failures and set an environment variable if tests fail
- Ensure code coverage and test summary jobs always run using `if: always()`
- Add step to explicitly fail workflow when tests fail
- Adjust permissions for `pull-requests` in workflows

[.github/workflows/go.yml]
- Updated the "Run Tests with Coverage" step to allow failures and set an environment variable if tests fail.
- Changed code coverage and test summary jobs to always run with the `if: always()` condition.
- Added a step to fail the workflow explicitly if tests failed.
- Adjusted permissions for `pull-requests` in certain workflows.
2025-03-22 19:53:43 -07:00
MSWS
8dd31f8a98 ci: Refactor Go workflow with test summary and improvements
- Simplify workflow trigger conditions and remove redundant event types in `.github/workflows/go.yml`
- Replace "Test" step with "Run Tests with Coverage" step, outputting results as JSON in `.github/workflows/go.yml`
- Introduce artifact archiving for test results (`test-results.json`) in `.github/workflows/go.yml`
- Refactor "Code Coverage Report" job for improved clarity and formatting in `.github/workflows/go.yml`
- Add a "Test Summary" job to parse test results and post PR comments in `.github/workflows/go.yml`

[.github/workflows/go.yml]
- Simplified workflow "trigger" conditions by removing extensive inline comments and unnecessary event types.
- Replaced the "Test" step with a new "Run Tests with Coverage" step that also outputs results as a JSON file.
- Introduced a new step to archive test results as a separate artifact ("test-results.json").
- Modified the "Code Coverage Report" job to adjust formatting and clarify steps without functional changes.
- Added a new "Test Summary" job:
  - Downloads and parses test results for passed/failed counts using `jq`.
  - Posts a test summary as a comment on pull requests using a sticky comment action.
2025-03-22 19:52:07 -07:00
MSWS
418e816e54 ci: Update Go CI workflow with triggers and code coverage jobs
```
Revamp CI workflow for improved clarity and functionality

- Rename the workflow from "Go Build and Test" to "CI" and update its trigger logic to better handle `push` and `pull_request` events.
- Refactor workflow jobs: rename `go-build-and-test` to `unit_tests` and introduce a new `code_coverage` job for pull request coverage reporting.
- Update dependencies to use the latest versions (`actions/checkout@v4`, `actions/setup-go@v4`, etc.) and simplify configuration (e.g., use `^1.22` for `go-version`).
- Add steps for generating and uploading code coverage details using `fgrosse/go-coverage-report@v1.1.1` and `actions/upload-artifact@v4`.
- Remove unused or redundant steps, such as searching for `go.mod` directories, and improve documentation with detailed comments about workflow purpose and trigger logic.
```

[.github/workflows/go.yml]
- Renamed the workflow from "Go Build and Test" to "CI".
- Updated the workflow triggers to include `pull_request` with events like `opened`, `reopened`, and `synchronize`, and restricted `push` events to the `main` branch.
- Added detailed explanation comments about the trigger logic and workflow purpose.
- Updated the `concurrency` section by removing it.
- Renamed the primary job from `go-build-and-test` to `unit_tests`.
- Replaced "Checkout code" with "Checkout repository" and updated to use `actions/checkout@v4`.
- Updated Go setup to use `actions/setup-go@v4` and simplified the `go-version` field to use `^1.22`.
- Added a step to run tests with code coverage output and specified a coverage profile file ("coverage.txt").
- Included a step to archive code coverage results using `actions/upload-artifact@v4`.
- Removed the step that searched for and processed directories with `go.mod`.
- Introduced a new `code_coverage` job to handle code coverage reporting specifically for pull requests, dependent on the `unit_tests` job.
- Configured permissions for `code_coverage` to allow commenting on pull requests.
- Added a step to generate a code coverage report using the `fgrosse/go-coverage-report@v1.1.1` action.
2025-03-22 19:51:55 -07:00
MSWS
ffa0a73d2f feat: Add algebraic move support with tests and validation
- Add `TestCreateMoveAlgebra` in `board_test.go` to validate move generation in algebraic notation, with coverage for various scenarios and panic handling.
- Remove outdated `TestMakeMoveStr` test from `board_test.go`.
- Introduce `CreateMoveAlgebra` method in `move.go` for algebraic notation move generation, with validation and fallback to `CreateMoveStr`.

[board/board_test.go]
- Added a new test `TestCreateMoveAlgebra` to validate move generation in algebraic notation, including setup, move creation, and verification of results.
  - Ensured coverage for different scenarios like knight moves and pawn moves across the board.
  - Added error handling to detect unexpected panics during test execution.
- Removed the `TestMakeMoveStr` test, which checked the proper movement of a pawn using `MakeMoveStr`, along with its associated validations.
[board/move.go]
- Added a new method `CreateMoveAlgebra` for generating a move based on algebraic notation.
  - Determines behavior for pawns based on the active player color.
  - Includes validation to ensure the move is valid, with error handling for invalid moves.
  - Falls back to `CreateMoveStr` for longer algebra strings.
2025-03-22 18:52:30 -07:00
MSWS
67ee26a484 refactor: Refactor pseudo-move legality and validation logic
Refactor and enhance move validation logic:

- Refactor validation logic for legality of pseudo-moves, ensuring proper handling of enemy moves.
- Modify checks to prevent illegal scenarios involving captures of the enemy king.
- Adjust pseudo castle move conditions to validate target positions and account for enemy rook captures.
- Streamline conditional flow by removing redundant checks.
2025-03-22 18:16:43 -07:00
MSWS
1b197dc642 fix: Restore and enhance move generation and board logic
- 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.
2025-03-22 18:10:09 -07:00
MSWS
8890fbbfe6 ci: Update Go version and improve test coverage setup
- Combine test commands in `go test` with coverage for `./...` and `./testdata/`
2025-03-22 17:58:01 -07:00
MSWS
54d81edb33 test: Refactor tests and workflows; comment out main function
- 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.
2025-03-22 17:55:32 -07:00
MSWS
1177bfa6bf test: Add JSON test cases and integration tests for chess moves
```
Add comprehensive test cases for chess scenarios and validate JSON parsing in integration tests

- Add `integration_test.go` to handle JSON test cases, parse data, and validate chess move generation against expected results.
- Add `checkmates.json` with test cases for various checkmate scenarios, including mirrors and edge cases.
- Add `famous.json` detailing positions and test sequences from historical chess games for validation.
- Add `standard.json` to test and verify early-game chess positions and standard move transitions.
- Add `promotions.json` with detailed cases for pawn promotions, including edge scenarios and forced moves.
- Add additional JSON files (`castling.json`, `taxing.json`, `pawns.json`, `stalemates.json`) with test data for specific chess rule validations and edge cases like castling, stalemates, and en passant captures.
```

[testdata/integration_test.go]
- Adds a new test file to validate JSON-defined chess scenarios against board states and expected moves.
- Defines structs for handling test data, including descriptions, starting positions, and expected outcomes.
- Implements a test function to read JSON files in the directory, parse them, and execute tests on the data.
- Introduces helper functions to parse JSON data and iterate through test cases.
- Adds logic to compare expected moves from JSON with generated moves from the chess board state.
- Includes error handling for file reading, JSON unmarshalling, and position validation from the chess board.
[testdata/checkmates.json]
- Added a new JSON file containing test cases for checkmate scenarios.
- Each test case includes a FEN description and an expected output.
  - Descriptions and tests cover specific checkmate types: ladder mate, smothered mate, en passant situations, and minimal-piece mates.
- Added transposed positions for each checkmate scenario to validate mirrored setups.
[testdata/famous.json]
- Added new JSON file containing chess positions and test cases.
- Included a "description" field specifying the context of the chess problems.
- Each test case specifies a starting position (given by a FEN string) and a list of moves along with their corresponding resulting positions (also as FEN strings).
- Added detailed test cases for two famous chess games: "The Game of the Century" and "The Gold Coins Game".
  - For "The Game of the Century", provided multiple legal move sequences and their outcomes from a specific mid-game position.
  - For "The Gold Coins Game", included potential moves and their resulting positions leading to the iconic "Gold Coin move".
- Enriched some moves with descriptive comments for historical or tactical significance.
- Added various chess scenarios to thoroughly test a move generator's capability to handle diverse situations.
[testdata/standard.json]
- Added a new JSON file containing test cases for specific chess board positions.
- The JSON includes:
  - Definitions of starting positions using FEN strings.
  - Descriptions of the starting positions, such as "Standard starting position" and "Ruy Lopez opening".
  - Expected potential moves with resulting FEN states after each move. These moves explore various legal possibilities from the starting positions.
- The file contains test cases primarily for validating early-game configurations and various move transitions in chess.
[testdata/promotions.json]
- Added a new file containing JSON data describing chess test cases focused on pawn promotions.
- Included multiple scenarios covering basic promotion, transposed positions, and edge cases such as forced promotion to escape check or mate.
- Detailed expected moves and resulting board configurations in FEN format for each scenario.
- Descriptions accompanied each test case to clarify the situations being tested, like promoting via capture, forced promotions, or specific checks on the king.
- Covered scenarios where multiple promotion options exist, including promotions resulting in check or checkmate.
[testdata/castling.json]
- Added a new JSON file for castling test cases.
- Created test cases for all possible castling scenarios, including:
  - Normal castling for both sides.
  - Castling when prohibited due to an attacking piece (rook, bishop, knight, queen, king, and pawn).
  - Castling into or through check.
  - Castling when the king or rooks have moved.
- Implemented edge cases, including en passant and pawn-promotion interference with castling rights.
- Included transposed positions to test symmetry and equivalence in board states.
- Supported scenarios where attacks on rooks do not affect castling ability.
- Verified that castling remains allowed despite irrelevant pawn attacks or unoccupied intermediate squares.
[testdata/taxing.json]
- Added a large JSON file containing test cases and expected results for chess positions.
- Introduced different scenarios to analyze edge cases:
  - Positions with pieces in maximal quantity for a specific type (e.g., maximum knights, maximum queens, maximum bishops).
  - Transposed positions to verify symmetric behavior.
  - Special rules scenarios like prohibited en passant captures due to check.
- Organized data with a `description` for each scenario, `start` positions in FEN format, and corresponding `expected` moves with their resulting positions.
- Ensured diverse test coverage, including:
  - Positions designed to stress test move generation.
  - Positions covering intricate rules interactions like pawn structure scenarios (en passant).
  - Positions with multiple complexity levels (low-mobility vs high-mobility positions).
[testdata/pawns.json]
- Added a new JSON file defining test cases involving pawn positions in chess.
- The test cases cover various scenarios with en passant possibilities, moves without en passant, and full pawn setups.
- Each test scenario details the starting board position (FEN), a description, and expected moves along with the resulting FEN after each move.
- Includes mirrored or transposed versions of positions to test symmetry and edge cases.
- Scenarios test both legal and illegal moves, focusing on edge cases like restricted en passant and pawn movement logic.
- Ensures test coverage for complex pawn interactions, including rows with dense pawn positions and potential captures.
- Scenarios also evaluate king movements in relation to pawns.
- Emphasizes positions where rule-specific mechanics, like en passant, are critical to validate correctness.
[testdata/stalemates.json]
- Added a new JSON test data file for stalemate cases in chess.
- Included multiple test cases with starting positions (FEN notation) and expected results.
- Each test case represents a specific stalemate scenario or its transpose (mirrored version).
- Some descriptions provide details about positions, such as the shortest stalemate possible.
- Empty arrays are used for expected outputs, implying no further data is expected from these stalemate setups.
2025-03-22 17:46:26 -07:00
MSWS
9bb1cadac7 refactor: Rename Board struct to Game and update references.
- Rename `Board` struct to `Game` across the codebase for better clarity and alignment with functionality.
- Update `board/move.go`: Adjust method receivers and references to use `Game` instead of `Board`, ensuring consistency.
- Update `board/board.go`: Refactor struct fields, method implementations, and FEN-related logic to accommodate the `Game` struct. Remove unused `Bitboard` type and clarify metadata fields (`HalfMoves`, `FullMoves`).
- Update `.github/workflows/go.yml`: Simplify the test command.
- Refactor tests (`board/move_test.go`, `board/board_test.go`) to align with the renamed `Game` struct and associated changes.
2025-03-22 16:48:51 -07:00
MSWS
fcc81550d7 refactor: Rename PrettySPrint method to PrettyPrint
Rename `PrettySPrint` method to `PrettyPrint` and update references

[board/board.go]
Renamed the method `PrettySPrint` to `PrettyPrint`.
2025-03-22 16:39:07 -07:00
MSWS
d3f392b6d1 refactor: Rename castling struct and fields for clarity and consistency
- Refactor `Castlability` struct to `Castling` and update field names from `CanQueenSide`/`CanKingSide` to `QueenSide`/`KingSide` in `board/board.go`.
- Rename `getCastlability` function to `formatCastling` and adjust logic for renamed struct and fields in `board/board.go`.
- Update tests in `board/board_test.go` to reflect renaming of struct and fields, including `Castlability` to `Castling` and method changes for `KingSide`/`QueenSide`.
- Rename variables and update conditions for `KingSide`/`QueenSide` in `board/move.go`.

[board/move.go]
The `CanKingSide` variable was renamed to `KingSide` and updated in the condition.
The `CanQueenSide` variable was renamed to `QueenSide` and updated in the condition.
[board/board_test.go]
Changes method calls to replace `CanKingSide` and `CanQueenSide` with `KingSide` and `QueenSide`.

Updates struct fields from `Castlability` to `Castling` where applicable.

Adjusts function tests to use updated naming conventions for castling (`Castlability` to `Castling`).

Aligns expected variables and logic in tests with the updated struct fields and method names (`CanKingSide`/`CanQueenSide` to `KingSide`/`QueenSide`).
[board/board.go]
The struct `Castlability` was renamed to `Castling` and the field names were simplified from `CanQueenSide` to `QueenSide` and from `CanKingSide` to `KingSide`.

References to `Castlability` in declarations, assignments, and history tracking were updated to `Castling`.

The function `getCastlability` was renamed to `formatCastling` and updated to use the renamed struct and fields.

The usage of `CanQueenSide` and `CanKingSide` in logic was updated to `QueenSide` and `KingSide`.

General cleanup in comments and function names to align with the new struct and field naming conventions.
2025-03-22 16:38:03 -07:00
MSWS
abf4080e5f docs: Add comment marker to PrettySPrint function
- Add inline comment marker to start of PrettySPrint function in board.go

[board/board.go]
Added an inline comment marker (//) at the start of the PrettySPrint function implementation.
2025-03-22 16:35:59 -07:00
MSWS
a1a1415b96 Limit piece movement and enhance game state handling
Improve move generation and board state management

- Limit move generation loop to a maximum of 16 pieces on the board
- Adjust position checks for new piece limit
- Handle king movements accurately in legal move calculations
- Remove unnecessary empty line in UndoMove function
- Refactor code for better readability and clarity
- Enhance tracking of castling states
- Ensure correct handling of the en passant rule
- Update history of castling states after an undo
2025-03-22 16:07:02 -07:00
MSWS
bdec2967b0 Improve logging and error handling in move tests
Refactor test logging and error handling in move tests

- Change logging method for performance test iterations to improve clarity
- Update error reporting to ensure tests fail immediately on calculation errors
- Remove unnecessary deferred function to streamline test execution
2025-03-22 15:57:52 -07:00
MSWS
3262ee2902 Enhance performance tests with parallel execution and recovery
Enable parallel testing for improved performance

- Implement parallel testing in `move_test.go`
- Add error recovery mechanism to `perft` function test
- Clean up test data by removing commented-out values
- Introduce a new FEN scenario for Kiwipete - Passant
- Update `knownPerfs` to eliminate a commented value in the test case for 6
2025-03-22 15:53:39 -07:00
MSWS
d5af1cdd3a Clarify en passant and castling move handling
Improve en passant handling and simplify castling logic

- Update handling of en passant moves to assign the `EnPassant` field correctly
- Remove redundant assignment of `EnPassant` at the end of the method
- Clarify castling conditions for better understanding
- Simplify test cases by removing unnecessary scenarios
- Add a test case for handling en passant on double undo
- Verify accurate game state restoration after multiple undos
- Ensure proper marking and unmarking of en passant under various conditions
2025-03-22 15:31:14 -07:00
MSWS
c7d3614172 Enhance tests for en passant and piece movement logic
- Implement tests for en passant feature in board_test.go
- Cover scenarios for marking and unmarking pieces
- Add a test case for handling multiple undos in en passant
- Validate pawn movement and capturing during en passant
- Confirm correct pawn promotion within tests
- Enhance pieces.go to handle default piece type with an underscore
- Modify panic error message format from hexadecimal to binary
2025-03-22 15:21:07 -07:00
MSWS
57bba0ef59 Refactor en passant logic and improve test clarity
Refactor board logic and improve tests

- Refactor import statements in pieces.go
- Add String method to Piece type for better representation
- Add isEnPassant field to Move struct
- Update move logic to mark en passant captures
- Adjust handling of pawn moves related to en passant
- Change MakeMove to not return a move
- Update applyEnPassant to accept pointer to Move
- Track en passant captures within Move struct
- Remove redundant condition check in UndoMove
- Enhance readability of variable assignments
- Comment out parallel test execution for debugging
- Modify error handling for accurate performance logging
- Correct expected board state after undo in en passant scenario
- Clarify comments in tests regarding en passant logic
- Improve clarity of error messages in test assertions
2025-03-22 14:48:33 -07:00
MSWS
5cedc0b351 Refactor chess move logic and enhance board functionality
- 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
2025-03-22 13:54:48 -07:00
MSWS
d3e142a7bf Implement en passant and promotion features in chess logic
- Add tests and functionality for en passant, pawn promotion, and undoing moves
- Refactor pawn movement logic for improved readability
- Update MakeMove and UndoMove to handle en passant and promotion
- Enhance test cases to cover new scenarios and improve performance tracking
2025-03-22 12:16:43 -07:00