summaryrefslogtreecommitdiffstats
path: root/src/jrummikub
diff options
context:
space:
mode:
authorIda Massow <massow@informatik.uni-luebeck.de>2011-05-31 00:58:48 +0200
committerIda Massow <massow@informatik.uni-luebeck.de>2011-05-31 00:58:48 +0200
commit0cb36fb752120a3b052a3f25acdd075ed8f80560 (patch)
tree75c28b0236c566a2b4fcf26ff357fcbc5c3ee991 /src/jrummikub
parentf22ff5f0f1d8f9838c30943bde658ca3f282bbc8 (diff)
downloadJRummikub-0cb36fb752120a3b052a3f25acdd075ed8f80560.tar
JRummikub-0cb36fb752120a3b052a3f25acdd075ed8f80560.zip
Man kann viele FAreben benutzen, alle Test laufen. Man kann auch Karten bis Wert X größer oder kleiner 13 nehmen. Alles nur im Model, aber getestet und toll
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@333 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub')
-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>();