diff options
author | Ida Massow <massow@informatik.uni-luebeck.de> | 2011-06-11 04:09:29 +0200 |
---|---|---|
committer | Ida Massow <massow@informatik.uni-luebeck.de> | 2011-06-11 04:09:29 +0200 |
commit | 2c4d2ba28baa858e9fb3eed52a9b76334330bcdf (patch) | |
tree | 600f91a2f310232d308eb5a198120510e49caa22 /src/jrummikub/model | |
parent | 8b1e09f0257de32213debc4bcfcebfc061d51bb2 (diff) | |
download | JRummikub-2c4d2ba28baa858e9fb3eed52a9b76334330bcdf.tar JRummikub-2c4d2ba28baa858e9fb3eed52a9b76334330bcdf.zip |
No Limits implementiert und getestet, geht
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@413 72836036-5685-4462-b002-a69064685172
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; } |