Scientist Seals Stranded upon an Iceberg Introduction

A family of seals are stranded upon an iceberg in the Arctic Circle. There is a radio transmitter located on the iceberg which the seals can use to call for help. However, only the daddy seal knows how to operate the radio transmitter. And worse, the ice is very slippery this time of year, so the seals will slide uncontrollably until they hit another seal or slide off the edge of the iceberg, making it very difficult for the daddy seal to reach the radio transmitter. Luckily, one of the seals is a computer scientist, so she decides to write a program to figure out how to manoeuvre the daddy seal to the radio transmitter. As there is not much space on the ice to write a program, she decides to make the program use as little bytes as possible.

Input Description

The seal's program will take input in from STDIN, command line arguments, or user input functions (such as raw_input()). It cannot be preinitialised in a variable (e.g. "This program expects the input in a variable x"). 

The first line of the input consists of two comma separated integers in the form 

A,B


Following that is B lines consisting of A characters each. Each line can only contain characters out of the following:


.: The cold, cold, ocean. The map will always have this as a border.
#: A part of the iceberg.
a...z: A seal that is not the daddy seal on the iceberg.
D: The daddy seal on the iceberg.
*: The radio transmitter.


(Note that the daddy seal is always notated with an uppercase D. A lowercase d is simply a regular seal.)

Output Description

According to the following rules regarding how the seals can move, output a list of instructions for the seals on how they should move to get the daddy seal to the radio transmitter.


Rule: All seals can move up (U), down (D), left (L), and right (R). They cannot slide diagonally.
Rule: Upon moving, a seal will continue to move in the same direction until it collides with another seal or falls into the sea.

If a seal collides with another seal, it will stop moving. The seal it collided with will not move.
If a seal falls into the sea, it will drown and disappear from the map. That is, it does not act as a collider for other seals and it cannot be moved again.

Rule: Two seals cannot move at the same time, neither can a seal be moved while another one is still moving. The next seal can only be moved once the previous seal has stopped moving.
Rule: There is no restriction regarding moving a seal multiple times, or the number of seals that drown.
Rule: A correct solution will have the daddy seal end at the radio transmitter. The daddy seal cannot simply pass the transmitter while sliding.


The output will consist of several lines, each in the form

A,B


Where A is the seal to move (D for the daddy seal, a...z for others), and B is the direction to move the seal (either U, D, L, or R). Note that you do not need to find the shortest route. Any route that gets the daddy seal to the goal is an acceptable output.

Example Inputs and Outputs

Input:

25,5
.........................
.#######################.
.####D#############*k###.
.#######################.
.........................


Output:

D,R


Input:

9,7
.........
.a#####b.
.#####d#.
.##l*###.
.###m#p#.
.#D#.#c#.
.........


Output (one possible output out of many):

m,R
b,L
D,U
D,R
D,D
D,L


Input:

26,5
..........................
.###..................###.
.l*##########v#########D#.
.###..................###.
..........................


Output (one possible output out of many):

v,D
D,L


If you have any other questions, please ask in the comments.
Python 3, 520 bytes



R=range
g=[list(input())for i in R(int(input().split(',')[1]))]
f=set(sum(g,[]))-set(".#*")
L=8
def P(p,g):
 if len(p)&gt;L:return
 for s in f:
  c=sum(y.index(s)for y in g if s in y)
  if c&lt;1:continue
  r,=[n for n in R(len(g))if s in g[n]]
  for d in R(4):
   m=p+s+",%s\n"%"LURD"[d];G=[y[:]for y in g];o="#";i,j=I,J=r,c
   while"#"==o:G[i][j]="#";G[I][J]=s;i,j=I,J;I,J=i+d%2*(d-2),j+(~d%-2&amp;d-1);o=G[I][J]
   if"."==o:G[i][j]="#"
   if"D"==s:
    if"."==o:continue
    if"*"==o:print(m);1/0
   P(m,G)
while 1:P("",g);L+=4


I may do a more detailed explanation later if people want, but basically this runs a depth-first search with iterative deepening on the state space of possible moves. If a move causes the daddy seal to fall off, it is immediately rejected. If the daddy ends up next to the transmitter, the sequence of moves is printed, and the program divides by zero to force an exit.

I can make the code run significantly faster by adding if G!=g: at the beginning of the second-last line, for 8 extra bytes--this rejects moves that don't change anything, such as k,L in the first test case.

The runtime varies noticeably from one run to the next, even with the same input--evidently a result of the fact that I pick the next seal to move by iterating over a set, which is an unordered type. I timed the second test case at 5 minutes 30 seconds, though it didn't seem that long the first time I ran it. With the optimization mentioned above, it's more like 40 seconds.