Skip to content

Commit 2a73ba0

Browse files
committed
Save users' last game ID instead of game number
1 parent aff9400 commit 2a73ba0

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

game_logic/complete-all-games.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ var completeAllGames = function(users, mongoData) {
1717

1818
//Runs and saves all games and returns a promise
1919
var prepRunAndSaveAllGames = function(mongoData, games, gameIndex, userLookup) {
20+
console.log(games.length + ' games left to play!');
2021
var game = games.shift(games);
2122

2223
//Run and save the first game in the queue
@@ -76,11 +77,11 @@ var runAndSaveGame = function(mongoData, game, gameIndex, userLookup) {
7677
//Loops through the entire game, saves each turn to the database
7778
var resolveGameAndSaveTurnsToDB = function(game) {
7879
//Get today's date in string form
79-
var date = getDateString();
80-
game.date = date;
80+
game.date = getDateString();
8181

8282
//Manually set the ID so Mongo doesn't just keep writing to the same document
83-
game._id = gameIndex.toString() + '|' + game.turn.toString() + '|' + date;
83+
game.baseId = gameIndex.toString() + '|' + game.date;
84+
game._id = game.baseId + '|' + game.turn.toString();
8485

8586
//Save the number of the game
8687
game.gameNumber = gameIndex;
@@ -115,17 +116,13 @@ var runAndSaveGame = function(mongoData, game, gameIndex, userLookup) {
115116

116117
//If game has ended, stop looping and set the max turn
117118
if (game.ended) {
118-
maxTurn = game.maxTurn;
119119
return game;
120120

121121
//Otherwise, continue with next turn and save that turn
122122
} else {
123123
//Advances the game one turn
124124
game.handleHeroTurn(direction);
125125

126-
//Manually set the ID so Mongo doesn't just keep writing to the same document
127-
game._id = game.turn + '|' + game.date;
128-
129126
return resolveGameAndSaveTurnsToDB(game);
130127
}
131128
}).catch(function(err) {

game_logic/plan-all-games.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var planAllGames = function(users) {
1919
var boardSize = 12;
2020

2121
//Maximum # of users per team?
22-
var maxUsersPerTeam = 12;
22+
var maxUsersPerTeam = 7;
2323

2424
//Used to look up hero port numbers
2525
var userLookup = {};
@@ -36,7 +36,7 @@ var planAllGames = function(users) {
3636
for (var gameIndex=0; gameIndex<numberOfGames; gameIndex++) {
3737
var game = createGameFromMap(secrets.rootDirectory +
3838
'/game_logic/maps/' + secrets.map + '.txt');
39-
game.maxTurn = 1250;
39+
game.maxTurn = 750;
4040
games.push(game);
4141

4242
//Keeps track of which team to add the

stats/save-user-stats.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ var Q = require('q');
22

33
//Saves the user stats to the database
44
//Returns a promise that resolves to the user object
5-
module.exports = function(mongoData, hero, gameNumber) {
5+
module.exports = function(mongoData, hero, gameId) {
66
var userCollection = mongoData.userCollection;
77
var deferred = Q.defer();
88

99
//Grab the user from the database
1010
return Q.ninvoke(userCollection, 'findOne', { githubHandle: hero.name }).then(function(user) {
1111

1212
//Update the number of the most recently played game
13-
user.mostRecentGameNumber = gameNumber;
13+
user.mostRecentGameId = gameId;
1414

1515
//Update the user's lifetime and most recent stats
1616
user.lifetimeStats.kills += hero.heroesKilled.length;

0 commit comments

Comments
 (0)