icfp-model/src/main/java/ru/bosony/model/mine/Mine.java
changeset 31 6f587e61e1a2
parent 30 666821484adc
child 40 daa0ff48b7d0
equal deleted inserted replaced
30:666821484adc 31:6f587e61e1a2
    32 	protected int				flooding							= 0;
    32 	protected int				flooding							= 0;
    33 	protected int				robotWaterproof						= 10;
    33 	protected int				robotWaterproof						= 10;
    34 	protected int				growth								= 25;
    34 	protected int				growth								= 25;
    35 	protected int				razorsCount							= 0;
    35 	protected int				razorsCount							= 0;
    36 	protected int				lambdasAndHighOrderRocksStartCount	= 0;
    36 	protected int				lambdasAndHighOrderRocksStartCount	= 0;
       
    37 	protected String			metadata							= "";
    37 	protected static Pattern	minePattern							= Pattern
    38 	protected static Pattern	minePattern							= Pattern
    38 																			.compile("(?s)(.*?)(\n\n(Water.*|Flooding.*|Waterproof.*|Trampoline.*|Growth.*|Razors.*)|$)");
    39 																			.compile("(?s)(.*?)(\n\n(Water.*|Flooding.*|Waterproof.*|Trampoline.*|Growth.*|Razors.*)|$)");
    39 	protected static Pattern	waterPattern						= Pattern.compile("(?s).*(?<=.*Water )(\\d+).*");
    40 	protected static Pattern	waterPattern						= Pattern.compile("(?s).*(?<=.*Water )(\\d+).*");
    40 	protected static Pattern	floodingPattern						= Pattern.compile("(?s).*(?<=.*Flooding )(\\d+).*");
    41 	protected static Pattern	floodingPattern						= Pattern.compile("(?s).*(?<=.*Flooding )(\\d+).*");
    41 	protected static Pattern	waterproofPattern					= Pattern
    42 	protected static Pattern	waterproofPattern					= Pattern
    66 			}
    67 			}
    67 			text += "\n";
    68 			text += "\n";
    68 		}
    69 		}
    69 		text = text.replaceAll("\n*$", "");
    70 		text = text.replaceAll("\n*$", "");
    70 		text += "\n\n";
    71 		text += "\n\n";
    71 		if (waterLevel != 0) {
    72 		text += metadata;
    72 			text += "Water " + waterLevel + "\n";
       
    73 		}
       
    74 		if (flooding != 0) {
       
    75 			text += "Flooding " + flooding + "\n";
       
    76 		}
       
    77 		text += "Waterproof " + robotWaterproof + "\n";
       
    78 		for (CellContent trampoline : CellContent.values()) {
       
    79 			if (trampoline.getTrampolineTarget() != null)
       
    80 				text += "Trampoline " + trampoline.toText() + " targets " + trampoline.getTrampolineTarget().toText()
       
    81 						+ "\n";
       
    82 		}
       
    83 		text += "Growth " + growth + "\n";
       
    84 		if (razorsCount != 0) {
       
    85 			text += "Razors " + razorsCount + "\n";
       
    86 		}
       
    87 		text = text.replaceAll("\n*$", "");
    73 		text = text.replaceAll("\n*$", "");
    88 		return text;
    74 		return text;
    89 	}
    75 	}
    90 
    76 
    91 	protected void fromText(String str) {
    77 	protected void fromText(String str) {
   116 				Cell cell = new Cell(new Coordinate(curX + 1, rows.length - curY), content);
   102 				Cell cell = new Cell(new Coordinate(curX + 1, rows.length - curY), content);
   117 				cells[curX][curY] = cell;
   103 				cells[curX][curY] = cell;
   118 			}
   104 			}
   119 		}
   105 		}
   120 
   106 
   121 		String metadata = matcher.group(3);
   107 		metadata = matcher.group(3);
   122 		if (metadata != null) {
   108 		if (metadata != null) {
   123 			// Water flooding
   109 			// Water flooding
   124 			String sWaterLevel = "";
   110 			String sWaterLevel = "";
   125 			String sFlooding = "";
   111 			String sFlooding = "";
   126 			String sRobotWaterproof = "";
   112 			String sRobotWaterproof = "";
   172 			}
   158 			}
   173 			if (sGrowth.length() > 0)
   159 			if (sGrowth.length() > 0)
   174 				growth = Integer.parseInt(sGrowth);
   160 				growth = Integer.parseInt(sGrowth);
   175 			if (sRazors.length() > 0)
   161 			if (sRazors.length() > 0)
   176 				razorsCount = Integer.parseInt(sRazors);
   162 				razorsCount = Integer.parseInt(sRazors);
   177 		}
   163 		} else
       
   164 			metadata = "";
   178 	}
   165 	}
   179 
   166 
   180 	public Cell getCell(Coordinate coordinate) {
   167 	public Cell getCell(Coordinate coordinate) {
   181 		if (coordinate == null)
   168 		if (coordinate == null)
   182 			return null;
   169 			return null;