X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FFootball.js;h=ffe6736b1daf268e29d0972a7699015392c20906;hb=63c42a8fd6ba2150af5c6f25afe7aaf5f20599aa;hp=d63cfee3ac33d84dda458bb5679e2eb918096208;hpb=2cfc3b918bf2c6581199f9ca72b61112c35fdb15;p=vchess.git diff --git a/client/src/variants/Football.js b/client/src/variants/Football.js index d63cfee3..ffe6736b 100644 --- a/client/src/variants/Football.js +++ b/client/src/variants/Football.js @@ -104,13 +104,13 @@ export class FootballRules extends ChessRules { } } - static GenRandInitFen(randomness) { - if (randomness == 0) + static GenRandInitFen(options) { + if (options.randomness == 0) return "rnbq1knbr/9/9/9/4a4/9/9/9/RNBQ1KNBR w 0"; let pieces = { w: new Array(8), b: new Array(8) }; for (let c of ["w", "b"]) { - if (c == 'b' && randomness == 1) { + if (c == 'b' && options.randomness == 1) { pieces['b'] = pieces['w']; break; } @@ -159,7 +159,7 @@ export class FootballRules extends ChessRules { V.OnBoard(i, j) && this.board[i][j] == V.EMPTY && ( - // In a corner? The, allow all ball moves + // In a corner? Then, allow all ball moves ([0, 8].includes(bp[0]) && [0, 8].includes(bp[1])) || // Do not end near the knight (Math.abs(i - x) >= 2 || Math.abs(j - y) >= 2) @@ -246,34 +246,17 @@ export class FootballRules extends ChessRules { const moves = super.getPotentialMovesFrom([x, y]) .filter(m => m.end.y != 4 || ![0, 8].includes(m.end.x)); // If bishop stuck in a corner: allow to jump over the next obstacle - if (moves.length == 0 && piece == V.BISHOP) { - if ( - x == 0 && y == 0 && - this.board[1][1] != V.EMPTY && - this.board[2][2] == V.EMPTY - ) { - return [super.getBasicMove([x, y], [2, 2])]; - } - if ( - x == 0 && y == 8 && - this.board[1][7] != V.EMPTY && - this.board[2][6] == V.EMPTY - ) { - return [super.getBasicMove([x, y], [2, 6])]; - } - if ( - x == 8 && y == 0 && - this.board[7][1] != V.EMPTY && - this.board[6][2] == V.EMPTY - ) { - return [super.getBasicMove([x, y], [6, 2])]; - } + if ( + moves.length == 0 && piece == V.BISHOP && + [0, 8].includes(x) && [0, 8].includes(y) + ) { + const indX = x == 0 ? [1, 2] : [7, 6]; + const indY = y == 0 ? [1, 2] : [7, 6]; if ( - x == 8 && y == 8 && - this.board[7][7] != V.EMPTY && - this.board[6][6] == V.EMPTY + this.board[indX[0]][indY[0]] != V.EMPTY && + this.board[indX[1]][indY[1]] == V.EMPTY ) { - return [super.getBasicMove([x, y], [6, 6])]; + return [super.getBasicMove([x, y], [indX[1], indY[1]])]; } } return moves; @@ -283,6 +266,7 @@ export class FootballRules extends ChessRules { const c = this.turn; let moves = []; let kicks = {}; + let adjacentPieces = false; for (let s of steps) { const [i, j] = [x + s[0], y + s[1]]; if ( @@ -293,20 +277,24 @@ export class FootballRules extends ChessRules { const kmoves = this.tryKickFrom([i, j]); kmoves.forEach(km => { const key = V.CoordsToSquare(km.start) + V.CoordsToSquare(km.end); - if (!kicks[km]) { + if (!kicks[key]) { moves.push(km); - kicks[km] = true; + kicks[key] = true; } }); + if (!adjacentPieces) adjacentPieces = true; } } - if (Object.keys(kicks).length > 0) { - // And, always add the "end" move. For computer, keep only one + if (adjacentPieces) { + // Add the "end" move (even if no valid kicks) outerLoop: for (let i=0; i < V.size.x; i++) { for (let j=0; j < V.size.y; j++) { if (this.board[i][j] != V.EMPTY && this.getColor(i, j) == c) { - moves.push(super.getBasicMove([x, y], [i, j])); - if (!!computer) break outerLoop; + moves.push({ + appear: [], vanish: [], + start: { x: x, y: y }, end: { x: i, y: j } + }); + if (computer) break outerLoop; //no choice for computer } } } @@ -314,22 +302,8 @@ export class FootballRules extends ChessRules { return moves; } - // No captures: - getSlideNJumpMoves([x, y], steps, oneStep) { - let moves = []; - outerLoop: for (let step of steps) { - let i = x + step[0]; - let j = y + step[1]; - let stepCount = 1; - while (V.OnBoard(i, j) && this.board[i][j] == V.EMPTY) { - moves.push(this.getBasicMove([x, y], [i, j])); - if (!!oneStep) continue outerLoop; - i += step[0]; - j += step[1]; - stepCount++; - } - } - return moves; + canTake() { + return false; } // Extra arg "computer" to avoid trimming all redundant pass moves: @@ -389,7 +363,7 @@ export class FootballRules extends ChessRules { play(move) { // Special message saying "passes are over" - const passesOver = (move.vanish.length == 2); + const passesOver = (move.vanish.length == 0); if (!passesOver) { this.prePlay(move); V.PlayOnBoard(this.board, move); @@ -411,7 +385,7 @@ export class FootballRules extends ChessRules { } undo(move) { - const passesOver = (move.vanish.length == 2); + const passesOver = (move.vanish.length == 0); if (move.turn[0] != this.turn) { [this.turn, this.subTurn] = move.turn; this.movesCount--; @@ -465,7 +439,7 @@ export class FootballRules extends ChessRules { // NOTE: evalPosition() is wrong, but unused since bot plays at random getNotation(move) { - if (move.vanish.length == 2) return "pass"; + if (move.vanish.length == 0) return "pass"; if (move.vanish[0].p != 'a') return super.getNotation(move); // Kick: simple notation (TODO?) return V.CoordsToSquare(move.end);