From 2c4d2ba28baa858e9fb3eed52a9b76334330bcdf Mon Sep 17 00:00:00 2001 From: Ida Massow Date: Sat, 11 Jun 2011 04:09:29 +0200 Subject: No Limits implementiert und getestet, geht git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@413 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/model/StoneSet.java | 44 +++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 16 deletions(-) (limited to 'src/jrummikub/model') 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, 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(INVALID, 0); } else if (stones.size() > settings.getStoneColors().size()) { - return new Pair( - 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(RUN, value); } else { return new Pair(GROUP, stones.size() * settings.getHighestValue()); @@ -126,24 +129,33 @@ public class StoneSet implements Iterable, 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; } -- cgit v1.2.3