1 class AntikingRules
extends ChessRules
6 return b
[1]=='a' ? "Antiking/"+b : b
;
9 static get ANTIKING() { return 'a'; }
13 super.initVariables(fen
);
14 this.antikingPos
= {'w':[-1,-1], 'b':[-1,-1]};
15 const position
= fen
.split(" ")[0].split("/");
16 for (let i
=0; i
<position
.length
; i
++)
19 for (let j
=0; j
<position
[i
].length
; j
++)
21 switch (position
[i
].charAt(j
))
24 this.antikingPos
['b'] = [i
,k
];
27 this.antikingPos
['w'] = [i
,k
];
30 let num
= parseInt(position
[i
].charAt(j
));
39 canTake([x1
,y1
], [x2
,y2
])
41 const piece1
= this.getPiece(x1
,y1
);
42 const piece2
= this.getPiece(x2
,y2
);
43 const color1
= this.getColor(x1
,y1
);
44 const color2
= this.getColor(x2
,y2
);
45 return !["a","A"].includes(piece2
) &&
46 ((piece1
!= "a" && color1
!= color2
) || (piece1
== "a" && color1
== color2
));
49 getPotentialMovesFrom([x
,y
])
51 switch (this.getPiece(x
,y
))
53 case VariantRules
.ANTIKING:
54 return this.getPotentialAntikingMoves([x
,y
]);
56 return super.getPotentialMovesFrom([x
,y
]);
60 getPotentialAntikingMoves(sq
)
62 const V
= VariantRules
;
63 return this.getSlideNJumpMoves(sq
,
64 V
.steps
[V
.ROOK
].concat(V
.steps
[V
.BISHOP
]), "oneStep");
67 isAttacked(sq
, colors
)
69 return (super.isAttacked(sq
, colors
) || this.isAttackedByAntiking(sq
, colors
));
72 isAttackedByKing([x
,y
], colors
)
74 const V
= VariantRules
;
75 if (this.getPiece(x
,y
) == V
.ANTIKING
)
76 return false; //antiking is not attacked by king
77 return this.isAttackedBySlideNJump([x
,y
], colors
, V
.KING
,
78 V
.steps
[V
.ROOK
].concat(V
.steps
[V
.BISHOP
]), "oneStep");
81 isAttackedByAntiking([x
,y
], colors
)
83 const V
= VariantRules
;
84 if (this.getPiece(x
,y
) == V
.KING
)
85 return false; //king is not attacked by antiking
86 return this.isAttackedBySlideNJump([x
,y
], colors
, V
.ANTIKING
,
87 V
.steps
[V
.ROOK
].concat(V
.steps
[V
.BISHOP
]), "oneStep");
93 const oppCol
= this.getOppCol(c
);
95 let res
= this.isAttacked(this.kingPos
[c
], oppCol
)
96 || !this.isAttacked(this.antikingPos
[c
], oppCol
);
101 getCheckSquares(move)
103 let res
= super.getCheckSquares(move);
106 if (!this.isAttacked(this.antikingPos
[c
], this.getOppCol(c
)))
107 res
.push(JSON
.parse(JSON
.stringify(this.antikingPos
[c
])));
112 updateVariables(move)
114 super.updateVariables(move);
115 const piece
= this.getPiece(move.start
.x
,move.start
.y
);
116 const c
= this.getColor(move.start
.x
,move.start
.y
);
117 // Update antiking position
118 if (piece
== VariantRules
.ANTIKING
)
120 this.antikingPos
[c
][0] = move.appear
[0].x
;
121 this.antikingPos
[c
][1] = move.appear
[0].y
;
125 unupdateVariables(move)
127 super.unupdateVariables(move);
128 const c
= this.getColor(move.start
.x
,move.start
.y
);
129 if (this.getPiece(move.start
.x
,move.start
.y
) == VariantRules
.ANTIKING
)
130 this.antikingPos
[c
] = [move.start
.x
, move.start
.y
];
135 const color
= this.turn
;
136 const oppCol
= this.getOppCol(color
);
137 if (!this.isAttacked(this.kingPos
[color
], oppCol
)
138 && this.isAttacked(this.antikingPos
[color
], oppCol
))
142 return color
== "w" ? "0-1" : "1-0";
145 // Pieces values (TODO: use Object.assign() + ChessRules.VALUES ?)
146 static get VALUES() {
158 static GenRandInitFen()
160 let randFen
= ChessRules
.GenRandInitFen();
162 let antikingPos
= _
.random(7);
163 let ranks23
= "pppppppp/" + (antikingPos
>0?antikingPos:"") + "A" + (antikingPos
<7?7-antikingPos:"");
164 randFen
= randFen
.replace("pppppppp/8", ranks23
);
166 antikingPos
= _
.random(7);
167 ranks23
= (antikingPos
>0?antikingPos:"") + "a" + (antikingPos
<7?7-antikingPos:"") + "/PPPPPPPP";
168 randFen
= randFen
.replace("8/PPPPPPPP", ranks23
);