X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FFootball.js;h=7829c2d6e67673b65cdcd98821db4cd58e0d9654;hb=4313762da3237b04f204e121a20cab3ba7bb5dd2;hp=98e2372ea9a1708c036a564e8a332711fe583f44;hpb=5c6c52ac1c7bbb2a58c60bf5f389e1be4b76b0c1;p=vchess.git diff --git a/client/src/variants/Football.js b/client/src/variants/Football.js index 98e2372e..7829c2d6 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; } @@ -235,7 +235,7 @@ export class FootballRules extends ChessRules { } } const kickedFrom = x + "-" + y; - moves.forEach(m => m.by = kickedFrom) + moves.forEach(m => m.start.by = kickedFrom) return moves; } @@ -282,6 +282,7 @@ export class FootballRules extends ChessRules { const steps = V.steps[V.ROOK].concat(V.steps[V.BISHOP]); const c = this.turn; let moves = []; + let kicks = {}; for (let s of steps) { const [i, j] = [x + s[0], y + s[1]]; if ( @@ -289,37 +290,32 @@ export class FootballRules extends ChessRules { this.board[i][j] != V.EMPTY && this.getColor(i, j) == c ) { - Array.prototype.push.apply(moves, this.tryKickFrom([i, j])); + const kmoves = this.tryKickFrom([i, j]); + kmoves.forEach(km => { + const key = V.CoordsToSquare(km.start) + V.CoordsToSquare(km.end); + if (!kicks[km]) { + moves.push(km); + kicks[km] = true; + } + }); } } - // And, always add the "end" move. For computer, keep only one - 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; + if (Object.keys(kicks).length > 0) { + // And, always add the "end" move. For computer, keep only one + 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; + } } } } 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: @@ -346,7 +342,7 @@ export class FootballRules extends ChessRules { filterValid(moves) { const L = this.kickedBy.length; const kb = this.kickedBy[L-1]; - return moves.filter(m => !m.by || !kb[m.by]); + return moves.filter(m => !m.start.by || !kb[m.start.by]); } getCheckSquares() { @@ -393,9 +389,9 @@ export class FootballRules extends ChessRules { } else { this.subTurn++; - if (!!move.by) { + if (!!move.start.by) { const L = this.kickedBy.length; - this.kickedBy[L-1][move.by] = true; + this.kickedBy[L-1][move.start.by] = true; } } } @@ -409,9 +405,9 @@ export class FootballRules extends ChessRules { } else { this.subTurn--; - if (!!move.by) { + if (!!move.start.by) { const L = this.kickedBy.length; - delete this.kickedBy[L-1][move.by]; + delete this.kickedBy[L-1][move.start.by]; } } if (!passesOver) {