From: Benjamin Auder Date: Wed, 12 Dec 2018 02:02:19 +0000 (+0100) Subject: Fix HalfChess, more random Loser initial position, continue draft of Ultima X-Git-Url: https://git.auder.net/variants/%24%7Bvname%7D/current/%7B%7B%20path%28%27fos_user_security_login%27%29%20%7D%7D?a=commitdiff_plain;h=2eef6db6cdce30fe785e601b88858c7fc743eee8;p=vchess.git Fix HalfChess, more random Loser initial position, continue draft of Ultima --- diff --git a/public/images/pieces/Ultima/bm.svg b/public/images/pieces/Ultima/bm.svg new file mode 100644 index 00000000..fdc0ee59 --- /dev/null +++ b/public/images/pieces/Ultima/bm.svg @@ -0,0 +1,92 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + diff --git a/public/images/pieces/Ultima/wm.svg b/public/images/pieces/Ultima/wm.svg new file mode 100644 index 00000000..bf9f16ad --- /dev/null +++ b/public/images/pieces/Ultima/wm.svg @@ -0,0 +1,97 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + diff --git a/public/javascripts/base_rules.js b/public/javascripts/base_rules.js index 750cd2d4..8de0176c 100644 --- a/public/javascripts/base_rules.js +++ b/public/javascripts/base_rules.js @@ -1033,11 +1033,10 @@ class ChessRules pieces[c][knight2Pos] = 'n'; pieces[c][rook2Pos] = 'r'; } - let fen = pieces["b"].join("") + + return pieces["b"].join("") + "/pppppppp/8/8/8/8/PPPPPPPP/" + pieces["w"].join("").toUpperCase() + " 1111"; //add flags - return fen; } // Return current fen according to pieces+colors state diff --git a/public/javascripts/components/game.js b/public/javascripts/components/game.js index d76ab011..208e0482 100644 --- a/public/javascripts/components/game.js +++ b/public/javascripts/components/game.js @@ -25,7 +25,6 @@ Vue.component('my-game', { }, render(h) { const [sizeX,sizeY] = VariantRules.size; - console.log(sizeX + " " + sizeY); const smallScreen = (screen.width <= 420); // Precompute hints squares to facilitate rendering let hintSquares = doubleArray(sizeX, sizeY, false); diff --git a/public/javascripts/variants/Half.js b/public/javascripts/variants/Half.js index 2f1174ed..6c6c7ebb 100644 --- a/public/javascripts/variants/Half.js +++ b/public/javascripts/variants/Half.js @@ -1,8 +1,35 @@ +// Standard rules on a 4x8 board with no pawns class HalfRules extends ChessRules { - // Standard rules on a 4x8 board with no pawns - - initVariables(fen) { } //nothing to do + 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 "-" ? + } } diff --git a/public/stylesheets/variant.sass b/public/stylesheets/variant.sass index 8839c342..3eec2900 100644 --- a/public/stylesheets/variant.sass +++ b/public/stylesheets/variant.sass @@ -81,10 +81,6 @@ div.board display: inline-block position: relative -div.board4 - width: 25% - padding-bottom: 25% - div.board8 width: 12.5% padding-bottom: 12.5% diff --git a/views/rules/Half.pug b/views/rules/Half.pug index 605eda4b..91b4a4e2 100644 --- a/views/rules/Half.pug +++ b/views/rules/Half.pug @@ -1,15 +1,15 @@ p.boxed - | 8x4 board with no pawns. Orthodox rules. + | 4x8 board with no pawns. Orthodox rules. figure.diagram-container .diagram - | fen:rkqr/nbbn/4/4/4/4/NBBN/RKQR: + | fen:rn4NR/kb4BK/qb4BQ/rn4NR: figcaption Initial position (non-random) h3 Specifications ul - li Chessboard: 8x4 (see diagram). + li Chessboard: 4x8 (see diagram). li Material: no pawns. li Non-capturing moves: standard. li Special moves: none. diff --git a/views/rules/Ultima.pug b/views/rules/Ultima.pug index 77bfd093..0a3cc7f0 100644 --- a/views/rules/Ultima.pug +++ b/views/rules/Ultima.pug @@ -1,7 +1,7 @@ p.boxed | Pieces look the same but behave very differently. | They generally move like an orthodox queen, - | but capturing rules are complex: you need to read on :) + | but capturing rules are complex. h3 Specifications