Java - 2632
While I admire the technical purity of Claudiu's answer, I decided to try my hand at making slightly more difficult puzzles ;)
Basic steps (pretty simple):
Randomize entry location
Step forward
For min(m,n)-1 steps:
Rotate left or right
Slide until I hit something or go a random distance
Place a rock in front of stopping location
If I can slide straight to any wall:
Slide to exit
Else
Create another step and try again
If at any step I get trapped, start over
If BFS finds shorter path, start over
I also mark each spot as 'nogo' as I'm sliding. If I end up on a nogo spot(or right in front of one which would mean a rock was going there), it's an invalid step.
So, basically the idea is to randomly generate a lot of maps, and keep the first one that is valid. I plan to make this smarter(backtracking, etc), but it works fine right now. It might also cut down on some redundant code, we'll see.
As it is, it generates small maps(15x10) almost instantly, medium(30x20) maps in a couple seconds, and large(40x30) in some random amount of time between 20 seconds and 20 minutes, depending on seed. It tests between 300k-500k maps/second on my machine, depending on size.
Side note: Sometimes the maps aren't too hard, simply because there are only as many rocks as steps, and unless the step takes you to a wall, most times there's only one option if you want to hit an actual rock. I'll fix that later by placing "random" rocks in safe spots after all the steps are drawn. Since nogo spots are already marked, that should be pretty simple. For now, just enjoy these examples:
Output showing different sizes/seeds:
$ java I 30 20 6851 $ java I 15 10 1 $ java I 15 10 65513
............................O. .......O....... ....O..........
.............................. ............... ...............
.............................. .........O..... .........O.....
..........O......O............ .............O. ..............O
...............O...........O.. ............... ...............
.............................. .......O....... .....O.O.......
.............................. O.............. ...............
........................O..... ............... ..........O....
.............................. ............... O..............
...O.......................O.. ......O........ ...............
O...............O.OO..........
..............O..........O....
...........O.................. T 14 R 6
....O......................... T 7 T 14
.............................. DLDLULURU LULDLDRURU
..............................
..............................
.................O............
.O............................
..............................
B 28
R 9
ULURDLDLDRURDLDRURUR
Max size 40x30:
$ java I 40 30 2
........................................
........................................
........................................
........................................
................O.......................
..........O.............................
........................................
.......O................................
.....................O..........O.......
......................O.................
.................................O......
......................................O.
........................................
........................................
..............................O.........
...........O............................
........................................
.......................................O
.........O...................O..........
....................O...................
...............................O........
............O..O......................O.
......O...........O.....................
..................O....O................
..................................O.....
........................................
..............................O.........
.....................................O..
...........O............................
...................O....................
B 19
B 11
URURDLULULDRDRDLULDLDLULURDLD
Golfed:
import java.util.*;import java.awt.*;class I{int m,n,p,g,a[][],b[][];Random r;Point s,e,c;ArrayList<Integer>z;void Q(String q,int l){if(l>0)System.out.println(q);else System.out.print(q);}void G(String[]y){m=Integer.valueOf(y[0]);n=Integer.valueOf(y[1]);p=Integer.valueOf(y[2]);r=new Random(p);Q("",1);int o=0,i,j,u=0;char t,f[]={85,76,68,82};while(o<3){if(++u%20000==0)Q("\r#"+u,0);a=new int[m+2][n+2];b=new int[m+2][n+2];for(i=0;i<m+2;i++)for(j=0;j<n+2;j++)if(i==0||i==m+1||j==0||j==n+1)a[i][j]=2;s=new Point();int e=r.nextInt(m*2+n*2);if(e<m*2){s.x=e%m+1;s.y=e<m?0:n+1;}else{s.y=(e-m*2)%n+1;s.x=(e-m*2)<n?0:m+1;}if(s.x<1)g=3;else if(s.x>m)g=1;else if(s.y<1)g=2;else if(s.y>n)g=0;a[s.x][s.y]=0;c=new Point(s);z=new ArrayList<Integer>();z.add(g);for(i=0;i++<Math.min(m,n)-1;)if(N()<1&&N()<1)break;o=((z.size()>=Math.min(m,n)-1)?1:0)+F()+((V()==z.size())?1:0);}Q("\r",0);for(j=1;j<n+1;j++){for(i=1;i<m+1;i++)Q(String.valueOf(a[i][j]>0?'O':'.'),0);Q("",1);}Q("\n\n",0);if(s.x<1||s.x>m){t=s.x<1?'L':'R';u=s.y;}else{t=s.y<1?'T':'B';u=s.x;}Q(t+" "+u,1);if(e.x<1||e.x>m){t=e.x<1?'L':'R';u=e.y;}else{t=e.y<1?'T':'B';u=e.x;}Q(t+" "+u,1);for(i=0;i<z.size();)Q(String.valueOf(f[z.get(i++)]),0);Q("",1);}public static void main(String[]a){new I().G(a);}int F(){int c=0;while(C()<1&&c++<10)if(N()<1)return 0;return e==null?0:1;}int C(){int d=g<2?-1:1;if(g%2<1){int y=c.y;while(y>0&&y<n+1){y+=d;if(a[c.x][y]==1)return 0;}e=new Point(c.x,y);}else{int x=c.x;while(x>0&&x<m+1){x+=d;if(a[x][c.y]==1)return 0;}e=new Point(x,c.y);}a[e.x][e.y]=0;return 1;}int V(){if((s.x-e.x)+(s.y-e.y)<2)return 0;Queue<Point>q=new ArrayDeque<Point>();Queue<Integer>d=new ArrayDeque<Integer>();a[s.x][s.y]=-2;q.add(s);d.add(0);while(q.size()>0){Point t=q.poll();int h=d.poll(),i=0;if(t.equals(e))return h;for(;i<4;i++){Point n=S(a,t,i<2?0:1,i%2<1?-1:1,99,1);if(a[n.x][n.y]==-2)continue;a[n.x][n.y]=-2;q.add(n);d.add(h+1);}}return 0;}int N(){Point q;int d=g<2?-1:1,x,y;System.arraycopy(a,0,b,0,a.length);q=S(b,c,g,d,r.nextInt((g%2<1?n:m)/2)+2,0);if(q.x<1||q.y<1||q.x>m||q.y>n||q.equals(c)||b[q.x][q.y]!=0)return 0;x=q.x;y=q.y;if(g%2<1)y+=d;else x+=d;if(b[x][y]<0)return 0;b[q.x][q.y]=-1;b[x][y]=1;int f=r.nextInt(2)<1?-1:1;g=g%2<1?(f<0?1:3):(g=f<0?0:2);c=q;System.arraycopy(b,0,a,0,a.length);z.add(g);return 1;}Point S(int[][]u,Point f,int w,int d,int q,int s){int i=1,x=f.x,y=f.y;for(;i<=q;i++){if(w%2<1)y=f.y+i*d;else x=f.x+i*d;if(e!=null&&e.x==x&&e.y==y)return e;if(y<0||y>n+1||x<0||x>m+1)return f;if(s<1&&u[x][y]<1)u[x][y]=-1;if(u[x][y]>0){if(w%2<1)y-=d;else x-=d;return new Point(x,y);}}if(w%2<1)return new Point(f.x,f.y+i*d);else return new Point(f.x+i*d,f.y);}}
With line breaks:
import java.util.*;
import java.awt.*;
class I{
int m,n,p,g,a[][],b[][];
Random r;
Point s,e,c;
ArrayList<Integer>z;
void Q(String q,int l){if(l>0)System.out.println(q);else System.out.print(q);}
void G(String[]y){
m=Integer.valueOf(y[0]);
n=Integer.valueOf(y[1]);
p=Integer.valueOf(y[2]);
r=new Random(p);
Q("",1);
int o=0,i,j,u=0;
char t,f[]={85,76,68,82};
while(o<3){
if(++u%20000==0)
Q("\r#"+u,0);
a=new int[m+2][n+2];
b=new int[m+2][n+2];
for(i=0;i<m+2;i++)
for(j=0;j<n+2;j++)
if(i==0||i==m+1||j==0||j==n+1)
a[i][j]=2;
s=new Point();
int e=r.nextInt(m*2+n*2);
if(e<m*2){
s.x=e%m+1;
s.y=e<m?0:n+1;
}else{
s.y=(e-m*2)%n+1;
s.x=(e-m*2)<n?0:m+1;
}
if(s.x<1)g=3;
else if(s.x>m)g=1;
else if(s.y<1)g=2;
else if(s.y>n)g=0;
a[s.x][s.y]=0;
c=new Point(s);
z=new ArrayList<Integer>();
z.add(g);
for(i=0;i++<Math.min(m,n)-1;)
if(N()<1&&N()<1)
break;
o=((z.size()>=Math.min(m,n)-1)?1:0)+F()+((V()==z.size())?1:0);
}
Q("\r",0);
for(j=1;j<n+1;j++){
for(i=1;i<m+1;i++)
Q(String.valueOf(a[i][j]>0?'O':'.'),0);
Q("",1);
}
Q("\n\n",0);
if(s.x<1||s.x>m){
t=s.x<1?'L':'R';
u=s.y;
}else{
t=s.y<1?'T':'B';
u=s.x;
}
Q(t+" "+u,1);
if(e.x<1||e.x>m){
t=e.x<1?'L':'R';
u=e.y;
} else {
t=e.y<1?'T':'B';
u=e.x;
}
Q(t+" "+u,1);
for(i=0;i<z.size();)
Q(String.valueOf(f[z.get(i++)]),0);
Q("",1);
}
public static void main(String[]a){
new I().G(a);
}
int F(){
int c=0;
while(C()<1&&c++<10)
if(N()<1)
return 0;
return e==null?0:1;
}
int C(){
int d=g<2?-1:1;
if(g%2<1){
int y=c.y;
while(y>0&&y<n+1){
y+=d;
if(a[c.x][y]==1)
return 0;
}
e=new Point(c.x,y);
}else{
int x=c.x;
while(x>0&&x<m+1){
x+=d;
if(a[x][c.y]==1)
return 0;
}
e=new Point(x,c.y);
}
a[e.x][e.y]=0;
return 1;
}
int V(){
if((s.x-e.x)+(s.y-e.y)<2)
return 0;
Queue<Point>q=new ArrayDeque<Point>();
Queue<Integer>d=new ArrayDeque<Integer>();
a[s.x][s.y]=-2;
q.add(s);
d.add(0);
while(q.size()>0){
Point t=q.poll();
int h=d.poll(),i=0;
if(t.equals(e))
return h;
for(;i<4;i++){
Point n=S(a,t,i<2?0:1,i%2<1?-1:1,99,1);
if(a[n.x][n.y]==-2)
continue;
a[n.x][n.y]=-2;
q.add(n);d.add(h+1);
}
}
return 0;
}
int N(){
Point q;
int d=g<2?-1:1,x,y;
System.arraycopy(a,0,b,0,a.length);
q=S(b,c,g,d,r.nextInt((g%2<1?n:m)/2)+2,0);
if(q.x<1||q.y<1||q.x>m||q.y>n||q.equals(c)||b[q.x][q.y]!=0)
return 0;
x=q.x;
y=q.y;
if(g%2<1)
y+=d;
else
x+=d;
if(b[x][y]<0)
return 0;
b[q.x][q.y]=-1;
b[x][y]=1;
int f=r.nextInt(2)<1?-1:1;
g=g%2<1?(f<0?1:3):(g=f<0?0:2);
c=q;
System.arraycopy(b,0,a,0,a.length);
z.add(g);
return 1;
}
Point S(int[][]u,Point f,int w,int d,int q,int s){
int i=1,x=f.x,y=f.y;
for(;i<=q;i++){
if(w%2<1)
y=f.y+i*d;
else
x=f.x+i*d;
if(e!=null&&e.x==x&&e.y==y)
return e;
if(y<0||y>n+1||x<0||x>m+1)
return f;
if(s<1&&u[x][y]<1)
u[x][y]=-1;
if(u[x][y]>0){
if(w%2<1)
y-=d;
else
x-=d;
return new Point(x,y);
}
}
if(w%2<1)
return new Point(f.x,f.y+i*d);
else
return new Point(f.x+i*d,f.y);
}
}
>
and<
(or any character) for the enter and the exit? The puzzles will be easier to read. \$\endgroup\$LDLDRULD
which is only 8 steps long \$\endgroup\$