Check-in [8f5135c552]
Not logged in
Overview
SHA1 Hash:8f5135c5528a7f4759668d30456936571438eb95
Date: 2012-07-13 23:32:47
User: kinaba
Comment:tenuki scoring.
Timelines: family | ancestors | descendants | both | trunk
Diffs: redesign
Downloads: Tarball | ZIP archive
Other Links: files | file ages | manifest
Tags And Properties
Changes

Modified test.d from [b27a6df805fe9112] to [ab6badd03b0f582a].

42 if(i) result ~= '\n'; 42 if(i) result ~= '\n'; 43 result ~= s.idup; 43 result ~= s.idup; 44 } 44 } 45 return result; 45 return result; 46 } 46 } 47 } 47 } 48 48 49 void command_R() { move(0, +1); } | 49 int command_R() { return move(0, +1); } 50 void command_L() { move(0, -1); } | 50 int command_L() { return move(0, -1); } 51 void command_U() { move(-1, 0); } | 51 int command_U() { return move(-1, 0); } 52 void command_D() { move(+1, 0); } | 52 int command_D() { return move(+1, 0); } 53 void wait() { update(); } | 53 int wait() { update(); return -1; } 54 54 55 void move(int dy, int dx) { | 55 int move(int dy, int dx) { 56 foreach(y,s; data) 56 foreach(y,s; data) 57 foreach(x,c; s) 57 foreach(x,c; s) 58 if(c == 'R') 58 if(c == 'R') 59 return move(dy, dx, y, x); 59 return move(dy, dx, y, x); > 60 assert(false); 60 } 61 } 61 62 > 63 int gained = 0; // TODO: atode naosu 62 void move(int dy, int dx, int y, int x) { | 64 int move(int dy, int dx, int y, int x) { > 65 int score = 0; > 66 if(data[y+dy][x+dx]=='\\') { > 67 score += 25; > 68 ++gained; > 69 } > 70 if(data[y+dy][x+dx]=='O') > 71 score += gained*50; > 72 63 if(data[y+dy][x+dx]==' ' || data[y+dy][x+dx]=='.' 73 if(data[y+dy][x+dx]==' ' || data[y+dy][x+dx]=='.' 64 || data[y+dy][x+dx]=='\\' || data[y+dy][x+dx]=='O') { 74 || data[y+dy][x+dx]=='\\' || data[y+dy][x+dx]=='O') { 65 data[y][x]=' '; 75 data[y][x]=' '; 66 data[y+dy][x+dx]='R'; 76 data[y+dy][x+dx]='R'; 67 } else if(dy==0 && data[y+dy][x+dx]=='*' && data[y+2*dy][x+2*dx] 77 } else if(dy==0 && data[y+dy][x+dx]=='*' && data[y+2*dy][x+2*dx] 68 data[y][x]=' '; 78 data[y][x]=' '; 69 data[y+dy][x+dx]='R'; 79 data[y+dy][x+dx]='R'; 70 data[y+2*dy][x+2*dx]='*'; 80 data[y+2*dy][x+2*dx]='*'; 71 } 81 } 72 update(); 82 update(); > 83 return score-1; 73 } 84 } 74 85 75 void update() { 86 void update() { 76 char[][] next; 87 char[][] next; 77 foreach(y,s; data) 88 foreach(y,s; data) 78 next ~= s.dup; 89 next ~= s.dup; 79 90 ................................................................................................................................................................................ 110 data = next; 121 data = next; 111 } 122 } 112 } 123 } 113 124 114 class MyForm : Form 125 class MyForm : Form 115 { 126 { 116 Map m; 127 Map m; > 128 int score; > 129 117 this(Map m) 130 this(Map m) 118 { 131 { 119 noMessageFilter(); 132 noMessageFilter(); 120 this.m = m; 133 this.m = m; 121 this.text = "Dark Integers"; 134 this.text = "Dark Integers"; 122 this.keyDown ~= &myKey; 135 this.keyDown ~= &myKey; > 136 this.score = 0; 123 } 137 } 124 override void onResize(EventArgs ev) { 138 override void onResize(EventArgs ev) { 125 invalidate(); 139 invalidate(); 126 } 140 } 127 override void onPaint(PaintEventArgs ev) 141 override void onPaint(PaintEventArgs ev) 128 { 142 { 129 int Z = min(this.clientSize.width, this.clientSize.height) / max 143 int Z = min(this.clientSize.width, this.clientSize.height) / max ................................................................................................................................................................................ 155 } 169 } 156 } 170 } 157 void myKey(Control c, KeyEventArgs ev) 171 void myKey(Control c, KeyEventArgs ev) 158 { 172 { 159 switch(ev.keyCode) 173 switch(ev.keyCode) 160 { 174 { 161 case Keys.DOWN: 175 case Keys.DOWN: 162 m.command_D(); | 176 score += m.command_D(); > 177 write("D"); > 178 stdout.flush(); 163 break; 179 break; 164 case Keys.UP: 180 case Keys.UP: 165 m.command_U(); | 181 score += m.command_U(); > 182 write("U"); > 183 stdout.flush(); 166 break; 184 break; 167 case Keys.LEFT: 185 case Keys.LEFT: 168 m.command_L(); | 186 score += m.command_L(); > 187 write("L"); > 188 stdout.flush(); 169 break; | 189 break; 170 case Keys.RIGHT: 190 case Keys.RIGHT: 171 m.command_R(); | 191 score += m.command_R(); > 192 write("R"); > 193 stdout.flush(); 172 break; 194 break; 173 case Keys.W: 195 case Keys.W: 174 m.wait(); | 196 score += m.wait(); > 197 write("W"); > 198 stdout.flush(); 175 break; 199 break; 176 default: 200 default: 177 break; 201 break; 178 } 202 } > 203 this.text = .text("Score: ", score); 179 invalidate(); 204 invalidate(); 180 } 205 } 181 } 206 } 182 207 183 void main(string[] args) 208 void main(string[] args) 184 { 209 { 185 Form myForm = new MyForm(new Map(File(args[1]))); 210 Form myForm = new MyForm(new Map(File(args[1]))); 186 Application.run(myForm); 211 Application.run(myForm); 187 } 212 }