1111 */
1212
1313// Initiate some global variables.
14- var global = {
15- defaults : {
16- module : 'example1' ,
17- deck : {
18- shuffleWhenCreated : true ,
19- addDiscardWhenShuffling : true ,
20- displaySize : 0 ,
21- autoFillDisplay : true ,
22- } ,
23- track : {
24- assumePresent : true ,
25- startSpaceId : false ,
26- loop : false ,
27- gridMovement : false ,
28- symmetricConnections : true ,
29- } ,
30- market : {
31- restockOnlyIncreases : true ,
32- } ,
33- goods : {
34- quantity : Number . POSITIVE_INFINITY ,
35- maxQuantity : Number . POSITIVE_INFINITY ,
36- } ,
37- diceRoll : {
38- quantity : 3 ,
39- numberOfSides : 6 ,
40- customSides : false ,
41- } ,
42- } ,
43- } ; // Further populated by buildInitialData().
14+ var global = { } ; // Further populated by buildInitialData().
4415var modules = { } ; // Populated by custom code.
45- var module = global . defaults . module ;
16+ var module ;
4617var gameState = { } ;
4718global . startTime = Date . now ( ) ;
4819
4920function simulate ( iterations = false , mod = false ) {
21+ // Set global default values.
22+ setInitialDefaults ( ) ;
23+
5024 // Set which module (game simulation) to run.
5125 if ( mod !== false )
5226 module = mod ;
@@ -55,18 +29,18 @@ function simulate(iterations = false, mod = false) {
5529 let gameStateSeed = modules [ module ] . buildInitialData ( ) ;
5630 log ( 'Initial data complete.' , 'system' ) ;
5731
58- // Variable used to save data from each game iteration.
59- let results = [ ] ;
60- // Start iterating game plays.
32+ /**
33+ * Start iterating game plays.
34+ */
35+ let results = [ ] ; // Variable used to save data from each game iteration.
6136 if ( ! iterations )
6237 iterations = global . defaults . iterations ;
6338 for ( let iteration = 1 ; iteration <= iterations ; iteration ++ ) {
64- log ( 'Starting iteration ' + iteration , 'system' ) ;
65- gameState = copy ( gameStateSeed ) ;
66-
6739 /**
6840 * Set up each game.
6941 */
42+ log ( 'Starting iteration ' + iteration , 'system' ) ;
43+ gameState = copy ( gameStateSeed ) ;
7044 // Set up agents, if any. Note that these are stored in an array,
7145 // not keyed by id, to allow setting and changing order.
7246 if ( gameState . agents ) {
@@ -85,7 +59,7 @@ function simulate(iterations = false, mod = false) {
8559 if ( gameState . tracks ) {
8660 delete ( gameState . tracks ) ;
8761 for ( let o of gameStateSeed . tracks ) {
88- new Track ( o . track , o . spaces ) ;
62+ new Track ( o . track , o . spaces , o . pawns ) ;
8963 }
9064 }
9165 if ( gameState . markets ) {
@@ -98,7 +72,9 @@ function simulate(iterations = false, mod = false) {
9872 // Make any customized additional processing of the game state.
9973 modules [ module ] . preIteration ( ) ;
10074
101- // Play the game until it is over.
75+ /**
76+ * Play the game until it is over.
77+ */
10278 gameState . round = 0 ;
10379 log ( 'Starting first round in iteration ' + iteration , 'system' ) ;
10480 while ( ! modules [ module ] . gameOver ( ) ) {
@@ -113,5 +89,8 @@ function simulate(iterations = false, mod = false) {
11389 results . push ( modules [ module ] . buildStatistics ( ) ) ;
11490 }
11591
92+ /**
93+ * Display the processed results.
94+ */
11695 return processResults ( results ) ;
11796}
0 commit comments