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.
This commit is contained in:
MSWS
2025-03-22 18:10:09 -07:00
parent 8890fbbfe6
commit 1b197dc642
3 changed files with 21 additions and 15 deletions

View File

@@ -118,7 +118,7 @@ func (game Game) GetMoves() []Move {
if targetRow != enemyRow { if targetRow != enemyRow {
continue continue
} }
if targetCol == 0 && enemyCol == 2 { if targetCol == 0 && enemyCol == 3 {
legal = false legal = false
break break
} }

32
main.go
View File

@@ -1,22 +1,28 @@
package main package main
import (
"fmt"
"github.com/msws/chess/board"
)
func main() { func main() {
// board, err := board.FromFEN("8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - - 0 1") board, err := board.FromFEN("8/8/4k3/8/8/8/4p3/R3K2R w KQ - 0 1")
// if err != nil { if err != nil {
// panic(err) panic(err)
// } }
// baseMoves := board.GetMoves() baseMoves := board.GetMoves()
// for _, move := range baseMoves { for _, move := range baseMoves {
// board.MakeMove(move) board.MakeMove(move)
// newMoves := board.GetMoves() newMoves := board.GetMoves()
// fmt.Printf("%v: %d moves\n", move, len(newMoves)) fmt.Printf("%v: %d moves\n", move, len(newMoves))
// fmt.Println(newMoves) fmt.Println(newMoves)
// board.UndoMove() board.UndoMove()
// } }
// fmt.Printf("(%d) %v", len(baseMoves), baseMoves) fmt.Printf("(%d) %v", len(baseMoves), baseMoves)
} }

View File

@@ -66,7 +66,7 @@ func testJson(t *testing.T, bytes []byte) {
func testData(t *testing.T, data TestData) { func testData(t *testing.T, data TestData) {
for _, test := range data.Tests { for _, test := range data.Tests {
t.Log(test.Start.Description) t.Log(test.Start.Description, test.Start.Fen)
t.Run(strings.ReplaceAll(test.Start.Fen, "/", "."), func(t *testing.T) { t.Run(strings.ReplaceAll(test.Start.Fen, "/", "."), func(t *testing.T) {
testCase(t, test.Start, test.Expected) testCase(t, test.Start, test.Expected)
}) })