Formula 1

Problem #445

Tags: c-1 games implementation

Who solved this?

No translations... yet

Game demo should be embedded here, alternatively use this direct link

This game exists in pencil-and-paper version, which wiki calls Racetrack - but I also found it in the book "Programming games and puzzles" by Jacque Arsac. It is non-interactive, step-based game, but still tricky, as you may judge by trying it in the demo box above.

You are driving the car along the road which is drawn on typical 2D grid. Car speed is determined by two components - forward and sideward. At every step you can increase or decrease each component by 1 (or simply keep current speed). Then car coordinates are updated with speed component values. Your goal is to reach the end of the road without crashing (flying out of the road) - and to do this fast enough (in terms of moves).

Let's show the car movement in example. Let starting piece of the road looks like this:

ooooooooooooooo....ooooooooooooooooooooooooooooooo
oooooooooooooo....oooooooooooooooooooooooooooooooo
ooooooooooooo....ooooooooooooooooooooooooooooooooo
oooooooooooo....oooooooooooooooooooooooooooooooooo
ooooooooooo....ooooooooooooooooooooooooooooooooooo
ooooooooooo....ooooooooooooooooooooooooooooooooooo
ooooooooooooo....ooooooooooooooooooooooooooooooooo
ooooooooooooooo....ooooooooooooooooooooooooooooooo
oooooooooooooooo....oooooooooooooooooooooooooooooo
oooooooooooooooooo....oooooooooooooooooooooooooooo
oooooooooooooooooo....oooooooooooooooooooooooooooo
oooooooooooooooooooo....oooooooooooooooooooooooooo
oooooooooooooooooooooo..@.oooooooooooooooooooooooo

The car starts at the first (lowest) row, at position marked with @. It's initial speed is 0, 0 (let's denote forward speed with first component and sideward with second). If we increase only forward speed on the first step, we crash immediately. Thus we also increase speed to the left (let's agree leftward speed is negative, to decrease X coordinate).

So on the first step speed becomes 1, -1 and we successfully get to the brink of the road in the next line. For the 2nd move let's again increase forward and leftward components of speed - it will become 2, -2. We got to the 4th row on the scheme above, again on its right edge. We continue increasing left and forward speed for the 3rd move, but regretfully this time we miss the road. Below is the same diagram with digits denoting positions after moves 1 and 2 and X marking the crash site:

ooooooooooo....ooooooooooooooooooooooooooooooooooo
ooooooooooooo....oXooooooooooooooooooooooooooooooo
ooooooooooooooo....ooooooooooooooooooooooooooooooo
oooooooooooooooo....oooooooooooooooooooooooooooooo
oooooooooooooooooo...2oooooooooooooooooooooooooooo
oooooooooooooooooo....oooooooooooooooooooooooooooo
oooooooooooooooooooo...1oooooooooooooooooooooooooo
oooooooooooooooooooooo..@.oooooooooooooooooooooooo

To avoid crash we, for exmaple, shouldn't increase the forward speed on the last move (so speed would be 2, -3 and we keep on the road).

A thing to note is we do not consider "corners" of the road between starting and stopping point of the move (as if jumping between two points). Of course it is a bit unrealistic, but otherwise collision-detection rules would be too complicated for human player.

Problem Description

Given a road of length about 300 and 4 cells wide at every row, you should propose sequence of moves which leads the car safely to the finish line (so that last move ends beyond the end of the road) - and do this in at most road_length / 3 moves - in other words your average forward speed is expected to be 3 or higher.

Your start position is always the cell to the right of the center line of the road (in the first "row" of it).

Controls for every move should be described with 1-2 symbol "word" consisting of letters A (accelerate), B (brake), L (left), R (right) - of them two first affect forward speed (adding or subtracting 1) and two last affect sideward speed (also by 1 each move). Other characters are ignored, so to keep the current speed use "word" X (or some other letter, or dash, or dot etc).

Input format: the first line contains length of the road and random seed (ignore it - it just may help if we need to debug checker). Next lines contain two integers each - X coordinates of the left and right edges of the road in the given "row".

Answer format: please output a sequence of control words.

Example:

input data:
300 123456
22 25
20 23
18 21
18 21
16 19
15 18
13 16
11 14
11 14
12 15
13 16
14 17
15 18

answer:
AL AL L ...

Here we describe the same road as in example above. And same sequence of moves (without accelerating on step 3 to avoid crash).

You need to login to get test data and submit solution.