summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/control
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2011-06-19 00:14:27 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2011-06-19 00:14:27 +0200
commit479384d6bfeea0c225af829cbc1cac730d87c844 (patch)
treef9a1ef3b2e87c9179d482443a11e98581e660939 /src/jrummikub/control
parente8549b95dff600aa173384a8f7bdbf0871ba9d47 (diff)
downloadJRummikub-479384d6bfeea0c225af829cbc1cac730d87c844.tar
JRummikub-479384d6bfeea0c225af829cbc1cac730d87c844.zip
Correctly show invalid sets
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@471 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub/control')
-rw-r--r--src/jrummikub/control/RoundControl.java93
-rw-r--r--src/jrummikub/control/turn/HumanTurnControl.java2
2 files changed, 52 insertions, 43 deletions
diff --git a/src/jrummikub/control/RoundControl.java b/src/jrummikub/control/RoundControl.java
index 930d861..174cc9a 100644
--- a/src/jrummikub/control/RoundControl.java
+++ b/src/jrummikub/control/RoundControl.java
@@ -50,9 +50,9 @@ public class RoundControl {
* Create a new RoundControl using the given gameState and view
*
* @param roundState
- * initial round state
+ * initial round state
* @param view
- * view used for user interaction
+ * view used for user interaction
*/
public RoundControl(IRoundState roundState, IView view) {
this.roundState = roundState;
@@ -129,12 +129,11 @@ public class RoundControl {
}
view.getTablePanel().setStoneSets(clonedTable.clone());
- view.setCurrentPlayerName(roundState.getActivePlayer()
- .getPlayerSettings().getName());
- view.setCurrentPlayerColor(roundState.getActivePlayer()
- .getPlayerSettings().getColor());
- view.setCurrentPlayerHasLaidOut(roundState.getActivePlayer()
- .getLaidOut());
+ view.setCurrentPlayerName(roundState.getActivePlayer().getPlayerSettings()
+ .getName());
+ view.setCurrentPlayerColor(roundState.getActivePlayer().getPlayerSettings()
+ .getColor());
+ view.setCurrentPlayerHasLaidOut(roundState.getActivePlayer().getLaidOut());
if (!isHuman)
startTurn();
@@ -160,11 +159,10 @@ public class RoundControl {
view.getPlayerPanel().setEndTurnMode(turnMode);
}
turnControl = TurnControlFactory.getFactory(
- roundState.getActivePlayer().getPlayerSettings().getType())
- .create();
+ roundState.getActivePlayer().getPlayerSettings().getType()).create();
turnControl.setup(new ITurnControl.TurnInfo(clonedTable, clonedHand,
- roundState.getActivePlayer().getLaidOut(), turnMode),
- roundState.getGameSettings(), view);
+ roundState.getActivePlayer().getLaidOut(), turnMode), roundState
+ .getGameSettings(), view);
turnControl.getEndOfTurnEvent().add(new IListener() {
@Override
public void handle() {
@@ -184,10 +182,8 @@ public class RoundControl {
void deal() {
for (int i = 0; i < roundState.getPlayerCount(); i++) {
IHand hand = roundState.getNthNextPlayer(i).getHand();
- for (int j = 0; j < roundState.getGameSettings()
- .getNumberOfStonesDealt(); j++) {
- hand.drop(roundState.getGameHeap().drawStone(), new Position(0,
- 0));
+ for (int j = 0; j < roundState.getGameSettings().getNumberOfStonesDealt(); j++) {
+ hand.drop(roundState.getGameHeap().drawStone(), new Position(0, 0));
}
}
}
@@ -198,13 +194,11 @@ public class RoundControl {
int totalValue = 0;
for (StoneSet set : newSets) {
- totalValue += set.classify(roundState.getGameSettings())
- .getSecond();
+ totalValue += set.classify(roundState.getGameSettings()).getSecond();
}
return totalValue == 0
- || totalValue >= roundState.getGameSettings()
- .getInitialMeldThreshold();
+ || totalValue >= roundState.getGameSettings().getInitialMeldThreshold();
}
private void endOfTurn() {
@@ -223,26 +217,46 @@ public class RoundControl {
if (lastTurnNotEnoughPoints) {
view.setInitialMeldError(roundState.getGameSettings()
.getInitialMeldThreshold());
+ view.setInvalidStoneSets(tableSetDifference(roundState.getTable(),
+ clonedTable));
} else if (lastTurnMeldError) {
view.setInitialMeldFirstError();
+ view.setInvalidStoneSets(touchedStoneSets());
} else {
- List<Stone> markedStones = new ArrayList<Stone>();
- for (Pair<StoneSet, Position> set : clonedTable) {
- if (set.getFirst().isValid(roundState.getGameSettings())) {
- continue;
- }
- for (Stone stone : set.getFirst()) {
- markedStones.add(stone);
- }
- }
view.setStoneCollectionHidden(true);
- view.setSelectedStones(markedStones);
+ view.setInvalidStoneSets(invalidStoneSets());
}
}
}
+ private List<StoneSet> invalidStoneSets() {
+ List<StoneSet> invalidSets = new ArrayList<StoneSet>();
+ for (Pair<StoneSet, Position> set : clonedTable) {
+ if (set.getFirst().isValid(roundState.getGameSettings())) {
+ continue;
+ }
+ invalidSets.add(set.getFirst());
+ }
+ return invalidSets;
+ }
+
+ private List<StoneSet> touchedStoneSets() {
+ List<StoneSet> touchedSets = new ArrayList<StoneSet>();
+ for (StoneSet set : tableSetDifference(roundState.getTable(), clonedTable)) {
+ for (Stone stone : set) {
+ if (!roundState.getActivePlayer().getHand().contains(stone)) {
+ touchedSets.add(set);
+ break;
+ }
+ }
+ }
+
+ return touchedSets;
+ }
+
private void nextPlayer() {
view.setSelectedStones(Collections.<Stone> emptyList());
+ view.setInvalidStoneSets(Collections.<StoneSet> emptyList());
view.setStoneCollectionHidden(false);
if (roundState.getLastPlayer() == null) {
if (roundState.getGameHeap().getSize() == 0) {
@@ -273,8 +287,7 @@ public class RoundControl {
}
if (!roundState.getActivePlayer().getLaidOut()) {
// Player touched forbidden stones
- if (!tableSetDifference(clonedTable, roundState.getTable())
- .isEmpty()) {
+ if (!tableSetDifference(clonedTable, roundState.getTable()).isEmpty()) {
rejectMove();
lastTurnMeldError = true;
return false;
@@ -285,8 +298,7 @@ public class RoundControl {
return false;
}
}
- Set<Stone> tableDiff = tableDifference(roundState.getTable(),
- clonedTable);
+ Set<Stone> tableDiff = tableDifference(roundState.getTable(), clonedTable);
roundState.setTable(clonedTable);
@@ -303,8 +315,7 @@ public class RoundControl {
}
private void rejectMove() {
- Set<Stone> tableDiff = tableDifference(roundState.getTable(),
- clonedTable);
+ Set<Stone> tableDiff = tableDifference(roundState.getTable(), clonedTable);
// deal penalty, reset
roundState.getGameHeap().putBack(tableDiff);
dealPenalty(tableDiff.size());
@@ -398,12 +409,10 @@ public class RoundControl {
stonePoints = playerHand.isInitialMeldPossible(roundState
.getGameSettings()) ? 200 : 100;
} else {
- stonePoints = playerHand.getStonePoints(roundState
- .getGameSettings());
+ stonePoints = playerHand.getStonePoints(roundState.getGameSettings());
}
- bestScore = updateBestScore(bestScore, -stonePoints, playerHand
- .getSize());
+ bestScore = updateBestScore(bestScore, -stonePoints, playerHand.getSize());
points.add(-stonePoints);
pointSum += stonePoints;
@@ -425,8 +434,8 @@ public class RoundControl {
private static Pair<Integer, Integer> updateBestScore(
Pair<Integer, Integer> bestScore, int stonePoints, int size) {
if (bestScore.getFirst() == stonePoints) {
- return new Pair<Integer, Integer>(stonePoints, Math.min(bestScore
- .getSecond(), size));
+ return new Pair<Integer, Integer>(stonePoints, Math.min(
+ bestScore.getSecond(), size));
} else if (bestScore.getFirst() < stonePoints) {
return new Pair<Integer, Integer>(stonePoints, size);
}
diff --git a/src/jrummikub/control/turn/HumanTurnControl.java b/src/jrummikub/control/turn/HumanTurnControl.java
index 447c44d..a9a73d7 100644
--- a/src/jrummikub/control/turn/HumanTurnControl.java
+++ b/src/jrummikub/control/turn/HumanTurnControl.java
@@ -441,7 +441,7 @@ public class HumanTurnControl extends AbstractTurnControl {
private void endOfTurn(boolean redeal) {
cleanUp();
- view.setSelectedStones(new ArrayList<Stone>());
+ view.setSelectedStones(Collections.<Stone> emptyList());
if (redeal) {
redealEvent.emit();
} else {