From 4dc853bf5d13ccf58ff8d3216debf16b9d7fa596 Mon Sep 17 00:00:00 2001 From: Oceankoh <36119714+Oceankoh@users.noreply.github.com> Date: Sun, 21 Jan 2024 04:35:27 +0800 Subject: [PATCH 1/2] return failed move when no piece found at origin square --- backend/src/chess/engine.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/backend/src/chess/engine.ts b/backend/src/chess/engine.ts index bd3902e..af486b0 100644 --- a/backend/src/chess/engine.ts +++ b/backend/src/chess/engine.ts @@ -53,8 +53,7 @@ const chess = new Chess(); function movePiece(square1, square2): string | FailedMove { const piece = chess.remove(square1); if (!piece) { - console.log(piece); - return null; + return new FailedMove(`No piece found at ${square1}`); } chess.put(piece, square2); const validate = validateFen(chess.fen()); @@ -69,8 +68,7 @@ function movePiece(square1, square2): string | FailedMove { function promotePiece(square1, square2, piece): string | FailedMove { const pawn = chess.remove(square1); if (!pawn) { - console.log(pawn); - return null; + return new FailedMove(`No piece found at ${square1}`); } chess.put({ type: piece, color: pawn.color }, square2); const validate = validateFen(chess.fen()); @@ -88,12 +86,16 @@ export async function interpretMove( ): Promise { const move = await llmInterpretPrompt(prompt, fen); if (move instanceof NormalMove) { + console.log('return normal move') return movePiece(move.square1, move.square2); } else if (move instanceof PromotionMove) { + console.log('return promotion move') return promotePiece(move.square1, move.square2, move.piece); } else if (move instanceof InvalidMove) { + console.log('return failed move') return new FailedMove(move.prompt); } else { + console.log('return unreachable') assertUnreachable(move); } } From 2d57561d89eca3c783103f6a3258c64d292ce6d8 Mon Sep 17 00:00:00 2001 From: Oceankoh <36119714+Oceankoh@users.noreply.github.com> Date: Sun, 21 Jan 2024 04:37:32 +0800 Subject: [PATCH 2/2] verbosity of failure messages --- backend/src/chess/engine.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/chess/engine.ts b/backend/src/chess/engine.ts index af486b0..5189330 100644 --- a/backend/src/chess/engine.ts +++ b/backend/src/chess/engine.ts @@ -53,7 +53,7 @@ const chess = new Chess(); function movePiece(square1, square2): string | FailedMove { const piece = chess.remove(square1); if (!piece) { - return new FailedMove(`No piece found at ${square1}`); + return new FailedMove(`Tried to move piece at ${square1} to ${square2} but there was no piece found at ${square1}`); } chess.put(piece, square2); const validate = validateFen(chess.fen()); @@ -68,7 +68,7 @@ function movePiece(square1, square2): string | FailedMove { function promotePiece(square1, square2, piece): string | FailedMove { const pawn = chess.remove(square1); if (!pawn) { - return new FailedMove(`No piece found at ${square1}`); + return new FailedMove(`Tried to promote piece at ${square1}, but there was no piece found at ${square1}`); } chess.put({ type: piece, color: pawn.color }, square2); const validate = validateFen(chess.fen());