lib/game.js
/**
	 * Finishes the game by opening the initially selected door or the
	 * remaining door depending on the player's decision.
	 * After this step, it is clear if the game has been won or lost.
	 * If the game is not in the final state, an error will be thrown.
	 * @param {boolean} shouldSwitch	open other door (true) or initial one?
	 */
Finishes the game by opening the initially selected door or the
remaining door depending on the player's decision.
After this step, it is clear if the game has been won or lost.
If the game is not in the final state, an error will be thrown.
Finishes the game by opening the initially selected door or the remaining door depending on the player ' s decision . After this step it is clear if the game has been won or lost . If the game is not in the final state an error will be thrown .
selectSwitchOrNot(shouldSwitch) {
		if (this.state !== State.STATE_QUESTION) {
			throw new Error('cannot select switch right now')
		}
		if (shouldSwitch) {
			this.playerPos = this.switchPos
		}
		this.doorStates.forEach((isOpen, index) => this.doorStates[index] = true)
		const won = this.playerPos === this.carPos
		this.state = won ? State.STATE_END_WON : State.STATE_END_LOST
		this.changeListener()
	}
selectSwitchOrNot ( shouldSwitch ) { if ( this . state !== State . STATE_QUESTION ) { throw new Error ( 'cannot select switch right now' ) } if ( shouldSwitch ) { this . playerPos = this . switchPos } this . doorStates . forEach ( ( isOpen , index ) => this . doorStates [ index ] = true ) const won = this . playerPos === this . carPos this . state = won ? State . STATE_END_WON : State . STATE_END_LOST this . changeListener ( ) }
Finishes the game by opening the initially selected door or the
 remaining door depending on the player's decision.
Finishes the game by opening the initially selected door or the remaining door depending on the player ' s decision .