6 return b
[1]=='a' ? "Antiking/"+b : b
;
9 static get ANTIKING() { return 'a'; }
11 canTake(color1
, color2
, [x
,y
])
13 const piece
= this.getPiece(x
,y
);
14 return (piece
!= "a" && color1
!= color2
) || (piece
== "a" && color1
== color2
);
17 getPotentialMovesFrom([x
,y
])
19 let c
= this.getColor(x
,y
);
20 switch (this.getPiece(x
,y
))
22 case VariantRules
.ANTIKING:
23 return this.getPotentialAntikingMoves(x
,y
,c
);
25 return super.getPotentielMovesFrom([x
,y
]);
29 // TODO: generaliser (à moindre coût) base_rules ? Ou spécialiser variantes ?
31 getPotentialAntikingMoves(x
, y
, c
)
36 // TODO: need to re-think some logic, since antikings capture same color
40 return (this.isAttackedByPawn(sq
, color
)
41 || this.isAttackedByRook(sq
, color
)
42 || this.isAttackedByKnight(sq
, color
)
43 || this.isAttackedByBishop(sq
, color
)
44 || this.isAttackedByQueen(sq
, color
)
45 || this.isAttackedByKing(sq
, color
)); //...
48 isAttackedByAntiking(sq
, color
)
56 let res
= this.isAttacked(this.kingPos
[c
], this.getOppCol(c
));
57 // TODO: also check that antiking is still in check
62 getCheckSquares(move, c
)
66 let res
= this.isAttacked(this.kingPos
[c
], this.getOppCol(c
))
67 ? [ JSON
.parse(JSON
.stringify(this.kingPos
[c
])) ] //need to duplicate!
73 // Apply a move on board
74 static PlayOnBoard(board
, move)
76 for (let psq
of move.vanish
)
77 board
[psq
.x
][psq
.y
] = VariantRules
.EMPTY
;
78 for (let psq
of move.appear
)
79 board
[psq
.x
][psq
.y
] = psq
.c
+ psq
.p
;
81 // Un-apply the played move
82 static UndoOnBoard(board
, move)
84 for (let psq
of move.appear
)
85 board
[psq
.x
][psq
.y
] = VariantRules
.EMPTY
;
86 for (let psq
of move.vanish
)
87 board
[psq
.x
][psq
.y
] = psq
.c
+ psq
.p
;
90 // TODO: need antikingPos as well
96 unupdateVariables(move)
104 if (!this.isAttacked(this.kingPos
[color
], this.getOppCol(color
)))
106 return color
== "w" ? "0-1" : "1-0";
110 static get VALUES() {
122 static GenRandInitFen()
124 // TODO: no need all code, just add an antiking at rondom on 3rd ranks
125 let pieces
= [new Array(8), new Array(8)];
126 // Shuffle pieces on first and last rank
127 for (let c
= 0; c
<= 1; c
++)
129 let positions
= _
.range(8);
131 // Get random squares for bishops
132 let randIndex
= 2 * _
.random(3);
133 let bishop1Pos
= positions
[randIndex
];
134 // The second bishop must be on a square of different color
135 let randIndex_tmp
= 2 * _
.random(3) + 1;
136 let bishop2Pos
= positions
[randIndex_tmp
];
137 // Remove chosen squares
138 positions
.splice(Math
.max(randIndex
,randIndex_tmp
), 1);
139 positions
.splice(Math
.min(randIndex
,randIndex_tmp
), 1);
141 // Get random squares for knights
142 randIndex
= _
.random(5);
143 let knight1Pos
= positions
[randIndex
];
144 positions
.splice(randIndex
, 1);
145 randIndex
= _
.random(4);
146 let knight2Pos
= positions
[randIndex
];
147 positions
.splice(randIndex
, 1);
149 // Get random square for queen
150 randIndex
= _
.random(3);
151 let queenPos
= positions
[randIndex
];
152 positions
.splice(randIndex
, 1);
154 // Rooks and king positions are now fixed, because of the ordering rook-king-rook
155 let rook1Pos
= positions
[0];
156 let kingPos
= positions
[1];
157 let rook2Pos
= positions
[2];
159 // Finally put the shuffled pieces in the board array
160 pieces
[c
][rook1Pos
] = 'r';
161 pieces
[c
][knight1Pos
] = 'n';
162 pieces
[c
][bishop1Pos
] = 'b';
163 pieces
[c
][queenPos
] = 'q';
164 pieces
[c
][kingPos
] = 'k';
165 pieces
[c
][bishop2Pos
] = 'b';
166 pieces
[c
][knight2Pos
] = 'n';
167 pieces
[c
][rook2Pos
] = 'r';
169 let fen
= pieces
[0].join("") +
170 "/pppppppp/8/8/8/8/PPPPPPPP/" +
171 pieces
[1].join("").toUpperCase() +