Differences From Artifact [ee76621ab7188714]:
- File        
src/solver.d
- 2012-07-16 04:28:04 - part of checkin [e784787a7c] on branch trunk - Renamed solvers. (user: kinaba) [annotate]
 
To Artifact [cc3cdceae20eed85]:
- File        
src/solver.d
- 2012-07-16 04:36:50 - part of checkin [b4c948b5ca] on branch trunk - Death move avoider for Sovler-wind. (user: kinaba) [annotate]
 
  607          this(in Game g)                                                              607          this(in Game g)
  608          {                                                                            608          {
  609                  this.g = g.clone();                                                  609                  this.g = g.clone();
  610          }                                                                            610          }
  611                                                                                       611  
  612          char single_step()                                                           612          char single_step()
  613          {                                                                            613          {
                                                                                        >   614                  auto dm = death_move(g);
                                                                                        >   615  
  614                  char c = think(g);                                               |   616                  char c = think(g, dm[0]);
                                                                                        >   617                  if(c == 'W') {
                                                                                        >   618                          wait_counter++;
                                                                                        >   619                          if(dm[0].count(c) || wait_counter>=3) {
                                                                                        >   620                                  c = 'A';
                                                                                        >   621                                  foreach(char cc; "DLRU")
                                                                                        >   622                                          if(dm[0].count(cc) == 0)
                                                                                        >   623                                                  c = cc;
                                                                                        >   624                          }
                                                                                        >   625                          if(wait_counter > 20)
                                                                                        >   626                                  c = 'A';
                                                                                        >   627                  } else {
                                                                                        >   628                          wait_counter = 0;
                                                                                        >   629                  }
  615                  if(c != 'A')                                                         630                  if(c != 'A')
  616                          g.command(c);                                                631                          g.command(c);
  617                  return c;                                                            632                  return c;
  618          }                                                                            633          }
  619                                                                                       634  
  620          void force(char c)                                                           635          void force(char c)
  621          {                                                                            636          {
  622                  if(c != 'A')                                                         637                  if(c != 'A')
  623                          g.command(c);                                                638                          g.command(c);
  624          }                                                                            639          }
  625                                                                                       640  
  626          char think(in Game g)                                                    |   641          int wait_counter = 0;
  627          {                                                                        <
  628                                                                                       642  
                                                                                        >   643          char think(in Game g, string death)
                                                                                        >   644          {
  629                  auto Q = new Queue!(Tuple!(Pos,Pos));                                645                  auto Q = new Queue!(Tuple!(Pos,Pos));
  630                  Q.push(tuple(g.map.robot.clone(), g.map.robot.clone()), 0);          646                  Q.push(tuple(g.map.robot.clone(), g.map.robot.clone()), 0);
  631                  Pos[][] V = new Pos[][](g.map.H+2, g.map.W+2);                       647                  Pos[][] V = new Pos[][](g.map.H+2, g.map.W+2);
  632                  while(!Q.empty) {                                                    648                  while(!Q.empty) {
  633                          auto tup = Q.pop();                                          649                          auto tup = Q.pop();
  634                          Pos  p    = tup[0][0];                                       650                          Pos  p    = tup[0][0];
  635                          Pos  prev = tup[0][1];                                       651                          Pos  prev = tup[0][1];
................................................................................................................................................................................
  652                                          p=q;                                         668                                          p=q;
  653                                  }                                                    669                                  }
  654                          }                                                            670                          }
  655                                                                                       671  
  656                          int[4] dy=[-1,+1,0,0];                                       672                          int[4] dy=[-1,+1,0,0];
  657                          int[4] dx=[0,0,-1,+1];                                       673                          int[4] dx=[0,0,-1,+1];
  658                          char[] ds=['D','U','L','R'];                                 674                          char[] ds=['D','U','L','R'];
  659                          for(int i=0; i<4; ++i)                                   |   675                          for(int i=0; i<4; ++i) {
  660                          {                                                        <
                                                                                        >   676                                  if(g.map.robot==p && death.count(ds[i]))
                                                                                        >   677                                          continue;
  661                                  int y=p.y+dy[i], x=p.x+dx[i];                        678                                  int y=p.y+dy[i], x=p.x+dx[i];
  662                                  if((g.map[y,x]==' '||g.map[y,x]=='\\'||g.map[y,x     679                                  if((g.map[y,x]==' '||g.map[y,x]=='\\'||g.map[y,x
  663                                          Q.push(tuple(new Pos(y,x),p), dist+1);       680                                          Q.push(tuple(new Pos(y,x),p), dist+1);
  664                                  }                                                    681                                  }
  665                          }                                                            682                          }
  666                  }                                                                    683                  }
                                                                                        >   684  
  667                  return 'A';                                                      |   685                  return 'W';
  668          }                                                                            686          }
  669  }                                                                                    687  }
  670                                                                                       688  
  671  //alias 侵掠如火!(疾如風) MainSolver;                                                       689  //alias 侵掠如火!(疾如風) MainSolver;
  672  alias 侵掠如火!(徐如林) MainSolver;                                                     |   690  //alias 侵掠如火!(徐如林) MainSolver;
  673  //alias 疾如風 MainSolver;                                                          |   691  alias 疾如風 MainSolver;
  674  //alias 徐如林 MainSolver;                                                              692  //alias 徐如林 MainSolver;
  675  //alias 不動如山 MainSolver;                                                             693  //alias 不動如山 MainSolver;