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 @computer-think="gameInProgress=false" @game-over="stopGame"
15 @game-stopped="gameStopped")
19 import ComputerGame from "@/components/ComputerGame.vue";
20 import { store } from "@/store";
21 import { getDiagram } from "@/utils/printDiagram";
33 gameInProgress: false,
34 // variables passed to ComputerGame:
44 "$route": function(newRoute) {
45 this.tryChangeVariant(newRoute.params["vname"]);
48 created: async function() {
49 // NOTE: variant cannot be set before store is initialized
50 this.tryChangeVariant(this.$route.params["vname"]);
53 clickReadRules: function() {
54 if (this.display != "rules")
55 this.display = "rules";
56 else if (this.gameInProgress)
57 this.display = "computer";
60 const fenParts = fen.split(" ");
62 position: fenParts[0],
64 orientation: fenParts[2],
68 tryChangeVariant: async function(vname) {
69 if (!vname || vname == "_unknown")
71 this.gameInfo.vname = vname;
72 const vModule = await import("@/variants/" + vname + ".js");
73 window.V = vModule.VariantRules;
74 // Method to replace diagrams in loaded HTML
75 const replaceByDiag = (match, p1, p2) => {
76 const args = this.parseFen(p2);
77 return getDiagram(args);
79 // (AJAX) Request to get rules content (plain text, HTML)
81 require("raw-loader!@/rules/" + vname + "/" + this.st.lang + ".pug")
82 // Next two lines fix a weird issue after last update (2019-11)
83 .replace(/\\[n"]/g, " ")
84 .replace('module.exports = "', '').replace(/"$/, "")
85 .replace(/(fen:)([^:]*):/g, replaceByDiag);
87 startGame: function(mode) {
88 if (this.gameInProgress)
90 this.gameInProgress = true;
91 this.display = "computer";
92 this.gameInfo.mode = mode;
93 this.gameInfo.score = "*";
94 this.gameInfo.fen = V.GenRandInitFen();
96 // user is willing to stop the game:
97 stopGame: function(score) {
98 this.gameInfo.score = score || "?";
99 this.gameInfo.mode = "analyze";
101 // The game is effectively stopped:
102 gameStopped: function() {
103 this.gameInProgress = false;
113 background-color: lightgrey
116 figure.diagram-container
117 margin: 15px 0 15px 0
129 margin-left: calc(10% - 20px)
131 @media screen and (max-width: 630px)
133 margin: 0 auto 10px auto
136 margin-right: calc(10% - 20px)
137 @media screen and (max-width: 630px)
147 background-color: #FFCC66
153 // To show (new) pieces, and/or there values...
154 figure.showPieces > img
157 figure.showPieces > figcaption
166 ol, ul:not(.browser-default)
169 ul:not(.browser-default)
172 ul:not(.browser-default) > li
173 list-style-type: disc
176 background-color: #e5e5ca
179 background-color: #6f8f57
181 // TODO: following is duplicated
185 display: inline-block
190 padding-bottom: 12.5%
203 img.piece, img.mark-square
217 filter: brightness(50%)