@@ -2,16 +2,23 @@ import game; bool rocky(char c){ return c=='*'||c=='@'; } -class Solver_0 +interface Solver +{ + // this(in Game g); + char single_step(); + void force(char c); +} + +class Solver_0 : Solver { this(in Game g) {} char single_step() { return 'W'; } void force(char c) {} } -class Solver_1 +class Solver_1 : Solver { int wait_count = 0; int choke_count = 0; @@ -166,13 +173,15 @@ if(g.map[y,x] == ' ' || g.map[y,x] == 'R') return false; if(rocky(g.map[y+1,x])) return true; - if(rocky(g.map[y+1,x-1]) && (g.map[y,x-1]=='\\'||rocky(g.map[y,x-1])) && (g.map[y+1,x]==' '||g.map[y+1,x]=='R')) + if(rocky(g.map[y+1,x-1]) && (g.map[y,x-1]=='\\'||rocky(g.map[y,x-1])) + && (g.map[y+1,x]==' '||g.map[y+1,x]=='R')) return true; if(rocky(g.map[y+1,x+1]) && rocky(g.map[y,x+1]) && (g.map[y+1,x]==' '||g.map[y+1,x]=='R')) return true; - if(rocky(g.map[y,x-1]) && (g.map[y-1,x-1]=='\\'||rocky(g.map[y-1,x-1])) && (g.map[y-1,x]==' '||g.map[y-1,x]=='R')) + if(rocky(g.map[y,x-1]) && (g.map[y-1,x-1]=='\\'||rocky(g.map[y-1,x-1])) + && (g.map[y-1,x]==' '||g.map[y-1,x]=='R')) return true; if(rocky(g.map[y,x+1]) && rocky(g.map[y-1,x+1]) && (g.map[y-1,x]==' '||g.map[y-1,x]=='R')) return true; return false; @@ -303,9 +312,9 @@ return (danger_ok ? [] : tryA()) ~ tryB() ~ tryC(); } } -class Solver_2(Solver) +class Solver_2(SubSolver) : Solver { string plan; bool plan_broken = true; @@ -315,12 +324,12 @@ this.g = g.clone(); make_plan(g); } - Tuple!(Solver,string) run_sub_solver(in Game g) + Tuple!(SubSolver,string) run_sub_solver(in Game g) { string log; - auto s = new Solver(g); + auto s = new SubSolver(g); while(!g.cleared && !g.dead && plan.length<=g.map.H*g.map.W) { char c = s.single_step(); if( c == 'A' ) break; @@ -332,9 +341,9 @@ } void make_plan(in Game g) { plan_broken = false; - Tuple!(Solver,string) x = run_sub_solver(g); + Tuple!(SubSolver,string) x = run_sub_solver(g); plan = x[1]; if(x[0].g.cleared) return; modify_plan(g, x[0].g.score); @@ -362,9 +371,9 @@ Tuple!(string,long) try_plan(string c, in Game g) { Game gg = g.clone(); foreach(cc;c)gg.command(cc); - Tuple!(Solver, string) x = run_sub_solver(gg); + Tuple!(SubSolver, string) x = run_sub_solver(gg); return tuple(x[1], x[0].g.score); } char single_step() { @@ -388,7 +397,26 @@ plan = plan[1..$]; } } +class MasterSolver : Solver +{ + this(in Game g) + { + int SIZE = g.map.H * g.map.W; + if( SIZE <= 32*32 ) + sub = new Solver_2!(Solver_1)(g); + else if( SIZE <= 100*100 ) + sub = new Solver_1(g); + else + sub = new Solver_1(g); + } + + private Solver sub; + char single_step() { return sub.single_step(); } + void force(char c) { sub.force(c); } +} + +alias MasterSolver MainSolver; //alias Solver_2!(Solver_1) MainSolver; //alias Solver_1 MainSolver; -alias Solver_0 MainSolver; +//alias Solver_0 MainSolver;