Live data from Hacker News

Elevator Saga – An elevator programming game

play.elevatorsaga.com

71–80 of 108 posts

Re: Elevator Saga – An elevator programming game

#72
post #68

Earlier quoted context omitted.

You're probably hitting an issue with the way that closures work in javascript (and many other languages). for(var i = 0; i Doesn't do what one might expect. When the anonymous function is invoked, it looks up the value of the 'i' identifier, which will have changed it's value to elevators.length by the end of the loop. To get the behavior you want, I've seen people do for(var i = 0; i This creates a new scope, which…

Thank you! Your suggestion makes sense indeed and works fine!

You can also use:

  elevators.forEach(function(elevator, elevatorNumber) {...});
This will provide each elevator with its index in the elevators array.

Re: Elevator Saga – An elevator programming game

#74
A couple of problems with the API.

First, why do you have to call checkDestinationQueue after modifying the queue? It's awfully redundant. I assume this is due to some kind of limitation.

And second, goingUpIndicator and goingDownIndicator are kind of sketchy. Can you activate both at the same time? What effect would that have? There should be a single property, directionIndicator of an enum type with the possible values up, down, and none. I don't think you can make enums in javascript though, but I don't know the language very well. I'm just explaining this in terms that I know; there probably is a suitable javascript equivalent or replacement.

Re: Elevator Saga – An elevator programming game

#78
Added solution: https://github.com/magwo/elevatorsaga/wiki/Solution-by-alber...

Can work for all up to 9, except 5. Can't get it to work. When it has to be done within 'x' moves, change foreach 'e' variable to var `e = `

Main 'pattern' behind it: the elevators decide everything. Each elevator does the same based on a global array of where passengers are waiting.

Re: Elevator Saga – An elevator programming game

#80

How are the passengers generated? Do they follow a realistic distribution, or are they just completely random? The game would be a lot more fun with realistic or even real measured workloads.

Dev here. :)

They spawn at a fixed rate, but at random floors, with 50% spawning at the bottom floor.

I agree it would be more interesting if there were patterns, distributions, more popular floors etc. Haven't gotten around to implementing it. There's a small unused bit of code here intended for this: https://github.com/magwo/elevatorsaga/blob/master/challenges...

Post reply on HN