-
Notifications
You must be signed in to change notification settings - Fork 320
Markavian's Solution
My solution for play.elevatorsaga.com: https://gist.github.com/Markavian/63c18050ddaeb4323bd7
I haven't measured its effectiveness yet, but its just barely able to pass the nightmare of Challenge 13. I'm pleased with its performance on all the other stages.
I've implemented a mode switch at the top of the file, (var stopAtRequests
). When true, elevators will stop at passing floors that have made a matching direction request if they have capacity. When false, elevators will effectively prioritise requests made within the elevator, and will idle to pick up the last button pressed.
I didn't have any particular method involved when I started writing my solution. I evolved it with each challenge as I began to understand the mechanics available to me.
Button presses on floors (up, and down) are stored in a shared, prioritized request list (var sharedRequestList
). Up requests are stored as positive integers, Down requests stored as negative integers. When an elevator is empty, it'll take the oldest request in the list (the first one) and go to that floor. Once the elevator has passengers, it is then slaved to delivering those passengers until it empties again. If an elevator arrives on a floor, and empties, it will mark itself as going in both directions to pick up anyone waiting.
Play it yourself at play.elevatorsaga.com