Ricochet Robots is a board game about optimizing moves. (see
wikipedia description)
The 4 pieces represent the "robots" Blue, Yellow, Red and Green on a board with 16x16 cells and some walls.
Rules: Each round one of the robots can be moved horizontally or vertically, and does not stop until it reaches an obstacle - either a wall or another robot.
E.G. in this example the Yellow on B14 can only reach A14 or B16 in one move, and nothing in between. You can only move one robot per round.
The object of the game is to bring one specific robot to an indicated target (here C9 marked with * ) using as few moves as possible.
(Since the goal has no neighboring wall you'll need to position other robots as obstacles nearby to reach it)
A B C D E F G H I J K L M N O P
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
1| | R | |1
. .---. . . . . . . . . . . .---. .
2| | | |2
. . . . . . . . . . . . . . . .
3| | |3
. . . . . . . . . . .---. . . . .
4| | |4
. . . . . .---. . . . . . . . .---.
5| |5
---. . . .---. . . . . . . . . . . .
6| | |6
. . . . . . . . . . . . . . . .
7| | | |7
.---. . . . . .---.---. .---. . .---. . .
8| | | | |8
. . . . . . . . . . . . . . . .
9| * | | |9
. . . . . . .---.---. . . .---. . . .
10| | B | |10
. . . .---. .---. . . . . . . . .---.
11| | |11
---. . . . . . . . . . . . . . . .
12| |12
. . . . . . .---. .---. . . . . . .
13| | | |13
.---. . . . . . . . . . . . . . .
14| (Y)| | |14
. . . . . . . . . . . . . .---. .
15| | | |15
. . .---. . . . . . . .---. . . . .
16| | G | |16
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
A B C D E F G H I J K L M N O P
Question:
- Whats the shortest solution (in number of rounds) to bring Yellow on target?
Please display the moves for each round at the end.
Provide a runnable Perl script solving it in under 15 min on a current home PC.
Bonus question:
If you are still bored...
- How many rounds do you need at most to reach any field?
- How many rounds to you need if the goal has to be reached by any of the robots, like the Blue?
Careful
I do have a script I wrote 16 years ago.
It needed over an hour back than and runs today in 1:30 min on my laptop, so it's solvable within the given margin. :)
But it took me two days to write it, and you might run into memory problems.
FUN
I had a lot back then, and learned a lot. Hope you too ... :)
Edits
added some clarifications and links
UPDATE
here the positions of the walls (yes strings as non-strict barewords, this script is old)
@vwalls=(A5,A11,B7,B13,C1,D15,E5,E10,G4,G10,H7,H9,H12,I7,I9,J12,K7,L3,
+L15,M9,N7,O1,O14,P4,P10); # below cell
@hwalls=(B2,B7,B14,D10,D15,E1,E6,E16,F4,F11,G8,G9,H13,I8,I9,I13,J1,K3,
+K8,L15,M10,N2,N7,N14,N16); # to the right
$Target="C9";
$Y="B14";
$R="J1";
$G="F16";
$B="M10";
UPDATE
It's specifically requested to bring Yellow on target, the first version was misleading, sorry.
removed (updated) marker in title again, to avoid "inheritance" to replies
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.