Diff
Not logged in

Differences From Artifact [1b2e4ad2dae20251]:

To Artifact [06258bf9d419d24b]:


84 assert( 1 == w.level(3) ); 84 assert( 1 == w.level(3) ); 85 assert( 1 == w.level(4) ); 85 assert( 1 == w.level(4) ); 86 assert( 1 == w.level(5) ); 86 assert( 1 == w.level(5) ); 87 } 87 } 88 88 89 //////////////////////////////////////////////////////////////////////////////// 89 //////////////////////////////////////////////////////////////////////////////// 90 90 > 91 class Hige > 92 { > 93 public immutable int pace; > 94 mixin DeriveCreate; > 95 mixin DeriveCompare; > 96 mixin DeriveShow; > 97 Hige clone() const { return cast(Hige)this; } > 98 > 99 static load(string[string] params) > 100 { > 101 return new Hige(params.get("Growth", "25").to!int()); > 102 } > 103 > 104 bool is_growing_turn(int turn) const > 105 { > 106 return pace ? turn%pace == pace-1 : false; > 107 } > 108 > 109 int until_rise(int turn) const > 110 { > 111 return pace ? pace-turn%pace : int.max; > 112 } > 113 } > 114 > 115 //////////////////////////////////////////////////////////////////////////////// > 116 91 class Map 117 class Map 92 { 118 { 93 mixin DeriveShow; 119 mixin DeriveShow; 94 120 95 static Map load(string[] raw_data, string[string] params, char[char] tra 121 static Map load(string[] raw_data, string[string] params, char[char] tra 96 { 122 { 97 // TODO: choose optimal representation. 123 // TODO: choose optimal representation. ................................................................................................................................................................................ 101 char[][] data; 127 char[][] data; 102 Pos robot; 128 Pos robot; 103 Pos lift; 129 Pos lift; 104 int waterproof; 130 int waterproof; 105 // TODO: immutable 131 // TODO: immutable 106 Pos[char] tr_target; 132 Pos[char] tr_target; 107 Pos[][char] tr_source; 133 Pos[][char] tr_source; > 134 const(Hige) hige; > 135 int razor; 108 136 109 Map clone() const { return new Map(this); } 137 Map clone() const { return new Map(this); } 110 this(in Map m) { 138 this(in Map m) { 111 foreach(s; m.data) 139 foreach(s; m.data) 112 this.data ~= s.dup; 140 this.data ~= s.dup; 113 this.robot = m.robot.clone(); 141 this.robot = m.robot.clone(); 114 this.lift = m.lift.clone(); 142 this.lift = m.lift.clone(); 115 this.waterproof = m.waterproof; 143 this.waterproof = m.waterproof; 116 this.tr_target = cast(Pos[char])m.tr_target; 144 this.tr_target = cast(Pos[char])m.tr_target; 117 this.tr_source = cast(Pos[][char])m.tr_source; 145 this.tr_source = cast(Pos[][char])m.tr_source; > 146 this.hige = m.hige.clone(); > 147 this.razor = m.razor; 118 } 148 } 119 149 120 this(string[] raw_data, string[string] params, char[char] trampo) 150 this(string[] raw_data, string[string] params, char[char] trampo) 121 { 151 { 122 int width = 0; 152 int width = 0; 123 foreach(r; raw_data) 153 foreach(r; raw_data) 124 width = max(width, r.length); 154 width = max(width, r.length); ................................................................................................................................................................................ 146 176 147 this.waterproof = params.get("Waterproof", "5").to!int(); 177 this.waterproof = params.get("Waterproof", "5").to!int(); 148 foreach(fr,to; trampo) { 178 foreach(fr,to; trampo) { 149 tr_target[fr] = tr_pos[to]; 179 tr_target[fr] = tr_pos[to]; 150 if(to !in tr_source) tr_source[to] = []; 180 if(to !in tr_source) tr_source[to] = []; 151 tr_source[to] ~= tr_pos[fr]; 181 tr_source[to] ~= tr_pos[fr]; 152 } 182 } > 183 > 184 this.hige = Hige.load(params); > 185 this.razor = params.get("Razors", "0").to!int(); 153 } 186 } 154 187 155 const @property { 188 const @property { 156 int H() { return data.length; } 189 int H() { return data.length; } 157 int W() { return data[0].length; } 190 int W() { return data[0].length; } 158 } 191 } 159 192 ................................................................................................................................................................................ 385 // TODO: when adding members, take care of clone(). 418 // TODO: when adding members, take care of clone(). 386 // TODO: fix this poor design. 419 // TODO: fix this poor design. 387 420 388 @property const { 421 @property const { 389 long score() { return lambda*25L*(1+exit_bonus) - turn; } 422 long score() { return lambda*25L*(1+exit_bonus) - turn; } 390 int water_level() { return water.level(turn); } 423 int water_level() { return water.level(turn); } 391 int water_until_rise() { return water.until_rise(turn); } 424 int water_until_rise() { return water.until_rise(turn); } > 425 int hige_until_rise() { return map.hige.until_rise(turn); } 392 bool cleared() { return exit_bonus>0; } 426 bool cleared() { return exit_bonus>0; } 393 int hp() { return map.waterproof - under_water; } 427 int hp() { return map.waterproof - under_water; } 394 long score_if_abort_now() { return lambda*25*(1+max(1,exit_bonus 428 long score_if_abort_now() { return lambda*25*(1+max(1,exit_bonus 395 } 429 } 396 } 430 } 397 < 398 unittest < 399 { < 400 Game.load(["###","...","#RL"], ["xxx":"yyy"]); < 401 } <