Skip to content

Commit e17c0c9

Browse files
committed
Minor updates to the Track class
1 parent 78e766a commit e17c0c9

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

000-simulation.gs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ var global = {
2222
},
2323
track: {
2424
assumePresent: true,
25+
startSpaceId: false,
2526
loop: false,
2627
gridMovement: false,
2728
symmetricConnections: true,

classes/120-Track.gs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ class Track {
9191
return s;
9292
}
9393

94+
// Returns the index for the start space.
95+
getStartSpaceIndex() {
96+
if (this.startSpaceId !== false)
97+
return this.spaceMapping[this.startSpaceId];
98+
return 0;
99+
}
100+
94101
/**
95102
* Returns the index for the space where the pawn is, or -1 if
96103
* pawn is missing (and should not be assumed to start at 0).
@@ -100,8 +107,8 @@ class Track {
100107
return this.pawnIndices[pawnId];
101108
}
102109
if (this.assumePresent) {
103-
this.pawnIndices[pawnId] = 0;
104-
return 0;
110+
this.pawnIndices[pawnId] = this.getStartSpaceIndex();
111+
return this.getStartSpaceIndex();
105112
}
106113
return -1;
107114
}
@@ -171,7 +178,7 @@ class Track {
171178
* Moves the pawn to the first space. Creates pawn if necessary.
172179
*/
173180
movePawnToStart(pawnId) {
174-
this.pawnIndices[pawnId] = 0;
181+
this.pawnIndices[pawnId] = this.getStartSpaceIndex();
175182
}
176183

177184
/**
@@ -185,14 +192,14 @@ class Track {
185192
* Tells whether the pawn is at the first space.
186193
*/
187194
isAtStart(pawnId) {
188-
return (this.pawnIndices[pawnId] == 0);
195+
return (this.pawnIndices[pawnId] === this.getStartSpaceIndex());
189196
}
190197

191198
/**
192199
* Tells whether the pawn is at the last space.
193200
*/
194201
isAtEnd(pawnId) {
195-
return (this.pawnIndices[pawnId] == this.spaces.length - 1);
202+
return (this.pawnIndices[pawnId] === this.spaces.length - 1);
196203
}
197204

198205
/**
@@ -253,8 +260,8 @@ class Track {
253260
}
254261

255262
/**
256-
* Builds a paths for the given pawn to the given space.
257-
* Returns true if the path could be built, otherwise false. The pawn path is only
263+
* Builds a path for the given pawn to the given space.
264+
* Returns true if the path could be built, otherwise false. The path path is only
258265
* updated if the path could be built -- otherwise it is left untouched.
259266
*/
260267
buildPath(pawnId, goalSpaceId) {

0 commit comments

Comments
 (0)