-
Notifications
You must be signed in to change notification settings - Fork 4
/
rtmese.admin.js
43 lines (34 loc) · 1.2 KB
/
rtmese.admin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
'use strict';
var config = require('./config');
var engine = require('./rtmese.engine');
// events: {tick: {key: value, ...}, ...}
// submissions: {tick: {player: [...]}, ...}
module.exports.init = function (count, ticks, events) {
var game = engine.init(count, ticks, config.rtmeseDelta);
game.events = events;
game.submissions = {};
return game;
};
module.exports.exec = function (game) {
var applyEvents = function (events) {
for (var i in events) {
if (typeof game.settings[i] === 'number') {
game.settings[i] = events[i];
} else {
throw Error('wrong setting name');
}
}
};
applyEvents(game.events[game.now_tickObj] || {});
var applySubmissions = function (submissions) {
for (var i in submissions) {
game.decisions.price[i] = submissions[i][0];
game.decisions.prod_rate[i] = submissions[i][1];
game.decisions.mk[i] = submissions[i][2];
game.decisions.ci[i] = submissions[i][3];
game.decisions.rd[i] = submissions[i][4];
}
};
applySubmissions(game.submissions[game.now_tick] || {});
return engine.exec(game);
};