Check-in [d0766ecd1b]
Not logged in
Overview
SHA1 Hash:d0766ecd1be3eea875d73cb98ce4e3b48d9799bb
Date: 2012-07-13 23:45:57
User: kinaba
Comment:Recognized robot crash condition.
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 [ab6badd03b0f582a] to [7e3fd51446530418].

4 4 import std.stdio; 5 5 import std.string; 6 6 import dfl.all; 7 7 8 8 class Map 9 9 { 10 10 private char[][] data; 11 + bool dead = false; 11 12 12 13 this(File input) 13 14 { 14 15 foreach(s; input.byLine()) 15 16 data ~= s.chomp.dup; 16 17 17 18 int width = 0; ................................................................................ 46 47 } 47 48 } 48 49 49 50 int command_R() { return move(0, +1); } 50 51 int command_L() { return move(0, -1); } 51 52 int command_U() { return move(-1, 0); } 52 53 int command_D() { return move(+1, 0); } 53 - int wait() { update(); return -1; } 54 + int wait() { if(dead)return 0; update(); return -1; } 54 55 55 56 int move(int dy, int dx) { 56 57 foreach(y,s; data) 57 58 foreach(x,c; s) 58 59 if(c == 'R') 59 60 return move(dy, dx, y, x); 60 61 assert(false); 61 62 } 62 63 63 64 int gained = 0; // TODO: atode naosu 64 65 int move(int dy, int dx, int y, int x) { 66 + if(dead) 67 + return 0; 65 68 int score = 0; 66 69 if(data[y+dy][x+dx]=='\\') { 67 70 score += 25; 68 71 ++gained; 69 72 } 70 73 if(data[y+dy][x+dx]=='O') 71 74 score += gained*50; ................................................................................ 89 92 next ~= s.dup; 90 93 91 94 bool lambda = false; 92 95 for(int y=1; y+1<H; ++y) 93 96 for(int x=1; x+1<W; ++x) 94 97 lambda |= (data[y][x] == '\\'); 95 98 96 - for(int y=1; y+1<H; ++y) 99 + for(int y=H-2; y>=1; --y) 97 100 for(int x=1; x+1<W; ++x) { 98 101 if(data[y][x]=='*') { 99 102 if(data[y+1][x]==' ') { 100 103 next[y][x]=' '; 101 104 next[y+1][x]='*'; 105 + if(next[y+2][x]=='R') 106 + dead=true; 102 107 } 103 108 else if(data[y+1][x]=='*' && data[y][x+1]==' ' && data[y+1][x+1]==' ') { 104 109 next[y][x]=' '; 105 110 next[y+1][x+1]='*'; 111 + if(next[y+2][x+1]=='R') 112 + dead=true; 106 113 } 107 114 else if(data[y+1][x]=='*' && data[y][x-1]==' ' && data[y+1][x-1]==' ') { 108 115 next[y][x]=' '; 109 116 next[y+1][x-1]='*'; 117 + if(next[y+2][x-1]=='R') 118 + dead=true; 110 119 } 111 120 else if(data[y+1][x]=='\\' && data[y][x+1]==' ' && data[y+1][x+1]==' ') { 112 121 next[y][x]=' '; 113 122 next[y+1][x+1]='*'; 123 + if(next[y+2][x+1]=='R') 124 + dead=true; 114 125 } 115 126 } 116 127 else if(data[y][x]=='L') { 117 128 if(!lambda) 118 129 next[y][x] = 'O'; 119 130 } 120 131 } ................................................................................ 148 159 if(m.data[y][x]=='*') { 149 160 g.drawText("岩", font, Color(0,0,0), Rect((x-1)*Z, (y-1)*Z, Z, Z)); 150 161 } 151 162 if(m.data[y][x]=='\\') { 152 163 g.drawText("λ", font, Color(0,255,0), Rect((x-1)*Z, (y-1)*Z, Z, Z)); 153 164 } 154 165 if(m.data[y][x]=='R') { 155 - g.drawText("R", font, Color(128,128,0), Rect((x-1)*Z, (y-1)*Z, Z, Z)); 166 + if(m.dead) 167 + g.drawText("Я", font, Color(255,0,0), Rect((x-1)*Z, (y-1)*Z, Z, Z)); 168 + else 169 + g.drawText("R", font, Color(128,128,0), Rect((x-1)*Z, (y-1)*Z, Z, Z)); 156 170 } 157 171 if(m.data[y][x]=='L') { 158 172 g.drawText("L", font, Color(255,255,0), Rect((x-1)*Z, (y-1)*Z, Z, Z)); 159 173 } 160 174 if(m.data[y][x]=='O') { 161 175 g.drawText("O", font, Color(255,255,0), Rect((x-1)*Z, (y-1)*Z, Z, Z)); 162 176 }