+ if (socket)
+ socket.send(JSON.stringify(Object.assign({code: code}, data)));
+}
+
+function initializeGame(vname, players, options) {
+ const gid =
+ Crypto.randomBytes(randstrSize).toString("hex").slice(0, randstrSize);
+ games[gid] = {
+ vname: vname,
+ players: players,
+ options: options,
+ time: Date.now(),
+ moveHash: {} //set of moves hashes seen so far
+ };
+ return gid;
+}
+
+// Provide seed in case of, so that both players initialize with same FEN
+function launchGame(gid) {
+ const gameInfo = Object.assign(
+ {seed: Math.floor(Math.random() * 19840), gid: gid},
+ games[gid]
+ );
+ // players array is supposed to be full:
+ for (const p of games[gid].players)
+ send(p.sid, "gamestart", gameInfo);
+}
+
+function getRandomVariant() {
+ // Pick a variant at random in the list
+ const index = Math.floor(Math.random() * variants.length);
+ return variants[index].name;