Mars Lander - Puzzle discussion

Same here, cannot get the achievement validated… :-\

Sorry, I had not seen CvxFous’s reply.

I set the angle is always 0 and I increase the engine power.
I calculate the vspeed in step 5 before the start:
a_fall=g-a_power
vspeed_step5 = a_fall_step1-a_fall_step2-a_fall_step3-a_fall_step4
-3.711-2.711-1.711-0.711=-8,844m/s
I start a test and I see:

step | power | vspeed
1	0	0
2	1	-3
3	2	-4
4	3	-5
5       4       -5

why vspeed -5 m/s in step 5?

You count the acceleration one step late it seems:

Step 1 : (p=0) v=0
Step 2 : (p=1) v=0 - 2.711 = -2.711 -> -3
Step 3 : (p=2) v=-2.711 - 1.711 = -4.422 -> -4
Step 4 : (p=3) v=-4.422 - 0.711 = -5.133 -> -5
Step 5 : (p=4) v=-5.133 + 0.289 = -4.842 -> -5

1 Like

I don’t know if it is the right place to post suggestions for a specific puzzle…

It would be great if the debug mode could show more self-explanatory information around the lander: I’d imagine 3 arrows originating from the lander (push, speed and acceleration). And the flames could be removed from the picture (again in debug mode).

I’m not sure how much work that would represent to be honest… but that could make the puzzle less scary to newcomers.

2 Likes

I think we all agree that the design of this puzzle could and should be improved :). And all ideas to improve the game are very welcome, thank you. However, improving that game would indeed represent some work and we are currently working on great new features that should land soon. I’m sorry I can’t tell you when it will be done.

Hi,

I completed the Mars Lander challenge but I am not satisfied by my solution. Here is what I did.

For level 1, I did a stupid reflex agent with a lot of if…else… Surely not the best solution but it is enough

For level 2 and 3, I solved it as a search problem. The state is the state of the lander. I used the following :

case class Lander (x : Double, y : Double, prevX : Double, prevY : Double, hSpeed : Double, vSpeed : Double, fuel : Int, angle : Int, power : Int) 

I can get the next step thanks to a physical approch. For those who are not physician (and I am not), here is what I did.

def getNextState(lander : Lander, action : Action) : Lander = {
        var nextP = lander.power + action.power
        var nextFuel = lander.fuel - nextP
        var nextAngle = lander.angle + action.angle
        var nextX = 2 * lander.x - lander.prevX - nextP * sin(toRadians(nextAngle))
        var nextY = 2 * lander.y - lander.prevY - g + nextP * cos(toRadians(nextAngle))
        var nextVx = lander.hSpeed - nextP * sin(toRadians(nextAngle))
        var nextVy = lander.vSpeed - g + nextP * cos(toRadians(nextAngle))
        var nextLander = Lander(nextX, nextY, lander.x, lander.y, nextVx, nextVy, nextFuel, nextAngle, nextP)
        nextLander
    }

Once I had it, I tried to do a complete depth first search (DFS) but there are too many state. So, I did a limited DFS of depth 5 and I had to do an evaluation function. I finally found something that works but I had to try a lot of different functions. I spent more time on the evaluation function than the rest of the code. Moreover, I found my evaluation was too complex :frowning: I had to catch a lot of exceptions in it.

Maybe I should try A* but I have also to find a correct evaluation function and the computation time may be too long.

Did you find a better way to do ? Are there algorithms for trajectory planning ? If you did like me, did you found a simple evaluation function ?

See you :slight_smile:

2 Likes

Spent a lot of time trying to figure out a correct physic algorithm for mars lander 2&3. Ended up coding just a bunch of basic heuristics like:

  • Adjust direction to landing spot
  • Landing or pre-landing phase
  • Revert rotation in case horizontal speed too high
  • Line of sight to landing zone detection in level 3
  • etc

Worked like a charm. See it in action http://imgur.com/a/ap3Y4

My advice: don’t overthink it.

11 Likes

I just joined CodinGame and had to reply, even if its a old comment.

I’m in the 3rd kind of people cuse i drop out of a mechanical engineering degree and now i’m one final project away to get my Computer Science degree… U get the point :wink:

Btw this is the 1st level that challenged me, i guess i really need to get a pen and work on the maths and algorithm this time… love it :smiley:

2 Likes

I saw some people having a few problems or just overthinking lvl 1…
Even for the economic achievement all i had to made was check the VS limit.

rotate = 0;
power= vSpeed<=-40 ? 4 : 0;

2 Likes

I am trying to predict the lander’s next position from the current information, how do I go about figuring out the timestep ? Thank you

So conceptually I know how I want to approach this puzzle, but I’m having trouble figuring out what mathematical steps to take in order to implement it. Perhaps somebody here could point me in the right direction.

So let’s say I have a direction vector indicating my current direction of motion, let’s say (0, -1) ie: falling straight down. And I also have a direction vector indicating the direction I want to be moving, say (1, 0) ie: moving rightward horizontally. What I’m trying to figure out is how do I determine the ideal acceleration direction to move my current direction closer to the direction I want.

For simplicity I’ll say as an example that I’m moving straight down (0, -1) and want to be moving straight up (0, 1). Obviously the optimal acceleration direction would be (0, 1). This becomes much more complicated however if I have a situation where say I’m currently moving (-0.8, -0.2) and I want to be moving (0.5, -0.5). I can’t seem to figure out a formula that works in all cases.

Thanks in advance for any advice folks!

If what you want is the acceleration, it’s pretty straightforward: v1 = v0 + a*dt, with dt = 1s, so a = v1 - v0. This is a vector formula, so it gives you both the direction and the value.

For the angle and power that you need to get that acceleration (if at all possible), you will need to factor in the gravity acceleration, i.e. solve a0 = g + P*(sin(A),cos(A)).

Now if that acceleration is not possible, you will want, as you say, to move your current direction “closest” to the wanted direction. Depending on the definition of “closest”, it can be much harder. You can also try to anticipate further ahead, so that you can reach exactly the speed you want when you want it.

How do you know that dt = 1s ? Where is it in the statement ?
Thanks

1 Like

I’m not sure actually, I can’t find it in the statement. But it is easy to check experimentally: in some run, check your altitude at t and t + dt, and your speed at t. You’ll see that you have the same value, hence dt=1s.

1 Like

Really nice puzzel

It is a 1 second timestep, I think it is written in the description

I solved economic puzzle 1 without any complex equations.
here is my code:

[EDIT: DO NOT GIVE ALORITHM TO SOLVE THE PUZZLE]

speed is distance divided by time, it is relation, we don’t need to know from what numbers this relations come from
we can have speed 36 km/h, we can have speed 10 m/s - these are the same speeds
so we don’t need exact value of time to work with speed, and with acceleration too
besides, from gravity, thrust, and scene dimensions you can derive time step length

actually, this is idea for a puzzle - detect gravity on an unknown planet, or anything else from these equations

I’ve finish game with 310l of fuel, but I did’t get +25 CP. Any ideas?