From f8f75fde6d6392aee2504df5bde05459d0b0c36f Mon Sep 17 00:00:00 2001 From: Jannis Harder Date: Tue, 3 May 2011 19:06:12 +0200 Subject: Classification of runs and sets git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@83 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/model/StoneSet.java | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/jrummikub/model/StoneSet.java b/src/jrummikub/model/StoneSet.java index 47e6786..6081730 100644 --- a/src/jrummikub/model/StoneSet.java +++ b/src/jrummikub/model/StoneSet.java @@ -10,6 +10,7 @@ import java.util.Set; import sun.reflect.generics.reflectiveObjects.NotImplementedException; import jrummikub.util.Pair; +import static jrummikub.model.StoneSet.Type.*; /** Class managing {@link Stone}s joined together to form sets */ public class StoneSet implements Iterable, Sizeable { @@ -25,14 +26,29 @@ public class StoneSet implements Iterable, Sizeable { this.stones = new ArrayList(stones); } + public enum Type { + GROUP, RUN, INVALID + } + /** * Test for rule conflict within the StoneSet * * @return true when the set is valid according to the rules */ public boolean isValid() { + return classify() != INVALID; + } + + /** + * Test for rule conflict within the StoneSet and determine whether the set + * is a group or a run + * + * @return GROUP or RUN for valid sets, INVALID otherwise + */ + public Type classify() { + // TODO: extend this for score calculation (release 2...) if (stones.size() < 3) { - return false; + return INVALID; } int nonJoker1 = -1, nonJoker2 = -1; for (int i = 0; i < stones.size(); i++) { @@ -43,17 +59,17 @@ public class StoneSet implements Iterable, Sizeable { nonJoker1 = i; } if (nonJoker2 == -1) { - return true; + return GROUP; } // is run if (stones.get(nonJoker1).getColor() == stones.get(nonJoker2) .getColor()) { - return isValidRun(nonJoker1); + return isValidRun(nonJoker1) ? RUN : INVALID; } // is group else { - return isValidGroup(); + return isValidGroup() ? GROUP : INVALID; } } -- cgit v1.2.3