Add very basic computer play for Takenmake
[vchess.git] / client / src / components / BaseGame.vue
CommitLineData
a6088c90 1<template lang="pug">
e71161fb 2div#baseGame
7e355d68 3 input#modalEog.modal(type="checkbox")
6808d7a1
BA
4 div#eogDiv(
5 role="dialog"
6 data-checkbox="modalEog"
7 )
9a3049f3 8 .card.text-center
7e355d68 9 label.modal-close(for="modalEog")
9a3049f3 10 h3.section {{ endgameMessage }}
cf94b843
BA
11 #gameContainer
12 #boardContainer
6808d7a1 13 Board(
a6836242 14 ref="board"
6808d7a1
BA
15 :vr="vr"
16 :last-move="lastMove"
20620465
BA
17 :analyze="game.mode=='analyze'"
18 :score="game.score"
6808d7a1
BA
19 :user-color="game.mycolor"
20 :orientation="orientation"
21 :vname="game.vname"
22 :incheck="incheck"
23 @play-move="play"
61656127 24 @click-square="clickSquare"
6808d7a1 25 )
20620465 26 #turnIndicator(v-if="showTurn") {{ turn }}
b1e46b33 27 #controls.button-group
b9a5fe01
BA
28 button(@click="gotoBegin()")
29 img.inline(src="/images/icons/fast-forward_rev.svg")
30 button(@click="undo()")
31 img.inline(src="/images/icons/play_rev.svg")
32 button(v-if="canFlip" @click="flip()")
33 img.inline(src="/images/icons/flip.svg")
54ec15eb
BA
34 button(
35 @click="runAutoplay()"
36 :class="{'in-autoplay': autoplay}"
37 )
38 img.inline(src="/images/icons/autoplay.svg")
b9a5fe01
BA
39 button(@click="play()")
40 img.inline(src="/images/icons/play.svg")
41 button(@click="gotoEnd()")
42 img.inline(src="/images/icons/fast-forward.svg")
cf94b843 43 #movesList
6808d7a1 44 MoveList(
933fd1f9 45 :show="showMoves"
feaf1bf7
BA
46 :canAnalyze="canAnalyze"
47 :canDownload="allowDownloadPGN"
6808d7a1
BA
48 :score="game.score"
49 :message="game.scoreMsg"
50 :firstNum="firstMoveNumber"
51 :moves="moves"
52 :cursor="cursor"
feaf1bf7
BA
53 @download="download"
54 @showrules="showRules"
55 @analyze="analyzePosition"
6808d7a1 56 @goto-move="gotoMove"
49dad261 57 @reset-arrows="resetArrows"
6808d7a1 58 )
41c80bb6 59 .clearer
a6088c90
BA
60</template>
61
62<script>
63import Board from "@/components/Board.vue";
f21cd6d9 64import MoveList from "@/components/MoveList.vue";
2c5d7b20 65import params from "@/parameters";
a6088c90
BA
66import { store } from "@/store";
67import { getSquareId } from "@/utils/squareId";
d4036efe 68import { getDate } from "@/utils/datetime";
602d6bef 69import { processModalClick } from "@/utils/modalClick";
77c50966 70import { getScoreMessage } from "@/utils/scoring";
e71161fb
BA
71import { getFullNotation } from "@/utils/notation";
72import { undoMove } from "@/utils/playUndo";
a6088c90 73export default {
6808d7a1 74 name: "my-base-game",
a6088c90
BA
75 components: {
76 Board,
6808d7a1 77 MoveList
a6088c90 78 },
e71161fb 79 props: ["game"],
a6088c90
BA
80 data: function() {
81 return {
82 st: store.state,
b7c32f1a 83 // NOTE: all following variables must be reset at the beginning of a game
e71161fb 84 vr: null, //VariantRules object, game state
a6088c90
BA
85 endgameMessage: "",
86 orientation: "w",
87 score: "*", //'*' means 'unfinished'
b7c32f1a 88 moves: [],
a6088c90
BA
89 cursor: -1, //index of the move just played
90 lastMove: null,
5157ce0b 91 firstMoveNumber: 0, //for printing
e71161fb 92 incheck: [], //for Board
57eb158f 93 inMultimove: false,
54ec15eb
BA
94 autoplay: false,
95 autoplayLoop: null,
57eb158f
BA
96 inPlay: false,
97 stackToPlay: []
a6088c90
BA
98 };
99 },
100 computed: {
6b9378a6
BA
101 turn: function() {
102 if (!this.vr) return "";
103 if (this.vr.showMoves != "all") {
104 return this.st.tr[
105 (this.vr.turn == 'w' ? "White" : "Black") + " to move"];
106 }
107 // Cannot flip: racing king or circular chess
108 return (
109 this.vr.movesCount == 0 && this.game.mycolor == "w"
110 ? this.st.tr["It's your turn!"]
111 : ""
112 );
113 },
1ef65040 114 // TODO: is it OK to pass "computed" as properties?
6b9378a6 115 // Also, some are seemingly not recomputed when vr is initialized.
a6088c90 116 showMoves: function() {
933fd1f9
BA
117 return this.game.score != "*"
118 ? "all"
6b9378a6 119 : (!!this.vr ? this.vr.showMoves : "none");
20620465
BA
120 },
121 showTurn: function() {
71ef1664
BA
122 return (
123 this.game.score == '*' &&
6b9378a6 124 !!this.vr && (this.vr.showMoves != "all" || !this.vr.canFlip)
71ef1664 125 );
a6088c90 126 },
20620465 127 canAnalyze: function() {
6b9378a6
BA
128 return (
129 this.game.mode != "analyze" &&
130 !!this.vr && this.vr.canAnalyze
131 );
20620465 132 },
71ef1664 133 canFlip: function() {
6b9378a6 134 return !!this.vr && this.vr.canFlip;
71ef1664 135 },
20620465 136 allowDownloadPGN: function() {
6b9378a6
BA
137 return (
138 this.game.score != "*" ||
139 (!!this.vr && this.vr.showMoves == "all")
140 );
6808d7a1 141 }
a6088c90 142 },
4b0384fa 143 created: function() {
b1e46b33 144 if (!!this.game.fenStart) this.re_setVariables();
4b0384fa 145 },
cf94b843 146 mounted: function() {
e71161fb
BA
147 if (!("ontouchstart" in window)) {
148 // Desktop browser:
149 const baseGameDiv = document.getElementById("baseGame");
150 baseGameDiv.tabIndex = 0;
151 baseGameDiv.addEventListener("click", this.focusBg);
152 baseGameDiv.addEventListener("keydown", this.handleKeys);
153 baseGameDiv.addEventListener("wheel", this.handleScroll);
154 }
42a92848
BA
155 document.getElementById("eogDiv")
156 .addEventListener("click", processModalClick);
cf94b843 157 },
54ec15eb
BA
158 beforeDestroy: function() {
159 if (!!this.autoplayLoop) clearInterval(this.autoplayLoop);
160 },
a6088c90 161 methods: {
9ca1e26b 162 focusBg: function() {
9ca1e26b
BA
163 document.getElementById("baseGame").focus();
164 },
165 handleKeys: function(e) {
6808d7a1
BA
166 if ([32, 37, 38, 39, 40].includes(e.keyCode)) e.preventDefault();
167 switch (e.keyCode) {
9ca1e26b
BA
168 case 37:
169 this.undo();
170 break;
171 case 39:
172 this.play();
173 break;
5701c228 174 case 38:
9ca1e26b
BA
175 this.gotoBegin();
176 break;
177 case 40:
178 this.gotoEnd();
179 break;
180 case 32:
9ca1e26b
BA
181 this.flip();
182 break;
183 }
184 },
dcd68c41 185 handleScroll: function(e) {
e71161fb
BA
186 e.preventDefault();
187 if (e.deltaY < 0) this.undo();
188 else if (e.deltaY > 0) this.play();
dcd68c41 189 },
49dad261
BA
190 resetArrows: function() {
191 // TODO: make arrows scale with board, and remove this
192 this.$refs["board"].cancelResetArrows();
193 },
0e16cb26
BA
194 showRules: function() {
195 //this.$router.push("/variants/" + this.game.vname);
196 window.open("#/variants/" + this.game.vname, "_blank"); //better
197 },
b1e46b33
BA
198 re_setVariables: function(game) {
199 if (!game) game = this.game; //in case of...
4b0384fa 200 this.endgameMessage = "";
8477e53d 201 // "w": default orientation for observed games
b1e46b33
BA
202 this.orientation = game.mycolor || "w";
203 this.moves = JSON.parse(JSON.stringify(game.moves || []));
e71161fb 204 // Post-processing: decorate each move with notation and FEN
b1e46b33
BA
205 this.vr = new V(game.fenStart);
206 const parsedFen = V.ParseFen(game.fenStart);
8477e53d
BA
207 const firstMoveColor = parsedFen.turn;
208 this.firstMoveNumber = Math.floor(parsedFen.movesCount / 2);
f54f4c26 209 let L = this.moves.length;
d4036efe 210 this.moves.forEach(move => {
e71161fb
BA
211 // Strategy working also for multi-moves:
212 if (!Array.isArray(move)) move = [move];
f54f4c26 213 move.forEach((m,idx) => {
1ef65040 214 m.index = this.vr.movesCount;
e71161fb 215 m.notation = this.vr.getNotation(m);
2c5d7b20 216 m.unambiguous = V.GetUnambiguousNotation(m);
e71161fb 217 this.vr.play(m);
f54f4c26
BA
218 if (idx < L - 1 && this.vr.getCheckSquares(this.vr.turn).length > 0)
219 m.notation += "+";
e71161fb 220 });
d4036efe 221 });
8477e53d 222 if (firstMoveColor == "b") {
311cba76 223 // 'start' & 'end' is required for Board component
6808d7a1 224 this.moves.unshift({
1ef65040 225 index: parsedFen.movesCount,
6808d7a1 226 notation: "...",
2c5d7b20 227 unambiguous: "...",
311cba76 228 start: { x: -1, y: -1 },
3a2a7b5f
BA
229 end: { x: -1, y: -1 },
230 fen: game.fenStart
6808d7a1 231 });
f54f4c26 232 L++;
697ee580 233 }
e71161fb 234 this.positionCursorTo(this.moves.length - 1);
9ef63965 235 this.incheck = this.vr.getCheckSquares(this.vr.turn);
f54f4c26 236 const score = this.vr.getCurrentScore();
3f22c2c3 237 if (L > 0 && this.moves[L - 1].notation != "...") {
5e1bc651
BA
238 if (["1-0","0-1"].includes(score)) this.moves[L - 1].notation += "#";
239 else if (this.incheck.length > 0) this.moves[L - 1].notation += "+";
3f22c2c3 240 }
4b0384fa 241 },
e71161fb
BA
242 positionCursorTo: function(index) {
243 this.cursor = index;
244 // Caution: last move in moves array might be a multi-move
245 if (index >= 0) {
246 if (Array.isArray(this.moves[index])) {
247 const L = this.moves[index].length;
248 this.lastMove = this.moves[index][L - 1];
249 } else {
250 this.lastMove = this.moves[index];
251 }
3a2a7b5f 252 } else this.lastMove = null;
e71161fb 253 },
63ca2b89 254 analyzePosition: function() {
7ba4a5bc 255 let newUrl =
6808d7a1
BA
256 "/analyse/" +
257 this.game.vname +
258 "/?fen=" +
259 this.vr.getFen().replace(/ /g, "_");
49dad261
BA
260 if (!!this.game.mycolor) newUrl += "&side=" + this.game.mycolor;
261 window.open("#" + newUrl);
603b8a8b 262 },
a6088c90
BA
263 download: function() {
264 const content = this.getPgn();
265 // Prepare and trigger download link
266 let downloadAnchor = document.getElementById("download");
267 downloadAnchor.setAttribute("download", "game.pgn");
6808d7a1
BA
268 downloadAnchor.href =
269 "data:text/plain;charset=utf-8," + encodeURIComponent(content);
a6088c90
BA
270 downloadAnchor.click();
271 },
272 getPgn: function() {
273 let pgn = "";
274 pgn += '[Site "vchess.club"]\n';
834c202a 275 pgn += '[Variant "' + this.game.vname + '"]\n';
1ef65040
BA
276 const gdt = getDate(new Date(this.game.created || Date.now()));
277 pgn += '[Date "' + gdt + '"]\n';
d4036efe
BA
278 pgn += '[White "' + this.game.players[0].name + '"]\n';
279 pgn += '[Black "' + this.game.players[1].name + '"]\n';
834c202a 280 pgn += '[Fen "' + this.game.fenStart + '"]\n';
2c5d7b20 281 pgn += '[Result "' + this.game.score + '"]\n';
1ef65040
BA
282 if (!!this.game.id) {
283 pgn += '[Cadence "' + this.game.cadence + '"]\n';
284 pgn += '[Url "' + params.serverUrl + '/game/' + this.game.id + '"]\n';
285 }
2c5d7b20 286 pgn += '\n';
e71161fb 287 for (let i = 0; i < this.moves.length; i += 2) {
2c5d7b20 288 if (i > 0) pgn += " ";
49dad261
BA
289 // Adjust dots notation for a better display:
290 let fullNotation = getFullNotation(this.moves[i]);
291 if (fullNotation == "...") fullNotation = "..";
1ef65040 292 pgn += (this.moves[i].index / 2 + 1) + "." + fullNotation;
e71161fb 293 if (i+1 < this.moves.length)
2c5d7b20 294 pgn += " " + getFullNotation(this.moves[i+1]);
a6088c90 295 }
2c5d7b20
BA
296 pgn += "\n\n";
297 for (let i = 0; i < this.moves.length; i += 2) {
1ef65040
BA
298 const moveNumber = this.moves[i].index / 2 + 1;
299 // Skip "dots move", useless for machine reading:
300 if (this.moves[i].notation != "...") {
301 pgn += moveNumber + ".w " +
302 getFullNotation(this.moves[i], "unambiguous") + "\n";
303 }
49dad261 304 if (i+1 < this.moves.length) {
1ef65040 305 pgn += moveNumber + ".b " +
49dad261
BA
306 getFullNotation(this.moves[i+1], "unambiguous") + "\n";
307 }
2c5d7b20
BA
308 }
309 return pgn;
a6088c90 310 },
b988c726
BA
311 showEndgameMsg: function(message) {
312 this.endgameMessage = message;
aae89b49 313 document.getElementById("modalEog").checked = true;
a6088c90 314 },
54ec15eb
BA
315 runAutoplay: function() {
316 const infinitePlay = () => {
317 if (this.cursor == this.moves.length - 1) {
318 clearInterval(this.autoplayLoop);
319 this.autoplayLoop = null;
320 this.autoplay = false;
321 return;
322 }
323 if (this.inPlay || this.inMultimove)
324 // Wait next tick
325 return;
326 this.play();
327 };
328 if (this.autoplay) {
329 this.autoplay = false;
330 clearInterval(this.autoplayLoop);
331 this.autoplayLoop = null;
332 } else {
333 this.autoplay = true;
1ef65040
BA
334 setTimeout(
335 () => {
336 infinitePlay();
337 this.autoplayLoop = setInterval(infinitePlay, 1500);
338 },
339 // Small delay otherwise the first move is played too fast
340 500
341 );
54ec15eb
BA
342 }
343 },
e71161fb 344 // Animate an elementary move
63ca2b89 345 animateMove: function(move, callback) {
a6088c90 346 let startSquare = document.getElementById(getSquareId(move.start));
f9c36b2d 347 if (!startSquare) return; //shouldn't happen but...
a6088c90
BA
348 let endSquare = document.getElementById(getSquareId(move.end));
349 let rectStart = startSquare.getBoundingClientRect();
350 let rectEnd = endSquare.getBoundingClientRect();
6808d7a1
BA
351 let translation = {
352 x: rectEnd.x - rectStart.x,
353 y: rectEnd.y - rectStart.y
354 };
355 let movingPiece = document.querySelector(
356 "#" + getSquareId(move.start) + " > img.piece"
357 );
efdfb4c7 358 // For some unknown reasons Opera get "movingPiece == null" error
2c5d7b20 359 // TODO: is it calling 'animate()' twice ? One extra time ?
efdfb4c7 360 if (!movingPiece) return;
a6088c90 361 const squares = document.getElementsByClassName("board");
6808d7a1 362 for (let i = 0; i < squares.length; i++) {
a6088c90 363 let square = squares.item(i);
2c5d7b20
BA
364 if (square.id != getSquareId(move.start))
365 // HACK for animation:
366 // (with positive translate, image slides "under background")
367 square.style.zIndex = "-1";
a6088c90 368 }
6808d7a1
BA
369 movingPiece.style.transform =
370 "translate(" + translation.x + "px," + translation.y + "px)";
910d631b 371 movingPiece.style.transitionDuration = "0.25s";
a6088c90 372 movingPiece.style.zIndex = "3000";
6808d7a1
BA
373 setTimeout(() => {
374 for (let i = 0; i < squares.length; i++)
a6088c90
BA
375 squares.item(i).style.zIndex = "auto";
376 movingPiece.style = {}; //required e.g. for 0-0 with KR swap
63ca2b89 377 callback();
a6088c90
BA
378 }, 250);
379 },
8055eabd
BA
380 // For Analyse mode:
381 emitFenIfAnalyze: function() {
382 if (this.game.mode == "analyze") {
383 this.$emit(
384 "fenchange",
f1c9d707 385 !!this.lastMove ? this.lastMove.fen : this.game.fenStart
8055eabd
BA
386 );
387 }
388 },
61656127
BA
389 clickSquare: function(square) {
390 // Some variants make use of a single click at specific times:
391 const move = this.vr.doClick(square);
392 if (!!move) this.play(move);
393 },
e71161fb 394 // "light": if gotoMove() or gotoEnd()
57eb158f 395 play: function(move, received, light, noemit) {
a6836242
BA
396 // Freeze while choices are shown:
397 if (this.$refs["board"].choices.length > 0) return;
57eb158f
BA
398 if (!!noemit) {
399 if (this.inPlay) {
400 // Received moves in observed games can arrive too fast:
401 this.stackToPlay.unshift(move);
402 return;
403 }
404 this.inPlay = true;
405 }
9d54ab89 406 const navigate = !move;
e71161fb 407 const playSubmove = (smove) => {
fbd68f75 408 smove.notation = this.vr.getNotation(smove);
2c5d7b20 409 smove.unambiguous = V.GetUnambiguousNotation(smove);
e71161fb 410 this.vr.play(smove);
f14572c4 411 this.lastMove = smove;
fbd68f75 412 if (!this.inMultimove) {
54ec15eb
BA
413 // Condition is "!navigate" but we mean "!this.autoplay"
414 if (!navigate) {
415 if (this.cursor < this.moves.length - 1)
416 this.moves = this.moves.slice(0, this.cursor + 1);
417 this.moves.push(smove);
418 }
fbd68f75
BA
419 this.inMultimove = true; //potentially
420 this.cursor++;
54ec15eb 421 } else if (!navigate) {
fbd68f75
BA
422 // Already in the middle of a multi-move
423 const L = this.moves.length;
424 if (!Array.isArray(this.moves[L-1]))
425 this.$set(this.moves, L-1, [this.moves[L-1], smove]);
6e47d367 426 else this.moves[L-1].push(smove);
e71161fb
BA
427 }
428 };
429 const playMove = () => {
54ec15eb 430 const animate = (
57d9b2c4 431 ["all", "highlight"].includes(V.ShowMoves) &&
54ec15eb
BA
432 (this.autoplay || !!received)
433 );
e71161fb
BA
434 if (!Array.isArray(move)) move = [move];
435 let moveIdx = 0;
436 let self = this;
437 const initurn = this.vr.turn;
438 (function executeMove() {
439 const smove = move[moveIdx++];
440 if (animate) {
441 self.animateMove(smove, () => {
442 playSubmove(smove);
443 if (moveIdx < move.length)
444 setTimeout(executeMove, 500);
445 else afterMove(smove, initurn);
446 });
447 } else {
448 playSubmove(smove);
449 if (moveIdx < move.length) executeMove();
450 else afterMove(smove, initurn);
451 }
452 })();
453 };
fbd68f75
BA
454 const computeScore = () => {
455 const score = this.vr.getCurrentScore();
f54f4c26 456 if (!navigate) {
5e1bc651
BA
457 if (["1-0","0-1"].includes(score)) this.lastMove.notation += "#";
458 else if (this.incheck.length > 0) this.lastMove.notation += "+";
f54f4c26 459 }
fbd68f75
BA
460 if (score != "*" && this.game.mode == "analyze") {
461 const message = getScoreMessage(score);
462 // Just show score on screen (allow undo)
463 this.showEndgameMsg(score + " . " + this.st.tr[message]);
464 }
465 return score;
466 };
e71161fb 467 const afterMove = (smove, initurn) => {
e71161fb
BA
468 if (this.vr.turn != initurn) {
469 // Turn has changed: move is complete
3a2a7b5f 470 if (!smove.fen)
2c5d7b20 471 // NOTE: only FEN of last sub-move is required (=> setting it here)
cc00b83c 472 smove.fen = this.vr.getFen();
b0a0468a
BA
473 // Is opponent in check?
474 this.incheck = this.vr.getCheckSquares(this.vr.turn);
3a2a7b5f 475 this.emitFenIfAnalyze();
e71161fb 476 this.inMultimove = false;
f54f4c26 477 this.score = computeScore();
54ec15eb 478 if (this.game.mode != "analyze" && !navigate) {
f54f4c26 479 if (!noemit) {
5aa14a21 480 // Post-processing (e.g. computer play).
f54f4c26 481 const L = this.moves.length;
5aa14a21
BA
482 // NOTE: always emit the score, even in unfinished,
483 // to tell Game::processMove() that it's not a received move.
f54f4c26
BA
484 this.$emit("newmove", this.moves[L-1], { score: this.score });
485 } else {
57eb158f
BA
486 this.inPlay = false;
487 if (this.stackToPlay.length > 0)
488 // Move(s) arrived in-between
489 this.play(this.stackToPlay.pop(), received, light, noemit);
490 }
e71161fb
BA
491 }
492 }
493 };
494 // NOTE: navigate and received are mutually exclusive
495 if (navigate) {
496 // The move to navigate to is necessarily full:
497 if (this.cursor == this.moves.length - 1) return; //no more moves
498 move = this.moves[this.cursor + 1];
54ec15eb
BA
499 if (!this.autoplay) {
500 // Just play the move:
501 if (!Array.isArray(move)) move = [move];
502 for (let i=0; i < move.length; i++) this.vr.play(move[i]);
503 if (!light) {
504 this.lastMove = move[move.length-1];
505 this.incheck = this.vr.getCheckSquares(this.vr.turn);
506 this.score = computeScore();
507 this.emitFenIfAnalyze();
508 }
509 this.cursor++;
510 return;
8055eabd 511 }
e71161fb 512 }
63ca2b89
BA
513 // Forbid playing outside analyze mode, except if move is received.
514 // Sufficient condition because Board already knows which turn it is.
6808d7a1 515 if (
6808d7a1 516 this.game.mode != "analyze" &&
dcb3637c 517 !navigate &&
e71161fb 518 !received &&
6808d7a1
BA
519 (this.game.score != "*" || this.cursor < this.moves.length - 1)
520 ) {
a6088c90
BA
521 return;
522 }
e71161fb
BA
523 // To play a received move, cursor must be at the end of the game:
524 if (received && this.cursor < this.moves.length - 1)
525 this.gotoEnd();
526 playMove();
527 },
528 cancelCurrentMultimove: function() {
e71161fb
BA
529 const L = this.moves.length;
530 let move = this.moves[L-1];
531 if (!Array.isArray(move)) move = [move];
532 for (let i=move.length -1; i >= 0; i--) this.vr.undo(move[i]);
533 this.moves.pop();
534 this.cursor--;
e90bafa8
BA
535 // The board may still show the possible moves: (TODO: bad solution)
536 this.$refs["board"].resetCurrentAttempt();
e71161fb
BA
537 this.inMultimove = false;
538 },
539 cancelLastMove: function() {
540 // The last played move was canceled (corr game)
541 this.undo();
542 this.moves.pop();
543 },
544 // "light": if gotoMove() or gotoBegin()
545 undo: function(move, light) {
a6836242
BA
546 // Freeze while choices are shown:
547 if (this.$refs["board"].choices.length > 0) return;
e71161fb
BA
548 if (this.inMultimove) {
549 this.cancelCurrentMultimove();
63ca2b89 550 this.incheck = this.vr.getCheckSquares(this.vr.turn);
e71161fb
BA
551 } else {
552 if (!move) {
3a2a7b5f
BA
553 const minCursor =
554 this.moves.length > 0 && this.moves[0].notation == "..."
555 ? 1
556 : 0;
557 if (this.cursor < minCursor) return; //no more moves
e71161fb
BA
558 move = this.moves[this.cursor];
559 }
e71161fb
BA
560 undoMove(move, this.vr);
561 if (light) this.cursor--;
562 else {
563 this.positionCursorTo(this.cursor - 1);
e71161fb 564 this.incheck = this.vr.getCheckSquares(this.vr.turn);
8055eabd 565 this.emitFenIfAnalyze();
63ca2b89 566 }
a6088c90 567 }
a6088c90
BA
568 },
569 gotoMove: function(index) {
a6836242 570 if (this.$refs["board"].choices.length > 0) return;
e71161fb
BA
571 if (this.inMultimove) this.cancelCurrentMultimove();
572 if (index == this.cursor) return;
573 if (index < this.cursor) {
574 while (this.cursor > index)
575 this.undo(null, null, "light");
576 }
577 else {
578 // index > this.cursor)
579 while (this.cursor < index)
580 this.play(null, null, "light");
581 }
582 // NOTE: next line also re-assign cursor, but it's very light
583 this.positionCursorTo(index);
8b405c81 584 this.incheck = this.vr.getCheckSquares(this.vr.turn);
8055eabd 585 this.emitFenIfAnalyze();
a6088c90
BA
586 },
587 gotoBegin: function() {
a6836242 588 if (this.$refs["board"].choices.length > 0) return;
e71161fb 589 if (this.inMultimove) this.cancelCurrentMultimove();
3a2a7b5f
BA
590 const minCursor =
591 this.moves.length > 0 && this.moves[0].notation == "..."
592 ? 1
593 : 0;
594 while (this.cursor >= minCursor) this.undo(null, null, "light");
595 this.lastMove = (minCursor == 1 ? this.moves[0] : null);
596 this.incheck = this.vr.getCheckSquares(this.vr.turn);
8055eabd 597 this.emitFenIfAnalyze();
a6088c90
BA
598 },
599 gotoEnd: function() {
a6836242 600 if (this.$refs["board"].choices.length > 0) return;
6808d7a1
BA
601 if (this.cursor == this.moves.length - 1) return;
602 this.gotoMove(this.moves.length - 1);
8055eabd 603 this.emitFenIfAnalyze();
a6088c90
BA
604 },
605 flip: function() {
a6836242 606 if (this.$refs["board"].choices.length > 0) return;
0e16cb26 607 this.orientation = V.GetOppCol(this.orientation);
6808d7a1
BA
608 }
609 }
a6088c90
BA
610};
611</script>
72ccbd67 612
41c80bb6 613<style lang="sass" scoped>
9a3049f3
BA
614[type="checkbox"]#modalEog+div .card
615 min-height: 45px
910d631b 616
cf94b843
BA
617#baseGame
618 width: 100%
4f518610
BA
619 &:focus
620 outline: none
cf94b843
BA
621
622#gameContainer
72ccbd67
BA
623 margin-left: auto
624 margin-right: auto
cf94b843 625
ed06d9e9
BA
626#downloadDiv
627 display: inline-block
628
72ccbd67 629#controls
28b32b4f 630 user-select: none
72ccbd67 631 button
b1e46b33 632 border: none
72ccbd67 633 margin: 0
feaf1bf7
BA
634 padding-top: 5px
635 padding-bottom: 5px
636
54ec15eb
BA
637.in-autoplay
638 background-color: #FACF8C
639
feaf1bf7 640img.inline
54ec15eb 641 height: 22px
feaf1bf7
BA
642 padding-top: 5px
643 @media screen and (max-width: 767px)
644 height: 18px
910d631b 645
0e16cb26
BA
646#turnIndicator
647 text-align: center
29bc61be 648 font-weight: bold
910d631b 649
72ccbd67 650#boardContainer
cf94b843 651 float: left
41c80bb6
BA
652// TODO: later, maybe, allow movesList of variable width
653// or e.g. between 250 and 350px (but more complicated)
910d631b 654
cf94b843
BA
655#movesList
656 width: 280px
657 float: left
910d631b 658
96e9585a
BA
659@media screen and (max-width: 767px)
660 #movesList
661 width: 100%
662 float: none
663 clear: both
72ccbd67 664</style>