File tree Expand file tree Collapse file tree 2 files changed +19
-8
lines changed Expand file tree Collapse file tree 2 files changed +19
-8
lines changed Original file line number Diff line number Diff line change 1
1
var createGameFromMap = require ( './create-game-from-map.js' ) ;
2
2
var secrets = require ( '../secrets.js' ) ;
3
3
4
+ //Helper function for generating random indices
5
+ var randomIndex = function ( maxExcl ) {
6
+ return Math . floor ( Math . random ( Date . now ( ) ) * maxExcl ) ;
7
+ } ;
8
+
9
+ var pickMap = function ( map ) {
10
+ if ( Array . isArray ( map ) ) {
11
+ return map [ randomIndex ( map . length ) ] ;
12
+ } else {
13
+ return map ;
14
+ }
15
+ } ;
16
+
4
17
//Synchronous, returns an array of all games that need
5
18
//to be run and a lookup for finding user info
6
19
var planAllGames = function ( users ) {
@@ -10,11 +23,6 @@ var planAllGames = function(users) {
10
23
//Makes it so the passed-in users array is not mutated
11
24
var users = users . slice ( )
12
25
13
- //Helper function for generating random indices
14
- var randomIndex = function ( maxExcl ) {
15
- return Math . floor ( Math . random ( Date . now ( ) ) * maxExcl ) ;
16
- } ;
17
-
18
26
//Set up game
19
27
var boardSize = 12 ;
20
28
@@ -34,8 +42,9 @@ var planAllGames = function(users) {
34
42
35
43
//Create games
36
44
for ( var gameIndex = 0 ; gameIndex < numberOfGames ; gameIndex ++ ) {
45
+ var map = pickMap ( secrets . map ) ;
37
46
var game = createGameFromMap ( secrets . rootDirectory +
38
- '/game_logic/maps/' + secrets . map + '.txt' ) ;
47
+ '/game_logic/maps/' + map + '.txt' ) ;
39
48
game . maxTurn = 1250 ;
40
49
games . push ( game ) ;
41
50
Original file line number Diff line number Diff line change @@ -73,7 +73,9 @@ var runGame = function() {
73
73
game . date = date ;
74
74
75
75
//Manually set the ID so Mongo doesn't just keep writing to the same document
76
- game . _id = '0' + '|' + game . turn + '|' + date ;
76
+ // game._id = '0' + '|' + game.turn + '|' + date;
77
+ game . baseId = '0|' + game . date ;
78
+ game . _id = game . baseId + '|' + game . turn . toString ( ) ;
77
79
78
80
//Open up the database connection
79
81
var openDatabasePromise = openGameDatabase ( ) ;
@@ -119,7 +121,7 @@ var runGame = function() {
119
121
game . handleHeroTurn ( direction ) ;
120
122
121
123
//Manually set the ID so Mongo doesn't just keep writing to the same document
122
- game . _id = '0' + '|' + game . turn + '|' + game . date ;
124
+ game . _id = game . baseId + '|' + game . turn . toString ( ) ;
123
125
124
126
return resolveGameAndSaveTurnsToDB ( game ) ;
125
127
}
You can’t perform that action at this time.
0 commit comments