Overview
SHA1 Hash: | 1b261bd13bd83d7a0b8ba9e532a0dedf01741a8e |
---|---|
Date: | 2012-07-16 15:32:03 |
User: | kinaba |
Comment: | Run Wind and Forest both and take better. |
Timelines: | family | ancestors | descendants | both | trunk |
Diffs: | redesign |
Downloads: | Tarball | ZIP archive |
Other Links: | files | file ages | manifest |
Tags And Properties
- branch=trunk inherited from [16f0b5784f]
- sym-trunk inherited from [16f0b5784f]
Changes
Modified src/main.d from [f6cab5c23c5cba1e] to [51a9d789eb377d34].
7 7 class CUI(Solver) : GameObserver 8 8 { 9 9 this(in Game g) { solver = new Solver(g); } 10 10 Solver solver; 11 11 bool fin; 12 12 override void on_game_changed(char c, in Game g, bool finished) { fin = finished; } 13 13 } 14 + 15 +class ForSafety : GameObserver 16 +{ 17 + this(in Game g) 18 + { 19 + if(g.map.W*g.map.H <= 1000) 20 + { 21 + try { 22 + score_log ~= g.score; 23 + auto fast_solver = new FastSolver(g); 24 + foreach(_; 0..g.map.W*g.map.H) { 25 + char c = fast_solver.single_step(); 26 + if(c=='A') break; 27 + const(Game) gg = fast_solver.current_game; 28 + log ~= c; 29 + score_log ~= gg.score; 30 + if(gg.cleared || gg.dead) break; 31 + } 32 + } catch { 33 + log = null; 34 + score_log = null; 35 + } 36 + } 37 + } 38 + override void on_game_changed(char c, in Game g, bool finished) {} 39 + string log; 40 + long[] score_log; 41 +} 14 42 15 43 void main() 16 44 { 17 45 auto d = new Driver(stdin); 18 - d.addObserver!(GuardedOutput)(); 46 + auto o = d.addObserver!(GuardedOutput)(); 19 47 auto c = d.addObserver!(CUI!MainSolver)(); 48 + auto f = d.addObserver!(ForSafety)(); 49 + o.safety_data(f.log, f.score_log); 20 50 while(!c.fin) 21 51 d.command(c.solver.single_step()); 22 52 }
Modified src/output.d from [95ed42a2d89e1fef] to [bdd3d4d83c822b4b].
36 36 log ~= c; 37 37 score_log ~= g.score; 38 38 if(finished || log.length+1==g.map.W*g.map.H) 39 39 flush(); 40 40 if(log.length+1==g.map.W*g.map.H) 41 41 application_exit(); 42 42 } 43 + 44 + void safety_data(string s_log, long[] s_score_log) { 45 + this.s_log = s_log; 46 + this.s_score_log = s_score_log; 47 + } 43 48 44 49 private: 45 50 string log; 46 51 long[] score_log; 47 52 bool flushed; 48 53 54 + string s_log; 55 + long[] s_score_log; 56 + 49 57 void flush() 50 58 { 51 59 if(flushed) 52 60 return; 53 61 54 - Tuple!(long, int) cand; 62 + Tuple!(long, int, immutable(char)*) cand; 55 63 cand[0] = long.min; 56 64 57 65 for(int i=0; i<score_log.length; ++i) 58 66 if(cand[0] < score_log[i]) 59 - cand = tuple(score_log[i],i); 67 + cand = tuple(score_log[i],i,log.ptr); 68 + for(int i=0; i<s_score_log.length; ++i) 69 + if(cand[0] < s_score_log[i]) 70 + cand = tuple(s_score_log[i],i,s_log.ptr); 60 71 61 - std.c.stdio.printf("%.*sA\n", cand[1], log.ptr); 72 + std.c.stdio.printf("%.*sA\n", cand[1], cand[2]); 62 73 std.c.stdio.fflush(std.c.stdio.stdout); 63 74 flushed = true; 64 75 } 65 76 66 77 private: 67 78 static __gshared GuardedOutput g_output; 68 79
Modified src/solver.d from [4eed871f814ba3b0] to [3f2a2d28b89b3fbf].
1 1 // 2 2 // http://en.wikipedia.org/wiki/F%C5%ABrinkazan 3 3 // 4 4 import util; 5 5 import game; 6 6 7 - 8 7 interface Solver 9 8 { 10 9 // this(in Game g); 11 10 char single_step(); 12 11 void force(char c); 13 12 } 14 13 ................................................................................ 721 720 sub_solver = new 侵掠如火!(疾如風)(g); 722 721 } 723 722 char single_step() { return sub_solver.single_step(); } 724 723 void force(char c) { return sub_solver.force(c); } 725 724 726 725 private Solver sub_solver; 727 726 } 727 + 728 +alias 侵掠如火!(疾如風) FastSolver; 728 729 729 730 //alias Switcher MainSolver; 730 731 //alias 侵掠如火!(疾如風) MainSolver; 731 732 alias 侵掠如火!(徐如林) MainSolver; 732 733 //alias 疾如風 MainSolver; 733 734 //alias 徐如林 MainSolver; 734 735 //alias 不動如山 MainSolver;