X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fvariants%2FUltima.js;h=9212afba9612ace343a13f3665920be3a93760ff;hb=2eef6db6cdce30fe785e601b88858c7fc743eee8;hp=812d440ba3a5b5d811ea7024b4ff21c19c0064a5;hpb=32cfcea44bf00b0c6c4d172cca715823076ff490;p=vchess.git diff --git a/public/javascripts/variants/Ultima.js b/public/javascripts/variants/Ultima.js index 812d440b..9212afba 100644 --- a/public/javascripts/variants/Ultima.js +++ b/public/javascripts/variants/Ultima.js @@ -1,8 +1,247 @@ class UltimaRules extends ChessRules { - // TODO: think about move UI for "removing an immobilized piece from the board" - // (extend game.js and feedback Rules.js with "there was a click, is it a move?") + static getPpath(b) + { + if (b[1] == "m") //'m' for Immobilizer (I is too similar to 1) + return "Ultima/" + b; + return b; //usual piece + } - // TODO: Keep usual pieces names here (but comment with Ultima pieces names) - // Just change moving + capturing modes. + initVariables(fen) + { + this.kingPos = {'w':[-1,-1], 'b':[-1,-1]}; + const fenParts = fen.split(" "); + const position = fenParts[0].split("/"); + for (let i=0; i filter directly in functions below + } + + getSlideNJumpMoves([x,y], steps, oneStep) + { + const color = this.getColor(x,y); + const piece = this.getPiece(x,y); + let moves = []; + const [sizeX,sizeY] = VariantRules.size; + outerLoop: + for (let step of steps) + { + let i = x + step[0]; + let j = y + step[1]; + while (i>=0 && i=0 && j=0 && i=0 + && j call the appropriate isAttackedBy... (exception of immobilizers) + // Other exception: a chameleon cannot attack a chameleon (seemingly...) + } + + isAttackedByQueen(sq, colors) + { + // Square (x,y) must be adjacent to a queen, and the queen must have + // some free space in the opposite direction from (x,y) + } + + updateVariables(move) + { + // Just update king position + const piece = this.getPiece(move.start.x,move.start.y); + const c = this.getColor(move.start.x,move.start.y); + if (piece == VariantRules.KING && move.appear.length > 0) + { + this.kingPos[c][0] = move.appear[0].x; + this.kingPos[c][1] = move.appear[0].y; + } + } + + static get VALUES() { //TODO: totally experimental! + return { + 'p': 1, + 'r': 2, + 'n': 5, + 'b': 3, + 'q': 3, + 'm': 5, + 'k': 1000 + }; + } + + static get SEARCH_DEPTH() { return 2; } //TODO? + + static GenRandInitFen() + { + let pieces = { "w": new Array(8), "b": new Array(8) }; + // Shuffle pieces on first and last rank + for (let c of ["w","b"]) + { + let positions = _.range(8); + // Get random squares for every piece, totally freely + + let randIndex = _.random(7); + const bishop1Pos = positions[randIndex]; + positions.splice(randIndex, 1); + + randIndex = _.random(6); + const bishop2Pos = positions[randIndex]; + positions.splice(randIndex, 1); + + randIndex = _.random(5); + const knight1Pos = positions[randIndex]; + positions.splice(randIndex, 1); + + randIndex = _.random(4); + const knight2Pos = positions[randIndex]; + positions.splice(randIndex, 1); + + randIndex = _.random(3); + const queenPos = positions[randIndex]; + positions.splice(randIndex, 1); + + randIndex = _.random(2); + const kingPos = positions[randIndex]; + positions.splice(randIndex, 1); + + randIndex = _.random(1); + const rookPos = positions[randIndex]; + positions.splice(randIndex, 1); + const immobilizerPos = positions[2]; + + pieces[c][bishop1Pos] = 'b'; + pieces[c][bishop2Pos] = 'b'; + pieces[c][knight1Pos] = 'n'; + pieces[c][knight2Pos] = 'n'; + pieces[c][queenPos] = 'q'; + pieces[c][kingPos] = 'k'; + pieces[c][rookPos] = 'r'; + pieces[c][immobilizerPos] = 'm'; + } + return pieces["b"].join("") + + "/pppppppp/8/8/8/8/PPPPPPPP/" + + pieces["w"].join("").toUpperCase() + + " 0000"; //TODO: flags?! + } + + getFlagsFen() + { + return "0000"; //TODO: or "-" ? + } }