Differences From Artifact [393baf841678f948]:
- File        
src/solver.d
- 2012-07-15 07:11:41 - part of checkin [e8aa141dbe] on branch trunk - Make manual GUI operation faster for Solver2 by delaying plan making. (user: kinaba) [annotate]
 - 2012-07-15 12:14:10 - part of checkin [e02668367d] on branch trunk - Revert redesign in the trunk. (user: kinaba) [annotate]
 
 
To Artifact [8629f9c48aba56fd]:
- File        
src/solver.d
- 2012-07-15 12:40:58 - part of checkin [c88611bab8] on branch trunk - horock solver (user: kinaba) [annotate]
 
 
    1  import util;                                                                           1  import util;
    2  import game;                                                                           2  import game;
    3                                                                                         3  
                                                                                        >     4  bool rocky(char c){ return c=='*'||c=='@'; }
                                                                                        >     5  
    4  class Solver_0                                                                         6  class Solver_0
    5  {                                                                                      7  {
    6          this(in Game g) {}                                                             8          this(in Game g) {}
    7          char single_step() { return 'W'; }                                             9          char single_step() { return 'W'; }
    8          void force(char c) {}                                                         10          void force(char c) {}
    9  }                                                                                     11  }
   10                                                                                        12  
................................................................................................................................................................................
  104                                                                                       106  
  105                  // 'dig' mode                                                        107                  // 'dig' mode
  106                  if(cand.empty) {                                                     108                  if(cand.empty) {
  107                          const(Pos)[] tgt;                                            109                          const(Pos)[] tgt;
  108                          for(int y=1; y<=g.map.H; ++y)                                110                          for(int y=1; y<=g.map.H; ++y)
  109                          for(int x=1; x<=g.map.W; ++x)                                111                          for(int x=1; x<=g.map.W; ++x)
  110                                  if(g.map[y,x]=='.')                                  112                                  if(g.map[y,x]=='.')
  111                                          if(g.map[y+1,x]=='*'||g.map[y+1,x-1]=='* |   113                                          if(rocky(g.map[y+1,x])||rocky(g.map[y+1,
  112                                           ||g.map[y,x+1]=='*'||g.map[y,x-1]=='*') |   114                                           ||rocky(g.map[y,x+1])||rocky(g.map[y,x-
  113                                                  tgt ~= new Pos(y,x);                 115                                                  tgt ~= new Pos(y,x);
  114                          cand ~= search(g, ro, tgt, death, true);                     116                          cand ~= search(g, ro, tgt, death, true);
  115                  }                                                                    117                  }
  116                                                                                       118  
  117                  if(cand.empty) {                                                     119                  if(cand.empty) {
  118                          choke_count++;                                               120                          choke_count++;
  119                          cand ~= tuple('W',int.max);                                  121                          cand ~= tuple('W',int.max);
................................................................................................................................................................................
  159                                                                                       161  
  160          Tuple!(char,int)[] search(in Game g, in Pos s, in Pos[] gs, string death     162          Tuple!(char,int)[] search(in Game g, in Pos s, in Pos[] gs, string death
  161          {                                                                            163          {
  162                  bool danger(int y, int x)                                            164                  bool danger(int y, int x)
  163                  {                                                                    165                  {
  164                          if(g.map[y,x] == ' ' || g.map[y,x] == 'R')                   166                          if(g.map[y,x] == ' ' || g.map[y,x] == 'R')
  165                                  return false;                                        167                                  return false;
  166                          if(g.map[y+1,x] == '*')                                  |   168                          if(rocky(g.map[y+1,x]))
                                                                                        >   169                                  return true;
                                                                                        >   170                          if(rocky(g.map[y+1,x-1]) && (g.map[y,x-1]=='\\'||rocky(g
  167                                  return true;                                         171                                  return true;
  168                          if(g.map[y+1,x-1]=='*' && (g.map[y,x-1]=='\\'||g.map[y,x |   172                          if(rocky(g.map[y+1,x+1]) && rocky(g.map[y,x+1]) && (g.ma
  169                                  return true;                                         173                                  return true;
  170                          if(g.map[y+1,x+1]=='*' && (g.map[y,x+1]=='*') && (g.map[ |   174                          if(rocky(g.map[y,x-1]) && (g.map[y-1,x-1]=='\\'||rocky(g
  171                                  return true;                                         175                                  return true;
  172                          if(g.map[y,x-1]=='*' && (g.map[y-1,x-1]=='\\'||g.map[y-1 <
  173                                  return true;                                     <
  174                          if(g.map[y,x+1]=='*' && (g.map[y-1,x+1]=='*') && (g.map[ |   176                          if(rocky(g.map[y,x+1]) && rocky(g.map[y-1,x+1]) && (g.ma
  175                                  return true;                                         177                                  return true;
  176                          return false;                                                178                          return false;
  177                  }                                                                    179                  }
  178                                                                                       180  
  179                  // avoid directly below '*'                                          181                  // avoid directly below '*'
  180                  Tuple!(char,int)[] tryA() {                                          182                  Tuple!(char,int)[] tryA() {
  181                          const(Pos)[] q;                                              183                          const(Pos)[] q;
................................................................................................................................................................................
  266                                  Pos[] q2;                                            268                                  Pos[] q2;
  267                                  foreach(p; q) {                                      269                                  foreach(p; q) {
  268                                          int[] yyy=[p.y-1,p.y+1,p.y,p.y];             270                                          int[] yyy=[p.y-1,p.y+1,p.y,p.y];
  269                                          int[] xxx=[p.x,p.x,p.x-1,p.x+1];             271                                          int[] xxx=[p.x,p.x,p.x-1,p.x+1];
  270                                          for(int i=0; i<yyy.length; ++i) {            272                                          for(int i=0; i<yyy.length; ++i) {
  271                                                  int y = yyy[i];                      273                                                  int y = yyy[i];
  272                                                  int x = xxx[i];                      274                                                  int x = xxx[i];
  273                                                  if(g.map[p] == '*') {            |   275                                                  if(rocky(g.map[p])) {
  274                                                          if(i>=4)continue;            276                                                          if(i>=4)continue;
  275                                                          if(y!=p.y)continue;          277                                                          if(y!=p.y)continue;
  276                                                          if(g.map[y,p.x+(p.x-x)]!     278                                                          if(g.map[y,p.x+(p.x-x)]!
  277                                                  }                                    279                                                  }
  278                                                  if('1'<=g.map[y,x]&&g.map[y,x]<=     280                                                  if('1'<=g.map[y,x]&&g.map[y,x]<=
  279                                                          foreach(ppp; g.map.tr_so     281                                                          foreach(ppp; g.map.tr_so
  280                                                                  yyy ~= ppp.y;        282                                                                  yyy ~= ppp.y;
................................................................................................................................................................................
  284                                                  }                                    286                                                  }
  285                                                  if(v[y][x]) continue;                287                                                  if(v[y][x]) continue;
  286                                                  if(y==s.y && x==s.x && i<4) {        288                                                  if(y==s.y && x==s.x && i<4) {
  287                                                          char c = "UDRL"[i];          289                                                          char c = "UDRL"[i];
  288                                                          if( death.count(c) == 0      290                                                          if( death.count(c) == 0 
  289                                                                  return [tuple(c,     291                                                                  return [tuple(c,
  290                                                  } else if(forbidden_cell[y][x]){     292                                                  } else if(forbidden_cell[y][x]){
  291                                                  } else if(g.map[y,x]==' '||g.map |   293                                                  } else if(g.map[y,x]==' '||g.map
  292                                                          q2 ~= new Pos(y,x);          294                                                          q2 ~= new Pos(y,x);
  293                                                          v[y][x]=true;                295                                                          v[y][x]=true;
  294                                                  }                                    296                                                  }
  295                                          }                                            297                                          }
  296                                  }                                                    298                                  }
  297                                  q = q2;                                              299                                  q = q2;
  298                          }                                                            300                          }