diff options
Diffstat (limited to 'src/jrummikub/model')
-rw-r--r-- | src/jrummikub/model/StoneSet.java | 44 |
1 files changed, 28 insertions, 16 deletions
diff --git a/src/jrummikub/model/StoneSet.java b/src/jrummikub/model/StoneSet.java index edd6f3f..c1d7a5d 100644 --- a/src/jrummikub/model/StoneSet.java +++ b/src/jrummikub/model/StoneSet.java @@ -85,17 +85,20 @@ public class StoneSet implements Iterable<Stone>, Sizeable, Serializable { if (nonJoker == -1) { if (stones.size() > settings.getHighestValue() - && stones.size() > settings.getStoneColors().size()) { + && stones.size() > settings.getStoneColors().size() + && !settings.isNoLimits()) { return new Pair<Type, Integer>(INVALID, 0); } else if (stones.size() > settings.getStoneColors().size()) { - return new Pair<Type, Integer>( - RUN, - (settings.getHighestValue() * (settings - .getHighestValue() + 1)) - / 2 - - (stones.size() - settings.getHighestValue()) - * (stones.size() - settings.getHighestValue() - 1) - / 2); + int value = 0; + int stoneValue = settings.getHighestValue(); + for (int i = 0; i < stones.size(); i++) { + value += stoneValue; + stoneValue--; + if (stoneValue == 0) { + stoneValue = settings.getHighestValue(); + } + } + return new Pair<Type, Integer>(RUN, value); } else { return new Pair<Type, Integer>(GROUP, stones.size() * settings.getHighestValue()); @@ -126,24 +129,33 @@ public class StoneSet implements Iterable<Stone>, Sizeable, Serializable { int startValue = stones.get(referencePosition).getValue() - referencePosition; int endValue = startValue + stones.size() - 1; - if (startValue < 1 || endValue > settings.getHighestValue()) { - return 0; + if (!settings.isNoLimits()) { + if (startValue < 1 || endValue > settings.getHighestValue()) { + return 0; + } } + int value = 0; for (int i = 0; i < stones.size(); i++) { + int expectedValue = i + startValue; + while (expectedValue < 1) { + expectedValue += settings.getHighestValue(); + } + while (expectedValue > settings.getHighestValue()) { + expectedValue -= settings.getHighestValue(); + } + value += expectedValue; + if (stones.get(i).isJoker()) { continue; } if (stones.get(i).getColor() != runColor) { return 0; } - if (stones.get(i).getValue() != i + startValue) { + + if (stones.get(i).getValue() != expectedValue) { return 0; } } - int value = 0; - for (int i = 0; i < stones.size(); i++) { - value += startValue + i; - } return value; } |