[HN Gopher] Elevator Saga: Elevator programming game
       ___________________________________________________________________
        
       Elevator Saga: Elevator programming game
        
       Author : homarp
       Score  : 149 points
       Date   : 2022-10-18 16:30 UTC (1 days ago)
        
 (HTM) web link (play.elevatorsaga.com)
 (TXT) w3m dump (play.elevatorsaga.com)
        
       | daitangio wrote:
       | Very nice! I like it a lot and remember me the disk drive "head"
       | algorithm for collecting data on different sectors (OS exam...24
       | years ago)
        
       | KingOfCoders wrote:
       | Nice, I used such code (elevators) as part of interviewing.
        
         | mikeatlas wrote:
         | I've had this prompt given to me in interviews.
        
       | glonq wrote:
       | Very fun. Pro tip: the riders are random in each test run, so if
       | you failed but were close, just re-run and you might get lucky.
        
       | fragmede wrote:
       | Reminds me of SimTower https://simtower.fandom.com/wiki/Elevators
        
         | metadat wrote:
         | I played this too much growing up. Never did figure out how to
         | survive becoming a 4 or 5 star hotel, the clientele always
         | vanished once the stars level increased that high and I was
         | never able to recover!
         | 
         | Fond memories of all 90s Maxis games!
        
           | dragontamer wrote:
           | IIRC, all offices need to be reset periodically.
           | 
           | Was it... setting the price high then low, then high again?
           | It was something like that.
           | 
           | All offices in SimTower had a time-limit on their usage. Once
           | they've been occupied for a few years, no one likes the
           | office and you need to manually refresh them by setting
           | prices through some price ritual (delete? Change prices? I
           | forget).
           | 
           | ----------
           | 
           | Alternatively, set the bottom 20 floors to hotels, and the
           | basement floors to a great parking lot + shopping center in
           | support of those hotels.
        
           | swyx wrote:
           | very "nobody goes there, it's too crowded" energy haha
        
         | omnibrain wrote:
         | I also immediately thought of Sim Tower. The introduction
         | chapter to the handbook mentioned that the Dev (Yoot Saito)
         | actually started with an elevator simulation.
        
       | anigbrowl wrote:
       | // Whenever the elevator is idle (has no more queued
       | destinations) ...
       | 
       | I don't get it. The first challenge is to fix the fact that the
       | idle loop never sends the elevator to floor 2, fair enough.
       | 
       | But generally when I run the simulation a person appears and
       | calls the elevator on floor 2, plus people get into the elevator
       | on floor 0 and don't get out on floor 1 (presumably because they
       | dream of going to floor 2). So how are their inputs not queued?
       | 
       | This might work better as an IDE that had a watch variable window
       | showing the queue. As it is I feel I'm experiencing a simulation
       | of badly documented code rather than a badly programmed elevator.
        
         | TylerE wrote:
         | Nothing in the starter template queues anything. You have to
         | wire that up.
        
           | anigbrowl wrote:
           | The quoted comment is taken directly from the starter
           | template. Hence my comment about 'badly documented code'.
        
             | throwaway4aday wrote:
             | The api documentation
             | https://play.elevatorsaga.com/documentation.html is
             | correct, you just need to think about the problem rather
             | than expect step by step handholding.
        
         | shagie wrote:
         | A person waiting for the elevator doesn't put anything into the
         | queue.
         | 
         | The loop for challenge 1 is:                 q: []       idle
         | -> enqueue 0, 1, 2 --- q: [0, 1, 2]       go to floor 0;
         | (noop@floor0)q: [1, 2]       go to floor 1;              q: [2]
         | go to floor 2;              q: []       idle -> enqueue 0, 1, 2
         | --- q: [0, 1, 2]       go to floor 0;              q: [1, 2]
         | ...
         | 
         | It doesn't matter if anyone wants to go to that floor who is in
         | the elevator or wants to get on the elevator at that floor.
         | 
         | https://play.elevatorsaga.com/documentation.html
         | 
         | And then you get into the events... something like this would
         | likely be interesting/chaotic.
         | elevator.on("floor_button_pressed", function(floorNum) {
         | elevator.goToFloor(floorNum, true);         })
        
           | anigbrowl wrote:
           | I'm not having difficulty understanding the coding problem.
           | I'm talking about how the comments would actually be
           | misleading to a person who was.
        
       | paxys wrote:
       | Very cool! I'd also love to see the option of putting the floor
       | selector outside the elevator, which seems to be getting more and
       | more common now in tall buildings.
        
       | DonHopkins wrote:
       | There needs to be a genre of elevator dating games.
        
       | swyx wrote:
       | 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 wrote:
         | According to https://news.ycombinator.com/item?id=27585467 the
         | repo is https://github.com/magwo/elevatorsaga but is also
         | abandoned
         | 
         | To answer your first question:
         | 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 wrote:
           | At 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 wrote:
         | Yup, I tried this a while back and gave up after not being able
         | to figure out where/how the queue worked.
        
       | loloquwowndueo wrote:
       | The elevators in Taipei 101 have to be among the most advanced,
       | and yet it was insane how long I had to wait for one, how
       | seemingly irrationally it went picking people up, and what a mess
       | it was figuring out your floor if you were using one of the
       | double-decker elevators (my point is : the computer should figure
       | it out for me).
       | 
       | I'm terribly unimpressed by people programming real elevators.
        
         | fragmede wrote:
         | Fun fact, elevator capacity is the limiting factor on
         | skyscraper size. Taipei 101 (which has, creativity, 101 floors)
         | has ultra high speed elevators, capable of running up to 37mph
         | and it is the world's fastest elevator. It'll go from the 5th
         | to the 89th floor in 37 seconds.
         | 
         | The programming may seem haphazard, and it might actually be,
         | I've never been there in person, but the elevator aren't bad
         | for lack of trying. The new elevator system where you tell it
         | the floor and it tells you which elevator to go to is part of
         | the programming optimization.
        
           | ouid wrote:
           | Isn't it also, for much the same reason, the limiting factor
           | on "linear city" length? https://www.neom.com/en-us
        
             | samatman wrote:
             | For a linear city it would be practical to shunt cars off
             | and onto the main line, so that throughput is a relatively
             | constant function of safe stopping distance between cars in
             | the event of emergency. So people traveling a short
             | distance don't slow down ones traveling a long distance.
        
           | CobrastanJorji wrote:
           | I wonder if this is a scenario where it would make sense to
           | advertise competence by offering more information to the
           | user. Imagine a big visualization on the ground floor showing
           | all 101 floors, the location of each elevator, which floors
           | are waiting on people, where each elevator plans to stop,
           | estimated ETAs, etc. It'd give waiting folks something pretty
           | to idly study, and it'd also provide reassurance that the
           | elevators are all doing quite a lot of work in a reasonably
           | intelligent way. You'd probably need to balance this against
           | some privacy concerns (maybe it's a bad idea to show people
           | exactly when someone in the penthouse gets into the
           | elevator).
        
             | Nextgrid wrote:
             | Short of privacy edge-cases, this would be a great idea.
             | Dump the raw state of the elevator scheduling algorithm for
             | the guests to look at while they wait.
        
             | fragmede wrote:
             | I think you're right. Part of the ML algorithm used to
             | drive lifts is to guess and learn when elevators
             | predictably need to be where (eg morning commute or lunch
             | time), but ML is horrible opaque and everyone thinks they
             | could do better.
        
       | NKosmatos wrote:
       | Nice one, reminds me of a similar programming assignment we had
       | back in the 90s, while learning assembly for the OS-9 RTOS.
        
       | xiaodai wrote:
       | this is a classic. i wonder what other programming games are
       | there though?
        
         | tarentel wrote:
         | Human Resource Machine is pretty interesting. TIS-100 is also
         | neat but it can be a bit much as it can definitely feel more
         | like programming than a game.
        
         | publicola1990 wrote:
         | Shenzhen I/O, is one of the many Zachtronics games which are
         | largely programming games.
        
         | schemescape wrote:
         | I've been working on a single-instruction (subleq) programming
         | game that runs in the browser:
         | 
         | https://jaredkrinke.itch.io/sic-1
         | 
         | Edit: very much inspired by TIS-100.
        
         | Behemoth66 wrote:
         | Bitburner is my favorite.
         | https://store.steampowered.com/app/1812820/Bitburner/
         | 
         | It's an idle game at its core so it feels like Factorio whereby
         | you try to automate as much as you can as efficiently as you
         | can.
        
         | ZetaZero wrote:
         | A mostly curated list:
         | https://www.reddit.com/r/programminggames/comments/d5pg8q/a_...
        
           | teddyh wrote:
           | See also: https://news.ycombinator.com/item?id=6345975
        
       | buescher wrote:
       | I think this has come up before. I'd love to know what a real
       | elevator programmer thinks about it. I suspect real-world
       | approaches to the problems the game presents are relatively
       | simple, and you spend most of your time on corner cases and other
       | issues that you would never anticipate if you weren't in the
       | industry.
        
         | schemescape wrote:
         | Pun intended?
        
         | jfaerge171 wrote:
         | It is a really great game. I am sure that the game has been on
         | hackernews before as I think I read about it here a long time
         | ago. In the old thread there was a comment from a poster that
         | worked with elevators and he said it was pretty close to the
         | real thing! However it missed one important thing... You could
         | do the most effective algorithms, but everything broke down
         | when partners having their own special badge summoned an
         | elevator. They should have the first empty one, and they should
         | ride alone to their office floor.
        
           | shagie wrote:
           | If you click on the domain name in parentheses next to the
           | article title, it will find all the posts to HN for that
           | domain name.
           | 
           | https://news.ycombinator.com/from?site=elevatorsaga.com
           | 
           | In 2015, it had 105 comments
           | https://news.ycombinator.com/item?id=8929314
           | 
           | In 2021, it had 99 comments
           | https://news.ycombinator.com/item?id=27487111
           | 
           | (it was posted many other times, but didn't get any traction)
        
             | latchkey wrote:
             | I use an extension [0] which puts all the links at the
             | bottom of the page. You missed the 2019 submission [1].
             | 
             | [0] https://github.com/plibither8/refined-hacker-news
             | 
             | [1] https://news.ycombinator.com/item?id=21425054
        
             | jfaerge171 wrote:
             | Thanks, I knew there was a better way than the search bar
             | below, but was in a bit of a hurry. Regarding the links, it
             | must have been in 2015 I read about it.
        
         | bombcar wrote:
         | Something like https://www.otis.com/en/us/products-
         | services/products/ems-pa... may be the place to start.
         | 
         | I know you can program them to "idle" on different floors
         | depending on time of day, and prioritize certain floors (e.g.,
         | try to always have one ready to go on the ground floor).
         | 
         | I wouldn't be surprised if you could find systems that
         | integrate with hotel doors, and when a hotel door is opened and
         | the light turned off on floor ten, it works to get an elevator
         | sent to floor ten.
        
           | Nextgrid wrote:
           | I think this is a system where AI could shine. Trained on
           | every possible data point you can get from the building
           | (status of individual lights, room occupancy, etc), it might
           | end up with a better strategy than what a human could come up
           | with.
        
         | im3w1l wrote:
         | There are (were? maybe they are getting better) a lot of awful
         | elevator programming out there. I assume whoever programmed it
         | was a contractor given a week to get something working, and
         | then they used the same logic ever since.
        
         | jonny_eh wrote:
         | Then again there's boneheaded elevator programming such as
         | this: https://www.youtube.com/watch?v=bH1xAbhlJSo
        
           | bombcar wrote:
           | There was some touchscreen elevator I had to deal with where
           | it couldn't work without bouncing, so trying to get floor 12
           | would end up with floor 11, 22, 1, 2 and maybe if lucky 12.
           | 
           | I only found on my last day there a handicap accessible
           | button panel that had all the floors as actual physical
           | buttons.
        
       | PinguTS wrote:
       | This reminds me of my university time as a student. In the
       | realtime OS/programming course we needed to build an elevator
       | with 4 cars in parallel entirely on an i386 (Embedded) in an
       | realtime OS including the simulation of people pressing the floor
       | numbers.
        
         | autoexec wrote:
         | Yeah, this is bringing back memories for me too. Is controlling
         | an elevator a common coding exercise? When I started learning C
         | I was just learning on my own and wrote something like this
         | too, although it was only 2 elevators I worked to limit the
         | amount of time people in an office building spent waiting. At
         | one point I had over 50 fake people each assigned to a floor
         | and a schedule (including breaks and and lunches), and even
         | cleaning staff who went floor to floor a couple times a day. I
         | don't remember where the idea for it came from though.
        
           | jeffreyrogers wrote:
           | I have had it as an interview question before.
        
       | DonHopkins wrote:
       | At SciFi conventions I had a friend who was good at lock picking,
       | and he picked the lock of the elevator control room at the top of
       | the hotel.
       | 
       | The elevators were controlled by cabinets of relays, and there
       | was a schematic of the elevator controller, which was pretty
       | straightforward to follow and not too complicated. You could
       | trigger the elevator into going to different floors by toggling
       | the relay corresponding to the call button with a pencil.
       | 
       | On one of the cabinets full of relays that controlled the
       | elevators was taped a piece of paper with the phone numbers of
       | all the emergency phones in every elevator. It was like
       | discovering the holy grail!
       | 
       | Since the elevators at SciFi cons were a bottleneck and always
       | crowded, it took a long time to wait for one and get to the lobby
       | or the floor of the party you wanted to attend.
       | 
       | So whenever I was in a hotel room and wanted to go somewhere
       | else, I would call up an elevator: "Ring!" Somebody would answer
       | and I'd say "Hello!". They'd invariably say "Hey, WTF, this is an
       | elevator!" I'd say "What floor are you on?" They'd tell me
       | something like "12.", and I'd ask "Are you going up or down?" If
       | they were going the right direction, then I'd then ask them
       | "Please press 27, I'll be waiting for you!"
       | 
       | And sometimes I'd prank call the elevators: "Ring!" "Hello, this
       | is Dominos Pizza!" "Hey, WTF, this is an elevator!" "What floor
       | are you on?" "12." "Please press Ground, I'm in the lobby with
       | your pizza. I'll be waiting for you!"
        
         | dbcurtis wrote:
         | I have written elevator interface code to allow robots to call
         | elevators for themselves. So, yeah, I had an ap for that. I
         | used my phone for testing.
        
       | rlv-dan wrote:
       | The best thing about this is that I no longer feel an urge for
       | another side project to make an elevator programming sim myself
       | :-)
        
       | zxcvbn4038 wrote:
       | Fun, but has not been updated in a while. Adding a hall of fame
       | with peoples algorithms ranked and available for others to
       | improve upon would be an awesome addition.
        
       | [deleted]
        
       ___________________________________________________________________
       (page generated 2022-10-19 23:01 UTC)