Skip to content

Instantly share code, notes, and snippets.

@graciano
Last active July 6, 2017 19:18
Show Gist options
  • Save graciano/842b78b17a0fdcb257cdd43212fc768d to your computer and use it in GitHub Desktop.
Save graciano/842b78b17a0fdcb257cdd43212fc768d to your computer and use it in GitHub Desktop.
{
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
}
}
@graciano
Copy link
Author

graciano commented Jul 5, 2017

it eventually gets to challenge 6, where the random factor will for sure fail

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment