summaryrefslogtreecommitdiffstats
path: root/src/jrummikub
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub')
-rw-r--r--src/jrummikub/model/StoneSet.java24
1 files changed, 20 insertions, 4 deletions
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<Stone>, Sizeable {
@@ -25,14 +26,29 @@ public class StoneSet implements Iterable<Stone>, Sizeable {
this.stones = new ArrayList<Stone>(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<Stone>, 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;
}
}