CoGo Rally
There's a game called Robo Rally, in which players "program" their robots five moves ahead, then simultaneously perform the moves, one at a time. The robots move over a "factory floor" grid, with the aim being to reach certain points on the board, in sequence, before the other robots do the same.
Game Rules
For the purposes of this challenge, the rules will be simplified as follows:
- Each robot starts with 6 lives
- Each robot has a different, randomly assigned starting position (out of a fixed set of starting positions)
- The aim of the game is to reach all three checkpoints in the assigned order, before any other robot does the same.
Movement Options
Each turn, your robot can make any one of the following movements:
- Rotate Clockwise 90 degrees
- Rotate Counter-clockwise 90 degrees
- Rotate 180 degrees
- Move Forward One
- Move Forward Two
- Move Forward Three [can only be used once until the next checkpoint is met]
- Reverse One (and stay facing the same way)
- Stay Still and gain 1 life, up to the maximum of 6
Your moves are pre-programmed in blocks of five, so choose carefully! The board may well be in a very different state in five moves time to what you think it will be.
Additionally, each movement is assigned a priority from 1-100. When you choose your block of five movements (you may use each movement any number of times, except the "move forward three", to form your five total movements) and the order they will occur in, you are also given five random numbers 1-100 to assign - one to each movement. Higher numbers will take priority where movements would cause two robots to enter the same space, for example.
Board Items
The board contains the following items:
- Floor - the default tile on the board. No special effect.
- Walls - block a robot's path. If a robot moves forward or backward into a wall, it wastes that move (i.e. stays still, but doesn't gain a life). If the robot used "Move Forward Two", for example, it may be possible that the Robot can only move Forward One, and then stops infront of a wall, wasting the second part of the movement.
- Laser gun - fire in a straight line in a specific direction until they hit a wall or a robot. If a robot is ontop of a laser gun, it will be hit but the laser won't fire further. While moving forward two or three, a robot may pass over the path of a laser gun without being affected by it.
- Conveyor Belts - at the end of a turn (single movement option), a conveyor belt will move the robot one space in the direction the conveyor is pointing. Doesn't block lasers. Conveyor belts NEVER ROTATE ROBOTS, even if they move the robot in a different direction to the one it is facing. While moving forward two or three, a robot may move over a conveyor belt without being affected by it.
- Checkpoints (1,2,3) - act as a save point on the Robot's path and also heals all of a robot's lives and resets their use of the "Move Forward Three" action, the first time the checkpoint is visited. Checkpoints must be visited sequentially to be activated. Acts as a piece of floor in all other respects. Robots must END THEIR TURN ON THE CHECKPOINT, after interaction with other Robots; and not just pass over it.
- Holes - move the robot back to the previously visited checkpoint, or start position. Robot loses half its remaining life, rounded down. Holes act immediately, as soon as the robot enters the space - it doesn't wait for the "board interactions" part of the turn order.
Interactions
Objects interact as follows:
- If a Robot moves into a space where another robot already exists, the other robot is shoved (moved) in the direction that the first robot was moving, one space; unless there is a wall or laser in the way. This effect may stack if multiple robots are in a line (i.e. all robots are shoved one space). This may cause a robot to fall into a hole or onto a conveyor belt.
- Moving off the edge of the board has the same effect as moving into a hole
- If a Laser fires and hits a robot, the robot stops the laser beam, and takes one damage.
- If a robot is facing another robot in a straight line with nothing blocking in between (i.e. no walls or other robots), the target robot takes 1 damage
- Therefore If two robots are facing towards each other with nothing blocking in between (i.e. no walls or other robots), both robots take one damage.
Turn Order
- determine (program) 5 movement options
- determine Priorities (1-100) for these five turns
- The programmed actions occur:
a. The first movement occurs for each player, in priority order from highest to lowest. Holes are acted on immediately (a robot cannot pass over a hole).
b. Robot Interactions are resolved (e.g. if one robot shoves another one)
c. Board Items act (lasers, conveyor belts, checkpoints)
i. If a robot loses all of its lives, it returns to the previous checkpoint (or start) with half lives (rounded up) and must sit out the remainder of the round
d. Robots fire
i. If a robot loses all of its lives, it returns to the previous checkpoint (or start) with half lives (rounded up) and must sit out the remainder of the round
e. Repeat for the remaining 4 movements
- Repeat until one robot has reached all three checkpoints sequentially, or all robots have lost their lives
The Challenge
Your robot must take the board (as a 2D array), and a seed for the Random number generator; and play the game on the given board.
The board is guaranteed to be solveable (there will always be a path from the start to each of the checkpoints)
Sample Board
The above board would be represented in an array as follows:
[0,0,0,0,0,0,0,0,0,0,0,0]
[0,0,0,0,0,0,0,0,0,0,0,0]
[0,0,0,0,0,0,LU,0,0,0,0,0]
[0,0,0,0,0,LL,2,LR,0,0,W,0]
[H,CL,CL,CL,CL,CL,CL,CL,CL,CL,0,0]
[0,0,0,0,0,CR,CR,CR,CR,CR,CR,H]
[0,W,0,0,0,0,0 ,0,0,0,0,0]
[0,W,0,0,0,0,W,0,W,0,0,0]
[1,W,0,0,0,0,CR,CR,CD,0,W,3]
[0,W,CR,CR,CR,0,CU,H,CD,W,0,0]
[0,LL,CR,CR,CR,CR,CU,CU,CL,0,0,0]
[0,0,S,S,S,S,0,0,W,0,0,0]
Where
Cx = Conveyor (x=Up, Down, Left, Right)
Lx = Laser gun (x=Up, Down, Left, Right)
S = Start
1,2,3 = Checkpoints
W = Wall
H = Hole
0 = Floor
Sandbox Questions
Should this be code-golf, where you implement your robot in the least code possible; or king-of-the-hill, or something else? If KotH, I've never set one before so some advice would be appreciated!