6 return b
[1]=='a' ? "Antiking/"+b : b
;
9 static get ANTIKING() { return 'a'; }
11 // TODO: more subtle than that, require changing args: wp, bk and not just colors
12 canTake(color1
, color2
)
14 return 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 getPotentialAntikingMoves(x
, y
, c
)
34 // TODO: need to re-think some logic, since antikings capture same color
38 return (this.isAttackedByPawn(sq
, color
)
39 || this.isAttackedByRook(sq
, color
)
40 || this.isAttackedByKnight(sq
, color
)
41 || this.isAttackedByBishop(sq
, color
)
42 || this.isAttackedByQueen(sq
, color
)
43 || this.isAttackedByKing(sq
, color
)); //...
46 isAttackedByAntiking(sq
, color
)
54 let res
= this.isAttacked(this.kingPos
[c
], this.getOppCol(c
));
55 // TODO: also check that antiking is still in check
60 getCheckSquares(move, c
)
64 let res
= this.isAttacked(this.kingPos
[c
], this.getOppCol(c
))
65 ? [ JSON
.parse(JSON
.stringify(this.kingPos
[c
])) ] //need to duplicate!
71 // Apply a move on board
72 static PlayOnBoard(board
, move)
74 for (let psq
of move.vanish
)
75 board
[psq
.x
][psq
.y
] = VariantRules
.EMPTY
;
76 for (let psq
of move.appear
)
77 board
[psq
.x
][psq
.y
] = psq
.c
+ psq
.p
;
79 // Un-apply the played move
80 static UndoOnBoard(board
, move)
82 for (let psq
of move.appear
)
83 board
[psq
.x
][psq
.y
] = VariantRules
.EMPTY
;
84 for (let psq
of move.vanish
)
85 board
[psq
.x
][psq
.y
] = psq
.c
+ psq
.p
;
88 // TODO: need antikingPos as well
94 unupdateVariables(move)
102 if (!this.isAttacked(this.kingPos
[color
], this.getOppCol(color
)))
104 return color
== "w" ? "0-1" : "1-0";
108 static get VALUES() {
120 static GenRandInitFen()
122 // TODO: no need all code, just add an antiking at rondom on 3rd ranks
123 let pieces
= [new Array(8), new Array(8)];
124 // Shuffle pieces on first and last rank
125 for (let c
= 0; c
<= 1; c
++)
127 let positions
= _
.range(8);
129 // Get random squares for bishops
130 let randIndex
= 2 * _
.random(3);
131 let bishop1Pos
= positions
[randIndex
];
132 // The second bishop must be on a square of different color
133 let randIndex_tmp
= 2 * _
.random(3) + 1;
134 let bishop2Pos
= positions
[randIndex_tmp
];
135 // Remove chosen squares
136 positions
.splice(Math
.max(randIndex
,randIndex_tmp
), 1);
137 positions
.splice(Math
.min(randIndex
,randIndex_tmp
), 1);
139 // Get random squares for knights
140 randIndex
= _
.random(5);
141 let knight1Pos
= positions
[randIndex
];
142 positions
.splice(randIndex
, 1);
143 randIndex
= _
.random(4);
144 let knight2Pos
= positions
[randIndex
];
145 positions
.splice(randIndex
, 1);
147 // Get random square for queen
148 randIndex
= _
.random(3);
149 let queenPos
= positions
[randIndex
];
150 positions
.splice(randIndex
, 1);
152 // Rooks and king positions are now fixed, because of the ordering rook-king-rook
153 let rook1Pos
= positions
[0];
154 let kingPos
= positions
[1];
155 let rook2Pos
= positions
[2];
157 // Finally put the shuffled pieces in the board array
158 pieces
[c
][rook1Pos
] = 'r';
159 pieces
[c
][knight1Pos
] = 'n';
160 pieces
[c
][bishop1Pos
] = 'b';
161 pieces
[c
][queenPos
] = 'q';
162 pieces
[c
][kingPos
] = 'k';
163 pieces
[c
][bishop2Pos
] = 'b';
164 pieces
[c
][knight2Pos
] = 'n';
165 pieces
[c
][rook2Pos
] = 'r';
167 let fen
= pieces
[0].join("") +
168 "/pppppppp/8/8/8/8/PPPPPPPP/" +
169 pieces
[1].join("").toUpperCase() +