File Annotation
Not logged in
3014ab5a8a 2012-07-15        kinaba: import util;
3014ab5a8a 2012-07-15        kinaba: import game;
3014ab5a8a 2012-07-15        kinaba: import output;
3014ab5a8a 2012-07-15        kinaba: import driver;
3014ab5a8a 2012-07-15        kinaba: import solver;
3014ab5a8a 2012-07-15        kinaba: 
3014ab5a8a 2012-07-15        kinaba: class CUI(Solver) : GameObserver
3014ab5a8a 2012-07-15        kinaba: {
3014ab5a8a 2012-07-15        kinaba: 	this(in Game g) { solver = new Solver(g); }
3014ab5a8a 2012-07-15        kinaba: 	Solver solver;
3014ab5a8a 2012-07-15        kinaba: 	bool fin;
3014ab5a8a 2012-07-15        kinaba: 	override void on_game_changed(char c, in Game g, bool finished) { fin = finished; }
3014ab5a8a 2012-07-15        kinaba: }
3014ab5a8a 2012-07-15        kinaba: 
1b261bd13b 2012-07-16        kinaba: class ForSafety : GameObserver
1b261bd13b 2012-07-16        kinaba: {
1b261bd13b 2012-07-16        kinaba: 	this(in Game g)
1b261bd13b 2012-07-16        kinaba: 	{
1b261bd13b 2012-07-16        kinaba: 		if(g.map.W*g.map.H <= 1000)
1b261bd13b 2012-07-16        kinaba: 		{
1b261bd13b 2012-07-16        kinaba: 			try {
1b261bd13b 2012-07-16        kinaba: 				score_log ~= g.score;
1b261bd13b 2012-07-16        kinaba: 				auto fast_solver = new FastSolver(g);
1b261bd13b 2012-07-16        kinaba: 				foreach(_; 0..g.map.W*g.map.H) {
1b261bd13b 2012-07-16        kinaba: 					char c = fast_solver.single_step();
1b261bd13b 2012-07-16        kinaba: 					if(c=='A') break;
1b261bd13b 2012-07-16        kinaba: 					const(Game) gg = fast_solver.current_game;
1b261bd13b 2012-07-16        kinaba: 					log ~= c;
1b261bd13b 2012-07-16        kinaba: 					score_log ~= gg.score;
1b261bd13b 2012-07-16        kinaba: 					if(gg.cleared || gg.dead) break;
1b261bd13b 2012-07-16        kinaba: 				}
1b261bd13b 2012-07-16        kinaba: 			} catch {
1b261bd13b 2012-07-16        kinaba: 				log = null;
1b261bd13b 2012-07-16        kinaba: 				score_log = null;
1b261bd13b 2012-07-16        kinaba: 			}
1b261bd13b 2012-07-16        kinaba: 		}
1b261bd13b 2012-07-16        kinaba: 	}
1b261bd13b 2012-07-16        kinaba: 	override void on_game_changed(char c, in Game g, bool finished) {}
1b261bd13b 2012-07-16        kinaba: 	string log;
1b261bd13b 2012-07-16        kinaba: 	long[] score_log;
1b261bd13b 2012-07-16        kinaba: }
1b261bd13b 2012-07-16        kinaba: 
3014ab5a8a 2012-07-15        kinaba: void main()
3014ab5a8a 2012-07-15        kinaba: {
3014ab5a8a 2012-07-15        kinaba: 	auto d = new Driver(stdin);
1b261bd13b 2012-07-16        kinaba: 	auto o = d.addObserver!(GuardedOutput)();
3014ab5a8a 2012-07-15        kinaba: 	auto c = d.addObserver!(CUI!MainSolver)();
1b261bd13b 2012-07-16        kinaba: 	auto f = d.addObserver!(ForSafety)();
1b261bd13b 2012-07-16        kinaba: 	o.safety_data(f.log, f.score_log);
3014ab5a8a 2012-07-15        kinaba: 	while(!c.fin)
3014ab5a8a 2012-07-15        kinaba: 		d.command(c.solver.single_step());
3014ab5a8a 2012-07-15        kinaba: }