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)
|
||||
|
||||
// Find and execute the move
|
||||
var validMove *chess.Move
|
||||
// Verify the move is valid first
|
||||
found := false
|
||||
for _, move := range game.ValidMoves() {
|
||||
if move.S1().String() == from && move.S2().String() == to {
|
||||
// Check promotion
|
||||
|
|
@ -748,17 +748,21 @@ func validateChessMove(fenStr, from, to, promotion string) MoveResult {
|
|||
continue
|
||||
}
|
||||
}
|
||||
validMove = &move
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if validMove == nil {
|
||||
if !found {
|
||||
return result
|
||||
}
|
||||
|
||||
// Make the move (second arg is options, nil for default)
|
||||
if err := game.Move(validMove, nil); err != nil {
|
||||
// Make the move using UCI notation (e.g., "e2e4" or "e7e8q" for promotion)
|
||||
uciMove := from + to
|
||||
if promotion != "" {
|
||||
uciMove += promotion
|
||||
}
|
||||
if err := game.PushNotationMove(uciMove, chess.UCINotation{}, nil); err != nil {
|
||||
return result
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue