projects
/
xogo.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
New variant idea
[xogo.git]
/
variants
/
Apocalypse
/
class.js
diff --git
a/variants/Apocalypse/class.js
b/variants/Apocalypse/class.js
index
0600991
..
3b735b1
100644
(file)
--- a/
variants/Apocalypse/class.js
+++ b/
variants/Apocalypse/class.js
@@
-40,7
+40,7
@@
export default class ApocalypseRules extends ChessRules {
genRandInitBaseFen() {
return {
genRandInitBaseFen() {
return {
- fen: "npppn/p3p/5/P3P/NPPPN
w 0
",
+ fen: "npppn/p3p/5/P3P/NPPPN",
o: {}
};
}
o: {}
};
}
@@
-68,7
+68,7
@@
export default class ApocalypseRules extends ChessRules {
return {
'p': {
"class": "pawn",
return {
'p': {
"class": "pawn",
-
moves
: [
+
both
: [
{
steps: [[pawnShift, 0], [pawnShift, -1], [pawnShift, 1]],
range: 1
{
steps: [[pawnShift, 0], [pawnShift, -1], [pawnShift, 1]],
range: 1
@@
-102,7
+102,7
@@
export default class ApocalypseRules extends ChessRules {
}
}
else {
}
}
else {
- const oppCol = C.GetOpp
Col
(this.getColor(x, y));
+ const oppCol = C.GetOpp
Turn
(this.getColor(x, y));
moves = super.getPotentialMovesFrom([x, y]).filter(m => {
// Remove pawn push toward own color (absurd)
return (
moves = super.getPotentialMovesFrom([x, y]).filter(m => {
// Remove pawn push toward own color (absurd)
return (
@@
-222,10
+222,13
@@
export default class ApocalypseRules extends ChessRules {
if (!res.wm || !res.bm)
return;
for (let c of ['w', 'b']) {
if (!res.wm || !res.bm)
return;
for (let c of ['w', 'b']) {
- const myMove = res[c + 'm'], oppMove = res[C.GetOpp
Col
(c) + 'm'];
+ const myMove = res[c + 'm'], oppMove = res[C.GetOpp
Turn
(c) + 'm'];
if (
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();
) {
// Whatever was supposed to vanish, finally doesn't vanish
myMove.vanish.pop();
@@
-235,8
+238,8
@@
export default class ApocalypseRules extends ChessRules {
// Collision (necessarily on empty square)
if (!res.wm.illegal && !res.bm.illegal) {
if (res.wm.vanish[0].p != res.bm.vanish[0].p) {
// 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
}
else {
// Collision of two pieces of same nature: both disappear
@@
-271,7
+274,7
@@
export default class ApocalypseRules extends ChessRules {
return res;
}
return res;
}
- play(move) {
+ play(move
, callback
) {
const color = this.turn;
if (color == 'w')
this.whiteMove.push(move);
const color = this.turn;
if (color == 'w')
this.whiteMove.push(move);
@@
-289,6
+292,7
@@
export default class ApocalypseRules extends ChessRules {
this.playOnBoard(move);
this.playVisual(move);
}
this.playOnBoard(move);
this.playVisual(move);
}
+ callback();
return;
}
if (color == this.playerColor && this.firstMove) {
return;
}
if (color == this.playerColor && this.firstMove) {
@@
-302,14
+306,14
@@
export default class ApocalypseRules extends ChessRules {
};
this.playVisual(revFirstMove);
}
};
this.playVisual(revFirstMove);
}
- this.turn = C.GetOpp
Col
(color);
+ this.turn = C.GetOpp
Turn
(color);
this.movesCount++;
this.subTurn = 1;
this.firstMove = null;
if (color == 'b') {
// A full turn just ended
const res = this.resolveSynchroneMove(move);
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: []};
// start + end don't matter for playOnBoard() and playVisual().
// Merging is necessary because moves may overlap.
let toPlay = {appear: [], vanish: []};
@@
-321,11
+325,12
@@
export default class ApocalypseRules extends ChessRules {
}
this.playOnBoard(toPlay);
this.playVisual(toPlay);
}
this.playOnBoard(toPlay);
this.playVisual(toPlay);
+ callback();
};
if (res.wm)
};
if (res.wm)
- this.animate(res.wm, () => {if (!res.bm)
callback
();});
+ this.animate(res.wm, () => {if (!res.bm)
afterAnimate
();});
if (res.bm)
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]++);
if (!res.wm && !res.bm) {
this.displayIllegalInfo("both illegal");
['w', 'b'].forEach(c => this.penalties[c]++);
@@
-340,6
+345,8
@@
export default class ApocalypseRules extends ChessRules {
}
this.whiteMove = [];
}
}
this.whiteMove = [];
}
+ else
+ callback();
}
displayIllegalInfo(msg) {
}
displayIllegalInfo(msg) {
@@
-370,9
+377,9
@@
export default class ApocalypseRules extends ChessRules {
return "*";
}
// Count footmen: if a side has none, it loses
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)]++;
}
if (this.board[i][j] != "" && this.getPiece(i, j) == 'p')
fmCount[this.getColor(i, j)]++;
}