Diff
Not logged in

Differences From Artifact [403db28cbc4609b7]:

To Artifact [074b8ae4c20c37c4]:


142 this.waterproof = m.waterproof; 142 this.waterproof = m.waterproof; 143 this.tr_target = cast(Pos[char])m.tr_target; 143 this.tr_target = cast(Pos[char])m.tr_target; 144 this.tr_source = cast(Pos[][char])m.tr_source; 144 this.tr_source = cast(Pos[][char])m.tr_source; 145 this.hige = m.hige.clone(); 145 this.hige = m.hige.clone(); 146 this.razor = m.razor; 146 this.razor = m.razor; 147 this.collected_lambda = m.collected_lambda; 147 this.collected_lambda = m.collected_lambda; 148 this.total_lambda = m.total_lambda; 148 this.total_lambda = m.total_lambda; > 149 this.may_update = (cast(Map)m).may_update.dup; 149 } 150 } 150 151 151 this(string[] raw_data, string[string] params, char[char] trampo) 152 this(string[] raw_data, string[string] params, char[char] trampo) 152 { 153 { 153 int width = 0; 154 int width = 0; 154 foreach(r; raw_data) 155 foreach(r; raw_data) 155 width = max(width, r.length); 156 width = max(width, r.length); ................................................................................................................................................................................ 163 for(int x=1; x<=W; ++x) { 164 for(int x=1; x<=W; ++x) { 164 if(this[y,x] == 'R') 165 if(this[y,x] == 'R') 165 this.robot = new Pos(y,x); 166 this.robot = new Pos(y,x); 166 if(this[y,x] == 'L' || this[y,x] == 'O') 167 if(this[y,x] == 'L' || this[y,x] == 'O') 167 this.lift = new Pos(y,x); 168 this.lift = new Pos(y,x); 168 if(this[y,x] == '\\' || this[y,x] == '@') 169 if(this[y,x] == '\\' || this[y,x] == '@') 169 total_lambda++; 170 total_lambda++; > 171 if(this[y,x] == '*' || this[y,x] == '@') > 172 may_update ~= new Pos(y,x); 170 } 173 } 171 174 172 Pos[char] tr_pos; 175 Pos[char] tr_pos; 173 for(int y=1; y<=H; ++y) 176 for(int y=1; y<=H; ++y) 174 for(int x=1; x<=W; ++x) { 177 for(int x=1; x<=W; ++x) { 175 char c = this[y,x]; 178 char c = this[y,x]; 176 if('1'<=c && c<='9' || 'A'<=c&&c<='I') 179 if('1'<=c && c<='9' || 'A'<=c&&c<='I') ................................................................................................................................................................................ 266 this[robot.y+dy,robot.x+dx] = ' '; 269 this[robot.y+dy,robot.x+dx] = ' '; 267 } 270 } 268 271 269 return update(turn); 272 return update(turn); 270 } 273 } 271 274 272 bool rocky(char c) { return c=='*' || c=='@'; } 275 bool rocky(char c) { return c=='*' || c=='@'; } > 276 Pos[] may_update; > 277 void emptified(Pos p) { > 278 for(int dy=0; dy<=+1; ++dy) > 279 for(int dx=-1; dx<=+1; ++dx) > 280 may_update ~= new Pos(p.y+dy, p.x+dx); > 281 } 273 282 274 bool move(int dy, int dx, int turn) 283 bool move(int dy, int dx, int turn) 275 { 284 { > 285 > 286 emptified(robot); > 287 276 int y = robot.y; 288 int y = robot.y; 277 int x = robot.x; 289 int x = robot.x; 278 if( '\\' == this[y+dy,x+dx] ) 290 if( '\\' == this[y+dy,x+dx] ) 279 collected_lambda++; 291 collected_lambda++; 280 if( '!' == this[y+dy,x+dx] ) 292 if( '!' == this[y+dy,x+dx] ) 281 razor++; 293 razor++; 282 if( " \\!.O".count(this[y+dy,x+dx])==1 ) { 294 if( " \\!.O".count(this[y+dy,x+dx])==1 ) { ................................................................................................................................................................................ 288 this[y,x]=' '; 300 this[y,x]=' '; 289 this[y+dy,x+dx]='R'; 301 this[y+dy,x+dx]='R'; 290 this[y+dy*2,x+dx*2]=rock; 302 this[y+dy*2,x+dx*2]=rock; 291 robot = new Pos(y+dy,x+dx); 303 robot = new Pos(y+dy,x+dx); 292 } else if('A'<=this[y+dy,x+dx] && this[y+dy,x+dx]<='I') { 304 } else if('A'<=this[y+dy,x+dx] && this[y+dy,x+dx]<='I') { 293 this[y,x]=' '; 305 this[y,x]=' '; 294 Pos tp = tr_target[this[y+dy,x+dx]]; 306 Pos tp = tr_target[this[y+dy,x+dx]]; 295 foreach(p; tr_source[this[tp]]) | 307 foreach(p; tr_source[this[tp]]) { > 308 emptified(p); 296 this[p] = ' '; 309 this[p] = ' '; > 310 } 297 this[tp] = 'R'; 311 this[tp] = 'R'; 298 robot = tp; 312 robot = tp; 299 } 313 } 300 return update(turn); 314 return update(turn); 301 } 315 } 302 316 303 bool update(int turn) 317 bool update(int turn) 304 { 318 { > 319 // Write after all the updates are processed. > 320 Tuple!(int,int,char)[] write_buffer; > 321 void write(int y, int x, char c) { write_buffer ~= tuple(y,x,c); > 322 void writep(Pos p, char c) { write_buffer ~= tuple(0+p.y,0+p.x,c > 323 scope(exit) { > 324 may_update.length = 0; > 325 foreach(wr; write_buffer) { > 326 this[wr[0],wr[1]] = wr[2]; > 327 if(rocky(wr[2])) > 328 may_update ~= new Pos(wr[0],wr[1]); > 329 if(wr[2]==' ') > 330 emptified(new Pos(wr[0], wr[1])); > 331 } > 332 } > 333 > 334 if(collected_lambda == total_lambda) > 335 if(this[lift]=='L') > 336 this[lift] = 'O'; > 337 305 bool dead = false; 338 bool dead = false; 306 < 307 char[][] next; < > 339 sort(may_update); 308 foreach(y,s; data) | 340 foreach(p; may_update) { 309 next ~= s.dup; < 310 < 311 ref char access(Pos p) { return next[H-p.y][p.x-1]; } < 312 < 313 for(int y=1; y<=H; ++y) < 314 for(int x=1; x<=W; ++x) { < 315 Pos p = new Pos(y,x); < > 341 int y = p.y, x = p.x; 316 char rock = this[p]; 342 char rock = this[p]; 317 if(rocky(this[p])) { 343 if(rocky(this[p])) { 318 if(this[p.D]==' ') { 344 if(this[p.D]==' ') { 319 access(p) =' '; | 345 writep(p, ' '); 320 access(p.D)=(rock=='@'&&this[p.D.D]!=' ' | 346 writep(p.D, (rock=='@'&&this[p.D.D]!=' ' 321 if(robot == p.D.D) 347 if(robot == p.D.D) 322 dead=true; 348 dead=true; 323 } 349 } 324 else if((rocky(this[p.D]) || this[p.D]=='\\') && 350 else if((rocky(this[p.D]) || this[p.D]=='\\') && 325 access(p)=' '; | 351 writep(p, ' '); 326 access(p.R.D)=(rock=='@'&&this[p.R.D.D]! | 352 writep(p.R.D,(rock=='@'&&this[p.R.D.D]!= 327 if(robot == p.R.D.D) 353 if(robot == p.R.D.D) 328 dead=true; 354 dead=true; 329 } 355 } 330 else if(rocky(this[p.D]) && this[p.L]==' ' && th 356 else if(rocky(this[p.D]) && this[p.L]==' ' && th 331 access(p)=' '; | 357 writep(p, ' '); 332 access(p.L.D)=(rock=='@'&&this[p.L.D.D]! | 358 writep(p.L.D, (rock=='@'&&this[p.L.D.D]! 333 if(robot == p.L.D.D) 359 if(robot == p.L.D.D) 334 dead=true; 360 dead=true; 335 } 361 } 336 } 362 } 337 else if(this[p]=='L') { < 338 if(collected_lambda == total_lambda) < 339 access(p) = 'O'; < 340 } < 341 else if(this[p]=='W') { 363 else if(this[p]=='W') { 342 if( hige.is_growing_turn(turn) ) 364 if( hige.is_growing_turn(turn) ) 343 for(int dy=-1; dy<=+1; ++dy) 365 for(int dy=-1; dy<=+1; ++dy) 344 for(int dx=-1; dx<=+1; ++dx) 366 for(int dx=-1; dx<=+1; ++dx) 345 if(this[p.y+dy,p.x+dx] == ' ') 367 if(this[p.y+dy,p.x+dx] == ' ') 346 access(new Pos(p.y+dy,p. | 368 write(p.y+dy,p.x+dx,'W') 347 } 369 } 348 } 370 } 349 data = next; < 350 return dead; 371 return dead; 351 } 372 } 352 } 373 } 353 374 354 //////////////////////////////////////////////////////////////////////////////// 375 //////////////////////////////////////////////////////////////////////////////// 355 376 356 class Game 377 class Game