Live data from Hacker News

Show HN: I built an autopilot for the lunar lander game

szhu.github.io

11–20 of 73 posts

Re: Show HN: I built an autopilot for the lunar lander game

#13
post #6

It's interesting to think about how the optimal strategy to land the lander would look like. If the distance to the moon was large, I would expect 4 phases: 1: Turn the lander towards the moon 2: Constant thrust towards the moon 3: Turn the lander away from the moon 4: Constant thrust away from the moon But if the initial distance is small enough, turning it around might not be worth it or even possible. So the optim…

almost guaranteed that this problem is already solved by the rocket scientists out there. hopefully someone on HN can point us to the relevant algorithm. this seems like a closed system at least in newtonian physics that should be easily solvable.

chatgpt pointed me to the Gravity Turn altho it refused to give me a formula for it https://en.wikipedia.org/wiki/Gravity_turn#Deorbit_and_entry

Re: Show HN: I built an autopilot for the lunar lander game

#14
It’s amazing how a simple algorithm performs so well, the autopilot is able to recover from some pretty extreme situations, and does it gracefully.

Adding some realism to the engine physics (firing delays, minimum firing time, power ramp up, heat limits etc) would likely make it 10x harder.

Re: Show HN: I built an autopilot for the lunar lander game

#15
post #8

I wanted to go for a record of as many flips as possible. So I boosted up to 25,000 feet; started spinning until it was doing about one flip per second; waited a few minutes; then turned on the autopilot to come into a landing. The autopilot did a perfect job of stopping the rotation and lateral motion, so the lander came down straight as an arrow. Unfortunately, the autopilot didn't even try to decelerate! I crashed…

The target velocity is a factor of height, and the autopilot has “160” hardcoded as the ceiling, so going above that means it will never decelerate fast enough.

https://github.com/szhu/lunar-lander-autopilot/blob/master/a...

Re: Show HN: I built an autopilot for the lunar lander game

#16
post #13
post #6

It's interesting to think about how the optimal strategy to land the lander would look like. If the distance to the moon was large, I would expect 4 phases: 1: Turn the lander towards the moon 2: Constant thrust towards the moon 3: Turn the lander away from the moon 4: Constant thrust away from the moon But if the initial distance is small enough, turning it around might not be worth it or even possible. So the optim…

almost guaranteed that this problem is already solved by the rocket scientists out there. hopefully someone on HN can point us to the relevant algorithm. this seems like a closed system at least in newtonian physics that should be easily solvable. chatgpt pointed me to the Gravity Turn altho it refused to give me a formula for it https://en.wikipedia.org/wiki/Gravity_turn#Deorbit_and_entry

This is typically solved using a class of control algorithm called Model Predictive Control which are capable of optimizing for a given cost function (such as using minimal fuel).

Search for "fuel optimal rocket landing algorithm" for good starting points.

Re: Show HN: I built an autopilot for the lunar lander game

#19
post #17

Would it be possible to put the autopilot in a bookmarklet for the original game?

I really wanted to!

But unfortunately none of the lander's stats are exposed as global variables, so the only way I could make the autopilot was by modifying the existing code. (My commits are actually broken down exactly like this: a commit to expose the necessary variables globally, and another to actually add the autopilot.)

I would also love to be able to play it in the original game though, so I made a PR! I think it would be cool for it to be able to be activated as an easter egg.

https://github.com/ehmorris/lunar-lander/pull/7

Post reply on HN