icfp-model/src/main/java/ru/bosony/model/mine/Mine.java
changeset 29 66aa96e8fd92
parent 27 505c25412b16
child 30 666821484adc
     1.1 --- a/icfp-model/src/main/java/ru/bosony/model/mine/Mine.java	Sun Jul 15 21:36:42 2012 +0400
     1.2 +++ b/icfp-model/src/main/java/ru/bosony/model/mine/Mine.java	Mon Jul 16 00:05:50 2012 +0400
     1.3 @@ -31,11 +31,15 @@
     1.4  	protected int				waterLevel				= 0;
     1.5  	protected int				flooding				= 0;
     1.6  	protected int				robotWaterproof			= 10;
     1.7 +	protected int				growth					= 25;
     1.8 +	protected int				razorsCount				= 0;
     1.9  	protected static Pattern	minePattern				= Pattern
    1.10 -																.compile("(?s)(.*?)(\n\n(Water.*|Flooding.*|Waterproof.*|Trampoline.*)|$)");
    1.11 +																.compile("(?s)(.*?)(\n\n(Water.*|Flooding.*|Waterproof.*|Trampoline.*|Growth.*|Razors.*)|$)");
    1.12  	protected static Pattern	waterPattern			= Pattern.compile("(?s).*(?<=.*Water )(\\d+).*");
    1.13  	protected static Pattern	floodingPattern			= Pattern.compile("(?s).*(?<=.*Flooding )(\\d+).*");
    1.14  	protected static Pattern	waterproofPattern		= Pattern.compile("(?s).*(?<=.*Waterproof )(\\d+).*");
    1.15 +	protected static Pattern	growthPattern			= Pattern.compile("(?s).*(?<=.*Growth )(\\d+).*");
    1.16 +	protected static Pattern	razorsPattern			= Pattern.compile("(?s).*(?<=.*Razors )(\\d+).*");
    1.17  	protected static Pattern	trampolinePattern		= Pattern
    1.18  																.compile("(?s).*?Trampoline ([A-I]) targets ([1-9]).*");
    1.19  	protected static String		firstTrampolineRegexp	= "(?s).*?Trampoline ([A-I]) targets ([1-9])";
    1.20 @@ -61,16 +65,22 @@
    1.21  		}
    1.22  		text = text.replaceAll("\n*$", "");
    1.23  		text += "\n\n";
    1.24 -		if (waterLevel != 0 || flooding != 0 || robotWaterproof != 10) {
    1.25 +		if (waterLevel != 0) {
    1.26  			text += "Water " + waterLevel + "\n";
    1.27 +		}
    1.28 +		if (flooding != 0) {
    1.29  			text += "Flooding " + flooding + "\n";
    1.30 -			text += "Waterproof " + robotWaterproof + "\n";
    1.31  		}
    1.32 +		text += "Waterproof " + robotWaterproof + "\n";
    1.33  		for (CellContent trampoline : CellContent.values()) {
    1.34  			if (trampoline.getTrampolineTarget() != null)
    1.35  				text += "Trampoline " + trampoline.toText() + " targets " + trampoline.getTrampolineTarget().toText()
    1.36  						+ "\n";
    1.37  		}
    1.38 +		text += "Growth " + growth + "\n";
    1.39 +		if (razorsCount != 0) {
    1.40 +			text += "Razors " + razorsCount + "\n";
    1.41 +		}
    1.42  		text = text.replaceAll("\n*$", "");
    1.43  		return text;
    1.44  	}
    1.45 @@ -145,6 +155,22 @@
    1.46  					break;
    1.47  				trampolines = trampolines.replaceFirst(firstTrampolineRegexp, "");
    1.48  			}
    1.49 +
    1.50 +			// Growth and razorsCount
    1.51 +			String sGrowth = "";
    1.52 +			String sRazors = "";
    1.53 +			Matcher growthMatcher = growthPattern.matcher(metadata);
    1.54 +			if (growthMatcher.matches()) {
    1.55 +				sGrowth = growthMatcher.group(1);
    1.56 +			}
    1.57 +			Matcher razorsMatcher = razorsPattern.matcher(metadata);
    1.58 +			if (razorsMatcher.matches()) {
    1.59 +				sRazors = razorsMatcher.group(1);
    1.60 +			}
    1.61 +			if (sGrowth.length() > 0)
    1.62 +				growth = Integer.parseInt(sGrowth);
    1.63 +			if (sRazors.length() > 0)
    1.64 +				razorsCount = Integer.parseInt(sRazors);
    1.65  		}
    1.66  	}
    1.67  
    1.68 @@ -256,4 +282,16 @@
    1.69  		return robotWaterproof;
    1.70  	}
    1.71  
    1.72 +	public int getGrowth() {
    1.73 +		return growth;
    1.74 +	}
    1.75 +
    1.76 +	public int getRazorsCount() {
    1.77 +		return razorsCount;
    1.78 +	}
    1.79 +
    1.80 +	public void setRazorsCount(int razorsCount) {
    1.81 +		this.razorsCount = razorsCount;
    1.82 +	}
    1.83 +
    1.84  }