return {
'p': {
"class": "pawn",
- moves: [
+ both: [
{
steps: [[pawnShift, 0], [pawnShift, -1], [pawnShift, 1]],
range: 1
}
}
else {
- const oppCol = C.GetOppCol(this.getColor(x, y));
+ const oppCol = C.GetOppTurn(this.getColor(x, y));
moves = super.getPotentialMovesFrom([x, y]).filter(m => {
// Remove pawn push toward own color (absurd)
return (
if (!res.wm || !res.bm)
return;
for (let c of ['w', 'b']) {
- const myMove = res[c + 'm'], oppMove = res[C.GetOppCol(c) + 'm'];
+ const myMove = res[c + 'm'], oppMove = res[C.GetOppTurn(c) + 'm'];
if (
- myMove.end.x == oppMove.start.x &&
- myMove.end.y == oppMove.start.y
+ // More general test than checking moves ends,
+ // because of potential pawn relocation
+ myMove.vanish.length == 2 &&
+ myMove.vanish[1].x == oppMove.start.x &&
+ myMove.vanish[1].y == oppMove.start.y
) {
// Whatever was supposed to vanish, finally doesn't vanish
myMove.vanish.pop();
// Collision (necessarily on empty square)
if (!res.wm.illegal && !res.bm.illegal) {
if (res.wm.vanish[0].p != res.bm.vanish[0].p) {
- const c = (res.wm.vanish[0].p == 'n' ? 'w' : 'b');
- res[c + 'm'].vanish.push(res[C.GetOppCol(c) + 'm'].appear.shift());
+ const vanishColor = (res.wm.vanish[0].p == 'n' ? 'b' : 'w');
+ res[vanishColor + 'm'].appear.shift();
}
else {
// Collision of two pieces of same nature: both disappear
return res;
}
- play(move) {
+ play(move, callback) {
const color = this.turn;
if (color == 'w')
this.whiteMove.push(move);
this.playOnBoard(move);
this.playVisual(move);
}
+ callback();
return;
}
if (color == this.playerColor && this.firstMove) {
};
this.playVisual(revFirstMove);
}
- this.turn = C.GetOppCol(color);
+ this.turn = C.GetOppTurn(color);
this.movesCount++;
this.subTurn = 1;
this.firstMove = null;
if (color == 'b') {
// A full turn just ended
const res = this.resolveSynchroneMove(move);
- const callback = () => {
+ const afterAnimate = () => {
// start + end don't matter for playOnBoard() and playVisual().
// Merging is necessary because moves may overlap.
let toPlay = {appear: [], vanish: []};
}
this.playOnBoard(toPlay);
this.playVisual(toPlay);
+ callback();
};
if (res.wm)
- this.animate(res.wm, () => {if (!res.bm) callback();});
+ this.animate(res.wm, () => {if (!res.bm) afterAnimate();});
if (res.bm)
- this.animate(res.bm, callback);
+ this.animate(res.bm, afterAnimate);
if (!res.wm && !res.bm) {
this.displayIllegalInfo("both illegal");
['w', 'b'].forEach(c => this.penalties[c]++);
}
this.whiteMove = [];
}
+ else
+ callback();
}
displayIllegalInfo(msg) {
return "*";
}
// Count footmen: if a side has none, it loses
- let fmCount = { 'w': 0, 'b': 0 };
- for (let i=0; i<5; i++) {
- for (let j=0; j<5; j++) {
+ let fmCount = {w: 0, b: 0};
+ for (let i=0; i<this.size.x; i++) {
+ for (let j=0; j<this.size.y; j++) {
if (this.board[i][j] != "" && this.getPiece(i, j) == 'p')
fmCount[this.getColor(i, j)]++;
}