From 0cb36fb752120a3b052a3f25acdd075ed8f80560 Mon Sep 17 00:00:00 2001 From: Ida Massow Date: Tue, 31 May 2011 00:58:48 +0200 Subject: =?UTF-8?q?Man=20kann=20viele=20FAreben=20benutzen,=20alle=20Test?= =?UTF-8?q?=20laufen.=20Man=20kann=20auch=20Karten=20bis=20Wert=20X=20gr?= =?UTF-8?q?=C3=B6=C3=9Fer=20oder=20kleiner=2013=20nehmen.=20Alles=20nur=20?= =?UTF-8?q?im=20Model,=20aber=20getestet=20und=20toll?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@333 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/model/StoneSet.java | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) (limited to 'src/jrummikub/model') diff --git a/src/jrummikub/model/StoneSet.java b/src/jrummikub/model/StoneSet.java index 3d6e49e..efe7a2e 100644 --- a/src/jrummikub/model/StoneSet.java +++ b/src/jrummikub/model/StoneSet.java @@ -73,20 +73,27 @@ public class StoneSet implements Iterable, Sizeable { } nonJoker = i; } - + if (nonJoker == -1) { - if (stones.size() > 13) { + if (stones.size() > settings.getHighestCard()) { return new Pair(INVALID, 0); - } else if (stones.size() > 4) { - return new Pair(RUN, 91 - (stones.size() - 13)*(stones.size() - 14)/2); + } else if (stones.size() > settings.getStoneColors().size()) { + return new Pair( + RUN, + (settings.getHighestCard() * (settings.getHighestCard() + 1)) + / 2 + - (stones.size() - settings.getHighestCard()) + * (stones.size() - settings.getHighestCard() - 1) + / 2); } else { - return new Pair(GROUP, stones.size() * 13); + return new Pair(GROUP, stones.size() + * settings.getHighestCard()); } } - - int runScore = isValidRun(nonJoker); - int groupScore = isValidGroup(stones.get(nonJoker).getValue()); - + + int runScore = isValidRun(nonJoker, settings); + int groupScore = isValidGroup(stones.get(nonJoker).getValue(), settings); + if (runScore > groupScore) { return new Pair(RUN, runScore); } else if (groupScore == 0) { @@ -101,13 +108,14 @@ public class StoneSet implements Iterable, Sizeable { * * @param referencePosition * position of stone used as reference (any non-joker stone) + * @param settings */ - private int isValidRun(int referencePosition) { + private int isValidRun(int referencePosition, GameSettings settings) { StoneColor runColor = stones.get(referencePosition).getColor(); int startValue = stones.get(referencePosition).getValue() - referencePosition; int endValue = startValue + stones.size() - 1; - if (startValue < 1 || endValue > 13) { + if (startValue < 1 || endValue > settings.getHighestCard()) { return 0; } for (int i = 0; i < stones.size(); i++) { @@ -115,7 +123,6 @@ public class StoneSet implements Iterable, Sizeable { continue; } if (stones.get(i).getColor() != runColor) { - // warum macht er das nicht? return 0; } if (stones.get(i).getValue() != i + startValue) { @@ -131,9 +138,11 @@ public class StoneSet implements Iterable, Sizeable { /** * Test for rule conflict within the StoneSet, assuming we have a group + * + * @param settings */ - private int isValidGroup(int value) { - if (stones.size() > 4) { + private int isValidGroup(int value, GameSettings settings) { + if (stones.size() > settings.getStoneColors().size()) { return 0; } Set seenColors = new HashSet(); -- cgit v1.2.3