package apostov;

import com.google.common.collect.ImmutableList;

public class CommandLineInterpreter {

	public void interpretArguments(final String[] arguments) {
		if (arguments.length == 2) {
			final HolecardHand hand1 = holecardHandFromFourCharacters(arguments[0]);
			final HolecardHand hand2 = holecardHandFromFourCharacters(arguments[1]);
			
			new HandResultEnumerator().enumerateBoardsAndMeasureWins(ImmutableList.of(hand1, hand2));
		} else {
			throw new RuntimeException("Unexpected number of arguments");
		}
	}
	
	private HolecardHand holecardHandFromFourCharacters(final String representation) {
		if (representation.length() != 4)
			throw new RuntimeException(representation + " is not a valid hand");

		final Card c1 = cardFromTwoLetterRepresentation(representation.substring(0, 2));
		final Card c2 = cardFromTwoLetterRepresentation(representation.substring(2, 4));
		
		return new HolecardHand(c1, c2);
	}
	
	private Card cardFromTwoLetterRepresentation(final String representation) {
		if (representation.length() != 2)
			throw new RuntimeException(representation + " is not a valid card");

		final char valueCharacter = representation.charAt(0);
		final char suitCharacter = representation.charAt(1);
		
		final Value value = Value.byShortName.get(valueCharacter);
		final Suit suit = Suit.byShortName.get(suitCharacter);
		
		if (suit == null || value == null)
			throw new RuntimeException(representation + " is not a valid card");
		
		return new Card(value, suit);
	}
}

@@ -13,16 +13,182 @@
 tov;%0D%0A%0D%0A
+import java.util.Arrays;%0D%0Aimport java.util.List;%0D%0Aimport java.util.Map;%0D%0Aimport java.util.stream.Collectors;%0D%0A%0D%0Aimport org.apache.commons.math3.fraction.Fraction;%0D%0A%0D%0A
 import c
@@ -359,17 +359,17 @@
 gth 
-=
+%3E
 = 2) %7B%0D%0A
 %09%09%09f
@@ -364,16 +364,21 @@
 = 2) %7B%0D%0A
+%09%09%09%0D%0A
 %09%09%09final
@@ -370,32 +370,37 @@
 %0D%0A%09%09%09%0D%0A%09%09%09final 
+List%3C
 HolecardHand han
@@ -399,149 +399,214 @@
 Hand
- hand1 = holecardHandFromFourCharacters(arguments%5B0%5D);%0D%0A%09%09%09final HolecardHand hand2 = holecardHandFromFourCharacters(arguments%5B1%5D);%0D%0A%09%09%09%0D%0A%09%09%09
+%3E competingHands = %0D%0A%09%09%09%09%09Arrays.stream(arguments)%0D%0A%09%09%09%09%09%09.map(arg -%3E holecardHandFromFourCharacters(arg))%0D%0A%09%09%09%09%09%09.collect(Collectors.toList());%0D%0A%09%09%09%0D%0A%09%09%09%0D%0A%09%09%09final Map%3CHolecardHand, Fraction%3E winsByHand = 
 new 
@@ -676,26 +676,322 @@
 ist.
-of(h
+copyOf(competingHands));%0D%0A%09%09%09for (final Map.Entry%3CHolecardH
 and
-1
 , 
-hand2));
+Fraction%3E entry : winsByHand.entrySet()) %7B%0D%0A%09%09%09%09final HolecardHand hand = entry.getKey();%0D%0A%09%09%09%09final Fraction fraction = entry.getValue();%0D%0A%09%09%09%09%0D%0A%09%09%09%09System.out.println(hand + %22%5Ct%22 + String.format(%22%25.02f%25%25%22, 100 * fraction.doubleValue()));%0D%0A%09%09%09%7D%0D%0A%09%09%09
 %0D%0A%09%09

allow for more than two competing hands