summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJannis Harder <harder@informatik.uni-luebeck.de>2011-05-03 19:06:12 +0200
committerJannis Harder <harder@informatik.uni-luebeck.de>2011-05-03 19:06:12 +0200
commitf8f75fde6d6392aee2504df5bde05459d0b0c36f (patch)
tree09019063beba8047a6bfb3570365427b871a2ae1 /src
parent2eaf873ec6dc8b7362896cdfe7fe1dc78230b18e (diff)
downloadJRummikub-f8f75fde6d6392aee2504df5bde05459d0b0c36f.tar
JRummikub-f8f75fde6d6392aee2504df5bde05459d0b0c36f.zip
Classification of runs and sets
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@83 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src')
-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;
}
}