4 .col-sm-12.col-md-10.col-md-offset-1.col-lg-8.col-lg-offset-2
6 button(@click="clickReadRules") Rules
7 button(v-show="!gameInProgress" @click="() => startGame('auto')")
9 button(v-show="!gameInProgress" @click="() => startGame('versus')")
11 button(v-show="gameInProgress" @click="() => stopGame()")
13 button(@click="gotoAnalyze") Analyze
14 .section-content(v-show="display=='rules'" v-html="content")
15 ComputerGame(v-show="display=='computer'" :game-info="gameInfo"
16 @game-over="stopGame" @game-stopped="gameStopped")
20 import ComputerGame from "@/components/ComputerGame.vue";
21 import { store } from "@/store";
22 import { getDiagram } from "@/utils/printDiagram";
34 gameInProgress: false,
35 // variables passed to ComputerGame:
45 "$route": function(newRoute) {
46 this.tryChangeVariant(newRoute.params["vname"]);
49 created: async function() {
50 // NOTE: variant cannot be set before store is initialized
51 this.tryChangeVariant(this.$route.params["vname"]);
54 clickReadRules: function() {
55 if (this.display != "rules")
56 this.display = "rules";
57 else if (this.gameInProgress)
58 this.display = "computer";
61 const fenParts = fen.split(" ");
63 position: fenParts[0],
65 orientation: fenParts[2],
69 tryChangeVariant: async function(vname) {
70 if (!vname || vname == "_unknown")
72 this.gameInfo.vname = vname;
73 const vModule = await import("@/variants/" + vname + ".js");
74 window.V = vModule.VariantRules;
75 // Method to replace diagrams in loaded HTML
76 const replaceByDiag = (match, p1, p2) => {
77 const args = this.parseFen(p2);
78 return getDiagram(args);
80 // (AJAX) Request to get rules content (plain text, HTML)
82 require("raw-loader!@/translations/rules/" + vname + "/" + this.st.lang + ".pug")
83 // Next two lines fix a weird issue after last update (2019-11)
84 .replace(/\\[n"]/g, " ")
85 .replace('module.exports = "', '').replace(/"$/, "")
86 .replace(/(fen:)([^:]*):/g, replaceByDiag);
88 startGame: function(mode) {
89 if (this.gameInProgress)
91 this.gameInProgress = true;
92 this.display = "computer";
93 this.gameInfo.mode = mode;
94 this.gameInfo.score = "*";
95 this.gameInfo.fen = V.GenRandInitFen();
97 // user is willing to stop the game:
98 stopGame: function(score) {
99 this.gameInfo.score = score || "?";
100 this.gameInfo.mode = "analyze";
102 // The game is effectively stopped:
103 gameStopped: function() {
104 this.gameInProgress = false;
106 gotoAnalyze: function() {
107 this.$router.push("/analyze/" + this.gameInfo.vname
108 + "/?fen=" + V.GenRandInitFen());
114 <style lang="sass" scoped>
118 // margin-right: auto
120 // figure.diagram-container
122 // @media screen and (max-width: 767px)
129 background-color: lightgrey
132 figure.diagram-container
133 margin: 15px 0 15px 0
145 margin-left: calc(10% - 20px)
147 @media screen and (max-width: 630px)
149 margin: 0 auto 10px auto
152 margin-right: calc(10% - 20px)
153 @media screen and (max-width: 630px)
163 background-color: #FFCC66
169 // To show (new) pieces, and/or there values...
170 figure.showPieces > img
173 figure.showPieces > figcaption
182 ol, ul:not(.browser-default)
185 ul:not(.browser-default)
188 ul:not(.browser-default) > li
189 list-style-type: disc
192 background-color: #e5e5ca
195 background-color: #6f8f57
197 // TODO: following is duplicated (Board.vue)
201 display: inline-block
206 padding-bottom: 12.5%
219 img.piece, img.mark-square
233 filter: brightness(50%)