Differences From Artifact [01f7e924127970bf]:
- File
src/solver.d
- 2012-07-14 18:26:12 - part of checkin [2f2eff2f03] on branch trunk - fall rock mode. (user: kinaba) [annotate]
To Artifact [d8cdcee0dd6dc539]:
- File
src/solver.d
- 2012-07-14 18:33:18 - part of checkin [ea96f24715] on branch trunk - Introduced choke_count to cumlatively count the robot chose to "wait" (user: kinaba) [annotate]
6 this(const(Game) g) {} 6 this(const(Game) g) {}
7 char single_step() { return 'W'; } 7 char single_step() { return 'W'; }
8 } 8 }
9 9
10 class Solver_1 10 class Solver_1
11 { 11 {
12 int wait_count = 0; 12 int wait_count = 0;
> 13 int choke_count = 0;
13 14
14 Game g; 15 Game g;
15 this(const(Game) g) 16 this(const(Game) g)
16 { 17 {
17 this.g = g.clone(); 18 this.g = g.clone();
18 forbidden_cell = new bool[][](g.map.H+2, g.map.W+2); 19 forbidden_cell = new bool[][](g.map.H+2, g.map.W+2);
19 } 20 }
................................................................................................................................................................................
68 if(g.map[y,x]=='.') 69 if(g.map[y,x]=='.')
69 if(g.map[y+1,x]=='*'||g.map[y+1,x-1]=='* 70 if(g.map[y+1,x]=='*'||g.map[y+1,x-1]=='*
70 ||g.map[y,x+1]=='*'||g.map[y,x-1]=='*') 71 ||g.map[y,x+1]=='*'||g.map[y,x-1]=='*')
71 tgt ~= new Pos(y,x); 72 tgt ~= new Pos(y,x);
72 cand ~= search(g, ro, tgt, death, true); 73 cand ~= search(g, ro, tgt, death, true);
73 } 74 }
74 75
75 if(cand.empty) | 76 if(cand.empty) {
> 77 choke_count++;
76 cand ~= tuple('W',int.max); 78 cand ~= tuple('W',int.max);
> 79 }
77 sort!((Tuple!(char,int) c1, Tuple!(char,int) c2){ 80 sort!((Tuple!(char,int) c1, Tuple!(char,int) c2){
78 if(c1[1] != c2[1]) 81 if(c1[1] != c2[1])
79 return c1[1] < c2[1]; 82 return c1[1] < c2[1];
80 return c1[0] < c2[0]; 83 return c1[0] < c2[0];
81 })(cand); 84 })(cand);
82 c = cand[0][0]; 85 c = cand[0][0];
83 86
................................................................................................................................................................................
85 foreach(char live; "UDLRW") 88 foreach(char live; "UDLRW")
86 if(death.count(live)==0) { 89 if(death.count(live)==0) {
87 c=live; 90 c=live;
88 break; 91 break;
89 } 92 }
90 } 93 }
91 94
92 if(c=='W') { | 95 if(c == 'W')
93 wait_count++; 96 wait_count++;
94 if(wait_count > g.map.H) <
95 c = 'A'; <
96 } <
97 else 97 else
98 wait_count = 0; 98 wait_count = 0;
> 99 if(choke_count >= g.map.H)
> 100 c = 'A';
99 101
100 bool[char] choice; 102 bool[char] choice;
101 foreach(t; cand) 103 foreach(t; cand)
102 choice[t[0]] = true; 104 choice[t[0]] = true;
103 log ~= tuple(ro.clone(), cast(int)choice.length); 105 log ~= tuple(ro.clone(), cast(int)choice.length);
104 if(log.length > 5) 106 if(log.length > 5)
105 log = log[$-5..$]; 107 log = log[$-5..$];