3 ms·
very excited about this! but the docs need a lot of work what is the return signature of getPressedFloors? how do you add stuff to the destination queue? can i
by swyx 4y ago
very excited about this! but the docs need a lot of work
what is the return signature of getPressedFloors? how do you add stuff to the destination queue? can i swap out the DQ with a priority queue? how do i store state between runs? can i run/deploy an ML model in this? so many questions
- mdaniel 4y agoAccording to https://news.ycombinator.com/item?id=27585467 https://news.ycombinator.com/item?id=27585467 the repo is https://github.com/magwo/elevatorsaga https://github.com/magwo/elevatorsaga but is also abandoned To answer your first question: https://github.com/magwo/elevatorsaga/blob/master/elevator.js#L166 https://github.com/magwo/elevatorsaga/blob/master/elevator.j... Be aware that it's just `eval(textarea.value)` so you can `console.log` or (presumably) `debugger;` in your code to inspect whatever you want. The developer tools likely will allow you to set breakpoints in the framework's code, too I was sad the `thing.on("some_event", () => { this. <-- isn't "thing"`, I had to `.bind(thing)` manually
- eyelidlessness 4y agoAt a glance (mobile sorry), it looks like .on is jQuery? If so, you don’t need bind, you just need `function`: thing.on("some_event", function() { // `this` is `thing` }) Arrow functions close over `this` from their outer scope.
- alar44 4y agoYup, I tried this a while back and gave up after not being able to figure out where/how the queue worked.
- tuukkah 4y agoYes, it's unfortunate that the game starts very easy but then immediately becomes quite difficult even requiring some reverse engineering. Basically, each elevator has a queue of the floors where it's going next. The elevator will always try to move to the floor at the front of the queue. When it stops at the destination floor, it removes that floor from the front of the queue. Whenever the queue is empty, the idle event triggers. elevator.goToFloor(floorNumber); // Adds floorNumber to the end of the queue elevator.goToFloor(floorNumber, true); // Adds floorNumber to the front of the queue (changing the destination immediately) elevator.stop(); // Clears the queue (stopping the elevator immediately) I suppose you can use your own queue data structure instead and keep at most one element in the built-in queue just to control the current direction of the elevator.