From: Benjamin Auder Date: Wed, 25 Jan 2023 09:11:55 +0000 (+0100) Subject: Advance on Checkered. TODO: fix checks detection by checkered pieces X-Git-Url: https://git.auder.net/variants/Chakart/css/assets/doc/html/DESCRIPTION?a=commitdiff_plain;h=616a8d7ae5ee96fe23d393cf6e4554b2cf3b9245;p=xogo.git Advance on Checkered. TODO: fix checks detection by checkered pieces --- diff --git a/base_rules.js b/base_rules.js index aa499f8..ec2571a 100644 --- a/base_rules.js +++ b/base_rules.js @@ -640,7 +640,7 @@ export default class ChessRules { 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"); } @@ -707,7 +707,7 @@ export default class ChessRules { 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; @@ -1016,7 +1016,7 @@ export default class ChessRules { 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); @@ -2426,7 +2426,7 @@ export default class ChessRules { 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); @@ -2503,8 +2503,8 @@ export default class ChessRules { 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); diff --git a/variants/Alapo/class.js b/variants/Alapo/class.js index 969c80f..9fcfc98 100644 --- a/variants/Alapo/class.js +++ b/variants/Alapo/class.js @@ -108,7 +108,7 @@ export default class AlapoRules extends ChessRules { // 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 ( diff --git a/variants/Alice/class.js b/variants/Alice/class.js index d1e389d..b6dd9e5 100644 --- a/variants/Alice/class.js +++ b/variants/Alice/class.js @@ -104,7 +104,7 @@ export default class AliceRules extends ChessRules { 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 => { diff --git a/variants/Allmate/class.js b/variants/Allmate/class.js index 5b237c0..e491e6d 100644 --- a/variants/Allmate/class.js +++ b/variants/Allmate/class.js @@ -35,7 +35,7 @@ export default class AllmateRules extends ChessRules { 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, @@ -58,7 +58,7 @@ export default class AllmateRules extends ChessRules { // 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 { // Remove pawn push toward own color (absurd) return ( @@ -222,7 +222,7 @@ export default class ApocalypseRules extends ChessRules { 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 @@ -306,7 +306,7 @@ export default class ApocalypseRules extends ChessRules { }; this.playVisual(revFirstMove); } - this.turn = C.GetOppCol(color); + this.turn = C.GetOppTurn(color); this.movesCount++; this.subTurn = 1; this.firstMove = null; diff --git a/variants/Avalanche/class.js b/variants/Avalanche/class.js index a1d4d54..dbbe9d5 100644 --- a/variants/Avalanche/class.js +++ b/variants/Avalanche/class.js @@ -118,7 +118,7 @@ export default class AvalancheRules extends ChessRules { 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) && diff --git a/variants/Bario/class.js b/variants/Bario/class.js index 1874383..2dd64d6 100644 --- a/variants/Bario/class.js +++ b/variants/Bario/class.js @@ -233,7 +233,7 @@ export default class BarioRules extends ChessRules { 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++; } diff --git a/variants/Baroque/class.js b/variants/Baroque/class.js index f2039d5..6434e05 100644 --- a/variants/Baroque/class.js +++ b/variants/Baroque/class.js @@ -99,7 +99,7 @@ export default class BaroqueRules extends AbstractSpecialCaptureRules { 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])]; diff --git a/variants/Benedict/class.js b/variants/Benedict/class.js index 5503f2f..0fda796 100644 --- a/variants/Benedict/class.js +++ b/variants/Benedict/class.js @@ -35,7 +35,7 @@ export default class BenedictRules extends AbstractFlipRules { } postProcessPotentialMoves(moves) { - const oppCol = C.GetOppCol(this.turn); + const oppCol = C.GetOppTurn(this.turn); let bMoves = super.postProcessPotentialMoves(moves); bMoves.forEach(m => { m.flips = []; diff --git a/variants/Chakart/class.js b/variants/Chakart/class.js index 4c55220..6ddc37c 100644 --- a/variants/Chakart/class.js +++ b/variants/Chakart/class.js @@ -220,7 +220,7 @@ export default class ChakartRules extends ChessRules { 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.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); @@ -353,7 +365,7 @@ export default class CheckeredRules extends ChessRules { 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) { @@ -361,7 +373,7 @@ export default class CheckeredRules extends ChessRules { 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 diff --git a/variants/Checkered/style.css b/variants/Checkered/style.css index a6582e7..91b60ac 100644 --- a/variants/Checkered/style.css +++ b/variants/Checkered/style.css @@ -1,17 +1,17 @@ @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'); } diff --git a/variants/Hex/class.js b/variants/Hex/class.js index f58800f..05200be 100644 --- a/variants/Hex/class.js +++ b/variants/Hex/class.js @@ -66,7 +66,7 @@ export default class HexRules extends AbstractClickFillRules { new PiPo({ x: coords.x, y: coords.y, - c: C.GetOppCol(this.turn), + c: C.GetOppTurn(this.turn), p: 'p' }) ); @@ -168,11 +168,11 @@ export default class HexRules extends AbstractClickFillRules { 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; diff --git a/variants/Weiqi/class.js b/variants/Weiqi/class.js index ca13fe1..04ad40a 100644 --- a/variants/Weiqi/class.js +++ b/variants/Weiqi/class.js @@ -137,7 +137,7 @@ export default class WeiqiRules extends ChessRules { 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: [], @@ -201,7 +201,7 @@ export default class WeiqiRules extends ChessRules { 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); diff --git a/variants/_Flip/class.js b/variants/_Flip/class.js index e2e2bf5..5af268f 100644 --- a/variants/_Flip/class.js +++ b/variants/_Flip/class.js @@ -27,7 +27,7 @@ export default class AbstractFlipRules extends ChessRules { 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]; } } diff --git a/variants/_SpecialCaptures/class.js b/variants/_SpecialCaptures/class.js index 9b48266..e6a0db1 100644 --- a/variants/_SpecialCaptures/class.js +++ b/variants/_SpecialCaptures/class.js @@ -23,7 +23,7 @@ export default class AbstractSpecialCaptureRules extends ChessRules { 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 @@ -61,7 +61,7 @@ export default class AbstractSpecialCaptureRules extends ChessRules { 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 @@ -91,7 +91,7 @@ export default class AbstractSpecialCaptureRules extends ChessRules { // 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])]; @@ -160,7 +160,7 @@ export default class AbstractSpecialCaptureRules extends ChessRules { 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])];