Diff
Not logged in

Differences From Artifact [ab6badd03b0f582a]:

To Artifact [7e3fd51446530418]:


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