Mars Lander - Puzzle discussion


Hi everybody,
Level 1, Java - I’m trying to figure out how the actual Y is computed. The vertical speed in each round is the speed from previous round minus gravity (3.711) plus power (that’s correct, read numbers match). With this I would expect that Y is the Y from the previous round plus speed. But that’s somehow wrong.

For example, with no power, the speed after the first round is -3.711 (rounded to -4, matches the read value). And I expect Y to be 2496.289 (2500 + (-3.711)) and rounded to 2496. But the read value is 2498. What am I missing?

I have tried to divide the speed by 2, subtract 1/(round number) and few other adjustments, but my computations never match the Y given by the line reading.


The 3.711 is acceleration. At the start of the turn you are at 0, at the end you are at -3.711. During the turn you slowly change from one speed to the other. Your speed for the turn will be velocity + (acceleration/2), which gives 2500 + (0 + (-3.711/2)) = 2498.1445. Unfortunately the server only sends you the integer part so if you need an accurate position / velocity you need to track it yourself and ignore the server.


Awesome series. But why so few tests? I substituted my primitive inefficient algorithm from the 2nd to the 3rd episode, and received a 250XP freebie for passing the “half” of tests without any complicated mathematics :confused:


I uses a physics approach as well, and I used EXCEL as a visualization tool for my algorithm which served me extremely well for quick tests :wink:

Critical for this algorithm is to know by when (how many seconds left) the lander will reach Ylanding based on current Yspeed and by when it will reach Xlanding based on current Xspeed. As both velocities vY and vX are limited, I also needed to calculate how many seconds to brake in X-direction to stay within landing limits of -20…20m/s and what this braking would do to the velocity in Y-direction.
To make it easier for me, I only allowed the most efficient rotate angles (45°, 0°, -45°) and built in an optimizer to find the best possible spot to land on within allowed X landing range.

The algorithm has just two outputs: modeFlagX and modeFlagY. modeFlagY is only set in case current vY is nearing maximum allowable Y-velocity based on time needed to reach destined X position and maximum Yspeed for landing (-40).
modeFlagX is just requesting the lander to accelerate, brake, or no change of direction needed based on target X. It will only allow to brake/accelerate if modeFlagY is NOT requesting to thrust upwards.

The algo for Level 2 DOES NOT NEED a pathfinding function yet, I will develop this for level3 later on.

I’ll post some snapshots once the forum lets me :wink:


@RoboStac’s post solved this for me. In my opinion, this behavior should have been better documented.

My new, working, state update looks like this:

thr = radians(thetan)
co = cos(thr)
si = -sin(thr)
vxn = clamp(vx+powern*si, -500, 500)
vyn = clamp(vy+powern*co+g, -500, 500)
xn = x+vx+0.5*powern*si
yn = y+vy+0.5*(powern*co+g)
fueln = fuel-powern