This commit is contained in:
parent
9984ab49fb
commit
07ef81c4c8
1 changed files with 10 additions and 6 deletions
|
|
@ -736,8 +736,8 @@ func validateChessMove(fenStr, from, to, promotion string) MoveResult {
|
||||||
|
|
||||||
game := chess.NewGame(fen)
|
game := chess.NewGame(fen)
|
||||||
|
|
||||||
// Find and execute the move
|
// Verify the move is valid first
|
||||||
var validMove *chess.Move
|
found := false
|
||||||
for _, move := range game.ValidMoves() {
|
for _, move := range game.ValidMoves() {
|
||||||
if move.S1().String() == from && move.S2().String() == to {
|
if move.S1().String() == from && move.S2().String() == to {
|
||||||
// Check promotion
|
// Check promotion
|
||||||
|
|
@ -748,17 +748,21 @@ func validateChessMove(fenStr, from, to, promotion string) MoveResult {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
validMove = &move
|
found = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if validMove == nil {
|
if !found {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make the move (second arg is options, nil for default)
|
// Make the move using UCI notation (e.g., "e2e4" or "e7e8q" for promotion)
|
||||||
if err := game.Move(validMove, nil); err != nil {
|
uciMove := from + to
|
||||||
|
if promotion != "" {
|
||||||
|
uciMove += promotion
|
||||||
|
}
|
||||||
|
if err := game.PushNotationMove(uciMove, chess.UCINotation{}, nil); err != nil {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue