This commit is contained in:
parent
b43c6210be
commit
89c2e1630d
1 changed files with 10 additions and 3 deletions
|
|
@ -550,7 +550,7 @@ func (m *ChessMatch) MatchLoop(ctx context.Context, logger runtime.Logger, db *s
|
|||
}
|
||||
|
||||
// Validate and apply the move
|
||||
result := validateChessMove(s.FEN, moveData.From, moveData.To, moveData.Promotion)
|
||||
result := validateChessMove(s.FEN, moveData.From, moveData.To, moveData.Promotion, logger)
|
||||
if !result.Valid {
|
||||
logger.Warn("Invalid move: %+v", moveData)
|
||||
continue
|
||||
|
|
@ -754,16 +754,20 @@ type MoveResult struct {
|
|||
}
|
||||
|
||||
// Validate chess move using corentings/chess/v2 library
|
||||
func validateChessMove(fenStr, from, to, promotion string) MoveResult {
|
||||
func validateChessMove(fenStr, from, to, promotion string, logger runtime.Logger) MoveResult {
|
||||
result := MoveResult{Turn: "w"}
|
||||
|
||||
logger.Info("validateChessMove: FEN=%s, move=%s%s", fenStr, from, to)
|
||||
|
||||
// Parse FEN
|
||||
fen, err := chess.FEN(fenStr)
|
||||
if err != nil {
|
||||
logger.Error("validateChessMove: FEN parse error: %v", err)
|
||||
return result
|
||||
}
|
||||
|
||||
game := chess.NewGame(fen)
|
||||
logger.Info("validateChessMove: Game created, valid moves count: %d", len(game.ValidMoves()))
|
||||
|
||||
// Verify move is valid first
|
||||
found := false
|
||||
|
|
@ -807,9 +811,11 @@ func validateChessMove(fenStr, from, to, promotion string) MoveResult {
|
|||
|
||||
// Check game over
|
||||
outcome := game.Outcome()
|
||||
method := game.Method()
|
||||
logger.Info("validateChessMove: outcome=%v, method=%v", outcome, method)
|
||||
|
||||
if outcome != chess.NoOutcome {
|
||||
result.GameOver = true
|
||||
method := game.Method()
|
||||
|
||||
switch outcome {
|
||||
case chess.WhiteWon:
|
||||
|
|
@ -819,6 +825,7 @@ func validateChessMove(fenStr, from, to, promotion string) MoveResult {
|
|||
case chess.Draw:
|
||||
result.Result = "1/2-1/2"
|
||||
}
|
||||
logger.Info("validateChessMove: GAME OVER detected! result=%s, reason will be set based on method", result.Result)
|
||||
|
||||
switch method {
|
||||
case chess.Checkmate:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue