From 130a166fd08355be5f2dfc923777c1c6d03f09ce Mon Sep 17 00:00:00 2001
From: Benjamin Auder <benjamin.auder@somewhere>
Date: Wed, 3 Jan 2024 01:40:00 +0100
Subject: [PATCH] Chakart: fixing attempt

---
 variants/Chakart/class.js | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/variants/Chakart/class.js b/variants/Chakart/class.js
index 2b502b6..3454d8f 100644
--- a/variants/Chakart/class.js
+++ b/variants/Chakart/class.js
@@ -130,6 +130,12 @@ export default class ChakartRules extends ChessRules {
     );
   }
 
+  isKing(x, y, p) {
+    if (!p)
+      p = this.getPiece(x, y);
+    return ['k', 'l'].includes(p);
+  }
+
   genRandInitBaseFen() {
     const s = FenUtil.setupPieces(
       ['r', 'n', 'b', 'q', 'k', 'b', 'n', 'r'],
@@ -630,19 +636,25 @@ export default class ChakartRules extends ChessRules {
         });
         break;
       case "koopa":
-        // Reverse move
+        // Reverse move, if possible
         em = new Move({
-          appear: [
-            new PiPo({
-              x: move.start.x, y: move.start.y, c: color, p: move.appear[0].p
-            })
-          ],
+          appear: [],
           vanish: [
             new PiPo({
               x: move.end.x, y: move.end.y, c: color, p: move.appear[0].p
             })
-          ]
+          ],
+          end: {x: move.start.x, y: move.start.y} //may be irrelevant
         });
+        em.koopa = true; //avoid applying effect
+        if (move.vanish.length == 0)
+          // After toadette+drop, just erase piece
+          break;
+        em.appear.push(
+          new PiPo({
+            x: move.start.x, y: move.start.y, c: color, p: move.appear[0].p
+          })
+        );
         if (this.board[move.start.x][move.start.y] != "") {
           // Pawn or knight let something on init square
           em.vanish.push(new PiPo({
@@ -652,7 +664,6 @@ export default class ChakartRules extends ChessRules {
             p: this.getPiece(move.start.x, move.start.y)
           }));
         }
-        em.koopa = true; //avoid applying effect
         break;
       case "chomp":
         // Eat piece
-- 
2.44.0