3 .col-sm-12.col-md-10.col-md-offset-1.col-lg-8.col-lg-offset-2
5 button(@click="clickReadRules") Read the rules
6 button(v-show="!gameInProgress" @click="() => startGame('auto')")
7 | Observe a sample game
8 button(v-show="!gameInProgress" @click="() => startGame('versus')")
10 button(v-show="gameInProgress" @click="() => stopGame()")
12 .section-content(v-show="display=='rules'" v-html="content")
13 ComputerGame(v-show="display=='computer'" :game-info="gameInfo"
14 @game-over="stopGame" @game-stopped="gameStopped")
18 import ComputerGame from "@/components/ComputerGame.vue";
19 import { store } from "@/store";
20 import { getDiagram } from "@/utils/printDiagram";
32 gameInProgress: false,
33 // variables passed to ComputerGame:
43 "$route": function(newRoute) {
44 this.tryChangeVariant(newRoute.params["vname"]);
47 created: async function() {
48 // NOTE: variant cannot be set before store is initialized
49 this.tryChangeVariant(this.$route.params["vname"]);
52 clickReadRules: function() {
53 if (this.display != "rules")
54 this.display = "rules";
55 else if (this.gameInProgress)
56 this.display = "computer";
59 const fenParts = fen.split(" ");
61 position: fenParts[0],
63 orientation: fenParts[2],
67 tryChangeVariant: async function(vname) {
68 if (!vname || vname == "_unknown")
70 this.gameInfo.vname = vname;
71 const vModule = await import("@/variants/" + vname + ".js");
72 window.V = vModule.VariantRules;
73 // Method to replace diagrams in loaded HTML
74 const replaceByDiag = (match, p1, p2) => {
75 const args = this.parseFen(p2);
76 return getDiagram(args);
78 // (AJAX) Request to get rules content (plain text, HTML)
80 require("raw-loader!@/rules/" + vname + "/" + this.st.lang + ".pug")
81 // Next two lines fix a weird issue after last update (2019-11)
82 .replace(/\\[n"]/g, " ")
83 .replace('module.exports = "', '').replace(/"$/, "")
84 .replace(/(fen:)([^:]*):/g, replaceByDiag);
86 startGame: function(mode) {
87 if (this.gameInProgress)
89 this.gameInProgress = true;
90 this.display = "computer";
91 this.gameInfo.mode = mode;
92 this.gameInfo.score = "*";
93 this.gameInfo.fen = V.GenRandInitFen();
95 // user is willing to stop the game:
96 stopGame: function(score) {
97 this.gameInfo.score = score || "?";
98 this.gameInfo.mode = "analyze";
100 // The game is effectively stopped:
101 gameStopped: function() {
102 this.gameInProgress = false;
112 background-color: lightgrey
115 figure.diagram-container
116 margin: 15px 0 15px 0
128 margin-left: calc(10% - 20px)
130 @media screen and (max-width: 630px)
132 margin: 0 auto 10px auto
135 margin-right: calc(10% - 20px)
136 @media screen and (max-width: 630px)
146 background-color: #FFCC66
152 // To show (new) pieces, and/or there values...
153 figure.showPieces > img
156 figure.showPieces > figcaption
165 ol, ul:not(.browser-default)
168 ul:not(.browser-default)
171 ul:not(.browser-default) > li
172 list-style-type: disc
175 background-color: #e5e5ca
178 background-color: #6f8f57
180 // TODO: following is duplicated
184 display: inline-block
189 padding-bottom: 12.5%
202 img.piece, img.mark-square
216 filter: brightness(50%)