@@ -101,8 +101,9 @@ char[][] data; Pos robot; Pos lift; int waterproof; + // TODO: immutable Pos[char] tr_target; Pos[][char] tr_source; Map clone() const { return new Map(this); } @@ -111,8 +112,10 @@ this.data ~= s.dup; this.robot = m.robot.clone(); this.lift = m.lift.clone(); this.waterproof = m.waterproof; + this.tr_target = cast(Pos[char])m.tr_target; + this.tr_source = cast(Pos[][char])m.tr_source; } this(string[] raw_data, string[string] params, char[char] trampo) { @@ -144,9 +147,9 @@ 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]; + tr_source[to] ~= tr_pos[fr]; } } const @property { @@ -229,8 +232,15 @@ this[y,x]=' '; this[y+dy,x+dx]='R'; this[y+dy*2,x+dx*2]='*'; robot = new Pos(y+dy,x+dx); + } else if('A'<=this[y+dy,x+dx] && this[y+dy,x+dx]<='I') { + this[y,x]=' '; + Pos tp = tr_target[this[y+dy,x+dx]]; + foreach(p; tr_source[this[tp]]) + this[p] = ' '; + this[tp] = 'R'; + robot = tp; } if( update() ) dead = true; return tuple(lambda,dead);