This is brilliant. Do you know of other games like this?
Elevator Saga – An elevator programming game
61–70 of 108 posts
Re: Elevator Saga – An elevator programming game
#62I wonder how much more efficient you could be, if people didn't just call for going up/down, but their destination floor.
They have that at work and it takes far longer to get an elevator. It's always annoying going to those buildings and using those elevators.
Re: Elevator Saga – An elevator programming game
#63My attempt at a basic smart algorithm. Not so easy... https://gist.github.com/kballenegger/e275a99d50de2ee07f97
here mine: https://gist.github.com/eridal/7ce55190837801811067 side note: why are you using underscore? I wanted to try your code, but doesn't work out-of-the-box.
Re: Elevator Saga – An elevator programming game
#64Earlier quoted context omitted.
Why do you have conditionals written like this: if (elevator.goingUpIndicator() == true)? Why not just: if (elevator.goingUpIndicator())?
I believe some people really need think in term of comparations and, for those, adding a "==" symbol make sense, even if the resultant code doesn't make any sense at all!! Also, I can never understand why people write .. if (foo()) { return true; } else { return false; } .. or things like extra parens on conditionals, or weird styles like: return (false); I strongly believe people write as they talk, and talk as they…
However, I don't agree that the shortest code is always the cleanest. In JS for example, I've found that wrapping every conditional body in braces even if it's a single statement helps avoid bugs and clear out ambiguity.
Also, this code:
if (foo()) {
return true;
} else {
return false;
}
is not equivalent to return foo();
because foo() could return something that isn't boolean. The correct short version would be: return !!foo();
It's far less obvious what is going on here. That said, I'd probably go with: return foo() ? true : false;Re: Elevator Saga – An elevator programming game
#65I used a for( var i =0;i < elevators.length;++i) statement to apply my code to each elevator, but people only keep using the last one. Could someone give me a hint? ;)
Re: Elevator Saga – An elevator programming game
#66Is it just me, or is programming more than one elevator buggy? I used a for( var i =0;i < elevators.length;++i) statement to apply my code to each elevator, but people only keep using the last one. Could someone give me a hint? ;)
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 ensures that 'i' has the value that was passed in. I'm afraid I'm a little too tired to look up the parts of the spec that make the semantics clear.Re: Elevator Saga – An elevator programming game
#67Here's a fairly simple strategy for beating challenges 1 - 5. Basically drop off people in the elevator according to whoever's floor is closest. Then once the elevator is empty go to the closest floor that has people waiting to be picked up. https://gist.github.com/cspags/93f18a2fe505bf4f1686
Re: Elevator Saga – An elevator programming game
#68Is it just me, or is programming more than one elevator buggy? I used a for( var i =0;i < elevators.length;++i) statement to apply my code to each elevator, but people only keep using the last one. Could someone give me a hint? ;)
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…
Re: Elevator Saga – An elevator programming game
#69I wonder how much more efficient you could be, if people didn't just call for going up/down, but their destination floor.
Re: Elevator Saga – An elevator programming game
#70I wonder how much more efficient you could be, if people didn't just call for going up/down, but their destination floor.
They have that at work and it takes far longer to get an elevator. It's always annoying going to those buildings and using those elevators.