bit o game logic and spanish and french dictionaties (unprocessed)
This commit is contained in:
@@ -4,6 +4,9 @@ const Router = require('./src/router.js');
|
||||
const Socket = require('./src/socketserver.js');
|
||||
const Locale = require('./src/locale.js');
|
||||
const Dict = require('./src/dictionary.js');
|
||||
const Dist = require('./src/letter-distributions.js');
|
||||
|
||||
const Helpers = require('./src/helpers.js');
|
||||
|
||||
require('dotenv').config();
|
||||
|
||||
@@ -31,9 +34,7 @@ function benchmarkDictionary()
|
||||
|
||||
// Time 10 thousand reads
|
||||
for (let i = 0; i < 10000; i++)
|
||||
{
|
||||
Dict.FindWord('en', 'ZZZS');
|
||||
}
|
||||
|
||||
hrTime = process.hrtime();
|
||||
let endTime = hrTime[0] * 1000000 + hrTime[1] / 1000;
|
||||
@@ -49,9 +50,7 @@ function benchmarkDictionary()
|
||||
|
||||
// Time 10 thousand reads
|
||||
for (let i = 0; i < 10000; i++)
|
||||
{
|
||||
Dict.FindWord('en', 'ZZZS');
|
||||
}
|
||||
|
||||
hrTime = process.hrtime();
|
||||
endTime = hrTime[0] * 1000000 + hrTime[1] / 1000;
|
||||
@@ -60,6 +59,4 @@ function benchmarkDictionary()
|
||||
}
|
||||
|
||||
|
||||
|
||||
main();
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
const Logger = require('./logger.js');
|
||||
const Registrar = require('./game-registrar.js');
|
||||
const Lobbies = require('./lobbies.js');
|
||||
const Dist = require('./letter-distributions.js');
|
||||
const Helpers = require('./helpers.js');
|
||||
|
||||
/*
|
||||
GAME OBJECT
|
||||
@@ -8,11 +10,9 @@ GAME OBJECT
|
||||
// reference UID
|
||||
lobbyuid: uid,
|
||||
locale: en,
|
||||
players: [{uid, activetiles, score}],
|
||||
players: [{uid, name, activetiles, score}],
|
||||
// index of players
|
||||
turn: int,
|
||||
// TODO: vvv
|
||||
turnstate:
|
||||
tilebag: []
|
||||
}
|
||||
NOTES
|
||||
@@ -27,16 +27,38 @@ function StartGame(lobby)
|
||||
// game uses the owners language
|
||||
const gameowner = Registrar.GetUserByUID(lobby.owneruid);
|
||||
|
||||
let tilebag = Dist.GenerateStartStateDistribution(gameowner.locale);
|
||||
|
||||
let players = lobby.players.map(i => { return {
|
||||
uid: i.uid,
|
||||
name: i.name,
|
||||
activetiles: [],
|
||||
score: 0
|
||||
}});
|
||||
|
||||
// shuffle for turn order
|
||||
players = Helpers.ShuffleArray(players);
|
||||
|
||||
console.log(players)
|
||||
|
||||
// populate users tile drawer
|
||||
|
||||
ActiveGames[lobby.uid] = {
|
||||
lobbyuid: lobby.uid,
|
||||
locale: gameowner.locale,
|
||||
|
||||
players: players,
|
||||
turn: 0,
|
||||
|
||||
tilebag: tilebag
|
||||
};
|
||||
|
||||
|
||||
return ActiveGames[lobby.uid];
|
||||
}
|
||||
|
||||
// returns tuple ([newtileset], [newusertiles])
|
||||
function ExchangeTiles(tileset, tilesToExchange)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
24
server/src/helpers.js
Normal file
24
server/src/helpers.js
Normal file
@@ -0,0 +1,24 @@
|
||||
|
||||
|
||||
function ShuffleArray(array)
|
||||
{
|
||||
let length = array.length;
|
||||
let index;
|
||||
let temp;
|
||||
|
||||
while (length)
|
||||
{
|
||||
index = Math.floor(Math.random() * length);
|
||||
length--;
|
||||
|
||||
temp = array[length];
|
||||
array[length] = array[index];
|
||||
array[index] = temp;
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
ShuffleArray: ShuffleArray
|
||||
};
|
||||
@@ -239,6 +239,28 @@ Distributions['cs'] = {
|
||||
};
|
||||
|
||||
|
||||
function GenerateStartStateDistribution(locale)
|
||||
{
|
||||
const loc = Distributions[locale];
|
||||
|
||||
let ret = [];
|
||||
|
||||
// loops over every point object and adds j amount of i letter
|
||||
// to ret for the game board
|
||||
for (let p of loc.dist)
|
||||
for (let i = 0; i < p.letters.length; i++)
|
||||
for (let j = 0; j < p.amounts[i]; j++)
|
||||
ret.push(p.letters[i]);
|
||||
|
||||
for (let i = 0; i < loc.blanktiles; i++)
|
||||
ret.push('_');
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
Distributions: Distributions
|
||||
Distributions: Distributions,
|
||||
|
||||
GenerateStartStateDistribution: GenerateStartStateDistribution
|
||||
};
|
||||
|
||||
@@ -70,8 +70,6 @@ async function Router(socket)
|
||||
socket.on('lobby-game-begin', args => LobbyGameBegin(socket, args));
|
||||
|
||||
|
||||
|
||||
|
||||
socket.on('disconnect', args => HandleDisconnect(socket, ...args));
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user