diff options
Diffstat (limited to 'src/jrummikub/model')
-rw-r--r-- | src/jrummikub/model/StoneSet.java | 43 |
1 files changed, 18 insertions, 25 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); } } |