From c09a94a359de9f2d13b36dc58b9ac55022379861 Mon Sep 17 00:00:00 2001 From: Jannis Harder Date: Sun, 29 May 2011 18:51:06 +0200 Subject: Classify for more than two jokers git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@305 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/model/StoneSet.java | 43 ++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 25 deletions(-) (limited to 'src/jrummikub') diff --git a/src/jrummikub/model/StoneSet.java b/src/jrummikub/model/StoneSet.java index 604d6ac..2700889 100644 --- a/src/jrummikub/model/StoneSet.java +++ b/src/jrummikub/model/StoneSet.java @@ -66,40 +66,33 @@ public class StoneSet implements Iterable, Sizeable { if (stones.size() < 3) { return new Pair(INVALID, 0); } - int nonJoker1 = -1, nonJoker2 = -1; + int nonJoker = -1; for (int i = 0; i < stones.size(); i++) { if (stones.get(i).isJoker()) { continue; } - nonJoker2 = nonJoker1; - nonJoker1 = i; + nonJoker = i; } - if (nonJoker2 == -1) { - // Z first - if (nonJoker1 == 0 && stones.get(nonJoker1).getValue() < 12) { - return new Pair(RUN, isValidRun(nonJoker1)); + + if (nonJoker == -1) { + if (stones.size() > 13) { + return new Pair(INVALID, 0); + } else if (stones.size() > 4) { + return new Pair(RUN, 91 - (stones.size() - 13)*(stones.size() - 14)/2); } else { - int value = stones.get(nonJoker1).getValue() * stones.size(); - return new Pair(GROUP, value); + return new Pair(GROUP, stones.size() * 13); } } - - // is run - if (stones.get(nonJoker1).getColor() == stones.get(nonJoker2) - .getColor()) { - if (isValidRun(nonJoker1) > 0) { - return new Pair(RUN, isValidRun(nonJoker1)); - } - return new Pair(INVALID, 0); - - } - // is group - else { - if (isValidGroup(stones.get(nonJoker1).getValue()) > 0) { - return new Pair(GROUP, isValidGroup(stones.get( - nonJoker1).getValue())); - } + + int runScore = isValidRun(nonJoker); + int groupScore = isValidGroup(stones.get(nonJoker).getValue()); + + if (runScore > groupScore) { + return new Pair(RUN, runScore); + } else if (groupScore == 0) { return new Pair(INVALID, 0); + } else { + return new Pair(GROUP, groupScore); } } -- cgit v1.2.3