const color = this.getColor(i, j);
const piece = this.getPiece(i, j);
addPiece(i, j, "g_pieces", this.pieces(color, i, j)[piece]["class"]);
- this.g_pieces[i][j].classList.add(C.GetColorClass(color));
+ this.g_pieces[i][j].classList.add(V.GetColorClass(color));
if (this.enlightened && !this.enlightened[i][j])
this.g_pieces[i][j].classList.add("hidden");
}
rcontainer.appendChild(r_cell);
let piece = document.createElement("piece");
C.AddClass_es(piece, this.pieces(c, c, p)[p]["class"]);
- piece.classList.add(C.GetColorClass(c));
+ piece.classList.add(V.GetColorClass(c));
piece.style.width = "100%";
piece.style.height = "100%";
this.r_pieces[c][p] = piece;
const cdisp = moves[i].choice || moves[i].appear[0].p;
C.AddClass_es(piece,
this.pieces(color, moves[i].end.x, moves[i].end.y)[cdisp]["class"]);
- piece.classList.add(C.GetColorClass(color));
+ piece.classList.add(V.GetColorClass(color));
piece.style.width = "100%";
piece.style.height = "100%";
choice.appendChild(piece);
this.g_pieces[a.x][a.y] = document.createElement("piece");
C.AddClass_es(this.g_pieces[a.x][a.y],
this.pieces(a.c, a.x, a.y)[a.p]["class"]);
- this.g_pieces[a.x][a.y].classList.add(C.GetColorClass(a.c));
+ this.g_pieces[a.x][a.y].classList.add(V.GetColorClass(a.c));
this.g_pieces[a.x][a.y].style.width = pieceWidth + "px";
this.g_pieces[a.x][a.y].style.height = pieceWidth + "px";
const [ip, jp] = this.getPixelPosition(a.x, a.y, r);
C.RemoveClass_es(movingPiece, pieces[startCode]["class"]);
C.AddClass_es(movingPiece, pieces[drag.p]["class"]);
if (apparentColor != drag.c) {
- movingPiece.classList.remove(C.GetColorClass(apparentColor));
- movingPiece.classList.add(C.GetColorClass(drag.c));
+ movingPiece.classList.remove(V.GetColorClass(apparentColor));
+ movingPiece.classList.add(V.GetColorClass(drag.c));
}
}
container.appendChild(movingPiece);
// Try both colors (to detect potential suicides)
let won = {};
for (let c of ['w', 'b']) {
- const oppCol = C.GetOppCol(c);
+ const oppCol = C.GetOppTurn(c);
const goal = (c == 'w' ? 0 : 5);
won[c] = this.board[goal].some((b,j) => {
return (
filterValid(moves) {
const color = this.turn;
- const oppCol = C.GetOppCol(color);
+ const oppCol = C.GetOppTurn(color);
const kingPos = this.searchKingPos(color)[0];
const kingPiece = this.getPiece(kingPos[0], kingPos[1]);
return super.filterValid(moves).filter(m => {
if (move.appear.length > 0)
this.curMove = move;
const color = this.turn;
- const oppCol = C.GetOppCol(this.turn);
+ const oppCol = C.GetOppTurn(this.turn);
let mv = new Move({
start: this.curMove.end,
end: this.curMove.end,
// is piece on square x,y mated by color?
isMated(x, y, color) {
- const myColor = C.GetOppCol(color);
+ const myColor = C.GetOppTurn(color);
if (!super.underAttack([x, y], color))
return false;
for (let i=0; i<this.size.x; i++) {
// Subturn 2: play a move for me (which just indicate a square).
getPotentialMovesFrom([x, y]) {
const color = this.turn;
- const oppCol = C.GetOppCol(color);
+ const oppCol = C.GetOppTurn(color);
if (this.subTurn == 2) {
// Just play a normal move (which in fact only indicate a square)
let movesHash = {};
getCurrentScore() {
// This function is only called at subTurn 1
- const color = C.GetOppCol(this.turn);
+ const color = C.GetOppTurn(this.turn);
if (this.searchKingPos(color).length == 0)
return (color == 'w' ? "0-1" : "1-0");
return "*";
postPlay(move) {
const color = this.turn;
if (this.subTurn == 2 || this.searchKingPos(color).length == 0) {
- this.turn = C.GetOppCol(color);
+ this.turn = C.GetOppTurn(color);
this.movesCount++;
}
this.subTurn = 3 - this.subTurn;
}
}
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 (
// More general test than checking moves ends,
// because of potential pawn relocation
};
this.playVisual(revFirstMove);
}
- this.turn = C.GetOppCol(color);
+ this.turn = C.GetOppTurn(color);
this.movesCount++;
this.subTurn = 1;
this.firstMove = null;
postPlay(move) {
const color = this.turn;
- const oppCol = C.GetOppCol(color);
+ const oppCol = C.GetOppTurn(color);
this.promotion = (
this.subTurn == 2 &&
move.end.x == (oppCol == 'w' ? 0 : this.size.x - 1) &&
tryChangeTurn(move, captureUndef) {
this.definition = null;
this.subTurn = captureUndef ? 0 : 1;
- this.turn = C.GetOppCol(this.turn);
+ this.turn = C.GetOppTurn(this.turn);
this.movesCount++;
}
isImmobilized([x, y]) {
const piece = this.getPiece(x, y);
const color = this.getColor(x, y);
- const oppCol = C.GetOppCol(color);
+ const oppCol = C.GetOppTurn(color);
const adjacentSteps = this.pieces()['k'].moves[0].steps;
for (let step of adjacentSteps) {
const [i, j] = [x + step[0], this.getY(y + step[1])];
}
postProcessPotentialMoves(moves) {
- const oppCol = C.GetOppCol(this.turn);
+ const oppCol = C.GetOppTurn(this.turn);
let bMoves = super.postProcessPotentialMoves(moves);
bMoves.forEach(m => {
m.flips = [];
moves = this.getDropMovesFrom([x, y]);
else if (this.egg == "kingboo") {
const color = this.turn;
- const oppCol = C.GetOppCol(color);
+ const oppCol = C.GetOppTurn(color);
// Only allow to swap (non-immobilized!) pieces
for (let i=0; i<this.size.x; i++) {
for (let j=0; j<this.size.y; j++) {
getPawnMovesFrom([x, y]) {
const color = this.turn;
- const oppCol = C.GetOppCol(color);
+ const oppCol = C.GetOppTurn(color);
const shiftX = (color == 'w' ? -1 : 1);
const firstRank = (color == "w" ? this.size.x - 1 : 0);
let moves = [];
play(move) {
const color = this.turn;
- const oppCol = C.GetOppCol(color);
+ const oppCol = C.GetOppTurn(color);
this.egg = move.egg;
if (move.egg == "toadette") {
this.reserve = { w: {}, b: {} };
)
) {
// "Forgotten" promotion, which occurred after some effect
- let moves = super.pawnPostProcess([move], color, C.GetOppCol(color));
+ let moves = super.pawnPostProcess([move], color, C.GetOppTurn(color));
super.showChoices(moves, r);
}
else
case "luigi":
case "waluigi":
// Change color of friendly or enemy piece, king excepted
- const oldColor = (move.egg == "waluigi" ? color : C.GetOppCol(color));
- const newColor = C.GetOppCol(oldColor);
+ const oldColor = (move.egg == "waluigi" ? color : C.GetOppTurn(color));
+ const newColor = C.GetOppTurn(oldColor);
const coords = getRandomPiece(oldColor);
if (coords) {
const piece = this.getPiece(coords[0], coords[1]);
};
}
+ static GetColorClass(c) {
+ if (c == 'c')
+ return "checkered";
+ return C.GetColorClass(c);
+ }
+
static board2fen(b) {
const checkered_codes = {
p: "s",
return super.fen2board(f);
}
+ genRandInitBaseFen() {
+ let res = super.genRandInitBaseFen();
+ res.o.flags += "1".repeat(16); //pawns flags
+ return res;
+ }
+
getPartFen(o) {
return Object.assign(
{
return false; //forbidden 2-squares jumps
}
if (
- this.board[m.end.x][m.end.y] == V.EMPTY &&
+ this.board[m.end.x][m.end.y] == "" &&
m.vanish.length == 2 &&
this.getColor(m.start.x, m.start.y) == "c"
) {
filterValid(moves) {
const color = this.turn;
- if (stage == 2 && this.sideCheckered == color)
+ if (this.stage == 2 && this.sideCheckered == color)
// Checkered cannot be under check (no king)
return moves;
let kingPos = super.searchKingPos(color);
return moves.filter(m => {
this.playOnBoard(m);
let res = true;
- if (stage == 1)
+ if (this.stage == 1)
res = !this.oppositeMoves(this.cmove, m);
if (res && m.appear.length > 0)
res = !this.underCheck(kingPos, oppCols);
underCheck(square_s, oppCols) {
if (this.stage == 2 && oppCol != this.sideCheckered)
return false; //checkered pieces is me, I'm not under check
- return super.underAttack(square_s, oppCols);
+ return square_s.some(sq => super.underAttack(sq, oppCols));
}
prePlay(move) {
super.prePlay(move);
if (
[1, 6].includes(move.start.x) &&
- move.vanish[0].p == V.PAWN &&
+ move.vanish[0].p == 'p' &&
Math.abs(move.end.x - move.start.x) == 2
) {
// This move turns off a 2-squares pawn flag
@import url("/base_pieces.css");
-piece.checkered-pawn {
+piece.checkered.pawn {
background-image: url('/variants/Checkered/pieces/cp.svg');
}
-piece.checkered-rook {
+piece.checkered.rook {
background-image: url('/variants/Checkered/pieces/cr.svg');
}
-piece.checkered-knight {
+piece.checkered.knight {
background-image: url('/variants/Checkered/pieces/cn.svg');
}
-piece.checkered-bishop {
+piece.checkered.bishop {
background-image: url('/variants/Checkered/pieces/cb.svg');
}
-piece.checkered-queen {
+piece.checkered.queen {
background-image: url('/variants/Checkered/pieces/cq.svg');
}
new PiPo({
x: coords.x,
y: coords.y,
- c: C.GetOppCol(this.turn),
+ c: C.GetOppTurn(this.turn),
p: 'p'
})
);
play(move) {
this.playOnBoard(move);
this.movesCount++;
- this.turn = C.GetOppCol(this.turn);
+ this.turn = C.GetOppTurn(this.turn);
}
getCurrentScore() {
- const oppCol = C.GetOppCol(this.turn);
+ const oppCol = C.GetOppTurn(this.turn);
// Search for connecting path of opp color:
let explored = {}, component;
let min, max;
if (this.board[x][y] != "" || this.turn != this.playerColor)
return null;
const color = this.turn;
- const oppCol = C.GetOppCol(color);
+ const oppCol = C.GetOppTurn(color);
let move = new Move({
appear: [new PiPo({x: x, y: y, c: color, p: 's'})],
vanish: [],
if (move.pass) {
if (this.turn != this.playerColor)
super.displayMessage(null, "pass", "pass-text", 2000);
- this.turn = C.GetOppCol(this.turn);
+ this.turn = C.GetOppTurn(this.turn);
}
else
super.play(move);
flipColorOf(flips) {
for (let xy of flips) {
- const newColor = C.GetOppCol(this.getColor(xy.x, xy.y));
+ const newColor = C.GetOppTurn(this.getColor(xy.x, xy.y));
this.board[xy.x][xy.y] = newColor + this.board[xy.x][xy.y][1];
}
}
addPincerCaptures(moves, byChameleon) {
const steps = this.pieces()['p'].moves[0].steps;
const color = this.turn;
- const oppCol = C.GetOppCol(color);
+ const oppCol = C.GetOppTurn(color);
moves.forEach(m => {
if (byChameleon && m.start.x != m.end.x && m.start.y != m.end.y)
// Chameleon not moving as pawn
addCoordinatorCaptures(moves, byChameleon) {
const color = this.turn;
- const oppCol = V.GetOppCol(color);
+ const oppCol = V.GetOppTurn(color);
const kp = this.searchKingPos(color)[0];
moves.forEach(m => {
// Check piece-king rectangle (if any) corners for enemy pieces
// Look in every direction for captures
const steps = this.pieces()['r'].moves[0].steps;
const color = this.turn;
- const oppCol = C.GetOppCol(color);
+ const oppCol = C.GetOppTurn(color);
let moves = [];
outerLoop: for (let step of steps) {
let [i, j] = [x + step[0], this.getY(y + step[1])];
const adjacentSteps = this.pieces()['r'].moves[0].steps;
let capturingPullDir = {};
const color = this.turn;
- const oppCol = C.GetOppCol(color);
+ const oppCol = C.GetOppTurn(color);
if (type != "push") {
adjacentSteps.forEach(step => {
const [bi, bj] = [sx - step[0], this.getY(sy - step[1])];