X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FTwokings.js;fp=client%2Fsrc%2Fvariants%2FTwokings.js;h=9e82a245d1c95a5eba0ac42ed9e8267cefb65d39;hb=14c35dc66973e66f9d9a680abb0a35db93ee2bcb;hp=0000000000000000000000000000000000000000;hpb=f82609cd2aea6d5ee880773795278948fbfac666;p=vchess.git diff --git a/client/src/variants/Twokings.js b/client/src/variants/Twokings.js new file mode 100644 index 00000000..9e82a245 --- /dev/null +++ b/client/src/variants/Twokings.js @@ -0,0 +1,83 @@ +import { ChessRules } from "@/base_rules"; +import { CoregalRules } from "@/variants/Coregal"; + +export class TwokingsRules extends CoregalRules { + static get PawnSpecs() { + return Object.assign( + {}, + ChessRules.PawnSpecs, + { promotions: ChessRules.PawnSpecs.promotions.concat([V.KING]) } + ); + } + + static IsGoodPosition(position) { + if (position.length == 0) return false; + const rows = position.split("/"); + if (rows.length != V.size.x) return false; + let kings = { "w": 0, "b": 0 }; + for (let row of rows) { + let sumElts = 0; + for (let i = 0; i < row.length; i++) { + if (['K','k'].includes(row[i])) kings[row[i]]++; + if (V.PIECES.includes(row[i].toLowerCase())) sumElts++; + else { + const num = parseInt(row[i]); + if (isNaN(num)) return false; + sumElts += num; + } + } + if (sumElts != V.size.y) return false; + } + // Two kings (at least) per side should be present: + if (Object.values(kings).some(v => v < 2)) return false; + return true; + } + + // Not scanning king positions. In this variant, scan the board everytime. + scanKings(fen) {} + + getCheckSquares(color) { + let squares = []; + const oppCol = V.GetOppCol(color); + for (let i=0; i