26 public class Mine implements TextRepresentable { |
26 public class Mine implements TextRepresentable { |
27 |
27 |
28 protected Cell[][] cells; |
28 protected Cell[][] cells; |
29 protected int sizeX; |
29 protected int sizeX; |
30 protected int sizeY; |
30 protected int sizeY; |
31 protected int waterLevel = 0; |
31 protected int waterLevel = 0; |
32 protected int flooding = 0; |
32 protected int flooding = 0; |
33 protected int robotWaterproof = 10; |
33 protected int robotWaterproof = 10; |
34 protected static Pattern pattern = Pattern.compile("(?s)(.*?)(\n\n)?(Water )?(\\d*)\n?(Flooding )?(\\d*)\n?(Waterproof )?(\\d*)"); |
34 protected static Pattern minePattern = Pattern |
|
35 .compile("(?s)(.*?)(\n\n(Water.*|Flooding.*|Waterproof.*)|$)"); |
|
36 protected static Pattern waterPattern = Pattern.compile("(?s).*(?<=.*Water )(\\d+).*"); |
|
37 protected static Pattern floodingPattern = Pattern.compile("(?s).*(?<=.*Flooding )(\\d+).*"); |
|
38 protected static Pattern waterproofPattern = Pattern.compile("(?s).*(?<=.*Waterproof )(\\d+).*"); |
35 |
39 |
36 public Mine(String text) { |
40 public Mine(String text) { |
37 fromText(text); |
41 fromText(text); |
38 if (findCells(OpenLambdaLift).size() != 0) |
42 if (findCells(OpenLambdaLift).size() != 0) |
39 throw new RuntimeException("Detected OpenLambdaLift in new map!"); |
43 throw new RuntimeException("Detected OpenLambdaLift in new map!"); |
61 } |
65 } |
62 return text; |
66 return text; |
63 } |
67 } |
64 |
68 |
65 protected void fromText(String str) { |
69 protected void fromText(String str) { |
66 Matcher matcher = pattern.matcher(str); |
70 Matcher matcher = minePattern.matcher(str); |
67 if (!matcher.matches()) |
71 if (!matcher.matches()) |
68 throw new RuntimeException("Can't parse mine from string"); |
72 throw new RuntimeException("Can't parse mine from string"); |
69 String body = matcher.group(1); |
73 String body = matcher.group(1); |
70 String[] rows = body.split("\n+"); |
74 String[] rows = body.split("\n+"); |
71 int y = rows.length; |
75 int y = rows.length; |
89 content = Empty; |
93 content = Empty; |
90 Cell cell = new Cell(new Coordinate(curX + 1, rows.length - curY), content); |
94 Cell cell = new Cell(new Coordinate(curX + 1, rows.length - curY), content); |
91 cells[curX][curY] = cell; |
95 cells[curX][curY] = cell; |
92 } |
96 } |
93 } |
97 } |
94 |
98 |
95 String sWaterLevel = matcher.group(4); |
99 String metadata = matcher.group(3); |
96 String sFlooding = matcher.group(6); |
100 String sWaterLevel = ""; |
97 String sRobotWaterproof = matcher.group(8); |
101 String sFlooding = ""; |
|
102 String sRobotWaterproof = ""; |
|
103 Matcher waterMatcher = waterPattern.matcher(metadata); |
|
104 if (waterMatcher.matches()) { |
|
105 sWaterLevel = waterMatcher.group(1); |
|
106 } |
|
107 Matcher floodingMatcher = floodingPattern.matcher(metadata); |
|
108 if (floodingMatcher.matches()) { |
|
109 sFlooding = floodingMatcher.group(1); |
|
110 } |
|
111 Matcher waterproofMatcher = waterproofPattern.matcher(metadata); |
|
112 if (waterproofMatcher.matches()) { |
|
113 sRobotWaterproof = waterproofMatcher.group(1); |
|
114 } |
98 if (sWaterLevel.length() > 0) |
115 if (sWaterLevel.length() > 0) |
99 waterLevel = Integer.parseInt(sWaterLevel); |
116 waterLevel = Integer.parseInt(sWaterLevel); |
100 if (sFlooding.length() > 0) |
117 if (sFlooding.length() > 0) |
101 flooding = Integer.parseInt(sFlooding); |
118 flooding = Integer.parseInt(sFlooding); |
102 if (sRobotWaterproof.length() > 0) |
119 if (sRobotWaterproof.length() > 0) |