From 656bfe905b723b13ac870c551c513c726e9cbe82 Mon Sep 17 00:00:00 2001 From: Jannis Harder Date: Wed, 25 May 2011 17:27:19 +0200 Subject: Implemented counting of identical stone pairs git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@275 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/model/Hand.java | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'src/jrummikub') diff --git a/src/jrummikub/model/Hand.java b/src/jrummikub/model/Hand.java index 7294ced..6e30a32 100644 --- a/src/jrummikub/model/Hand.java +++ b/src/jrummikub/model/Hand.java @@ -104,10 +104,18 @@ public class Hand extends StoneTray implements IHand { @Override public boolean isInitialMeldPossible() { + Pair, Integer>, Integer> stoneCounts = countStones(); + + return findSetsWithTotalPoints(settings.getInitialMeldThreshold(), + stoneCounts.getFirst(), stoneCounts.getSecond()); + } + + private Pair, Integer>, Integer> countStones() { int jokerCount = 0; TreeMap, Integer> stoneCounts = new TreeMap, Integer>( comparator); - + + for (Pair entry : this) { if (entry.getFirst().isJoker()) { jokerCount++; @@ -119,9 +127,7 @@ public class Hand extends StoneTray implements IHand { incrementStoneCount(stoneCounts, key); } } - - return findSetsWithTotalPoints(settings.getInitialMeldThreshold(), - stoneCounts, jokerCount); + return new Pair, Integer>, Integer>(stoneCounts, jokerCount); } private void incrementStoneCount( @@ -264,7 +270,13 @@ public class Hand extends StoneTray implements IHand { @Override public int getIdenticalStoneCount() { - // TODO Auto-generated method stub - return 0; + Pair, Integer>, Integer> stoneCounts = countStones(); + int pairCount = 0; + + for(int count : stoneCounts.getFirst().values()) { + pairCount += count / 2; + } + + return pairCount; } } -- cgit v1.2.3