diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/jrummikub/model/Hand.java | 24 |
1 files changed, 18 insertions, 6 deletions
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<Stone> implements IHand { @Override public boolean isInitialMeldPossible() { + Pair<TreeMap<Pair<Integer, StoneColor>, Integer>, Integer> stoneCounts = countStones(); + + return findSetsWithTotalPoints(settings.getInitialMeldThreshold(), + stoneCounts.getFirst(), stoneCounts.getSecond()); + } + + private Pair<TreeMap<Pair<Integer, StoneColor>, Integer>, Integer> countStones() { int jokerCount = 0; TreeMap<Pair<Integer, StoneColor>, Integer> stoneCounts = new TreeMap<Pair<Integer, StoneColor>, Integer>( comparator); - + + for (Pair<Stone, Position> entry : this) { if (entry.getFirst().isJoker()) { jokerCount++; @@ -119,9 +127,7 @@ public class Hand extends StoneTray<Stone> implements IHand { incrementStoneCount(stoneCounts, key); } } - - return findSetsWithTotalPoints(settings.getInitialMeldThreshold(), - stoneCounts, jokerCount); + return new Pair<TreeMap<Pair<Integer, StoneColor>, Integer>, Integer>(stoneCounts, jokerCount); } private void incrementStoneCount( @@ -264,7 +270,13 @@ public class Hand extends StoneTray<Stone> implements IHand { @Override public int getIdenticalStoneCount() { - // TODO Auto-generated method stub - return 0; + Pair<TreeMap<Pair<Integer, StoneColor>, Integer>, Integer> stoneCounts = countStones(); + int pairCount = 0; + + for(int count : stoneCounts.getFirst().values()) { + pairCount += count / 2; + } + + return pairCount; } } |