X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FAntiking.js;h=21e37f4b86f1d367aa86ac94b4760df668211ba6;hb=a97bdbda4ecf83645d409b717e36828784d1450d;hp=7b57e74aecc4017a2040fa1b40ce63bca0733f8f;hpb=0c3fe8a6c3e02af46e0bc646b40c1a0c420f9dcd;p=vchess.git diff --git a/client/src/variants/Antiking.js b/client/src/variants/Antiking.js index 7b57e74a..21e37f4b 100644 --- a/client/src/variants/Antiking.js +++ b/client/src/variants/Antiking.js @@ -1,207 +1,217 @@ import { ChessRules } from "@/base_rules"; -import { ArrayFun} from "@/utils/array"; +import { ArrayFun } from "@/utils/array"; import { randInt } from "@/utils/alea"; -export const VariantRules = class AntikingRules extends ChessRules -{ - static getPpath(b) - { - return b[1]=='a' ? "Antiking/"+b : b; - } - - static get ANTIKING() { return 'a'; } - - static get PIECES() - { - return ChessRules.PIECES.concat([V.ANTIKING]); - } - - setOtherVariables(fen) - { - super.setOtherVariables(fen); - this.antikingPos = {'w':[-1,-1], 'b':[-1,-1]}; - const rows = V.ParseFen(fen).position.split("/"); - for (let i=0; i0?antikingPos["w"]:"") - + "A" + (antikingPos["w"]<7?7-antikingPos["w"]:""); - const ranks23_white = (antikingPos["b"]>0?antikingPos["b"]:"") + "a" - + (antikingPos["b"]<7?7-antikingPos["b"]:"") + "/PPPPPPPP"; - return pieces["b"].join("") + "/" + ranks23_black + - "/8/8/" + - ranks23_white + "/" + pieces["w"].join("").toUpperCase() + - " w 0 1111 -"; - } -} + const oppCol = V.GetOppCol(color); + if ( + !this.isAttacked(this.kingPos[color], [oppCol]) && + this.isAttacked(this.antikingPos[color], [oppCol]) + ) { + return "1/2"; + } + return color == "w" ? "0-1" : "1-0"; + } + + static get VALUES() { + return Object.assign( + { a: 1000 }, + ChessRules.VALUES + ); + } + + static GenRandInitFen() { + let pieces = { w: new Array(8), b: new Array(8) }; + let antikingPos = { w: -1, b: -1 }; + for (let c of ["w", "b"]) { + let positions = ArrayFun.range(8); + + // Get random squares for bishops, but avoid corners; because, + // if an antiking blocks a cornered bishop, it can never be checkmated + let randIndex = 2 * randInt(1, 4); + const bishop1Pos = positions[randIndex]; + let randIndex_tmp = 2 * randInt(3) + 1; + const bishop2Pos = positions[randIndex_tmp]; + positions.splice(Math.max(randIndex, randIndex_tmp), 1); + positions.splice(Math.min(randIndex, randIndex_tmp), 1); + + randIndex = randInt(6); + const knight1Pos = positions[randIndex]; + positions.splice(randIndex, 1); + randIndex = randInt(5); + const knight2Pos = positions[randIndex]; + positions.splice(randIndex, 1); + + randIndex = randInt(4); + const queenPos = positions[randIndex]; + positions.splice(randIndex, 1); + + const rook1Pos = positions[0]; + const kingPos = positions[1]; + const rook2Pos = positions[2]; + + // Random squares for antikings + antikingPos[c] = randInt(8); + + pieces[c][rook1Pos] = "r"; + pieces[c][knight1Pos] = "n"; + pieces[c][bishop1Pos] = "b"; + pieces[c][queenPos] = "q"; + pieces[c][kingPos] = "k"; + pieces[c][bishop2Pos] = "b"; + pieces[c][knight2Pos] = "n"; + pieces[c][rook2Pos] = "r"; + } + const ranks23_black = + "pppppppp/" + + (antikingPos["w"] > 0 ? antikingPos["w"] : "") + + "A" + + (antikingPos["w"] < 7 ? 7 - antikingPos["w"] : ""); + const ranks23_white = + (antikingPos["b"] > 0 ? antikingPos["b"] : "") + + "a" + + (antikingPos["b"] < 7 ? 7 - antikingPos["b"] : "") + + "/PPPPPPPP"; + return ( + pieces["b"].join("") + + "/" + + ranks23_black + + "/8/8/" + + ranks23_white + + "/" + + pieces["w"].join("").toUpperCase() + + " w 0 1111 -" + ); + } +};