-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample.js
34 lines (33 loc) · 1007 Bytes
/
sample.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
(function() {
var engine = {
turn: 0,
scores: [],
initialize: function(playerCount) {
console.log("initialize");
this.scores = _.range(playerCount).map(function() { return 0; });
},
processTurn: function(cmdsList) {
console.log("processTurn");
this.turn++;
_.each(cmdsList, function(cmds, index) {
this.scores[index] += _.reduce(cmds, function(memo, cmd) { return memo + parseInt(cmd); }, 0);
}, this);
return "processTurn " + this.turn;
},
isFinished: function() {
console.log("isFinished");
return this.turn == 2;
},
getStatus: function() {
console.log("getStatus");
return _.map(_.range(this.scores), function(i) {
return "getStatus turn: " + this.turn + ", scores: " + this.scores.join(', ');
}, this);
},
getRanking: function() {
console.log("getRanking");
return "getRanking scores:" + this.scores.join(', ');
},
};
return engine;
}).call(this);