Mars Lander Fuel puzzle discussion

I’m using floats for the shuttle position and speed parameters and all simulation calculations. As far as I remember, if I wanted the exact (integer) results for the shuttle parameters I round to nearest, after all commands for the turns are applied:

(float turn0X, float turn0y) -> apply turn0 rotate and power using float calculations ->
(float turn1X, float turn1y) -> apply turn1 rotate and power using float calculations ->
(float turn2X, float turn2y) -> apply turn2 rotate and power using float calculations ->
(float turn3X, float turn3y)

print(round(turn3X)) // To see if the X for turn 3 matches the X for turn 3 from the CG platform
print(round(turn3Y)) // To see if the Y for turn 3 matches the Y for turn 3 from the CG platform

I am trying to display the landers’ landing path with Python turtle. But the drawing is really slow. This is a population of 200. I am afraid it could not finish in a given amount of time. Is this due to the python turtle package or my algoritem ? Or this is correct?

How can i reduce his vertical speed

I had the same problem and finally solved it.
Remember that given a constant acceleration,

speed(t) = initial_speed + acceleration * t
position(t) = initial_position + initial_speed * t + 1/2 * acceleration * t^2

Here is my simulation sequence

update rotate and power
calculate acceleration vector (combining power/orientation and gravity)
position += speed + 1/2 * acceleration
speed += acceleration

acceleration, speed and position are float 2D vectors.
I never round values.

With that I managed to exactly reproduce every position and speed.

Hope it will help you

8 Likes

It’s been a long time since I messed with this but my memory is that the sim is keeping your position in a float (maybe a double), but it gives you the rounded number in the inputs. Or at least, I built my bot with that assumption and didn’t have any mismatches between expected and actual position.

2 Likes

for anyone looking to simulate the next turn, this was pretty accurate for me

    const radians = R * (Math.PI / 180)
    const xAcc = Math.sin(radians) * P
    const yAcc = Math.cos(radians) * P - gravity
    HS -= xAcc
    VS += yAcc
    const newX = X + HS - xAcc * 0.5
    const newY = Y + VS + yAcc * 0.5 + gravity

4 Likes

Hi!
I am trying to solve by solving this system of equation.
I’m stuck because I can’t isolate more than one unknown.
Do you think is possible?

I am not very smart and dont understand this simulation, it was not working for me so I rewrited like so:

//Be aware of gravity sign
MARS_GRAVITY = 3.711;
//Convert degree to radians for sin() / cos() methods
radians = Math.toRadians(rotateAngle);
//sin() of 90 / -90 will return 1 / -1 so if shuttle pointing left/right full power goes along X axis
xAcc = Math.sin(radians) * power;
//cos() of 0 / 180 = 1 / -1
yAcc = Math.cos(radians) * power - MARS_GRAVITY;
//We need to reverse X acceleration sign because in puzzle positive acceleration is along x axis, but in
//the formula positive sin(90) = 1 is left (conter-clockwise)
x += hSpeed - xAcc * 0.5;
y += vSpeed + yAcc * 0.5;
//If simple - we applying “turn” acceleration as half of it because acceleration is not instant, but after the
//turn we save full acceleration to speed value as we reach it during turn
hSpeed -= xAcc;
vSpeed += yAcc;

Hi all.
I’m trying to learn Genetic algo and apply it to this mars lander game.
Just to be sure I got it right

For each input :
   update ship status
     generate a list of random (angle, power) tuple (that's the population in GA)
        apply each tuple to the ship to get a new ship status and evaluate a score ,
        sort the result by score , to get the best 30% plus 20% random
        complete this new list with  mix of them (the crossover in GA tutorial)
        repeat the above 3 steps until you get a short list of result:
 print the best gene (tuple)

Is my above statement correct ??
If so, based on the previous post i understand how apply to the ship.
But how to evaluate the best score since the goal change over time ??
first goal use less fuel and later then land slow and straight ??

or did i get this completely wrong ??

I think you have got the main idea more or less correct. The percentages will be subject to tuning.

For me, each candidate is a list of tuples sufficient to cover the whole simulation (until it crashes / lands). The basis of my evaluation is different according to how the simulation of the candidate ends, e.g. fuel remaining if landed, distance to landing area if crashed outside landing area, and angle and velocity if crashed within landing area. There is no single right approach; you can devise your own basis of evaluation.

You could have a look at this also: A Dedicated Landing with a Genetic Algorithm

5 Likes

Hello,
I am facing a timeout issue with Mars Lander Optimization puzzle which I am bit surprised of.
Like in other Optimization puzzles, my bot is considering that on first round 1000 ms is allowed to answer then 100 ms on following turns.
This assumption works well for validators 2 to 5 but not on the first one which is generating a timeout.
If I do submit my code, same thing happens : first test is failing (easiest one) which I guess is for this timeout problem and all the others pass.

Any clue on why this difference between Validator 1 and the others regarding timeout value for first turn ?
Is something specific on Mars Lander Optim puzzle ?

Hi Gloopy. My best guess would be that your simulations take longer in the fist round because there are no mountains close to the starting position. It typically takes longer for the lander to crash in round 1 if you simulate random strategies.

Thank you very much, sir!

Also, position and speed are stored as floats and rounded at display.
E.g.
if x0 = 1.5 (displayed as x=2)
and vx = 1.9m/s (displayed as 2m/s)
then x1 will be 3.4 (display 3, not 4)

Thanks for your hint WouterSolutions.
I don’t think that the sim code is very sensitive to the number of simulations performed, I will check. But you made me realize that I may have a bug elsewhere especially if I cannot land in a fixed number of turns for this case.

salut je suis de montbéliard , bien joué pour ton score !

Wow… here’s what I get (though this might vary based on how quickly my simulations run) : /

1 - Easy on the right: 175
2 - Initial speed, correct side: 277
3 - Initial speed, wrong side: 470
4 - Deep canyon: 464
5 - High ground: 677
Total: 2063

After years of hesitation, I decided to give this optimization problem a go. With no prior knowledge of genetic algorithms, the article of Di_Masta was enough to reach the #24 spot. If you want to solve this game but struggle, a simple genetic algorithm does wonders.

1 Like

I came here a bit late, still glad i made 2215 points with no genetic algo.

GA is unnecessarily complicated. Simulated annealing gives similar results for this task.