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 ++++++++++++++-------------------- test/jrummikub/model/StoneSetTest.java | 2 +- 2 files changed, 19 insertions(+), 26 deletions(-) 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); } } diff --git a/test/jrummikub/model/StoneSetTest.java b/test/jrummikub/model/StoneSetTest.java index a44818c..f53163e 100644 --- a/test/jrummikub/model/StoneSetTest.java +++ b/test/jrummikub/model/StoneSetTest.java @@ -165,7 +165,7 @@ public class StoneSetTest { new Stone(RED), new Stone(RED))); assertSet(GROUP, 4 * 13, Arrays.asList(new Stone(RED), new Stone(RED), new Stone(RED), new Stone(RED))); - assertSet(RUN, 5 * 11, Arrays.asList(new Stone(RED), + assertSet(RUN, 13 + 12 + 11 + 10 + 9, Arrays.asList(new Stone(RED), new Stone(RED), new Stone(RED), new Stone(RED), new Stone(RED))); assertSet(RUN, 5 * 10, Arrays.asList(new Stone(RED), new Stone(RED), new Stone(RED), new Stone(RED), new Stone(12, RED))); -- cgit v1.2.3