@@ -6,9 +6,9 @@ this(in Game g) {} char single_step() { return 'W'; } void force(char c) {} } -/* + class Solver_1 { int wait_count = 0; int choke_count = 0; @@ -16,9 +16,9 @@ Game g; this(in Game g) { this.g = g.clone(); - forbidden_cell = new bool[][](g.map.H+2, g.map.W+2); + forbidden_cell = new bool[][](g.H+2, g.W+2); } char single_step() { @@ -42,9 +42,9 @@ Game gg = g.clone(); gg.command(c); if( !gg.cleared && gg.dead ) death ~= c; - else if( gg.map.robot != g.map.robot ) + else if( gg.robot != g.robot ) choice++; else if( c != 'W' ) // meaningless move death ~= c; } @@ -55,18 +55,18 @@ bool[][] forbidden_cell; char act(const(Game) g, string death, int breath) { - const Pos ro = g.map.robot; - const Pos li = g.map.lift; - Pos[] la = g.map.lambdas(); + const Pos ro = g.robot; + const Pos li = g.lift; + Pos[] la = g.lambdas(); sort!((Pos a,Pos b){ int ad=abs(a.y-li.y)+abs(a.x-li.x); int bd=abs(b.y-li.y)+abs(b.x-li.x); return ad>bd;; })(la); - Pos[] ra = g.map.razors(); - const(Pos)[] hi = g.map.objects('W'); + Pos[] ra = g.razors(); + const(Pos)[] hi = g.higes(); Tuple!(char,int)[] cand; char c = 'W'; if( la.empty ) { @@ -75,26 +75,26 @@ cand ~= search(g, ro, la~ra, death); } // 'higesori' mode - if( !hi.empty && g.map.razor>0 ) { + if( !hi.empty && g.num_razor>0 ) { int his = 0; for(int dy=-1; dy<=+1; ++dy) for(int dx=-1; dx<=+1; ++dx) - if(g.map[ro.y+dy,ro.x+dx] == 'W') + if(g[ro.y+dy,ro.x+dx] == 'W') his++; if(his>=2 || his==hi.length) cand = [tuple('S',int.max)]; if(cand.empty) { const(Pos)[] tgt; - for(int y=1; y<=g.map.H; ++y) - for(int x=1; x<=g.map.W; ++x) - if(g.map[y,x]=='.'||g.map[y,x]==' ') { + for(int y=1; y<=g.H; ++y) + for(int x=1; x<=g.W; ++x) + if(g[y,x]=='.'||g[y,x]==' ') { his = 0; for(int dy=-1; dy<=+1; ++dy) for(int dx=-1; dx<=+1; ++dx) - if(g.map[y+dy,x+dx] == 'W') + if(g[y+dy,x+dx] == 'W') his++; if(his>=2) tgt ~= new Pos(y,x); } @@ -104,13 +104,13 @@ // 'dig' mode if(cand.empty) { const(Pos)[] tgt; - for(int y=1; y<=g.map.H; ++y) - for(int x=1; x<=g.map.W; ++x) - if(g.map[y,x]=='.') - if(g.map[y+1,x]=='*'||g.map[y+1,x-1]=='*'||g.map[y+1,x+1]=='*' - ||g.map[y,x+1]=='*'||g.map[y,x-1]=='*') + for(int y=1; y<=g.H; ++y) + for(int x=1; x<=g.W; ++x) + if(g[y,x]=='.') + if(g[y+1,x]=='*'||g[y+1,x-1]=='*'||g[y+1,x+1]=='*' + ||g[y,x+1]=='*'||g[y,x-1]=='*') tgt ~= new Pos(y,x); cand ~= search(g, ro, tgt, death, true); } @@ -136,9 +136,9 @@ if(c == 'W') wait_count++; else wait_count = 0; - if(choke_count >= g.map.H) + if(choke_count >= g.H) c = 'A'; bool[char] choice; foreach(t; cand) @@ -160,19 +160,19 @@ Tuple!(char,int)[] search(in Game g, in Pos s, in Pos[] gs, string death, bool danger_ok=false) { bool danger(int y, int x) { - if(g.map[y,x] == ' ' || g.map[y,x] == 'R') + if(g[y,x] == ' ' || g[y,x] == 'R') return false; - if(g.map[y+1,x] == '*') + if(g[y+1,x] == '*') + return true; + if(g[y+1,x-1]=='*' && (g[y,x-1]=='\\'||g[y,x-1]=='*') && (g[y+1,x]==' '||g[y+1,x]=='R')) return true; - if(g.map[y+1,x-1]=='*' && (g.map[y,x-1]=='\\'||g.map[y,x-1]=='*') && (g.map[y+1,x]==' '||g.map[y+1,x]=='R')) + if(g[y+1,x+1]=='*' && (g[y,x+1]=='*') && (g[y+1,x]==' '||g[y+1,x]=='R')) return true; - if(g.map[y+1,x+1]=='*' && (g.map[y,x+1]=='*') && (g.map[y+1,x]==' '||g.map[y+1,x]=='R')) + if(g[y,x-1]=='*' && (g[y-1,x-1]=='\\'||g[y-1,x-1]=='*') && (g[y-1,x]==' '||g[y-1,x]=='R')) return true; - if(g.map[y,x-1]=='*' && (g.map[y-1,x-1]=='\\'||g.map[y-1,x-1]=='*') && (g.map[y-1,x]==' '||g.map[y-1,x]=='R')) - return true; - if(g.map[y,x+1]=='*' && (g.map[y-1,x+1]=='*') && (g.map[y-1,x]==' '||g.map[y-1,x]=='R')) + if(g[y,x+1]=='*' && (g[y-1,x+1]=='*') && (g[y-1,x]==' '||g[y-1,x]=='R')) return true; return false; } @@ -181,9 +181,9 @@ const(Pos)[] q; foreach(p; gs) if(!danger(p.y,p.x)) q ~= p; - bool[][] v = new bool[][](g.map.H+2, g.map.W+2); + bool[][] v = new bool[][](g.H+2, g.W+2); foreach(p; q) v[p.y][p.x]=true; for(int step=1; q.length; ++step) { Pos[] q2; foreach(p; q) { @@ -191,10 +191,10 @@ int[] xxx=[p.x,p.x,p.x-1,p.x+1]; for(int i=0; i=4) { + } else if(g[y,x]==' '||g[y,x]=='\\'||g[y,x]=='.'||g[y,x]=='!'||i>=4) { if(danger(y,x)) continue; q2 ~= new Pos(y,x); v[y][x]=true; @@ -221,9 +221,9 @@ // any empty space is my ground Tuple!(char,int)[] tryB() { const(Pos)[] q; foreach(p; gs) q ~= p; - bool[][] v = new bool[][](g.map.H+2, g.map.W+2); + bool[][] v = new bool[][](g.H+2, g.W+2); foreach(p; q) v[p.y][p.x]=true; for(int step=10; q.length; ++step) { Pos[] q2; foreach(p; q) { @@ -231,10 +231,10 @@ int[] xxx=[p.x,p.x,p.x-1,p.x+1]; for(int i=0; i=4) { + } else if(g[y,x]==' '||g[y,x]=='\\'||g[y,x]=='.'||g[y,x]=='!'||i>=4) { q2 ~= new Pos(y,x); v[y][x]=true; } } @@ -259,9 +259,9 @@ // push rocks! Tuple!(char,int)[] tryC() { const(Pos)[] q; foreach(p; gs) q ~= p; - bool[][] v = new bool[][](g.map.H+2, g.map.W+2); + bool[][] v = new bool[][](g.H+2, g.W+2); foreach(p; q) v[p.y][p.x]=true; for(int step=20; q.length; ++step) { Pos[] q2; foreach(p; q) { @@ -269,15 +269,15 @@ int[] xxx=[p.x,p.x,p.x-1,p.x+1]; for(int i=0; i=4)continue; if(y!=p.y)continue; - if(g.map[y,p.x+(p.x-x)]!=' '&&g.map[y,p.x+(p.x-x)]!='R')continue; + if(g[y,p.x+(p.x-x)]!=' '&&g[y,p.x+(p.x-x)]!='R')continue; } - if('1'<=g.map[y,x]&&g.map[y,x]<='9') { - foreach(ppp; g.map.tr_source[g.map[y,x]]) { + if('1'<=g[y,x]&&g[y,x]<='9') { + foreach(ppp; g.trampoline_rev(g[y,x])) { yyy ~= ppp.y; xxx ~= ppp.x; } continue; @@ -287,9 +287,9 @@ char c = "UDRL"[i]; if( death.count(c) == 0 ) return [tuple(c,step)]; } else if(forbidden_cell[y][x]){ - } else if(g.map[y,x]==' '||g.map[y,x]=='\\'||g.map[y,x]=='.'||g.map[y,x]=='*'||g.map[y,x]=='!'||i>=4) { + } else if(g[y,x]==' '||g[y,x]=='\\'||g[y,x]=='.'||g[y,x]=='*'||g[y,x]=='!'||i>=4) { q2 ~= new Pos(y,x); v[y][x]=true; } } @@ -317,9 +317,9 @@ Tuple!(Solver,string) run_sub_solver(in Game g) { string log; auto s = new Solver(g); - while(!g.cleared && !g.dead && plan.length<=g.map.H*g.map.W) { + while(!g.cleared && !g.dead && plan.length<=g.H*g.W) { char c = s.single_step(); if( c == 'A' ) break; log ~= c; @@ -386,7 +386,6 @@ plan = plan[1..$]; } } -//alias Solver_2!(Solver_1) MainSolver; -alias Solver_1 MainSolver; -*/ +alias Solver_2!(Solver_1) MainSolver; +//alias Solver_1 MainSolver;