Index: src/cui_auto_main.d ================================================================== --- src/cui_auto_main.d +++ src/cui_auto_main.d @@ -1,13 +1,27 @@ import util; import game; import output; import driver; import solver; + +class CUI(Solver) : GameObserver +{ + this(const(Game) g) { + solver = new Solver(g); + } + Solver solver; + bool fin; + override void on_game_changed(char c, const(Game) g, bool finished) + { + fin = finished; + } +} void main(string[] args) { Driver d = new Driver(stdin); d.addObserver!(GuardedOutput)(); - Solver s = d.addObserver!(Solver)(); - s.run(&d.command); + auto c = d.addObserver!(CUI!Solver_1)(); + while(!c.fin) + d.command(c.solver.single_step()); } Index: src/gui.d ================================================================== --- src/gui.d +++ src/gui.d @@ -15,12 +15,20 @@ } private void delegate(char c) fn; void set_fn(F)(F f) { this.fn = f; } - void run() + void run(bool automate = false) { + if(automate) { + Timer t = new Timer; + t.interval = 100; + t.tick ~= (Timer sender, EventArgs ea){ + fn(solver.single_step()); + }; + t.start(); + } Application.run(this); } override void on_game_changed(char c, const(Game) g, bool finished) {