Differences From Artifact [e22cb888fb6353ea]:
- File
src/solver.d
- 2012-07-14 13:02:03 - part of checkin [b4aceba693] on branch trunk - 1 step death move detector rev.1 (user: kinaba) [annotate]
To Artifact [6098061a6d0ff01b]:
- File
src/solver.d
- 2012-07-14 13:21:56 - part of checkin [5fc8a9c49b] on branch trunk - rock pusher. (user: kinaba) [annotate]
74 74 else
75 75 g_wc = 0;
76 76 return c;
77 77 }
78 78
79 79 Tuple!(char,int) search(in Game g, in Pos s, in Pos o, string death)
80 80 {
81 + // avoid directly below '*'
81 82 const(Pos)[] q = [o];
82 83 bool[][] v = new bool[][](g.map.H+2, g.map.W+2);
84 + v[o.y][o.x]=true;
83 85 for(int step=1; q.length; ++step) {
84 86 Pos[] q2;
85 87 foreach(p; q) {
86 88 int[] dy=[-1,+1,0,0];
87 89 int[] dx=[0,0,-1,+1];
88 90 for(int i=0; i<4; ++i) {
89 91 int y = p.y+dy[i];
................................................................................
100 102 q2 ~= new Pos(y,x);
101 103 v[y][x]=true;
102 104 }
103 105 }
104 106 }
105 107 q = q2;
106 108 }
109 +
110 + // any empty space is my ground
107 111 q = [o];
108 112 v = new bool[][](g.map.H+2, g.map.W+2);
113 + v[o.y][o.x]=true;
109 114 for(int step=1000; q.length; ++step) {
110 115 Pos[] q2;
111 116 foreach(p; q) {
112 117 int[] dy=[-1,+1,0,0];
113 118 int[] dx=[0,0,-1,+1];
114 119 for(int i=0; i<4; ++i) {
115 120 int y = p.y+dy[i];
................................................................................
123 128 q2 ~= new Pos(y,x);
124 129 v[y][x]=true;
125 130 } else if(g.map[y,x]=='.'/* && g[y-1,x]!='*'*/) {
126 131 q2 ~= new Pos(y,x);
127 132 v[y][x]=true;
128 133 }
129 134 }
135 + }
136 + q = q2;
137 + }
138 +
139 + // push rocks!
140 + q = [o];
141 + v = new bool[][](g.map.H+2, g.map.W+2);
142 + v[o.y][o.x]=true;
143 + for(int step=2000; q.length; ++step) {
144 + Pos[] q2;
145 + foreach(p; q) {
146 + int[] dy=[-1,+1,0,0];
147 + int[] dx=[0,0,-1,+1];
148 + for(int i=0; i<4; ++i) {
149 + int y = p.y+dy[i];
150 + int x = p.x+dx[i];
151 + if(v[y][x]) continue;
152 + if(y==s.y && x==s.x) {
153 + char c = "UDRL"[i];
154 + if( death.count(c) == 0 )
155 + return tuple(c,step);
156 + } else if(g.map[y,x]==' '||g.map[y,x]=='\\') {
157 + q2 ~= new Pos(y,x);
158 + v[y][x]=true;
159 + } else if(g.map[y,x]=='.'/* && g[y-1,x]!='*'*/) {
160 + q2 ~= new Pos(y,x);
161 + v[y][x]=true;
162 + } else if(dy[i]==0 && g.map[y,x]=='*' && (g.map[y+dy[i],x+dx[i]]==' '||g.map[y+dy[i],x+dx[i]]=='R')) {
163 + q2 ~= new Pos(y,x);
164 + v[y][x]=true;
165 + }
166 + }
130 167 }
131 168 q = q2;
132 169 }
133 170 return tuple('W', int.max);
134 171 }
135 172 }