Preparando MOJI
You have a robot in a two-dimensional labyrinth which consists of N × M cells. Some pairs of cells adjacent by side are separated by a wall or a door. The labyrinth itself is separated from the outside with walls around it. Some labyrinth cells are the exits. In order to leave the labyrinth the robot should reach any exit. There are keys in some cells. Any key can open any door but after the door is opened the key stays in the lock. Thus every key can be used only once. There are no labyrinth cells that contain both a key and an exit. Also there can not be both a wall and a door between the pair of adjacent cells.
Your need to write a program in abc language (see the language description below) that will lead the robot to one of the exits. Lets numerate the labyrinth rows from 0 to N - 1 top to bottom and the columns – from 0 to M - 1 left to right.
In abc language the following primary commands are available:
Also, there are the following control commands in abc language:
Note that the control and the primary commands can be fit into each other arbitrarily.
The robot will fulfill your commands sequentially until it exits the labyrinth, or it runs out of the commands, or the terminate command is run, or the quantity of the fulfilled commands exceeds the bound number 5·106.
In abc language each command is a separate word and should be separated from other commands with at least one space symbol.
You should write a program that prints the sequence of commands leading the robot out of the labyrinth. Of course, as you are a good programmer, you should optimize these sequence.
The number of the non-space symbols in the sequence should not exceed 107. If you succeed in finding the way out of the labyrinth i you’ll be granted the number of points equal to:
In case your sequence doesn’t lead the robot to the exit you’ll be granted 0 points. Your programs result will be the sum of all Si. You should maximize this total sum.
All labyrinths will be known and available to you. You can download the archive with labyrinths by any of the given links, password to extract files is aimtechiscool:
In order to make local testing of your programs more convenient, the program calculating your results (checker) and the labyrinth visualizer will be available. This program is written in python3 programming language, that’s why you’re going to need python3 interpreter, as well as pillow library, which you can install with the following command pip3 install pillow. pip3 is a utility program for python3 package (library) installation. It will be installed automatically with the python3 interpreter.
Example command to run checker and visualizer: python3 aimmaze.py maze.in robot.abc --image maze.png. The checker can be run separately of visualization: python3 aimmaze.py maze.in robot.abc. Flag --output-log will let you see the information of robots each step: python3 aimmaze.py maze.in robot.abc --output-log. Note python3 can be installed as python on your computer.
To adjust image settings, you can edit constants at the beginning of the program aimmaze.py.
The first line contains integers i, W, N, M, x0, y0, C, D, K, E.
The x coordinate corresponds to the row number, y – to the column number. (0, 0) cell is located on the left-up corner, so that down direction increases the x coordinate, while right direction increases the y coordinate.
Each of the next C lines contains 4 integers each x1, y1, x2, y2 – the coordinates of cells with a wall between them in a zero based indexing. It is guaranteed that |x1 - x2| + |y1 - y2| = 1, 0 ≤ x1, x2 ≤ N - 1, 0 ≤ y1, y2 ≤ M - 1. Also there are always walls around the labyrinth’s borders, which are not given in the labyrinths description.
Each of the next D lines contains door description in the same format as walls description. It is guaranteed that doors and walls don’t overlap.
Each of the next K rows contains a pair of integer which are the key coordinates in a zero based indexing.
Each of the next E rows contains a pair of integer which are the exit coordinates in a zero based indexing.
It is guaranteed that the robots starting position as well as keys and exits are located in pairwise different cells.
Print a program in abc language which passes the given labyrinth. Commands have to be separated by at least one space symbol. You can use arbitrary formatting for the program.
1 1 30 30 1 1 1 1 1 1
1 1 1 2
2 2 2 3
1 4
9 0
for-1111
take
open-up
open-left
open-right
open-down
move-left
if-ok
for-11
move-left
take
open-up
open-left
open-right
open-down
end
else
move-right
if-ok
for-11
move-right
take
open-up
open-left
open-right
open-down
end
else endif
endif
move-up
if-ok
for-11
move-up
take
open-up
open-left
open-right
open-down
end
else
move-down
if-ok
for-11
move-down
take
open-up
open-left
open-right
open-down
end
else endif
endif
end