Overview
SHA1 Hash: | 99d27d1a039e3d50597b133144b15794d5f08f9f |
---|---|
Date: | 2012-07-15 01:46:37 |
User: | kinaba |
Comment: | parser for trampoline. |
Timelines: | family | ancestors | descendants | both | trunk |
Diffs: | redesign |
Downloads: | Tarball | ZIP archive |
Other Links: | files | file ages | manifest |
Tags And Properties
- branch=trunk inherited from [16f0b5784f]
- sym-trunk inherited from [16f0b5784f]
Changes
Modified src/game.d from [3baab0ddf11cca7d] to [6d5cf776b9d55f93].
43 { 43 { 44 public immutable int base, pace; 44 public immutable int base, pace; 45 mixin DeriveCreate; 45 mixin DeriveCreate; 46 mixin DeriveCompare; 46 mixin DeriveCompare; 47 mixin DeriveShow; 47 mixin DeriveShow; 48 Water clone() const { return cast(Water)this; } 48 Water clone() const { return cast(Water)this; } 49 49 50 static load(string[string] params) | 50 static load(string[][string] params) 51 { 51 { 52 return new Water( 52 return new Water( 53 params.get("Water", "0").to!int(), | 53 params.get("Water", ["0"])[0].to!int(), 54 params.get("Flooding", "0").to!int() | 54 params.get("Flooding", ["0"])[0].to!int() 55 ); 55 ); 56 } 56 } 57 57 58 int level(int number_of_update) const 58 int level(int number_of_update) const 59 { 59 { 60 return pace ? base+(number_of_update/pace) : base; 60 return pace ? base+(number_of_update/pace) : base; 61 } 61 } ................................................................................................................................................................................ 88 88 89 //////////////////////////////////////////////////////////////////////////////// 89 //////////////////////////////////////////////////////////////////////////////// 90 90 91 class Map 91 class Map 92 { 92 { 93 mixin DeriveShow; 93 mixin DeriveShow; 94 94 95 static Map load(string[] raw_data, string[string] params) | 95 static Map load(string[] raw_data, string[][string] params) 96 { 96 { 97 // TODO: choose optimal representation. 97 // TODO: choose optimal representation. 98 return new Map(raw_data, params); 98 return new Map(raw_data, params); 99 } 99 } 100 100 101 char[][] data; 101 char[][] data; 102 Pos robot; 102 Pos robot; ................................................................................................................................................................................ 108 foreach(s; m.data) 108 foreach(s; m.data) 109 this.data ~= s.dup; 109 this.data ~= s.dup; 110 this.robot = m.robot.clone(); 110 this.robot = m.robot.clone(); 111 this.lift = m.lift.clone(); 111 this.lift = m.lift.clone(); 112 this.waterproof = m.waterproof; 112 this.waterproof = m.waterproof; 113 } 113 } 114 114 115 this(string[] raw_data, string[string] params) | 115 this(string[] raw_data, string[][string] params) 116 { 116 { 117 int width = 0; 117 int width = 0; 118 foreach(r; raw_data) 118 foreach(r; raw_data) 119 width = max(width, r.length); 119 width = max(width, r.length); 120 foreach(r; raw_data) { 120 foreach(r; raw_data) { 121 this.data ~= r.dup; 121 this.data ~= r.dup; 122 this.data[$-1].length = width; 122 this.data[$-1].length = width; ................................................................................................................................................................................ 127 for(int x=1; x<=W; ++x) { 127 for(int x=1; x<=W; ++x) { 128 if(this[y,x] == 'R') 128 if(this[y,x] == 'R') 129 this.robot = new Pos(y,x); 129 this.robot = new Pos(y,x); 130 if(this[y,x] == 'L' || this[y,x] == 'O') 130 if(this[y,x] == 'L' || this[y,x] == 'O') 131 this.lift = new Pos(y,x); 131 this.lift = new Pos(y,x); 132 } 132 } 133 133 134 this.waterproof = params.get("Waterproof", "5").to!int(); | 134 this.waterproof = params.get("Waterproof", ["5"])[0].to!int(); 135 } 135 } 136 136 137 const @property { 137 const @property { 138 int H() { return data.length; } 138 int H() { return data.length; } 139 int W() { return data[0].length; } 139 int W() { return data[0].length; } 140 } 140 } 141 141 ................................................................................................................................................................................ 273 273 274 class Game 274 class Game 275 { 275 { 276 mixin DeriveShow; 276 mixin DeriveShow; 277 277 278 static Game load(File input) 278 static Game load(File input) 279 { 279 { 280 string[] raw_data; | 280 string[] raw_data; 281 string[string] params; | 281 string[][string] params; 282 282 283 // Raw map data; read until empty line. 283 // Raw map data; read until empty line. 284 for(string line; !(line=input.readln().chomp()).empty; ) 284 for(string line; !(line=input.readln().chomp()).empty; ) 285 raw_data ~= line; 285 raw_data ~= line; 286 286 287 // Additional commands; read until EOF. 287 // Additional commands; read until EOF. 288 for(string line; !(line=input.readln()).empty; ) { 288 for(string line; !(line=input.readln()).empty; ) { 289 string[] ss = line.split(); 289 string[] ss = line.split(); 290 if( ss.length == 2 ) < 291 params[ss[0]] = ss[1]; | 290 params[ss[0]] = ss[1..$]; 292 } 291 } 293 292 294 return load(raw_data, params); 293 return load(raw_data, params); 295 } 294 } 296 295 297 static Game load(string[] raw_data, string[string] params) | 296 static Game load(string[] raw_data, string[][string] params) 298 { 297 { 299 return new Game(raw_data, params); 298 return new Game(raw_data, params); 300 } 299 } 301 300 302 this(string[] raw_data, string[string] params) | 301 this(string[] raw_data, string[][string] params) 303 { 302 { 304 this.map = Map.load(raw_data, params); 303 this.map = Map.load(raw_data, params); 305 this.water = Water.load(params); 304 this.water = Water.load(params); 306 } 305 } 307 306 308 Game clone() const { return new Game(this); } 307 Game clone() const { return new Game(this); } 309 this(in Game g) { 308 this(in Game g) {