Differences From Artifact [accda2201a6a857e]:
- File        
src/solver.d
- 2012-07-16 08:06:06 - part of checkin [3893826f55] on branch trunk - dangerness loosened. (user: kinaba) [annotate]
 
To Artifact [da568e3b806540de]:
- File        
src/solver.d
- 2012-07-16 08:59:54 - part of checkin [9e34cad783] on branch trunk - One-way road finder. (user: kinaba) [annotate]
 
  162          }                                                                            162          }
  163                                                                                       163  
  164          Tuple!(Pos, int)[] log;                                                      164          Tuple!(Pos, int)[] log;
  165          bool[][] forbidden_cell;                                                     165          bool[][] forbidden_cell;
  166                                                                                       166  
  167          char act(const(Game) g, string death, int breath)                            167          char act(const(Game) g, string death, int breath)
  168          {                                                                            168          {
                                                                                        >   169                  foreach(char c; "UDLR")
                                                                                        >   170                          if( death.count(c)==0 && is_one_way_load(g,c) )
                                                                                        >   171                                  return c;
                                                                                        >   172  
  169                  const Pos    ro = g.map.robot;                                       173                  const Pos    ro = g.map.robot;
  170                  const Pos    li = g.map.lift;                                        174                  const Pos    li = g.map.lift;
  171                  Pos[] la = g.map.lambdas();                                          175                  Pos[] la = g.map.lambdas();
  172                  sort!((Pos a,Pos b){                                                 176                  sort!((Pos a,Pos b){
  173                          int ad=abs(a.y-li.y)+abs(a.x-li.x);                          177                          int ad=abs(a.y-li.y)+abs(a.x-li.x);
  174                          int bd=abs(b.y-li.y)+abs(b.x-li.x);                          178                          int bd=abs(b.y-li.y)+abs(b.x-li.x);
  175                          return ad>bd;;                                               179                          return ad>bd;;
................................................................................................................................................................................
  448                                  first_step = false;                                  452                                  first_step = false;
  449                                  q = q2;                                              453                                  q = q2;
  450                          }                                                            454                          }
  451                          return [];                                                   455                          return [];
  452                  }                                                                    456                  }
  453                  return (danger_ok ? [] : tryA()) ~ tryB() ~ tryC();                  457                  return (danger_ok ? [] : tryA()) ~ tryB() ~ tryC();
  454          }                                                                            458          }
                                                                                        >   459  
                                                                                        >   460          bool is_one_way_load(in Game g, char c)
                                                                                        >   461          {
                                                                                        >   462                  Pos p = g.map.robot.clone();
                                                                                        >   463                  Pos q;
                                                                                        >   464                  if(c=='U') q=new Pos(p.y+1,p.x);
                                                                                        >   465                  if(c=='D') q=new Pos(p.y-1,p.x);
                                                                                        >   466                  if(c=='L') q=new Pos(p.y,p.x-1);
                                                                                        >   467                  if(c=='R') q=new Pos(p.y,p.x+1);
                                                                                        >   468                  char d = g.map[q];
                                                                                        >   469                  if(!(d==' '||d=='.'||d=='!'))
                                                                                        >   470                          return false;
                                                                                        >   471  
                                                                                        >   472                  bool found_lambda = false;
                                                                                        >   473                  int[4] dy=[-1,+1,0,0];
                                                                                        >   474                  int[4] dx=[0,0,+1,-1];
                                                                                        >   475                  for(;;)
                                                                                        >   476                  {
                                                                                        >   477                          Pos r = null;
                                                                                        >   478                          for(int i=0; i<4; ++i) {
                                                                                        >   479                                  int y=q.y+dy[i];
                                                                                        >   480                                  int x=q.x+dx[i];
                                                                                        >   481                                  if(x==p.x && y==p.y)
                                                                                        >   482                                          continue;
                                                                                        >   483                                  char e = g.map[y,x];
                                                                                        >   484                                  if(e=='#')
                                                                                        >   485                                          continue;
                                                                                        >   486                                  if(e==' '||e=='.'||e=='!'||e=='R'||e=='\\') {
                                                                                        >   487                                          if(r !is null)
                                                                                        >   488                                                  return false;
                                                                                        >   489                                          r = new Pos(y,x);
                                                                                        >   490                                          if(e=='\\')
                                                                                        >   491                                                  found_lambda = true;
                                                                                        >   492                                          continue;
                                                                                        >   493                                  }
                                                                                        >   494                                  return false;
                                                                                        >   495                          }
                                                                                        >   496                          if(r is null)
                                                                                        >   497                                  break;
                                                                                        >   498                          p=q;
                                                                                        >   499                          q=r;
                                                                                        >   500                  }
                                                                                        >   501                  return found_lambda;
                                                                                        >   502          }
  455  }                                                                                    503  }
  456                                                                                       504  
  457  ///                                                                                  505  ///
  458  /// Solver "Fire": in raiding and plundering other solvers, be like fire.            506  /// Solver "Fire": in raiding and plundering other solvers, be like fire.
  459  ///                                                                                  507  ///
  460  class 侵掠如火(SubSolver) : Solver                                                       508  class 侵掠如火(SubSolver) : Solver
  461  {                                                                                    509  {
................................................................................................................................................................................
  759                                                                                       807  
  760          private Solver sub_solver;                                                   808          private Solver sub_solver;
  761  }                                                                                    809  }
  762                                                                                       810  
  763  alias 侵掠如火!(疾如風!(false)) FastSolver;                                                 811  alias 侵掠如火!(疾如風!(false)) FastSolver;
  764                                                                                       812  
  765  alias Switcher MainSolver;                                                           813  alias Switcher MainSolver;
  766  //alias 侵掠如火!(徐如林) MainSolver;                                                   |   814  //alias 徐如林 MainSolver;