From f7aace72346b32af6b6aeb7e650d762ec263ff2f Mon Sep 17 00:00:00 2001 From: Ida Massow Date: Mon, 16 May 2011 20:54:37 +0200 Subject: =?UTF-8?q?Tests=20und=20imlementierung=20f=C3=BCr=20Wert=20von=20?= =?UTF-8?q?Sets=20bestimmen,=20fertig=20und=20getestet?= 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@242 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/model/StoneSet.java | 57 +++++++++++++++++++++++++++------------ src/jrummikub/model/Table.java | 2 +- 2 files changed, 41 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/jrummikub/model/StoneSet.java b/src/jrummikub/model/StoneSet.java index b798ad0..2fd8e96 100644 --- a/src/jrummikub/model/StoneSet.java +++ b/src/jrummikub/model/StoneSet.java @@ -52,7 +52,7 @@ public class StoneSet implements Iterable, Sizeable { * @return true when the set is valid according to the rules */ public boolean isValid() { - return classify() != INVALID; + return classify().getFirst() != INVALID; } /** @@ -61,10 +61,11 @@ public class StoneSet implements Iterable, Sizeable { * * @return GROUP or RUN for valid sets, INVALID otherwise */ - public Type classify() { + // TODO: Vernünftige Werte Returnen + public Pair classify() { // TODO: extend this for score calculation (release 2...) if (stones.size() < 3) { - return INVALID; + return new Pair(INVALID, 0); } int nonJoker1 = -1, nonJoker2 = -1; for (int i = 0; i < stones.size(); i++) { @@ -75,18 +76,36 @@ public class StoneSet implements Iterable, Sizeable { nonJoker1 = i; } if (nonJoker2 == -1) { - return GROUP; + // Z first + if (nonJoker1 == 0 && stones.get(nonJoker1).getValue() < 12) { + int origValue = stones.get(nonJoker1).getValue(); + int value = 0; + for (int i = 0; i < stones.size(); i++) { + value += origValue + i; + } + return new Pair(RUN, value); + } else { + int value = stones.get(nonJoker1).getValue() * stones.size(); + return new Pair(GROUP, value); + } } + // is run if (stones.get(nonJoker1).getColor() == stones.get(nonJoker2) .getColor()) { - return isValidRun(nonJoker1) ? RUN : INVALID; + if (isValidRun(nonJoker1) > 0) { + return new Pair(RUN, isValidRun(nonJoker1)); + } + return new Pair(INVALID, 0); } // is group else { - return isValidGroup(stones.get(nonJoker1).getValue()) ? GROUP - : INVALID; + if (isValidGroup(stones.get(nonJoker1).getValue()) > 0) { + return new Pair(GROUP, isValidGroup(stones.get( + nonJoker1).getValue())); + } + return new Pair(INVALID, 0); } } @@ -96,13 +115,13 @@ public class StoneSet implements Iterable, Sizeable { * @param referencePosition * position of stone used as reference (any non-joker stone) */ - private boolean isValidRun(int referencePosition) { + private int isValidRun(int referencePosition) { StoneColor runColor = stones.get(referencePosition).getColor(); int startValue = stones.get(referencePosition).getValue() - referencePosition; int endValue = startValue + stones.size() - 1; if (startValue < 1 || endValue > 13) { - return false; + return 0; } for (int i = 0; i < stones.size(); i++) { if (stones.get(i).isJoker()) { @@ -110,21 +129,25 @@ public class StoneSet implements Iterable, Sizeable { } if (stones.get(i).getColor() != runColor) { // warum macht er das nicht? - return false; + return 0; } if (stones.get(i).getValue() != i + startValue) { - return false; + return 0; } } - return true; + int value = 0; + for (int i = 0; i < stones.size(); i++) { + value += startValue + i; + } + return value; } /** * Test for rule conflict within the StoneSet, assuming we have a group */ - private boolean isValidGroup(int value) { + private int isValidGroup(int value) { if (stones.size() > 4) { - return false; + return 0; } Set seenColors = new HashSet(); for (Stone i : stones) { @@ -132,15 +155,15 @@ public class StoneSet implements Iterable, Sizeable { continue; } if (i.getValue() != value) { - return false; + return 0; } if (seenColors.contains(i.getColor())) { - return false; + return 0; } else { seenColors.add(i.getColor()); } } - return true; + return value * stones.size(); } /** diff --git a/src/jrummikub/model/Table.java b/src/jrummikub/model/Table.java index f134975..a3e25eb 100644 --- a/src/jrummikub/model/Table.java +++ b/src/jrummikub/model/Table.java @@ -79,7 +79,7 @@ public class Table extends StoneTray implements ITable { StoneSet leftSet = firstSplit.getFirst(); StoneSet rightSet = secondSplit.getSecond(); - if (set.classify() == StoneSet.Type.RUN) { + if (set.classify().getFirst() == StoneSet.Type.RUN) { Position leftPosition, rightPosition; leftPosition = setPosition; rightPosition = new Position(setPosition.getX() + stonePosition + 1, -- cgit v1.2.3