+++ /dev/null
-// Show a variant summary on index
-Vue.component('my-variant-summary', {
- props: ['vobj','index'],
- template: `
- <div class="variant col-sm-12 col-md-5 col-lg-4" :id="vobj.name"
- :class="{'col-md-offset-1': index%2==0, 'col-lg-offset-2': index%2==0}">
- <a :href="url">
- <h4 class="boxtitle text-center">
- {{ vobj.name }}
- <span class="count-players">
- / {{ vobj.count }}
- </span>
- </h4>
- <p class="description text-center">
- {{ translate(vobj.desc) }}
- </p>
- </a>
- </div>
- `,
- computed: {
- url: function() {
- return "/" + this.vobj.name;
- },
- },
- methods: {
- translate: function(text) {
- return translations[text];
- },
- },
-})
+++ /dev/null
-// Remove item in array (if present)
-var removeItem = function(array, rfun)
-{
- let index = array.findIndex(rfun);
- if (index >= 0)
- array.splice(index, 1);
-}
-
-// Remove several item matching a condition
-var removeMultiple = function(array, rfun)
-{
- // Reverse loop because of the splice below
- for (let i=array.length-1; i>=0; i--)
- {
- if (rfun(array[i]))
- array.splice(i, 1);
- }
-}
-
-// Double array intialization
-var doubleArray = function(size1, size2, initElem)
-{
- return _.map(_.range(size1), () => {
- return _.map(_.range(size2), () => {
- return initElem; //can be undefined
- })
- });
-}
-
-var copyDoubleArray = function(arr)
-{
- return _.map(_.range(arr.length), (el1,i) => {
- return _.map(_.range(arr[0].length), (el2,j) => {
- return arr[i][j];
- })
- });
-}
+++ /dev/null
-new Vue({
- el: "#VueElement",
- data: {
- display: "", //default to main hall; see "created()" function
- gameRef: undefined, //...for now
- probId: undefined,
- conn: null,
- mode: "analyze",
- allowChat: false,
- allowMovelist: true,
- // Settings initialized with values from localStorage
- settings: {
- bcolor: localStorage["bcolor"] || "lichess",
- sound: parseInt(localStorage["sound"]) || 2,
- hints: parseInt(localStorage["hints"]) || 1,
- coords: !!eval(localStorage["coords"]),
- highlight: !!eval(localStorage["highlight"]),
- sqSize: parseInt(localStorage["sqSize"]),
- },
- },
- created: function() {
- window.onhashchange = this.setDisplay;
- if (!!localStorage["variant"])
- location.hash = "#game?id=" + localStorage["gameId"];
- else
- this.setDisplay();
- // Our ID, always set (DB id if registered, collision-free random string otherwise)
- this.myid = user.id || localStorage["myid"] || "anon-" + getRandString();
- this.conn = new WebSocket(socketUrl + "/?sid=" + this.myid + "&page=" + variant.id);
- const socketCloseListener = () => {
- this.conn = new WebSocket(socketUrl + "/?sid=" + this.myid + "&page=" + variant.id);
- }
- this.conn.onclose = socketCloseListener;
- },
- methods: {
- // Game is over, clear storage and put it in indexedDB
- archiveGame: function() {
- // TODO: ...
- //clearStorage();
- },
- setDisplay: function() {
- // Prevent set display if there is a running game
- if (!!localStorage["variant"])
- return;
- if (!location.hash)
- location.hash = "#room"; //default
- const hashParts = location.hash.substr(1).split("?");
- this.display = hashParts[0];
- if (hashParts[0] == "problems" && !!hashParts[1])
- {
- // Show a specific problem
- this.probId = hashParts[1].split("=")[1];
- }
- else if (hashParts[0] == "game" && !!hashParts[1])
- {
- // Show a specific game, maybe with a user ID
- const params = hashParts[1].split("&").filter(h => h.split("=")[1]);
- // TODO: Vue.set(...) probably required here
- this.gameRef = {
- id: params[0],
- uid: params[1], //may be undefined
- };
- }
- // Close menu on small screens:
- let menuToggle = document.getElementById("drawer-control");
- if (!!menuToggle)
- menuToggle.checked = false;
- },
- },
-});
+++ /dev/null
-doctype html
-html
- main#VueElement
- my-upsert-user
- .container
- v-bind:vobj="v" v-bind:index="idx" v-bind:key="v.name")
- .row(v-show="display=='correspondance'")
- my-correspondance
- .row
- my-room(v-show="display=='room'" :conn="conn" :settings="settings")
- my-tab-games(v-show="display=='tabGames'")
- my-rules(v-show="display=='rules'" :settings="settings")
- my-problems(v-show="display=='problems'" :prob-id="probId" :settings="settings")
- my-game(v-show="display=='game'" :game-ref="gameRef" :conn="conn"
- :allow-chat="allowChat" :allow-movelist="allowMovelist"
- :mode="mode" :settings="settings" @game-over="archiveGame")
-
- // TODO: get rid of underscore
- // (used essentially for _.random(), _.sample() and _.range())
- script(src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js")
- // TODO: add only the necessary icons to mini-css custom build
- script(src="//unpkg.com/feather-icons")
- script(src="/javascripts/utils/printDiagram.js")
- script(src="/javascripts/utils/datetime.js")
- script(src="/javascripts/utils/squareId.js")
- script(src="/javascripts/utils/misc.js")
- script(src="/javascripts/utils/ajax.js")
- script(src="/javascripts/utils/array.js")
- script(src="/javascripts/shared/nbPlayers.js")
- script(src="/javascripts/shared/challengeCheck.js")
- script(src="/javascripts/shared/userCheck.js")
- script(src="/javascripts/components/upsertUser.js")
- script(src="/javascripts/components/variantSummary.js")
- script(src="/javascripts/components/correspondance.js")
- script(src="/javascripts/components/board.js")
- script(src="/javascripts/components/chat.js")
- script(src="/javascripts/components/gameList.js")
- script(src="/javascripts/components/challengeList.js")
- script(src="/javascripts/components/moveList.js")
- script(src="/javascripts/components/game.js")
- script(src="/javascripts/components/rules.js")
- script(src="/javascripts/components/room.js")
- script(src="/javascripts/components/tabGames.js")
- script(src="/javascripts/components/problemSummary.js")
- script(src="/javascripts/components/problems.js")
- script(src="/javascripts/base_rules.js")
- script(src="/javascripts/contactForm.js")
- script(src="/javascripts/socket_url.js")
- script(src="/javascripts/index.js")
- script(src="/javascripts/variant.js")
- script(src="/javascripts/app.js")
.col-sm-12.col-md-10.col-md-offset-1.col-lg-8.col-lg-offset-2
img(src="./assets/images/index/unicorn.svg")
.info-container
- p vchess.club {{ $lang }}
+ p vchess.club
img(src="./assets/images/index/wildebeest.svg")
.row
// Menu (top of page):
a(href="https://github.com/yagu0/vchess") Source code
p.clickable(onClick="doClick('modalContact')")
= translations["Contact form"]
+ //my-game(:game-ref="gameRef" :mode="mode" :settings="settings" @game-over="archiveGame")
+ //// TODO: add only the necessary icons to mini-css custom build
+ //script(src="//unpkg.com/feather-icons")
</template>
<script>
// Shuffle pieces on first and last rank
for (let c of ["w","b"])
{
- let positions = _.range(8);
+ let positions = range(8);
// Get random squares for bishops
- let randIndex = 2 * _.random(3);
+ let randIndex = 2 * random(4);
const bishop1Pos = positions[randIndex];
// The second bishop must be on a square of different color
- let randIndex_tmp = 2 * _.random(3) + 1;
+ let randIndex_tmp = 2 * random(4) + 1;
const bishop2Pos = positions[randIndex_tmp];
// Remove chosen squares
positions.splice(Math.max(randIndex,randIndex_tmp), 1);
positions.splice(Math.min(randIndex,randIndex_tmp), 1);
// Get random squares for knights
- randIndex = _.random(5);
+ randIndex = random(6);
const knight1Pos = positions[randIndex];
positions.splice(randIndex, 1);
- randIndex = _.random(4);
+ randIndex = random(5);
const knight2Pos = positions[randIndex];
positions.splice(randIndex, 1);
// Get random square for queen
- randIndex = _.random(3);
+ randIndex = random(4);
const queenPos = positions[randIndex];
positions.splice(randIndex, 1);
let moves1 = this.getAllValidMoves("computer");
// Can I mate in 1 ? (for Magnetic & Extinction)
- for (let i of _.shuffle(_.range(moves1.length)))
+ for (let i of shuffle(range(moves1.length)))
{
this.play(moves1[i]);
let finish = (Math.abs(this.evalPosition()) >= V.THRESHOLD_MATE);
let candidates = [0]; //indices of candidates moves
for (let j=1; j<moves1.length && moves1[j].eval == moves1[0].eval; j++)
candidates.push(j);
- let currentBest = moves1[_.sample(candidates, 1)];
+ let currentBest = moves1[sample(candidates)];
// From here, depth >= 3: may take a while, so we control time
const timeStart = Date.now();
candidates = [0];
for (let j=1; j<moves1.length && moves1[j].eval == moves1[0].eval; j++)
candidates.push(j);
- return moves1[_.sample(candidates, 1)];
+ return moves1[sample(candidates)];
}
alphabeta(depth, alpha, beta)
h3#settingsTitle.section {{ $tr["Preferences"] }}
fieldset
label(for="setSqSize") {{ $tr["Square size (in pixels). 0 for 'adaptative'"] }}
- input#setSqSize(type="number" v-model="settings.sqSize")
+ input#setSqSize(type="number" v-model="$settings.sqSize")
fieldset
label(for="selectHints") {{ $tr["Show move hints?"] }}
- select#setHints(v-model="settings.hints")
+ select#setHints(v-model="$settings.hints")
option(value="0") {{ $tr["None"] }}
option(value="1") {{ $tr["Moves from a square"] }}
option(value="2") {{ $tr["Pieces which can move"] }}
fieldset
label(for="setHighlight") {{ $tr["Highlight squares? (Last move & checks)"] }}
- input#setHighlight(type="checkbox" v-model="settings.highlight")
+ input#setHighlight(type="checkbox" v-model="$settings.highlight")
fieldset
label(for="setCoords") {{ $tr["Show board coordinates?"] }}
- input#setCoords(type="checkbox" v-model="settings.coords")
+ input#setCoords(type="checkbox" v-model="$settings.coords")
fieldset
label(for="selectColor") {{ $tr["Board colors"] }}
- select#setBcolor(v-model="settings.bcolor")
+ select#setBcolor(v-model="$settings.bcolor")
option(value="lichess") {{ $tr["brown"] }}
option(value="chesscom") {{ $tr["green"] }}
option(value="chesstempo") {{ $tr["blue"] }}
fieldset
label(for="selectSound") {{ $tr["Play sounds?"] }}
- select#setSound(v-model="settings.sound")
+ select#setSound(v-model="$settings.sound")
option(value="0") {{ $tr["None"] }}
option(value="1") {{ $tr["New game"] }}
option(value="2") {{ $tr["All"] }}
<script>
export default {
name: "Settings",
- props: ["settings"],
+ //props: ["settings"],
methods: {
updateSettings: function(event) {
const propName =
'clearer': true,
},
},
- [_.range(sizeX).map(i => {
+ [...Array(sizeX).keys()].map(i => {
let ci = (this.orientation=='w' ? i : sizeX-i-1);
return h(
'div',
},
style: { 'opacity': this.choices.length>0?"0.5":"1" },
},
- _.range(sizeY).map(j => {
+ [...Array(sizeY).keys()].map(j => {
let cj = (this.orientation=='w' ? j : sizeY-j-1);
let elems = [];
if (this.vr.board[ci][cj] != V.EMPTY && (variant.name!="Dark"
'in-shadow': variant.name=="Dark" && !this.gameOver
&& this.mode != "analyze"
&& !this.vr.enlightened[this.userColor][ci][cj],
- 'highlight': showLight && !!lm && _.isMatch(lm.end, {x:ci,y:cj}),
+ 'highlight': showLight && !!lm && lm.end.x == ci && lm.end.y == cj,
'incheck': showLight && incheckSq[ci][cj],
},
attrs: {
render: function(h) {
return h(App);
},
-// data: {
-// lang: "",
-// },
watch: {
$lang: async function(newLang) {
// Fill modalWelcome, and import translations from "./translations/$lang.js"
// NOTE: in this version, we don't say on which page we are, yet
// ==> we'll say "enter/leave" page XY (in fact juste "enter", seemingly)
Vue.prototype.$conn = new WebSocket(params.socketUrl + "/?sid=" + myid);
+ // Settings initialized with values from localStorage
+ Vue.prototype.$settings = {
+ bcolor: localStorage["bcolor"] || "lichess",
+ sound: parseInt(localStorage["sound"]) || 2,
+ hints: parseInt(localStorage["hints"]) || 1,
+ coords: !!eval(localStorage["coords"]),
+ highlight: !!eval(localStorage["highlight"]),
+ sqSize: parseInt(localStorage["sqSize"]),
+ };
+ const socketCloseListener = () => {
+ Vue.prototype.$conn = new WebSocket(params.socketUrl + "/?sid=" + myid);
+ }
+ Vue.prototype.$conn.onclose = socketCloseListener;
//TODO: si une partie en cours dans storage, rediriger vers cette partie
//(à condition que l'URL n'y corresponde pas déjà !)
// TODO: à l'arrivée sur le site : set peerID (un identifiant unique
// en tout cas...) si pas trouvé dans localStorage "myid"
// (l'identifiant de l'utilisateur si connecté)
+// if (!!localStorage["variant"])
+// location.hash = "#game?id=" + localStorage["gameId"];
},
// Later, for icons (if using feather):
// mounted: function() {
// problems: on-demand
//
// See https://router.vuejs.org/guide/essentials/dynamic-matching.html#reacting-to-params-changes
+// created: function() {
+// window.onhashchange = this.setDisplay;
+// },
+//});
name: "test",
component: loadView("Test"),
},
+ // TODO: gameRef, problemId: https://router.vuejs.org/guide/essentials/dynamic-matching.html
]
});
--- /dev/null
+// Remove item(s) in array (if present)
+export function remove(array, rfun, all)
+{
+ const index = array.findIndex(rfun);
+ if (index >= 0)
+ {
+ array.splice(index, 1);
+ if (!!all)
+ {
+ // Reverse loop because of the splice below
+ for (let i=array.length-1; i>=index; i--)
+ {
+ if (rfun(array[i]))
+ array.splice(i, 1);
+ }
+ }
+ }
+}
+
+// Double array intialization
+export function init(size1, size2, initElem)
+{
+ return [...Array(size1)].map(e => Array(size2).fill(initElem));
+}
return (x<10 ? "0" : "") + x;
}
-function getDate(d)
+export function getDate(d)
{
return d.getFullYear() + '-' + zeroPad(d.getMonth()+1) + '-' + zeroPad(d.getDate());
}
-function getTime(d)
+export function getTime(d)
{
return zeroPad(d.getHours()) + ":" + zeroPad(d.getMinutes()) + ":" +
zeroPad(d.getSeconds());
+++ /dev/null
-// TODO: adapt for client side https://stackoverflow.com/a/4079798
-// ==> Each translation file should be loaded dynamically
-// (each rules definition too, + modal welcome)
-
-// Select a language based on browser preferences, or cookie
-module.exports = function(req, res)
-{
- // If preferred language already set:
- if (!!req.cookies["lang"])
- return req.cookies["lang"];
-
- // Else: search and set it
- const supportedLang = ["en","es","fr"];
- const langString = req.headers["accept-language"];
- let langArray = langString
- .replace(/;q=[0-9.]+/g, "") //priority
- .replace(/-[A-Z]+/g, "") //region (skipped for now...)
- .split(",") //may have some duplicates, but removal is too costly
- let bestLang = "en"; //default: English
- for (let lang of langArray)
- {
- if (supportedLang.includes(lang))
- {
- bestLang = lang;
- break;
- }
- }
- // Cookie expires in 183 days (expressed in milliseconds)
- res.cookie('lang', bestLang, { maxAge: 183*24*3600*1000 });
- return bestLang;
-}
return defaut; //cookie not found
},
+ random: function(min, max)
+ {
+ if (!max)
+ {
+ max = min;
+ min = 0;
+ }
+ return Math.floor(Math.random() * (max - min) ) + min;
+ },
+
+ // Inspired by https://github.com/jashkenas/underscore/blob/master/underscore.js
+ sample: function(arr, n)
+ {
+ n = n || 1;
+ let cpArr = arr.map(e => e);
+ for (let index = 0; index < n; index++)
+ {
+ const rand = getRandInt(index, n);
+ const temp = cpArr[index];
+ cpArr[index] = cpArr[rand];
+ cpArr[rand] = temp;
+ }
+ return cpArr.slice(0, n);
+ },
+
+ shuffle: function(arr)
+ {
+ return sample(arr, arr.length);
+ },
+
+ range: function(max)
+ {
+ return [...Array(max).keys()];
+ }
+
+ // TODO: rename into "cookie" et supprimer les deux ci-dessous
// Random (enough) string for socket and game IDs
getRandString: function()
{
{
document.getElementById(elemId).click(); //or ".checked = true"
},
-
- translate: function(msg)
- {
- return translations[msg];
- },
};
// args: object with position (mandatory), and
// orientation, marks, shadow (optional)
-function getDiagram(args)
+export function getDiagram(args)
{
// Obtain the array of pieces images names:
const board = V.GetBoard(args.position);
// Get the identifier of a HTML square from its numeric coordinates o.x,o.y.
-function getSquareId(o)
+export function getSquareId(o)
{
// NOTE: a separator is required to allow any size of board
return "sq-" + o.x + "-" + o.y;
}
// Inverse function
-function getSquareFromId(id)
+export function getSquareFromId(id)
{
const idParts = id.split('-');
return [parseInt(idParts[1]), parseInt(idParts[2])];
let antikingPos = { "w": -1, "b": -1 };
for (let c of ["w","b"])
{
- let positions = _.range(8);
+ let positions = range(8);
// Get random squares for bishops, but avoid corners; because,
// if an antiking blocks a cornered bishop, it can never be checkmated
- let randIndex = 2 * _.random(1,3);
+ let randIndex = 2 * random(1,4);
const bishop1Pos = positions[randIndex];
- let randIndex_tmp = 2 * _.random(2) + 1;
+ let randIndex_tmp = 2 * random(3) + 1;
const bishop2Pos = positions[randIndex_tmp];
positions.splice(Math.max(randIndex,randIndex_tmp), 1);
positions.splice(Math.min(randIndex,randIndex_tmp), 1);
- randIndex = _.random(5);
+ randIndex = random(6);
const knight1Pos = positions[randIndex];
positions.splice(randIndex, 1);
- randIndex = _.random(4);
+ randIndex = random(5);
const knight2Pos = positions[randIndex];
positions.splice(randIndex, 1);
- randIndex = _.random(3);
+ randIndex = random(4);
const queenPos = positions[randIndex];
positions.splice(randIndex, 1);
const rook2Pos = positions[2];
// Random squares for antikings
- antikingPos[c] = _.random(7);
+ antikingPos[c] = random(8);
pieces[c][rook1Pos] = 'r';
pieces[c][knight1Pos] = 'n';
// Shuffle pieces on first and last rank
for (let c of ["w","b"])
{
- let positions = _.range(8);
+ let positions = range(8);
// Get random squares for every piece, totally freely
- let randIndex = _.random(7);
+ let randIndex = random(8);
const bishop1Pos = positions[randIndex];
positions.splice(randIndex, 1);
- randIndex = _.random(6);
+ randIndex = random(7);
const bishop2Pos = positions[randIndex];
positions.splice(randIndex, 1);
- randIndex = _.random(5);
+ randIndex = random(6);
const knight1Pos = positions[randIndex];
positions.splice(randIndex, 1);
- randIndex = _.random(4);
+ randIndex = random(5);
const knight2Pos = positions[randIndex];
positions.splice(randIndex, 1);
- randIndex = _.random(3);
+ randIndex = random(4);
const queenPos = positions[randIndex];
positions.splice(randIndex, 1);
- randIndex = _.random(2);
+ randIndex = random(3);
const kingPos = positions[randIndex];
positions.splice(randIndex, 1);
- randIndex = _.random(1);
+ randIndex = random(2);
const rookPos = positions[randIndex];
positions.splice(randIndex, 1);
const immobilizerPos = positions[0];
super.setFlags(fenflags); //castleFlags
this.pawnFlags =
{
- "w": _.map(_.range(8), i => true), //pawns can move 2 squares?
- "b": _.map(_.range(8), i => true)
+ "w": [...Array(8).fill(true)], //pawns can move 2 squares?
+ "b": [...Array(8).fill(true)],
};
if (!fenflags)
return;
let candidates = [0];
for (let j=1; j<moves.length && moves[j].eval == moves[0].eval; j++)
candidates.push(j);
- return moves[_.sample(candidates, 1)];
+ return moves[sample(candidates)];
}
}
getCapturedFen()
{
- let counts = _.map(_.range(14), 0);
+ let counts = [...Array(14).fill(0)];
let i = 0;
for (let j=0; j<V.PIECES.length; j++)
{
// Shuffle pieces on first and last rank
for (let c of ["w","b"])
{
- let positions = _.range(10);
+ let positions = range(10);
// Get random squares for bishops
- let randIndex = 2 * _.random(4);
+ let randIndex = 2 * random(5);
let bishop1Pos = positions[randIndex];
// The second bishop must be on a square of different color
- let randIndex_tmp = 2 * _.random(4) + 1;
+ let randIndex_tmp = 2 * random(5) + 1;
let bishop2Pos = positions[randIndex_tmp];
// Remove chosen squares
positions.splice(Math.max(randIndex,randIndex_tmp), 1);
positions.splice(Math.min(randIndex,randIndex_tmp), 1);
// Get random squares for knights
- randIndex = _.random(7);
+ randIndex = random(8);
let knight1Pos = positions[randIndex];
positions.splice(randIndex, 1);
- randIndex = _.random(6);
+ randIndex = random(7);
let knight2Pos = positions[randIndex];
positions.splice(randIndex, 1);
// Get random square for queen
- randIndex = _.random(5);
+ randIndex = random(6);
let queenPos = positions[randIndex];
positions.splice(randIndex, 1);
// ...random square for marshall
- randIndex = _.random(4);
+ randIndex = random(5);
let marshallPos = positions[randIndex];
positions.splice(randIndex, 1);
// ...random square for cardinal
- randIndex = _.random(3);
+ randIndex = random(4);
let cardinalPos = positions[randIndex];
positions.splice(randIndex, 1);
// Shuffle pieces on first and last rank
for (let c of ["w","b"])
{
- let positions = _.range(8);
+ let positions = range(8);
// Get random squares for bishops
- let randIndex = 2 * _.random(3);
+ let randIndex = 2 * random(4);
let bishop1Pos = positions[randIndex];
// The second bishop must be on a square of different color
- let randIndex_tmp = 2 * _.random(3) + 1;
+ let randIndex_tmp = 2 * random(4) + 1;
let bishop2Pos = positions[randIndex_tmp];
// Remove chosen squares
positions.splice(Math.max(randIndex,randIndex_tmp), 1);
positions.splice(Math.min(randIndex,randIndex_tmp), 1);
// Get random squares for knights
- randIndex = _.random(5);
+ randIndex = random(6);
let knight1Pos = positions[randIndex];
positions.splice(randIndex, 1);
- randIndex = _.random(4);
+ randIndex = random(5);
let knight2Pos = positions[randIndex];
positions.splice(randIndex, 1);
// Get random square for queen
- randIndex = _.random(3);
+ randIndex = random(4);
let queenPos = positions[randIndex];
positions.splice(randIndex, 1);
// Random square for king (no castle)
- randIndex = _.random(2);
+ randIndex = random(3);
let kingPos = positions[randIndex];
positions.splice(randIndex, 1);
candidates.push(i);
}
- const selected = doubleMoves[_.sample(candidates, 1)].moves;
+ const selected = doubleMoves[sample(candidates)].moves;
if (selected.length == 1)
return selected[0];
return selected;
let pieces = { "w": new Array(8), "b": new Array(8) };
for (let c of ["w","b"])
{
- let positions = _.range(8);
+ let positions = range(8);
- let randIndex = _.random(7);
+ let randIndex = random(8);
const kingPos = positions[randIndex];
positions.splice(randIndex, 1);
positions.splice(knight1Index, 1);
// King+knight1 are on two consecutive squares: one light, one dark
- randIndex = 2 * _.random(2);
+ randIndex = 2 * random(3);
const bishop1Pos = positions[randIndex];
- let randIndex_tmp = 2 * _.random(2) + 1;
+ let randIndex_tmp = 2 * random(3) + 1;
const bishop2Pos = positions[randIndex_tmp];
positions.splice(Math.max(randIndex,randIndex_tmp), 1);
positions.splice(Math.min(randIndex,randIndex_tmp), 1);
- randIndex = _.random(3);
+ randIndex = random(4);
const knight2Pos = positions[randIndex];
positions.splice(randIndex, 1);
- randIndex = _.random(2);
+ randIndex = random(3);
const queenPos = positions[randIndex];
positions.splice(randIndex, 1);
let pieces = { "w": new Array(10), "b": new Array(10) };
for (let c of ["w","b"])
{
- let positions = _.range(11);
+ let positions = range(11);
// Get random squares for bishops + camels (different colors)
- let randIndexes = _.sample(_.range(6), 2).map(i => { return 2*i; });
+ let randIndexes = sample(range(6), 2).map(i => { return 2*i; });
let bishop1Pos = positions[randIndexes[0]];
let camel1Pos = positions[randIndexes[1]];
// The second bishop (camel) must be on a square of different color
- let randIndexes_tmp = _.sample(_.range(5), 2).map(i => { return 2*i+1; });
+ let randIndexes_tmp = sample(range(5), 2).map(i => { return 2*i+1; });
let bishop2Pos = positions[randIndexes_tmp[0]];
let camel2Pos = positions[randIndexes_tmp[1]];
for (let idx of randIndexes.concat(randIndexes_tmp)
positions.splice(idx, 1);
}
- let randIndex = _.random(6);
+ let randIndex = random(7);
let knight1Pos = positions[randIndex];
positions.splice(randIndex, 1);
- randIndex = _.random(5);
+ randIndex = random(6);
let knight2Pos = positions[randIndex];
positions.splice(randIndex, 1);
- randIndex = _.random(4);
+ randIndex = random(5);
let queenPos = positions[randIndex];
positions.splice(randIndex, 1);
// Random square for wildebeest
- randIndex = _.random(3);
+ randIndex = random(4);
let wildebeestPos = positions[randIndex];
positions.splice(randIndex, 1);
+++ /dev/null
-<template>
- <div class="about">
- <h1>This is an about page</h1>
- </div>
-</template>
--- /dev/null
+<template>
+ <div class="about">
+ <h1>This is an about page</h1>
+ </div>
+</template>
+ methods: {
+ // Game is over, clear storage and put it in indexedDB
+ archiveGame: function() {
+ // TODO: ...
+ //clearStorage();
+ },
+ },
+<template>
+ <div class="home">
+ <Home msg="Welcome to Your Vue.js Apppp"/>
+ </div>
+</template>
+
+<script>
+// @ is an alias to /src
+import HelloWorld from "@/components/HelloWorld.vue";
+
+export default {
+ name: "home",
+ components: {
+ HelloWorld,
+ }
+};
+</script>
+
// main playing hall: chat + online players + current challenges + button "new game"
// TODO: my-challenge-list, gérant clicks sur challenges, affichage, réception/émission des infos sur challenges ; de même, my-player-list
// TODO: si on est en train de jouer une partie, le notifier aux nouveaux connectés
}
};
</script>
+
+// Show a variant summary on index
+Vue.component('my-variant-summary', {
+ props: ['vobj','index'],
+ template: `
+ <div class="variant col-sm-12 col-md-5 col-lg-4" :id="vobj.name"
+ :class="{'col-md-offset-1': index%2==0, 'col-lg-offset-2': index%2==0}">
+ <a :href="url">
+ <h4 class="boxtitle text-center">
+ {{ vobj.name }}
+ <span class="count-players">
+ / {{ vobj.count }}
+ </span>
+ </h4>
+ <p class="description text-center">
+ {{ translate(vobj.desc) }}
+ </p>
+ </a>
+ </div>
+ `,
+ computed: {
+ url: function() {
+ return "/" + this.vobj.name;
+ },
+ },
+ methods: {
+ translate: function(text) {
+ return translations[text];
+ },
+ },
+})
+<template>
+ <div class="about">
+ <h1>This is an about page</h1>
+ </div>
+</template>
// "My" games: tabs my archived local games, my correspondance games
// + my imported games (of any type).
// TODO: later, also add possibility to upload a game (parse PGN).
+<template>
+ <div class="test">
+ <TestComp :vname="variant.name"/>
+ </div>
+</template>
+
+<script>
+// @ is an alias to /src
+import TestComp from "@/components/TestComp.vue";
+
+export default {
+ name: "test",
+ components: {
+ TestComp,
+ },
+ data: function() {
+ return {
+ variant: {name: "Atomic", id: 3},
+ };
+ }
+};
+</script>
Vue.component('my-problems', {
props: ["probId","settings"],
data: function () {
+++ /dev/null
-<template>
- <div class="test">
- <TestComp :vname="variant.name"/>
- </div>
-</template>
-
-<script>
-// @ is an alias to /src
-import TestComp from "@/components/TestComp.vue";
-
-export default {
- name: "test",
- components: {
- TestComp,
- },
- data: function() {
- return {
- variant: {name: "Atomic", id: 3},
- };
- }
-};
-</script>