X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FBall.js;h=fb2172b1f2cd1d4ab3795db4b580a72c821a8c33;hb=5d74fceaa93054b410f469fe6ed4d5a4609bf98d;hp=03a9b483d0864a5fc1cc191bd2eab5cbaa829bb0;hpb=a6363ac14efd09ad3c08c929a06af462995201bc;p=vchess.git diff --git a/client/src/variants/Ball.js b/client/src/variants/Ball.js index 03a9b483..fb2172b1 100644 --- a/client/src/variants/Ball.js +++ b/client/src/variants/Ball.js @@ -3,6 +3,7 @@ import { ArrayFun } from "@/utils/array"; import { shuffle } from "@/utils/alea"; export class BallRules extends ChessRules { + static get Lines() { return [ // White goal: @@ -35,7 +36,7 @@ export class BallRules extends ChessRules { } static get BALL() { - // Ball is already taken: + // 'b' is already taken: return "aa"; } @@ -94,18 +95,19 @@ export class BallRules extends ChessRules { const rows = position.split("/"); if (rows.length != V.size.x) return false; let pieces = { "w": 0, "b": 0 }; - const withBall = Object.keys(V.HAS_BALL_DECODE).concat([V.BALL]); + const withBall = Object.keys(V.HAS_BALL_DECODE).concat(['a']); let ballCount = 0; for (let row of rows) { let sumElts = 0; for (let i = 0; i < row.length; i++) { const lowerRi = row[i].toLowerCase(); if (V.PIECES.includes(lowerRi)) { - if (lowerRi != V.BALL) pieces[row[i] == lowerRi ? "b" : "w"]++; + if (lowerRi != 'a') pieces[row[i] == lowerRi ? "b" : "w"]++; if (withBall.includes(lowerRi)) ballCount++; sumElts++; - } else { - const num = parseInt(row[i]); + } + else { + const num = parseInt(row[i], 10); if (isNaN(num)) return false; sumElts += num; } @@ -203,8 +205,10 @@ export class BallRules extends ChessRules { if (rem2 == positions[1] % 2) { // Fix bishops (on different colors) for (let i=4; i<9; i++) { - if (positions[i] % 2 != rem2) + if (positions[i] % 2 != rem2) { [positions[1], positions[i]] = [positions[i], positions[1]]; + break; + } } } rem2 = positions[2] % 2; @@ -336,7 +340,8 @@ export class BallRules extends ChessRules { }) ); } - } else if (mv.vanish[1].c == mv.vanish[0].c) { + } + else if (mv.vanish[1].c == mv.vanish[0].c) { // Pass the ball: the passing unit does not disappear mv.appear.push(JSON.parse(JSON.stringify(mv.vanish[0]))); mv.appear[0].p = V.HAS_BALL_CODE[mv.vanish[1].p]; @@ -362,6 +367,7 @@ export class BallRules extends ChessRules { if ( m.vanish.length == 2 && m.vanish[1].p != 'a' && + m.vanish[0].c != m.vanish[1].c && Object.keys(V.HAS_BALL_DECODE).includes(m.appear[0].p) ) { const color = this.turn; @@ -564,4 +570,5 @@ export class BallRules extends ChessRules { finalSquare ); } + };