};
}
+ static get LANCERS() {
+ return ['c', 'd', 'e', 'f', 'g', 'h', 'm', 'o'];
+ }
+
getLancerOptions(x, y) {
let options = [];
if (y > 0)
};
}
- static get LANCERS() {
- return ['c', 'd', 'e', 'f', 'g', 'h', 'm', 'o'];
- }
-
// obj == "-", {-1,-1} or ["]{x,y}["]
static convertPush(obj) {
if (typeof obj === "string")
}, super.pieces(color, x, y));
}
- canStepOver(i, j, p, c) {
- const colIJ = this.getColor(i, j);
- return this.board[i][j] == "" || (V.LANCERS.includes(p) && c == colIJ);
- }
-
canIplay(x, y) {
if (
this.pushFrom.x == x && this.pushFrom.y == y &&
return super.canIplay(x, y);
}
+ canStepOver(i, j, p, c) {
+ const colIJ = this.getColor(i, j);
+ return this.board[i][j] == "" || (V.LANCERS.includes(p) && c == colIJ);
+ }
+
isImmobilized([x, y]) {
const color = this.getColor(x, y);
const oppCol = C.GetOppTurn(color);
return res;
}
+// TODO: sentry nudge
+
+ // after pushedTo, if lancer : allow reorient + move, or just reorient (move to king) if stuck
+
+ // later, if stuck, allow reorient only (just click)
+ // doClick(coords) { TODO
+
getPotentialMovesFrom([x, y], color) {
if (this.pushFrom.x < 0 || this.pushedTo.x >= 0) {
let smoves = super.getPotentialMovesFrom([x, y], color);
// Forbid direction x,y --> pushFrom if x,y == pushedTo
if (x == this.pushedTo.x && y == this.pushedTo.y) {
smoves = smoves.filter(m => {
+ let sx = this.pushFrom.x - x,
+ sy = this.pushFrom.y - y;
+ let divideBy = sx != 0 && sy != 0 && Math.abs(sx) != Math.abs(sy)
+ ? 1
+ : Math.max(sx, sy);
return ( !super.compatibleStep(
[x, y], [m.end.x, m.end.y],
- [this.pushFrom.x - x, this.pushFrom.y - y]
+ [sx / divideBy, sy / divideBy]
) );
});
}
+
+ // TODO: lancer special case, move as a queen after push
+
return smoves.concat(this.getPassMoves(x, y));
}
// pushFrom.x >= 0 && pushedTo.x < 0
m.appear[0].c = m.vanish[0].c = oppCol;
m.appear.push( new PiPo({x:x, y:y, p:'s', c:this.turn}) );
});
-
-console.log(pmoves);
-
return pmoves;
-
-
-
- }
-
- postPlay(move) {
- if (
- move.vanish.length > 0 &&
- move.vanish[0].p == 's' &&
- move.appear[0].c != move.vanish[0].c
- ) {
- // Sentry push ("capturing" part)
- this.pushFrom = {x: move.end.x, y: move.end.y};
- this.pushedTo = {x: -1, y: -1};
- }
- else if (move.vanish.length > 0 && move.vanish[0].c != this.turn)
- this.pushedTo = {x: move.end.x, y: move.end.y};
- else {
- // All other cases: just reset both push variables
- this.pushFrom = {x: -1, y: -1};
- this.pushedTo = {x: -1, y: -1};
- }
- super.postPlay(move);
- }
-
- isLastMove(move) {
- if (move.vanish[0].p == 's' && move.appear[0].c != move.vanish[0].c)
- return false;
- return super.isLastMove(move);
}
postProcessPotentialMoves(moves) {
(
(m.vanish.length > 0 && V.LANCERS.includes(m.vanish[0].p)) &&
// Next line test checks that the lancer wasn't just pushed away
- (m.start.x != this.pushFrom.x || m.start.y != this.pushFrom.y)
+ (m.start.x != this.pushedTo.x || m.start.y != this.pushedTo.y)
)
) {
this.getLancerOptions(m.end.x, m.end.y).forEach(o => {
}) );
});
}
- else if (m.vanish.length == m.appear.length || m.vanish[0].p != 's')
- finalMoves.push(m);
- else {
+ else if (m.vanish.length == 2 && m.vanish[0].p == 's') {
// Sentry "capture" --> remove sentry from final square (TODO: blink?)
- const [x, y] = [m.end.x, m.end.y]
- const p = this.getPiece(x, y);
- const c = this.getColor(x, y);
finalMoves.push( new Move({
- appear: [new PiPo({x:m.end.x,y:m.end.y,c:c,p:p})],
- vanish: [ m.vanish[0] ]
+ appear: [],
+ vanish: [ m.vanish[0] ],
+ end: m.end
}) );
}
+ else
+ finalMoves.push(m);
}
return finalMoves;
}
+ postPlay(move) {
+ if (
+ move.appear.length == 0 &&
+ move.vanish.length > 0 &&
+ move.vanish[0].p == 's'
+ ) {
+ // Sentry push ("capturing" part)
+ this.pushFrom = {x: move.end.x, y: move.end.y};
+ this.pushedTo = {x: -1, y: -1};
+ }
+ else if (move.vanish.length > 0 && move.vanish[0].c != this.turn)
+ this.pushedTo = {x: move.end.x, y: move.end.y};
+ else {
+ // All other cases: just reset both push variables
+ this.pushFrom = {x: -1, y: -1};
+ this.pushedTo = {x: -1, y: -1};
+ }
+ super.postPlay(move);
+ }
+
+ isLastMove(move) {
+ if (move.appear.length == 0) //move.vanish[0].p == 's'
+ return false;
+ return super.isLastMove(move);
+ }
+
underAttack([x, y], oppCols) {
+ if (super.underAttack([x, y], oppCols))
+ return true;
// TODO: check enemy sentry(ies), for each, check all of our own pieces which attack the square (if belonging to opponent!). Then, call :
- return super.underAttack([x, y], oppCols);
+ const oppCol = oppCols[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) == 's' &&
+ this.getColor(i, j) == oppCol
+ ) {
+ this.pieces()['s'].both[0].steps.forEach(s => {
+ let ii = i + s[0];
+ // TODO.........
+ if (true)
+ return true;
+ });
+ }
+ }
+ }
+ return false;
}
// Lazy sentry attacks check: after push move
updateReserve(color, piece, count) {
if (V.LANCERS.includes(piece))
// Show only one lancer orientation, and reorient when drop:
- piece = color == 'w' ? 'c' : 'g';
+ piece = (color == 'w' ? 'c' : 'g');
super.updateReserve(color, piece, count);
}