Last active
July 6, 2017 19:18
-
-
Save graciano/842b78b17a0fdcb257cdd43212fc768d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
init: function(elevators, floors) { | |
for (let floor of floors) { | |
floor.on("up_button_pressed", function() { | |
for(let elevator of elevators) { | |
elevator.checkDestinationQueue(); | |
if(elevator.destinationQueue.lenght > 0 && elevator.loadFactor == 1){ | |
elevator.destinationQueue.push(floor); | |
elevator.checkDestinationQueue(); | |
} | |
} | |
}) | |
} | |
for (let elevator of elevators) { | |
elevator.on('idle', () => { | |
elevator.checkDestinationQueue(); | |
if(elevator.destinationQueue.lenght > 0 && elevator.loadFactor == 1){ | |
elevator.goToFloor(elevator.destinationQueue.pop()); | |
elevator.checkDestinationQueue(); | |
} | |
else{ | |
elevator.goToFloor(parseInt(Math.random() * floors.length)); | |
} | |
}); | |
elevator.on("floor_button_pressed", (num) => { | |
elevator.checkDestinationQueue(); | |
elevator.destinationQueue.push(num); | |
elevator.checkDestinationQueue(); | |
}); | |
} | |
}, | |
update: function(dt, elevators, floors) { | |
// We normally don't need to do anything here | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it eventually gets to challenge 6, where the random factor will for sure fail