Fix Cannibal variant. TODO: better kings images
[vchess.git] / client / src / variants / Eightpieces.js
index a0eed50..bea261a 100644 (file)
@@ -2,7 +2,7 @@ import { ArrayFun } from "@/utils/array";
 import { randInt } from "@/utils/alea";
 import { ChessRules, PiPo, Move } from "@/base_rules";
 
-export const VariantRules = class EightpiecesRules extends ChessRules {
+export class EightpiecesRules extends ChessRules {
   static get JAILER() {
     return "j";
   }
@@ -247,21 +247,23 @@ export const VariantRules = class EightpiecesRules extends ChessRules {
   // Because of the lancers, getPiece() could be wrong:
   // use board[x][y][1] instead (always valid).
   getBasicMove([sx, sy], [ex, ey], tr) {
+    const initColor = this.getColor(sx, sy);
+    const initPiece = this.board[sx][sy].charAt(1);
     let mv = new Move({
       appear: [
         new PiPo({
           x: ex,
           y: ey,
-          c: tr ? tr.c : this.getColor(sx, sy),
-          p: tr ? tr.p : this.board[sx][sy].charAt(1)
+          c: tr ? tr.c : initColor,
+          p: tr ? tr.p : initPiece
         })
       ],
       vanish: [
         new PiPo({
           x: sx,
           y: sy,
-          c: this.getColor(sx, sy),
-          p: this.board[sx][sy].charAt(1)
+          c: initColor,
+          p: initPiece
         })
       ]
     });