Your task is to program a robot so that it reaches the hole in the ground on each of the maps within reasonable time. If the robot reaches the hole, it falls down into it and thus victory is assured, even if the program never stops running.
Since the robot has to be programmed by manually punching in ones and zeroes, you want to solve the problems using as few commands as possible. Labels are translated to positions by the assembler and integrated into the gotoblocked and call commands, so the programmer never has to punch them into the robot. Therefore, they do not count towards the score. If the robot tries to move into a wall or off the map, nothing happens.
The language consists of these statements:
forwardmove the robot forward one steprightrotate 90 degrees clockwiseleftrotate 90 degrees counter-clockwisefor X {A1 A2 .. An}repeat commandsA1, A2, ..., AnXtimescall Xcall a subroutine, beginning at label Xreturnreturn from the subroutinegotoblocked Xjump to label X if there is a wall immediately in front of the robotmylabel:a label used bycalland/orgotoblocked. Loops may not contain any labels. Labels may only contain letters.
The input files consist of:
testcase_name
N M
and then an N by M grid of:
.empty square#blocked squareMthe hole in the ground that we want to end up in<>^vstarting position of the robot, directed left, right, up or down, respectively.
The maps can be found at http://progolymp.se/uploads/robot.zip
Your task is to solve all the maps.
Validation:
The code you submit will be executed against all the test cases, starting at the label testcasename for each map. Follow the formatting in the example program.
Scoring: The score is the number of statements (excluding labels) in the whole file, i.e. the code used to solve all testcases. Code reuse between testcases is ok.
Example program with starting points for testcases robot_cross and robot_maze (that solves neither):
walkandreturn:
for 100 {
forward
}
robotmaze:
gotoblocked done
right
right
for 100 {
for 3 {
forward
}
}
done:
return
robotcross:
for 100 {
call walkandreturn
right
}
Automated judge can be found at http://progolymp.se/uploads/robot.jar.
To test a file against the testcase robot_ew_manuell, add this to the end of your program file:
main:
call robotewmanuell
The judge starts execution at the label main, but we want it to start at robotmaze instead. This causes the judge to jump to where it should start, and saves me from having to write a new judge.
The actual judge can then be run like this:
java -cp robot.jar parser.Runner robot_ew_manuell.in < my_solution.ans
Help wanted
If you have a good place to mirror the files, or a way to post them on the site, please do.
This problem is based on the final problem of the 2016 online qualifier of Programmeringsolympiaden. https://po.kattis.com/problems/robotoptimering The original problem was authored by Johan Sannemo and Anton Grensjö. CC BY-SA licensed, just like Stack Exchange.