From: Benjamin Auder <benjamin.auder@somewhere> Date: Wed, 4 Mar 2020 15:56:03 +0000 (+0100) Subject: Allow to set also randomness against computer X-Git-Url: https://git.auder.net/doc/html/css/scripts/%7B%7B%20asset%28%27mixstore/DESCRIPTION?a=commitdiff_plain;h=f35b9960e1c527fc400ebac85321bd4712459da3;p=vchess.git Allow to set also randomness against computer --- diff --git a/client/src/base_rules.js b/client/src/base_rules.js index 93772b9b..d2b8a7fd 100644 --- a/client/src/base_rules.js +++ b/client/src/base_rules.js @@ -240,7 +240,6 @@ export const ChessRules = class ChessRules { // Setup the initial random (asymmetric) position static GenRandInitFen(randomness) { - if (!randomness) randomness = 2; if (randomness == 0) // Deterministic: return "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w 0 1111 -"; diff --git a/client/src/components/ComputerGame.vue b/client/src/components/ComputerGame.vue index 9699c5a8..5782ba6a 100644 --- a/client/src/components/ComputerGame.vue +++ b/client/src/components/ComputerGame.vue @@ -58,7 +58,7 @@ export default { if (!game) { game = { vname: this.gameInfo.vname, - fenStart: V.GenRandInitFen(), + fenStart: V.GenRandInitFen(this.st.settings.randomness), moves: [] }; game.fen = game.fenStart; diff --git a/client/src/components/Settings.vue b/client/src/components/Settings.vue index 6e623ba4..6adf9b0b 100644 --- a/client/src/components/Settings.vue +++ b/client/src/components/Settings.vue @@ -52,6 +52,12 @@ div type="checkbox" v-model="st.settings.sound" ) + fieldset + label(for="setRandomness") {{ st.tr["Randomness against computer"] }} + select#setRandomness(v-model="st.settings.randomness") + option(value="0") {{ st.tr["Deterministic"] }} + option(value="1") {{ st.tr["Symmetric random"] }} + option(value="2") {{ st.tr["Asymmetric random"] }} </template> <script> @@ -83,7 +89,7 @@ export default { const propName = event.target.id .substr(3) .replace(/^\w/, c => c.toLowerCase()); - const value = propName == "bcolor" + const value = ["bcolor","randomness"].includes(propName) ? event.target.value : event.target.checked; store.updateSetting(propName, value); diff --git a/client/src/store.js b/client/src/store.js index 10ad10e6..705f473c 100644 --- a/client/src/store.js +++ b/client/src/store.js @@ -76,8 +76,12 @@ export const store = { bcolor: localStorage.getItem("bcolor") || "lichess", sound: getItemDefaultTrue("sound"), hints: getItemDefaultTrue("hints"), - highlight: getItemDefaultTrue("highlight") + highlight: getItemDefaultTrue("highlight"), + randomness: parseInt(localStorage.getItem("randomness")) }; + if (isNaN(this.state.settings.randomness)) + // Default: random asymmetric + this.state.settings.randomness = 2; const supportedLangs = ["en", "es", "fr"]; const navLanguage = navigator.language.substr(0,2); this.state.lang = diff --git a/client/src/translations/en.js b/client/src/translations/en.js index 856034cc..9a938055 100644 --- a/client/src/translations/en.js +++ b/client/src/translations/en.js @@ -96,6 +96,7 @@ export const translations = { "participant(s):": "participant(s):", "Random?": "Random?", "Randomness": "Randomness", + "Randomness against computer": "Randomness against computer", Refuse: "Refuse", Register: "Register", "Registration complete! Please check your emails now": "Registration complete! Please check your emails now", diff --git a/client/src/translations/es.js b/client/src/translations/es.js index 15926180..c6c7f083 100644 --- a/client/src/translations/es.js +++ b/client/src/translations/es.js @@ -96,6 +96,7 @@ export const translations = { "participant(s):": "participante(s):", "Random?": "Aleatorio?", "Randomness": "Grado de azar", + "Randomness against computer": "Grado de azar contra la computadora", Refuse: "Rechazar", Register: "Registrarse", "Registration complete! Please check your emails now": "¡Registro completo! Revise sus correos electrónicos ahora", diff --git a/client/src/translations/fr.js b/client/src/translations/fr.js index 848241a3..ef52e67c 100644 --- a/client/src/translations/fr.js +++ b/client/src/translations/fr.js @@ -96,6 +96,7 @@ export const translations = { "participant(s):": "participant(s) :", "Random?": "Aléatoire?", "Randomness": "Degré d'aléa", + "Randomness against computer": "Degré d'aléa contre l'ordinateur", Refuse: "Refuser", Register: "S'enregistrer", "Registration complete! Please check your emails now": "Enregistrement terminé ! Allez voir vos emails maintenant", diff --git a/client/src/variants/Antiking.js b/client/src/variants/Antiking.js index 1c062bbf..6771089f 100644 --- a/client/src/variants/Antiking.js +++ b/client/src/variants/Antiking.js @@ -152,7 +152,6 @@ export const VariantRules = class AntikingRules extends ChessRules { } static GenRandInitFen(randomness) { - if (!randomness) randomness = 2; if (randomness == 0) return "rnbqkbnr/pppppppp/3A4/8/8/3a4/PPPPPPPP/RNBQKBNR w 0 1111 -"; diff --git a/client/src/variants/Baroque.js b/client/src/variants/Baroque.js index a860fe79..246f5111 100644 --- a/client/src/variants/Baroque.js +++ b/client/src/variants/Baroque.js @@ -546,7 +546,6 @@ export const VariantRules = class BaroqueRules extends ChessRules { } static GenRandInitFen(randomness) { - if (!randomness) randomness = 2; if (randomness == 0) // Deterministic: return "rnbqkbnrm/pppppppp/8/8/8/8/PPPPPPPP/MNBKQBNR w 0"; diff --git a/client/src/variants/Circular.js b/client/src/variants/Circular.js index 93df8efc..d0abe1cc 100644 --- a/client/src/variants/Circular.js +++ b/client/src/variants/Circular.js @@ -31,7 +31,6 @@ export const VariantRules = class CircularRules extends ChessRules { } static GenRandInitFen(randomness) { - if (!randomness) randomness = 2; if (randomness == 0) return "8/8/pppppppp/rnbqkbnr/8/8/PPPPPPPP/RNBQKBNR w 0 1111111111111111"; diff --git a/client/src/variants/Grand.js b/client/src/variants/Grand.js index c910dd8e..359671b6 100644 --- a/client/src/variants/Grand.js +++ b/client/src/variants/Grand.js @@ -317,7 +317,6 @@ export const VariantRules = class GrandRules extends ChessRules { } static GenRandInitFen(randomness) { - if (!randomness) randomness = 2; if (randomness == 0) { return "rnbqkmcbnr/pppppppppp/10/10/10/10/10/10/PPPPPPPPPP/RNBQKMCBNR " + "w 0 1111 - 00000000000000"; diff --git a/client/src/variants/Losers.js b/client/src/variants/Losers.js index b4385bab..caebd297 100644 --- a/client/src/variants/Losers.js +++ b/client/src/variants/Losers.js @@ -143,7 +143,6 @@ export const VariantRules = class LosersRules extends ChessRules { } static GenRandInitFen(randomness) { - if (!randomness) randomness = 2; if (randomness == 0) return "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w 0 -"; diff --git a/client/src/variants/Rifle.js b/client/src/variants/Rifle.js index 61c2c352..ccec48ef 100644 --- a/client/src/variants/Rifle.js +++ b/client/src/variants/Rifle.js @@ -1,11 +1,6 @@ import { ChessRules, PiPo, Move } from "@/base_rules"; export const VariantRules = class RifleRules extends ChessRules { - static get HasEnpassant() { - // Due to the capturing mode, en passant is disabled - return false; - } - getBasicMove([sx, sy], [ex, ey], tr) { let mv = new Move({ appear: [], @@ -46,4 +41,77 @@ export const VariantRules = class RifleRules extends ChessRules { return mv; } + + getPotentialPawnMoves([x, y]) { + const color = this.turn; + let moves = []; + const [sizeX, sizeY] = [V.size.x, V.size.y]; + const shiftX = color == "w" ? -1 : 1; + const startRank = color == "w" ? sizeX - 2 : 1; + const lastRank = color == "w" ? 0 : sizeX - 1; + + const finalPieces = + x + shiftX == lastRank + ? [V.ROOK, V.KNIGHT, V.BISHOP, V.QUEEN] + : [V.PAWN]; + if (this.board[x + shiftX][y] == V.EMPTY) { + for (let piece of finalPieces) { + moves.push( + this.getBasicMove([x, y], [x + shiftX, y], { + c: color, + p: piece + }) + ); + } + if ( + x == startRank && + this.board[x + 2 * shiftX][y] == V.EMPTY + ) { + moves.push(this.getBasicMove([x, y], [x + 2 * shiftX, y])); + } + } + // Captures + for (let shiftY of [-1, 1]) { + if ( + y + shiftY >= 0 && + y + shiftY < sizeY && + this.board[x + shiftX][y + shiftY] != V.EMPTY && + this.canTake([x, y], [x + shiftX, y + shiftY]) + ) { + for (let piece of finalPieces) { + moves.push( + this.getBasicMove([x, y], [x + shiftX, y + shiftY], { + c: color, + p: piece + }) + ); + } + } + } + + // En passant + const Lep = this.epSquares.length; + const epSquare = this.epSquares[Lep - 1]; //always at least one element + if ( + !!epSquare && + epSquare.x == x + shiftX && + Math.abs(epSquare.y - y) == 1 + ) { + let enpassantMove = new Move({ + appear: [], + vanish: [], + start: {x:x, y:y}, + end: {x:x+shiftX, y:epSquare.y} + }); + enpassantMove.vanish.push({ + x: x, + y: epSquare.y, + p: "p", + c: this.getColor(x, epSquare.y) + }); + moves.push(enpassantMove); + } + + return moves; + } }; diff --git a/client/src/variants/Royalrace.js b/client/src/variants/Royalrace.js index ff6e1e1d..9318c122 100644 --- a/client/src/variants/Royalrace.js +++ b/client/src/variants/Royalrace.js @@ -20,7 +20,6 @@ export const VariantRules = class RoyalraceRules extends ChessRules { } static GenRandInitFen(randomness) { - if (!randomness) randomness = 2; if (randomness == 0) return "11/11/11/11/11/11/11/11/11/QRBNP1pnbrq/KRBNP1pnbrk w 0"; diff --git a/client/src/variants/Upsidedown.js b/client/src/variants/Upsidedown.js index 44dab7f0..2260b673 100644 --- a/client/src/variants/Upsidedown.js +++ b/client/src/variants/Upsidedown.js @@ -21,7 +21,6 @@ export const VariantRules = class UpsidedownRules extends ChessRules { } static GenRandInitFen(randomness) { - if (!randomness) randomness = 2; if (randomness == 0) return "RNBQKBNR/PPPPPPPP/8/8/8/8/pppppppp/rnbqkbnr w 0"; diff --git a/client/src/views/Rules.vue b/client/src/views/Rules.vue index 556ea863..1851609f 100644 --- a/client/src/views/Rules.vue +++ b/client/src/views/Rules.vue @@ -153,7 +153,7 @@ export default { }, gotoAnalyze: function() { this.$router.push( - "/analyse/" + this.gameInfo.vname + "/?fen=" + V.GenRandInitFen() + "/analyse/" + this.gameInfo.vname + "/?fen=" + V.GenRandInitFen(2) ); } }