Almost finished problems logic. TODO: showProblem() part
[vchess.git] / public / javascripts / variants / Antiking.js
index b22cbd7..2821f3f 100644 (file)
@@ -1,13 +1,16 @@
 class AntikingRules extends ChessRules
 {
-       // Path to pieces
        static getPpath(b)
        {
                return b[1]=='a' ? "Antiking/"+b : b;
        }
 
        static get ANTIKING() { return 'a'; }
-       
+
+       static get PIECES() {
+               return ChessRules.PIECES.concat([V.ANTIKING]);
+       }
+
        initVariables(fen)
        {
                super.initVariables(fen);
@@ -50,7 +53,7 @@ class AntikingRules extends ChessRules
        {
                switch (this.getPiece(x,y))
                {
-                       case VariantRules.ANTIKING:
+                       case V.ANTIKING:
                                return this.getPotentialAntikingMoves([x,y]);
                        default:
                                return super.getPotentialMovesFrom([x,y]);
@@ -59,7 +62,6 @@ class AntikingRules extends ChessRules
 
        getPotentialAntikingMoves(sq)
        {
-               const V = VariantRules;
                return this.getSlideNJumpMoves(sq,
                        V.steps[V.ROOK].concat(V.steps[V.BISHOP]), "oneStep");
        }
@@ -71,7 +73,6 @@ class AntikingRules extends ChessRules
 
        isAttackedByKing([x,y], colors)
        {
-               const V = VariantRules;
                if (this.getPiece(x,y) == V.ANTIKING)
                        return false; //antiking is not attacked by king
                return this.isAttackedBySlideNJump([x,y], colors, V.KING,
@@ -80,7 +81,6 @@ class AntikingRules extends ChessRules
 
        isAttackedByAntiking([x,y], colors)
        {
-               const V = VariantRules;
                if ([V.KING,V.ANTIKING].includes(this.getPiece(x,y)))
                        return false; //(anti)king is not attacked by antiking
                return this.isAttackedBySlideNJump([x,y], colors, V.ANTIKING,
@@ -115,7 +115,7 @@ class AntikingRules extends ChessRules
                const piece = this.getPiece(move.start.x,move.start.y);
                const c = this.getColor(move.start.x,move.start.y);
                // Update antiking position
-               if (piece == VariantRules.ANTIKING)
+               if (piece == V.ANTIKING)
                {
                        this.antikingPos[c][0] = move.appear[0].x;
                        this.antikingPos[c][1] = move.appear[0].y;
@@ -126,7 +126,7 @@ class AntikingRules extends ChessRules
        {
                super.unupdateVariables(move);
                const c = this.getColor(move.start.x,move.start.y);
-               if (this.getPiece(move.start.x,move.start.y) == VariantRules.ANTIKING)
+               if (this.getPiece(move.start.x,move.start.y) == V.ANTIKING)
                        this.antikingPos[c] = [move.start.x, move.start.y];
        }
 
@@ -142,17 +142,11 @@ class AntikingRules extends ChessRules
                return color == "w" ? "0-1" : "1-0";
        }
 
-       // Pieces values (TODO: use Object.assign() + ChessRules.VALUES ?)
        static get VALUES() {
-               return {
-                       'p': 1,
-                       'r': 5,
-                       'n': 3,
-                       'b': 3,
-                       'q': 9,
-                       'k': 1000,
-                       'a': 1000
-               };
+               return Object.assign(
+                       ChessRules.VALUES,
+                       { 'a': 1000 }
+               );
        }
 
        static GenRandInitFen()
@@ -206,7 +200,7 @@ class AntikingRules extends ChessRules
                let fen = pieces["b"].join("") + "/" + ranks23_black +
                        "/8/8/" +
                        ranks23_white + "/" + pieces["w"].join("").toUpperCase() +
-                       " 1111"; //add flags
+                       " 1111";
                return fen;
        }
 }