Artifact 42db89cb5c63a7bd058af1a219926cfe8c85dbf3
1 import util;
2 import game;
3 import output;
4
5 int g_wc = 0;
6
7 void act(Game g)
8 {
9 Pos ro = g.map.robot;
10 Pos[] la = g.map.lambdas();
11 Pos li = g.map.lift;
12
13 char c = 'W';
14 if( la.empty ) {
15 auto r = search(g, ro, li);
16 c = r[0];
17 } else {
18 Tuple!(char,int)[] cand;
19 foreach(lam; la)
20 cand ~= search(g, ro, lam);
21 sort!((Tuple!(char,int) c1, Tuple!(char,int) c2){
22 if(c1[1] != c2[1])
23 return c1[1] < c2[1];
24 return c1[0] < c2[0];
25 })(cand);
26 c = cand[0][0];
27 }
28 if(c=='W') {
29 g_wc++;
30 if(g_wc > 10)
31 c = 'A';
32 }
33 else
34 g_wc = 0;
35 g.command(c);
36 }
37
38 Tuple!(char,int) search(Game g, Pos s, Pos o)
39 {
40 Pos[] q = [o];
41 bool[][] v = new bool[][](g.map.H+2, g.map.W+2);
42 for(int step=1; q.length; ++step) {
43 Pos[] q2;
44 foreach(p; q) {
45 int[] dy=[-1,+1,0,0];
46 int[] dx=[0,0,-1,+1];
47 for(int i=0; i<4; ++i) {
48 int y = p.y+dy[i];
49 int x = p.x+dx[i];
50 if(v[y][x]) continue;
51 if(y==s.y && x==s.x) {
52 if(i==0) return tuple('U',step);
53 if(i==1) return tuple('D',step);
54 if(i==2) return tuple('R',step);
55 if(i==3) return tuple('L',step);
56 } else if(g.map[y,x]==' '||g.map[y,x]=='\\') {
57 q2 ~= new Pos(y,x);
58 v[y][x]=true;
59 } else if(g.map[y,x]=='.' && g.map[y-1,x]!='*') {
60 q2 ~= new Pos(y,x);
61 v[y][x]=true;
62 }
63 }
64 }
65 q = q2;
66 }
67 q = [o];
68 v = new bool[][](g.map.H+2, g.map.W+2);
69 for(int step=1000; q.length; ++step) {
70 Pos[] q2;
71 foreach(p; q) {
72 int[] dy=[-1,+1,0,0];
73 int[] dx=[0,0,-1,+1];
74 for(int i=0; i<4; ++i) {
75 int y = p.y+dy[i];
76 int x = p.x+dx[i];
77 if(v[y][x]) continue;
78 if(y==s.y && x==s.x) {
79 if(i==0) return tuple('U',step);
80 if(i==1) return tuple('D',step);
81 if(i==2) return tuple('R',step);
82 if(i==3) return tuple('L',step);
83 } else if(g.map[y,x]==' '||g.map[y,x]=='\\') {
84 q2 ~= new Pos(y,x);
85 v[y][x]=true;
86 } else if(g.map[y,x]=='.'/* && g[y-1,x]!='*'*/) {
87 q2 ~= new Pos(y,x);
88 v[y][x]=true;
89 }
90 }
91 }
92 q = q2;
93 }
94 return tuple('W', int.max);
95 }
96
97 void main(string[] args)
98 {
99 auto g = Game.load(stdin);
100 g.set_output(new GuardedOutput(g));
101
102 while(!g.dead && !g.cleared)
103 act(g);
104 }