I recently moved to an apartment overlooking the inner ring-road of town, and every day, a beautiful scene unfolds. The traffic lights are apparently so confusing (mostly because the Dutch are used to complex intersections, and this one is too simple for them to wrap their heads around), that the intersection invariably winds up as something that must have been the inspiration for a certain game which I shall call Evening Commute for copyright reasons which I will undoubtedly have circumvented by my clever renaming...
Please help my fellow confused Dutchmen, and make sure the red car makes it through the maze during Rush Hour!
Explanation of the game
The goal is to have the red car go to the right of a 6x6 grid (all the way off to the right), while only going straight forward or backward in the lengthwise direction of the car (which is 2 grid points long). For simplicity, the red car is always on the 3rd row.
Of course, there are obstacles: other cars and trucks, with length two. They can be placed horizontally and vertically, and can only move in their lengthwise direction. They cannot pass through other cars. All cars move at 1 grid point per move. The game is won when the red car can move off the grid at the right side of the board.
Explanation of the challenge
- Input: a valid game board, which is a 6x6 string with dots
.for empty tiles,
R's for the red (target) car on row 3, hex numbers 0 through B for cars (length 2), and hex numbers C through F for trucks (length 3). You need not worry about invalid boards; we are dealing with a carnage-free intersection.
...... 11..22 RRC... ..C..3 ..C..3 ..66..
As can be seen, numbers can be skipped; furthermore, there may be only trucks or only cars.
- Output: a sequence of moves. Each move is identified as XY, with X the identifier of the vehicle, and Y the move, which is one of
v^<>, or down, up, left and right respectively for those not familiar with a certain programming language. The move
Rxmeans 'move the red car off the board' and will always indicate the end of the sequence (and only appear at the end, of course!). Since the output is fairly unambigious, any easily human readable sequence of moves will do (newlines, leading spaces are allowed; even a single undelimited string will do; however, you are not allowed to use underhanded tricks on the output). A solution to above problem may be, for example,
In- and output is, if I made the challenge correctly, case-independent, and newlines can be assumed to be convenient to your language (no need for
The number of bytes (code-golf-style) plus the sum of the number of moves it takes you for each of the following test cases (I tried to calibrate the minimum number of moves to be competitive). Your program should be fully capable of solving any other test case I may throw at it, and hard-coding test cases will give you a penalty of
2^64, but if that's favourable, you might want to rethink your strategy.
11...C D..E.C DRRE.C D..E.. 2...33 2.FFF. 112.33 442..C DRR..C DEEE.C D..566 77.588 C.1DDD C.12.. CRR2.. 3344.E .....E 5566.E C11.2. C34.2D C34RRD EEE5.D ..6577 88699.
...next code-golf, somebody should make me a Rush Hour image recognition system.