@@ -91,18 +91,20 @@ class Map { mixin DeriveShow; - static Map load(string[] raw_data, string[string] params) + static Map load(string[] raw_data, string[string] params, char[char] trampo) { // TODO: choose optimal representation. - return new Map(raw_data, params); + return new Map(raw_data, params, trampo); } char[][] data; Pos robot; Pos lift; int waterproof; + Pos[char] tr_target; + Pos[][char] tr_source; Map clone() const { return new Map(this); } this(in Map m) { foreach(s; m.data) @@ -111,9 +113,9 @@ this.lift = m.lift.clone(); this.waterproof = m.waterproof; } - this(string[] raw_data, string[string] params) + this(string[] raw_data, string[string] params, char[char] trampo) { int width = 0; foreach(r; raw_data) width = max(width, r.length); @@ -129,10 +131,23 @@ this.robot = new Pos(y,x); if(this[y,x] == 'L' || this[y,x] == 'O') this.lift = new Pos(y,x); } + + Pos[char] tr_pos; + for(int y=1; y<=H; ++y) + for(int x=1; x<=W; ++x) { + char c = this[y,x]; + if('1'<=c && c<='9' || 'A'<=c&&c<='I') + tr_pos[c] = new Pos(y,x); + } this.waterproof = params.get("Waterproof", "5").to!int(); + foreach(fr,to; trampo) { + tr_target[fr] = tr_pos[to]; + if(to !in tr_source) tr_source[to] = []; + tr_source[to] ~= tr_pos[to]; + } } const @property { int H() { return data.length; } @@ -284,25 +299,28 @@ for(string line; !(line=input.readln().chomp()).empty; ) raw_data ~= line; // Additional commands; read until EOF. + char[char] trampo; for(string line; !(line=input.readln()).empty; ) { string[] ss = line.split(); if( ss.length == 2 ) params[ss[0]] = ss[1]; + if( ss.length == 4 && ss[0]=="Trampoline" && ss[2]=="targets" ) + trampo[ss[1][0]] = ss[3][0]; } - return load(raw_data, params); + return load(raw_data, params, trampo); } - static Game load(string[] raw_data, string[string] params) + static Game load(string[] raw_data, string[string] params, char[char] trampo = null) { - return new Game(raw_data, params); + return new Game(raw_data, params, trampo); } - this(string[] raw_data, string[string] params) + this(string[] raw_data, string[string] params, char[char] trampo) { - this.map = Map.load(raw_data, params); + this.map = Map.load(raw_data, params, trampo); this.water = Water.load(params); } Game clone() const { return new Game(this); }