Black Box is a board game, Your task is to reveal all clues.
What is black box
Black box is a board game with hidden atoms, Your task is given input, All atoms, reveal all clues.
I/O
Input
The atoms can be any 1-char that is not newline (Used for separator) Like this.
O....
...O.
..O..
.....
....O
Output
When the code reveals all clues (See Below) the output of The given input above can be:
HRHH1
H 1
R H
H H
2 R
H H
H2HRH
or
[["H", "R", "H", "H", "1"], ["1", "H", "H", "R", "H"], ["H", "R", "H", "2", "H"], ["H", "2", "H", "R", "H"]]
Ignore the number, This doesn't mean anything, the number must be non-unique and must work with >9 detours
Task
Hit
Atoms interact with rays in three ways. A direct impact on an atom by a ray is a "hit".
.........
.........
.O.....O.
.........
.........
...O.....H 1
.........
.......O.
Thus, ray 1 fired into the box configuration at left strikes an atom directly, generating a "hit", designated by an "H". A ray which hits an atom does not emerge from the box.
Deflection
The interaction resulting from a ray which does not actually hit an atom, but which passes directly to one side of the ball is called a "deflection". The angle of deflection for this ray/atom interaction is 90 degrees. Ray 2 is deflected by the atom at left, exiting the box as shown.
2
.........
.........
.O.....O.
.........
.........2
...O.....
.........
.......O.
Explanation in ASCII art:
2
....^....
....^....
.O..^..O.
....^....
....\<<<<2
...O.....
.........
.......O.
Reflection
The final type of interaction of a ray with an atom is a "reflection", designated by an "R". This occurs in two circumstances. If an atom is at the edge of the grid, any ray which is aimed into the grid directly beside it causes a reflection.
.........
.........
.O.....O.
.........
.........
...O.....
.........
.......O.
RHR
354
Rays 3 and 4 at left would each generate a reflection, due to the atom at the edge. Ray 5 would be a hit on the atom.
Double deflection
The other circumstance leading to a reflection is when two deflections cancel out. In the grid at left, ray 6 results in a reflection due to its interaction with the atoms in the grid.
6
R
.....
..O.O
.....
.....
.....
Detour
Rays that don't result in hits or reflections are called "detours". These may be single or multiple deflections, or misses. A detour has an entry and an exit location, while hits and reflections only have an entry location for a hit, and a single entry/exit location for a reflection.
8 8
.........
.........
.O.....O.
.........9
.........
...O.....
.........9
.......O.
Of course, more complex situations result when these behaviors interact. Ray 8 results in two deflections, as does ray 9.
Some rays travel a twisted course, like ray 1 at left.
.........
.........
.O.....O.
.........
1.........
...O.....
.........
.......O.
1
Notice that this complex set of five deflections above looks exactly like a single deflection, as shown by ray 2 at left. Things are not always as simple as they seem within a black box.
.........
.........
.........
.....O...
1.........
.........
.........
.........
1
Reflections and hits can be more complex, too. Ray 2 gets deflected by the first atom, reflected by the next two atoms and again deflected by the original atom, yielding a reflection.
.O...
.....R 2
.....
.O.O.
.....
Ray 3 below gets deflected by the first atom, then by the second atom, and then hits the third atom, yielding a hit.
...O.
O....
.....
3 H.....
...O.
Explanation in ASCII Art:
8 8
..v...^..
..\>>>/.
.O.....O.
......../9
........v
...O....v
........\9
.......O.
.........
.........
.O.....O.
../>>>\..
1>>/...v..
...O..v..
..../</..
....v..O.
1
.........
.........
.........
.....O...
1>>>>\....
....v....
....v....
....v....
1
Test cases
O....
...O.
..O..
.....
....O
->
HRHH1
H 1
R H
H H
2 R
H H
H2HRH
O
->
H
H H
H
OOO
O O
OOO
->
HHH
H H
H H
H H
HHH
..O..
O...O
..O..
->
HRHRH
R R
H H
R R
HRHRH
...
...
...
->
123
4 4
5 5
6 6
123
....
O...
...O
....
->
H1HH
R 1
H R
R H
2 R
HH2H
```
o
s as single atoms. \$\endgroup\$