summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/jrummikub/model/StoneSet.java37
1 files changed, 23 insertions, 14 deletions
diff --git a/src/jrummikub/model/StoneSet.java b/src/jrummikub/model/StoneSet.java
index 3d6e49e..efe7a2e 100644
--- a/src/jrummikub/model/StoneSet.java
+++ b/src/jrummikub/model/StoneSet.java
@@ -73,20 +73,27 @@ public class StoneSet implements Iterable<Stone>, Sizeable {
}
nonJoker = i;
}
-
+
if (nonJoker == -1) {
- if (stones.size() > 13) {
+ if (stones.size() > settings.getHighestCard()) {
return new Pair<Type, Integer>(INVALID, 0);
- } else if (stones.size() > 4) {
- return new Pair<Type, Integer>(RUN, 91 - (stones.size() - 13)*(stones.size() - 14)/2);
+ } else if (stones.size() > settings.getStoneColors().size()) {
+ return new Pair<Type, Integer>(
+ RUN,
+ (settings.getHighestCard() * (settings.getHighestCard() + 1))
+ / 2
+ - (stones.size() - settings.getHighestCard())
+ * (stones.size() - settings.getHighestCard() - 1)
+ / 2);
} else {
- return new Pair<Type, Integer>(GROUP, stones.size() * 13);
+ return new Pair<Type, Integer>(GROUP, stones.size()
+ * settings.getHighestCard());
}
}
-
- int runScore = isValidRun(nonJoker);
- int groupScore = isValidGroup(stones.get(nonJoker).getValue());
-
+
+ int runScore = isValidRun(nonJoker, settings);
+ int groupScore = isValidGroup(stones.get(nonJoker).getValue(), settings);
+
if (runScore > groupScore) {
return new Pair<Type, Integer>(RUN, runScore);
} else if (groupScore == 0) {
@@ -101,13 +108,14 @@ public class StoneSet implements Iterable<Stone>, Sizeable {
*
* @param referencePosition
* position of stone used as reference (any non-joker stone)
+ * @param settings
*/
- private int isValidRun(int referencePosition) {
+ private int isValidRun(int referencePosition, GameSettings settings) {
StoneColor runColor = stones.get(referencePosition).getColor();
int startValue = stones.get(referencePosition).getValue()
- referencePosition;
int endValue = startValue + stones.size() - 1;
- if (startValue < 1 || endValue > 13) {
+ if (startValue < 1 || endValue > settings.getHighestCard()) {
return 0;
}
for (int i = 0; i < stones.size(); i++) {
@@ -115,7 +123,6 @@ public class StoneSet implements Iterable<Stone>, Sizeable {
continue;
}
if (stones.get(i).getColor() != runColor) {
- // warum macht er das nicht?
return 0;
}
if (stones.get(i).getValue() != i + startValue) {
@@ -131,9 +138,11 @@ public class StoneSet implements Iterable<Stone>, Sizeable {
/**
* Test for rule conflict within the StoneSet, assuming we have a group
+ *
+ * @param settings
*/
- private int isValidGroup(int value) {
- if (stones.size() > 4) {
+ private int isValidGroup(int value, GameSettings settings) {
+ if (stones.size() > settings.getStoneColors().size()) {
return 0;
}
Set<StoneColor> seenColors = new HashSet<StoneColor>();