Index: src/main.d ================================================================== --- src/main.d +++ src/main.d @@ -9,14 +9,44 @@ this(in Game g) { solver = new Solver(g); } Solver solver; bool fin; override void on_game_changed(char c, in Game g, bool finished) { fin = finished; } } + +class ForSafety : GameObserver +{ + this(in Game g) + { + if(g.map.W*g.map.H <= 1000) + { + try { + score_log ~= g.score; + auto fast_solver = new FastSolver(g); + foreach(_; 0..g.map.W*g.map.H) { + char c = fast_solver.single_step(); + if(c=='A') break; + const(Game) gg = fast_solver.current_game; + log ~= c; + score_log ~= gg.score; + if(gg.cleared || gg.dead) break; + } + } catch { + log = null; + score_log = null; + } + } + } + override void on_game_changed(char c, in Game g, bool finished) {} + string log; + long[] score_log; +} void main() { auto d = new Driver(stdin); - d.addObserver!(GuardedOutput)(); + auto o = d.addObserver!(GuardedOutput)(); auto c = d.addObserver!(CUI!MainSolver)(); + auto f = d.addObserver!(ForSafety)(); + o.safety_data(f.log, f.score_log); while(!c.fin) d.command(c.solver.single_step()); } Index: src/output.d ================================================================== --- src/output.d +++ src/output.d @@ -38,29 +38,40 @@ if(finished || log.length+1==g.map.W*g.map.H) flush(); if(log.length+1==g.map.W*g.map.H) application_exit(); } + + void safety_data(string s_log, long[] s_score_log) { + this.s_log = s_log; + this.s_score_log = s_score_log; + } private: string log; long[] score_log; bool flushed; + string s_log; + long[] s_score_log; + void flush() { if(flushed) return; - Tuple!(long, int) cand; + Tuple!(long, int, immutable(char)*) cand; cand[0] = long.min; for(int i=0; i