3 Commits

Author SHA1 Message Date
Isaac
bbaf785ef8 Apply GoLand formatting (#7) 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
8 changed files with 50 additions and 27 deletions

View File

@@ -5,15 +5,15 @@ on:
paths:
- "**/*.go"
- "testdata/*.json"
- ".github/workflows/go.yml"
- ".github/workflows/buildtest.yml"
jobs:
unit_tests:
name: "Unit tests"
runs-on: ubuntu-latest
build:
permissions:
checks: write
pull-requests: write
name: "Build"
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
@@ -23,13 +23,26 @@ jobs:
with:
go-version: ^1.23
- name: Setup Golang caches
uses: actions/cache@v4
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-golang-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-golang-
- name: Build
run: go build -v ./...
- name: Install dependencies
run: go install github.com/jstemmer/go-junit-report/v2@latest
- name: Test with coverage
run: |
go test -cover -coverprofile=coverage.txt -json ./... ./testdata > test-results.json
- name: Generate JUnit report
if: always()
run: go-junit-report < test-results.json > test-results.xml

14
.github/workflows/static.yml vendored Normal file
View File

@@ -0,0 +1,14 @@
name: "Static"
on: [ "push", "pull_request" ]
jobs:
ci:
name: "Run CI"
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- uses: dominikh/staticcheck-action@v1.3.1
with:
version: "latest"

2
.gitignore vendored
View File

@@ -1 +1,3 @@
chess
.vscode
.idea

View File

@@ -49,7 +49,7 @@ func TestGenerateRow(t *testing.T) {
},
"All Pawns": {
input: "pppppppp",
result: [8]Piece{Pawn | Black, Pawn | Black, Pawn | Black, Pawn | Black, Pawn | Black, Pawn | Black, Pawn | Black, Pawn | Black},
result: [8]Piece{Black | Pawn, Black | Pawn, Black | Pawn, Black | Pawn, Black | Pawn, Black | Pawn, Black | Pawn, Black | Pawn},
},
"Starting Row": {
input: "RNBQKBNR",
@@ -57,15 +57,15 @@ func TestGenerateRow(t *testing.T) {
},
"Rooks Only": {
input: "r6R",
result: [8]Piece{Rook | Black, 0, 0, 0, 0, 0, 0, Rook | White},
result: [8]Piece{Rook | Black, 0, 0, 0, 0, 0, 0, White | Rook},
},
"Alternating Pawns": {
input: "pP1Pp2P",
result: [8]Piece{Pawn | Black, Pawn | White, 0, Pawn | White, Pawn | Black, 0, 0, Pawn | White},
result: [8]Piece{Pawn | Black, White | Pawn, 0, White | Pawn, Pawn | Black, 0, 0, White | Pawn},
},
"Many Kings": {
input: "KKKKkkkk",
result: [8]Piece{King | White, King | White, King | White, King | White, King | Black, King | Black, King | Black, King | Black},
result: [8]Piece{White | King, White | King, White | King, White | King, Black | King, Black | King, King | Black, King | Black},
},
}
@@ -115,10 +115,10 @@ func getStartBoard() *[8][8]Piece {
func getTestBoard() *[8][8]Piece {
board := [8][8]Piece{
{0, 0, Pawn | White, 0, 0, 0, Knight | White},
{0, 0, White | Pawn, 0, 0, 0, White | Knight},
{0, Pawn | Black, 0, 0, 0, Bishop | Black},
{Bishop | White, 0, 0, 0, Rook | Black},
{0, 0, 0, Queen | White, 0, 0, 0, Queen | Black},
{White | Bishop, 0, 0, 0, Black | Rook},
{0, 0, 0, White | Queen, 0, 0, 0, Black | Queen},
{Pawn | Black, Pawn | Black, Pawn | Black},
{Pawn | Black, Pawn | Black},
{Pawn | Black},

View File

@@ -565,12 +565,6 @@ func filter[T any](arr []T, predicate func(T) bool) []T {
return ret
}
func (board Game) filterEnemies(moves []Move) []Move {
return filter(moves, func(m Move) bool {
return m.Capture == 0 || m.Piece.GetColor() == m.Capture.GetColor()
})
}
func (board Game) filterAllies(moves []Move) []Move {
return filter(moves, func(m Move) bool {
return m.Capture == 0 || m.Piece.GetColor() != m.Capture.GetColor()

View File

@@ -76,12 +76,12 @@ func getTestData() []struct {
rune rune
piece Piece
}{
{rune: 'K', piece: King | White},
{rune: 'Q', piece: Queen | White},
{rune: 'R', piece: Rook | White},
{rune: 'B', piece: Bishop | White},
{rune: 'N', piece: Knight | White},
{rune: 'P', piece: Pawn | White},
{rune: 'K', piece: White | King},
{rune: 'Q', piece: White | Queen},
{rune: 'R', piece: White | Rook},
{rune: 'B', piece: White | Bishop},
{rune: 'N', piece: White | Knight},
{rune: 'P', piece: White | Pawn},
{rune: 'k', piece: King | Black},
{rune: 'q', piece: Queen | Black},
{rune: 'r', piece: Rook | Black},

2
go.mod
View File

@@ -2,4 +2,4 @@ module github.com/msws/chess
go 1.22.8
require github.com/google/go-cmp v0.6.0
require github.com/google/go-cmp v0.7.0

4
go.sum
View File

@@ -1,2 +1,2 @@
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=