6293256fec 2012-07-14 kinaba: import std.algorithm; 6293256fec 2012-07-14 kinaba: import std.array; 6293256fec 2012-07-14 kinaba: import std.conv; 6293256fec 2012-07-14 kinaba: import std.stdio; 6293256fec 2012-07-14 kinaba: import std.string; 6293256fec 2012-07-14 kinaba: import std.typecons; 6293256fec 2012-07-14 kinaba: import core.stdc.signal; 6293256fec 2012-07-14 kinaba: import core.stdc.stdlib; 6293256fec 2012-07-14 kinaba: import dfl.all; 6293256fec 2012-07-14 kinaba: 6293256fec 2012-07-14 kinaba: class Map 6293256fec 2012-07-14 kinaba: { 6293256fec 2012-07-14 kinaba: private char[][] data; 6293256fec 2012-07-14 kinaba: bool dead = false; 6293256fec 2012-07-14 kinaba: bool cleared = false; 6293256fec 2012-07-14 kinaba: int water = 0; 6293256fec 2012-07-14 kinaba: int flooding = 0; 6293256fec 2012-07-14 kinaba: int water_proof = 10; 6293256fec 2012-07-14 kinaba: int underwater = 0; 6293256fec 2012-07-14 kinaba: int flooding_counter = 0; 6293256fec 2012-07-14 kinaba: 6293256fec 2012-07-14 kinaba: this(File input) 6293256fec 2012-07-14 kinaba: { 6293256fec 2012-07-14 kinaba: string line; 6293256fec 2012-07-14 kinaba: while( (line=input.readln().chomp()).length ) 6293256fec 2012-07-14 kinaba: data ~= line.dup; 6293256fec 2012-07-14 kinaba: 6293256fec 2012-07-14 kinaba: int width = 0; 6293256fec 2012-07-14 kinaba: foreach(s; data) 6293256fec 2012-07-14 kinaba: width = max(width, s.length); 6293256fec 2012-07-14 kinaba: 6293256fec 2012-07-14 kinaba: // space padding and sentinels 6293256fec 2012-07-14 kinaba: foreach(ref s; data) { 6293256fec 2012-07-14 kinaba: int p = s.length; 6293256fec 2012-07-14 kinaba: s.length = width; 6293256fec 2012-07-14 kinaba: s[p..$] = ' '; 6293256fec 2012-07-14 kinaba: s = '#' ~ s ~ '#'; 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: 6293256fec 2012-07-14 kinaba: // vertical sentinel 6293256fec 2012-07-14 kinaba: char[] sen = new char[width+2]; 6293256fec 2012-07-14 kinaba: sen[] = '#'; 6293256fec 2012-07-14 kinaba: data = sen.dup ~ data ~ sen; 6293256fec 2012-07-14 kinaba: 6293256fec 2012-07-14 kinaba: // flooding 6293256fec 2012-07-14 kinaba: water = H-1; 6293256fec 2012-07-14 kinaba: while( (line=input.readln()).length ) { 6293256fec 2012-07-14 kinaba: string[] ss = line.split(); 6293256fec 2012-07-14 kinaba: if(ss.length==2 && ss[0]=="Water") 6293256fec 2012-07-14 kinaba: water = H-1 - ss[1].to!int(); 6293256fec 2012-07-14 kinaba: else if(ss.length==2 && ss[0]=="Flooding") 6293256fec 2012-07-14 kinaba: flooding = ss[1].to!int(); 6293256fec 2012-07-14 kinaba: else if(ss.length==2 && ss[0]=="Waterproof") 6293256fec 2012-07-14 kinaba: water_proof = ss[1].to!int(); 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: 6293256fec 2012-07-14 kinaba: @property const 6293256fec 2012-07-14 kinaba: { 6293256fec 2012-07-14 kinaba: int W() { return data[0].length; } 6293256fec 2012-07-14 kinaba: int H() { return data.length; } 6293256fec 2012-07-14 kinaba: string toString() { 6293256fec 2012-07-14 kinaba: string result; 6293256fec 2012-07-14 kinaba: foreach(i,s; data) { 6293256fec 2012-07-14 kinaba: if(i) result ~= '\n'; 6293256fec 2012-07-14 kinaba: result ~= s.idup; 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: return result; 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: 6293256fec 2012-07-14 kinaba: int command_R() { if(dead)return 0; write("R"); return move(0, +1); } 6293256fec 2012-07-14 kinaba: int command_L() { if(dead)return 0; write("L"); return move(0, -1); } 6293256fec 2012-07-14 kinaba: int command_U() { if(dead)return 0; write("U"); return move(-1, 0); } 6293256fec 2012-07-14 kinaba: int command_D() { if(dead)return 0; write("D"); return move(+1, 0); } 6293256fec 2012-07-14 kinaba: int wait() { if(dead)return 0; update(); write("W"); return -1; } 6293256fec 2012-07-14 kinaba: int abort() { if(dead)return 0; cleared=true; write("A"); return gained*25; } 6293256fec 2012-07-14 kinaba: 6293256fec 2012-07-14 kinaba: int move(int dy, int dx) { 6293256fec 2012-07-14 kinaba: foreach(y,s; data) 6293256fec 2012-07-14 kinaba: foreach(x,c; s) 6293256fec 2012-07-14 kinaba: if(c == 'R') 6293256fec 2012-07-14 kinaba: return move(dy, dx, y, x); 6293256fec 2012-07-14 kinaba: assert(false); 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: 6293256fec 2012-07-14 kinaba: int gained = 0; // TODO: atode naosu 6293256fec 2012-07-14 kinaba: int move(int dy, int dx, int y, int x) { 6293256fec 2012-07-14 kinaba: if(dead) 6293256fec 2012-07-14 kinaba: return 0; 6293256fec 2012-07-14 kinaba: int score = 0; 6293256fec 2012-07-14 kinaba: if(data[y+dy][x+dx]=='\\') { 6293256fec 2012-07-14 kinaba: score += 25; 6293256fec 2012-07-14 kinaba: ++gained; 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: if(data[y+dy][x+dx]=='O') { 6293256fec 2012-07-14 kinaba: score += gained*50; 6293256fec 2012-07-14 kinaba: cleared = true; 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: 6293256fec 2012-07-14 kinaba: if(data[y+dy][x+dx]==' ' || data[y+dy][x+dx]=='.' 6293256fec 2012-07-14 kinaba: || data[y+dy][x+dx]=='\\' || data[y+dy][x+dx]=='O') { 6293256fec 2012-07-14 kinaba: data[y][x]=' '; 6293256fec 2012-07-14 kinaba: data[y+dy][x+dx]='R'; 6293256fec 2012-07-14 kinaba: } else if(dy==0 && data[y+dy][x+dx]=='*' && data[y+2*dy][x+2*dx]==' ') { 6293256fec 2012-07-14 kinaba: data[y][x]=' '; 6293256fec 2012-07-14 kinaba: data[y+dy][x+dx]='R'; 6293256fec 2012-07-14 kinaba: data[y+2*dy][x+2*dx]='*'; 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: update(); 6293256fec 2012-07-14 kinaba: return score-1; 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: 6293256fec 2012-07-14 kinaba: void update() { 6293256fec 2012-07-14 kinaba: char[][] next; 6293256fec 2012-07-14 kinaba: foreach(y,s; data) 6293256fec 2012-07-14 kinaba: next ~= s.dup; 6293256fec 2012-07-14 kinaba: 6293256fec 2012-07-14 kinaba: bool lambda = false; 6293256fec 2012-07-14 kinaba: for(int y=1; y+1<H; ++y) 6293256fec 2012-07-14 kinaba: for(int x=1; x+1<W; ++x) 6293256fec 2012-07-14 kinaba: lambda |= (data[y][x] == '\\'); 6293256fec 2012-07-14 kinaba: 6293256fec 2012-07-14 kinaba: for(int y=H-2; y>=1; --y) 6293256fec 2012-07-14 kinaba: for(int x=1; x+1<W; ++x) { 6293256fec 2012-07-14 kinaba: if(data[y][x]=='*') { 6293256fec 2012-07-14 kinaba: if(data[y+1][x]==' ') { 6293256fec 2012-07-14 kinaba: next[y][x]=' '; 6293256fec 2012-07-14 kinaba: next[y+1][x]='*'; 6293256fec 2012-07-14 kinaba: if(next[y+2][x]=='R') 6293256fec 2012-07-14 kinaba: dead=true; 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: else if(data[y+1][x]=='*' && data[y][x+1]==' ' && data[y+1][x+1]==' ') { 6293256fec 2012-07-14 kinaba: next[y][x]=' '; 6293256fec 2012-07-14 kinaba: next[y+1][x+1]='*'; 6293256fec 2012-07-14 kinaba: if(next[y+2][x+1]=='R') 6293256fec 2012-07-14 kinaba: dead=true; 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: else if(data[y+1][x]=='*' && data[y][x-1]==' ' && data[y+1][x-1]==' ') { 6293256fec 2012-07-14 kinaba: next[y][x]=' '; 6293256fec 2012-07-14 kinaba: next[y+1][x-1]='*'; 6293256fec 2012-07-14 kinaba: if(next[y+2][x-1]=='R') 6293256fec 2012-07-14 kinaba: dead=true; 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: else if(data[y+1][x]=='\\' && data[y][x+1]==' ' && data[y+1][x+1]==' ') { 6293256fec 2012-07-14 kinaba: next[y][x]=' '; 6293256fec 2012-07-14 kinaba: next[y+1][x+1]='*'; 6293256fec 2012-07-14 kinaba: if(next[y+2][x+1]=='R') 6293256fec 2012-07-14 kinaba: dead=true; 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: else if(data[y][x]=='L') { 6293256fec 2012-07-14 kinaba: if(!lambda) 6293256fec 2012-07-14 kinaba: next[y][x] = 'O'; 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: data = next; 6293256fec 2012-07-14 kinaba: 6293256fec 2012-07-14 kinaba: if(flooding) { 6293256fec 2012-07-14 kinaba: bool wa = false; 6293256fec 2012-07-14 kinaba: for(int y=water; y+1<H; ++y) 6293256fec 2012-07-14 kinaba: for(int x=1; x+1<W; ++x) 6293256fec 2012-07-14 kinaba: if(data[y][x]=='R') { 6293256fec 2012-07-14 kinaba: wa = true; 6293256fec 2012-07-14 kinaba: underwater++; 6293256fec 2012-07-14 kinaba: if(underwater > water_proof) 6293256fec 2012-07-14 kinaba: dead = true; 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: flooding_counter ++; 6293256fec 2012-07-14 kinaba: if(flooding_counter == flooding) { 6293256fec 2012-07-14 kinaba: flooding_counter = 0; 6293256fec 2012-07-14 kinaba: water --; 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: 6293256fec 2012-07-14 kinaba: int clever() 6293256fec 2012-07-14 kinaba: { 6293256fec 2012-07-14 kinaba: if(dead) 6293256fec 2012-07-14 kinaba: return 0; 6293256fec 2012-07-14 kinaba: int sy,sx; 6293256fec 2012-07-14 kinaba: int[] ly,lx; 6293256fec 2012-07-14 kinaba: int oy,ox; 6293256fec 2012-07-14 kinaba: for(int y=0; y<H; ++y) 6293256fec 2012-07-14 kinaba: for(int x=0; x<W; ++x) 6293256fec 2012-07-14 kinaba: if(data[y][x]=='R') 6293256fec 2012-07-14 kinaba: sy=y, sx=x; 6293256fec 2012-07-14 kinaba: else if(data[y][x]=='\\') 6293256fec 2012-07-14 kinaba: ly~=y, lx~=x; 6293256fec 2012-07-14 kinaba: else if(data[y][x]=='O') 6293256fec 2012-07-14 kinaba: oy=y, ox=x; 6293256fec 2012-07-14 kinaba: if(ly.length==0) { 6293256fec 2012-07-14 kinaba: auto r = search(sy,sx,oy,ox); 6293256fec 2012-07-14 kinaba: switch(r[0]) { 6293256fec 2012-07-14 kinaba: case 'D': return command_D(); 6293256fec 2012-07-14 kinaba: case 'U': return command_U(); 6293256fec 2012-07-14 kinaba: case 'L': return command_L(); 6293256fec 2012-07-14 kinaba: case 'R': return command_R(); 6293256fec 2012-07-14 kinaba: case 'A': return abort(); 6293256fec 2012-07-14 kinaba: default: return wait(); 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: } else { 6293256fec 2012-07-14 kinaba: Tuple!(char,int)[] cand; 6293256fec 2012-07-14 kinaba: for(int i=0; i<ly.length; ++i) { 6293256fec 2012-07-14 kinaba: auto r = search(sy,sx,ly[i],lx[i]); 6293256fec 2012-07-14 kinaba: cand ~= r; 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: sort!((Tuple!(char,int) c1, Tuple!(char,int) c2){ 6293256fec 2012-07-14 kinaba: if(c1[1] != c2[1]) 6293256fec 2012-07-14 kinaba: return c1[1] < c2[1]; 6293256fec 2012-07-14 kinaba: return c1[0] < c2[0]; 6293256fec 2012-07-14 kinaba: })(cand); 6293256fec 2012-07-14 kinaba: switch(cand[0][0]) { 6293256fec 2012-07-14 kinaba: case 'D': return command_D(); 6293256fec 2012-07-14 kinaba: case 'U': return command_U(); 6293256fec 2012-07-14 kinaba: case 'L': return command_L(); 6293256fec 2012-07-14 kinaba: case 'R': return command_R(); 6293256fec 2012-07-14 kinaba: case 'A': return abort(); 6293256fec 2012-07-14 kinaba: default: return wait(); 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: return wait(); 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: Tuple!(char,int) search(int sy, int sx, int oy, int ox) 6293256fec 2012-07-14 kinaba: { 6293256fec 2012-07-14 kinaba: alias Tuple!(int,"y",int,"x") Pt; 6293256fec 2012-07-14 kinaba: Pt[] q = [Pt(oy,ox)]; 6293256fec 2012-07-14 kinaba: bool[][] v = new bool[][](H,W); 6293256fec 2012-07-14 kinaba: for(int step=1; q.length; ++step) { 6293256fec 2012-07-14 kinaba: Pt[] q2; 6293256fec 2012-07-14 kinaba: foreach(p; q) { 6293256fec 2012-07-14 kinaba: int[] dy=[-1,+1,0,0]; 6293256fec 2012-07-14 kinaba: int[] dx=[0,0,-1,+1]; 6293256fec 2012-07-14 kinaba: for(int i=0; i<4; ++i) { 6293256fec 2012-07-14 kinaba: int y = p.y+dy[i]; 6293256fec 2012-07-14 kinaba: int x = p.x+dx[i]; 6293256fec 2012-07-14 kinaba: if(v[y][x]) continue; 6293256fec 2012-07-14 kinaba: if(y==sy && x==sx) { 6293256fec 2012-07-14 kinaba: if(i==0) return tuple('D',step); 6293256fec 2012-07-14 kinaba: if(i==1) return tuple('U',step); 6293256fec 2012-07-14 kinaba: if(i==2) return tuple('R',step); 6293256fec 2012-07-14 kinaba: if(i==3) return tuple('L',step); 6293256fec 2012-07-14 kinaba: } else if(data[y][x]==' '||data[y][x]=='\\') { 6293256fec 2012-07-14 kinaba: q2 ~= Pt(y,x); 6293256fec 2012-07-14 kinaba: v[y][x]=true; 6293256fec 2012-07-14 kinaba: } else if(data[y][x]=='.' && data[y-1][x]!='*') { 6293256fec 2012-07-14 kinaba: q2 ~= Pt(y,x); 6293256fec 2012-07-14 kinaba: v[y][x]=true; 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: q = q2; 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: q = [Pt(oy,ox)]; 6293256fec 2012-07-14 kinaba: v = new bool[][](H,W); 6293256fec 2012-07-14 kinaba: for(int step=1<<10; q.length; ++step) { 6293256fec 2012-07-14 kinaba: Pt[] q2; 6293256fec 2012-07-14 kinaba: foreach(p; q) { 6293256fec 2012-07-14 kinaba: 6293256fec 2012-07-14 kinaba: int[] dy=[-1,+1,0,0]; 6293256fec 2012-07-14 kinaba: int[] dx=[0,0,-1,+1]; 6293256fec 2012-07-14 kinaba: for(int i=0; i<4; ++i) { 6293256fec 2012-07-14 kinaba: int y = p.y+dy[i]; 6293256fec 2012-07-14 kinaba: int x = p.x+dx[i]; 6293256fec 2012-07-14 kinaba: if(v[y][x]) continue; 6293256fec 2012-07-14 kinaba: if(y==sy && x==sx) { 6293256fec 2012-07-14 kinaba: if(i==0) return tuple('D',step); 6293256fec 2012-07-14 kinaba: if(i==1) return tuple('U',step); 6293256fec 2012-07-14 kinaba: if(i==2) return tuple('R',step); 6293256fec 2012-07-14 kinaba: if(i==3) return tuple('L',step); 6293256fec 2012-07-14 kinaba: } else if(data[y][x]==' '||data[y][x]=='\\') { 6293256fec 2012-07-14 kinaba: q2 ~= Pt(y,x); 6293256fec 2012-07-14 kinaba: v[y][x]=true; 6293256fec 2012-07-14 kinaba: } else if(data[y][x]=='.'/* && data[y-1][x]!='*'*/) { 6293256fec 2012-07-14 kinaba: q2 ~= Pt(y,x); 6293256fec 2012-07-14 kinaba: v[y][x]=true; 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: q = q2; 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: return tuple('A',int.max); 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: 6293256fec 2012-07-14 kinaba: class MyForm : Form 6293256fec 2012-07-14 kinaba: { 6293256fec 2012-07-14 kinaba: Map m; 6293256fec 2012-07-14 kinaba: int score; 6293256fec 2012-07-14 kinaba: 6293256fec 2012-07-14 kinaba: this(Map m) 6293256fec 2012-07-14 kinaba: { 6293256fec 2012-07-14 kinaba: noMessageFilter(); 6293256fec 2012-07-14 kinaba: this.m = m; 6293256fec 2012-07-14 kinaba: this.text = .text("Score: ", score, " air[",m.water_proof-m.underwater,"]"); 6293256fec 2012-07-14 kinaba: this.keyDown ~= &myKey; 6293256fec 2012-07-14 kinaba: this.score = 0; 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: override void onResize(EventArgs ev) { 6293256fec 2012-07-14 kinaba: invalidate(); 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: override void onPaint(PaintEventArgs ev) 6293256fec 2012-07-14 kinaba: { 6293256fec 2012-07-14 kinaba: int Z = min(this.clientSize.width/(m.W-2), this.clientSize.height/(m.H-2)); 6293256fec 2012-07-14 kinaba: Font font = new Font("MS Gothic", Z-4); 6293256fec 2012-07-14 kinaba: Graphics g = ev.graphics; 6293256fec 2012-07-14 kinaba: g.fillRectangle(Color(0,233,255), Rect(0,Z*(m.water-1),this.clientSize.width,this.clientSize.height-(Z*(m.water-1)))); 6293256fec 2012-07-14 kinaba: for(int y=1; y+1<m.H; ++y) 6293256fec 2012-07-14 kinaba: for(int x=1; x+1<m.W; ++x) { 6293256fec 2012-07-14 kinaba: if(m.data[y][x]=='*') { 6293256fec 2012-07-14 kinaba: g.drawText("岩", font, Color(0,0,0), Rect((x-1)*Z, (y-1)*Z, Z, Z)); 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: if(m.data[y][x]=='\\') { 6293256fec 2012-07-14 kinaba: g.drawText("λ", font, Color(0,255,0), Rect((x-1)*Z, (y-1)*Z, Z, Z)); 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: if(m.data[y][x]=='R') { 6293256fec 2012-07-14 kinaba: if(m.dead) 6293256fec 2012-07-14 kinaba: g.drawText("Я", font, Color(255,0,0), Rect((x-1)*Z, (y-1)*Z, Z, Z)); 6293256fec 2012-07-14 kinaba: else 6293256fec 2012-07-14 kinaba: g.drawText("R", font, Color(128,128,0), Rect((x-1)*Z, (y-1)*Z, Z, Z)); 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: if(m.data[y][x]=='L') { 6293256fec 2012-07-14 kinaba: g.drawText("扉", font, Color(255,255,0), Rect((x-1)*Z, (y-1)*Z, Z, Z)); 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: if(m.data[y][x]=='O') { 6293256fec 2012-07-14 kinaba: g.drawText("外", font, Color(255,255,0), Rect((x-1)*Z, (y-1)*Z, Z, Z)); 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: if(m.data[y][x]=='#') { 6293256fec 2012-07-14 kinaba: g.drawText("#", font, Color(0,0,0), Rect((x-1)*Z, (y-1)*Z, Z, Z)); 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: if(m.data[y][x]=='.') { 6293256fec 2012-07-14 kinaba: g.drawText("・", font, Color(128,40,0), Rect((x-1)*Z, (y-1)*Z, Z, Z)); 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: void myKey(Control c, KeyEventArgs ev) 6293256fec 2012-07-14 kinaba: { 6293256fec 2012-07-14 kinaba: switch(ev.keyCode) 6293256fec 2012-07-14 kinaba: { 6293256fec 2012-07-14 kinaba: case Keys.DOWN: 6293256fec 2012-07-14 kinaba: score += m.command_D(); 6293256fec 2012-07-14 kinaba: stdout.flush(); 6293256fec 2012-07-14 kinaba: break; 6293256fec 2012-07-14 kinaba: case Keys.UP: 6293256fec 2012-07-14 kinaba: score += m.command_U(); 6293256fec 2012-07-14 kinaba: stdout.flush(); 6293256fec 2012-07-14 kinaba: break; 6293256fec 2012-07-14 kinaba: case Keys.LEFT: 6293256fec 2012-07-14 kinaba: score += m.command_L(); 6293256fec 2012-07-14 kinaba: stdout.flush(); 6293256fec 2012-07-14 kinaba: break; 6293256fec 2012-07-14 kinaba: case Keys.RIGHT: 6293256fec 2012-07-14 kinaba: score += m.command_R(); 6293256fec 2012-07-14 kinaba: stdout.flush(); 6293256fec 2012-07-14 kinaba: break; 6293256fec 2012-07-14 kinaba: case Keys.W: 6293256fec 2012-07-14 kinaba: score += m.wait(); 6293256fec 2012-07-14 kinaba: stdout.flush(); 6293256fec 2012-07-14 kinaba: break; 6293256fec 2012-07-14 kinaba: case Keys.A: 6293256fec 2012-07-14 kinaba: score += m.abort(); 6293256fec 2012-07-14 kinaba: stdout.flush(); 6293256fec 2012-07-14 kinaba: break; 6293256fec 2012-07-14 kinaba: case Keys.G: 6293256fec 2012-07-14 kinaba: score += m.clever(); 6293256fec 2012-07-14 kinaba: stdout.flush(); 6293256fec 2012-07-14 kinaba: break; 6293256fec 2012-07-14 kinaba: default: 6293256fec 2012-07-14 kinaba: break; 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: if(m.cleared) { 6293256fec 2012-07-14 kinaba: writeln(); 6293256fec 2012-07-14 kinaba: writeln("Score: ", score); 6293256fec 2012-07-14 kinaba: Application.exit(); 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: this.text = .text("Score: ", score, " air[",m.water_proof-m.underwater,"]"); 6293256fec 2012-07-14 kinaba: invalidate(); 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: 6293256fec 2012-07-14 kinaba: extern(C) { 6293256fec 2012-07-14 kinaba: void sigint(int) { 6293256fec 2012-07-14 kinaba: write("A"); 6293256fec 2012-07-14 kinaba: stdout.flush(); 6293256fec 2012-07-14 kinaba: exit(0); 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: } 6293256fec 2012-07-14 kinaba: 6293256fec 2012-07-14 kinaba: void main(string[] args) 6293256fec 2012-07-14 kinaba: { 6293256fec 2012-07-14 kinaba: signal(SIGINT, &sigint); 6293256fec 2012-07-14 kinaba: 6293256fec 2012-07-14 kinaba: Form myForm = new MyForm(new Map(File(args[1]))); 6293256fec 2012-07-14 kinaba: Application.run(myForm); 6293256fec 2012-07-14 kinaba: }