@@ -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