summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/jrummikub/model/StoneSet.java43
-rw-r--r--test/jrummikub/model/StoneSetTest.java2
2 files changed, 19 insertions, 26 deletions
diff --git a/src/jrummikub/model/StoneSet.java b/src/jrummikub/model/StoneSet.java
index 604d6ac..2700889 100644
--- a/src/jrummikub/model/StoneSet.java
+++ b/src/jrummikub/model/StoneSet.java
@@ -66,40 +66,33 @@ public class StoneSet implements Iterable<Stone>, Sizeable {
if (stones.size() < 3) {
return new Pair<Type, Integer>(INVALID, 0);
}
- int nonJoker1 = -1, nonJoker2 = -1;
+ int nonJoker = -1;
for (int i = 0; i < stones.size(); i++) {
if (stones.get(i).isJoker()) {
continue;
}
- nonJoker2 = nonJoker1;
- nonJoker1 = i;
+ nonJoker = i;
}
- if (nonJoker2 == -1) {
- // Z first
- if (nonJoker1 == 0 && stones.get(nonJoker1).getValue() < 12) {
- return new Pair<Type, Integer>(RUN, isValidRun(nonJoker1));
+
+ if (nonJoker == -1) {
+ if (stones.size() > 13) {
+ return new Pair<Type, Integer>(INVALID, 0);
+ } else if (stones.size() > 4) {
+ return new Pair<Type, Integer>(RUN, 91 - (stones.size() - 13)*(stones.size() - 14)/2);
} else {
- int value = stones.get(nonJoker1).getValue() * stones.size();
- return new Pair<Type, Integer>(GROUP, value);
+ return new Pair<Type, Integer>(GROUP, stones.size() * 13);
}
}
-
- // is run
- if (stones.get(nonJoker1).getColor() == stones.get(nonJoker2)
- .getColor()) {
- if (isValidRun(nonJoker1) > 0) {
- return new Pair<Type, Integer>(RUN, isValidRun(nonJoker1));
- }
- return new Pair<Type, Integer>(INVALID, 0);
-
- }
- // is group
- else {
- if (isValidGroup(stones.get(nonJoker1).getValue()) > 0) {
- return new Pair<Type, Integer>(GROUP, isValidGroup(stones.get(
- nonJoker1).getValue()));
- }
+
+ int runScore = isValidRun(nonJoker);
+ int groupScore = isValidGroup(stones.get(nonJoker).getValue());
+
+ if (runScore > groupScore) {
+ return new Pair<Type, Integer>(RUN, runScore);
+ } else if (groupScore == 0) {
return new Pair<Type, Integer>(INVALID, 0);
+ } else {
+ return new Pair<Type, Integer>(GROUP, groupScore);
}
}
diff --git a/test/jrummikub/model/StoneSetTest.java b/test/jrummikub/model/StoneSetTest.java
index a44818c..f53163e 100644
--- a/test/jrummikub/model/StoneSetTest.java
+++ b/test/jrummikub/model/StoneSetTest.java
@@ -165,7 +165,7 @@ public class StoneSetTest {
new Stone(RED), new Stone(RED)));
assertSet(GROUP, 4 * 13, Arrays.asList(new Stone(RED),
new Stone(RED), new Stone(RED), new Stone(RED)));
- assertSet(RUN, 5 * 11, Arrays.asList(new Stone(RED),
+ assertSet(RUN, 13 + 12 + 11 + 10 + 9, Arrays.asList(new Stone(RED),
new Stone(RED), new Stone(RED), new Stone(RED), new Stone(RED)));
assertSet(RUN, 5 * 10, Arrays.asList(new Stone(RED),
new Stone(RED), new Stone(RED), new Stone(RED), new Stone(12, RED)));