diff options
author | Jannis Harder <harder@informatik.uni-luebeck.de> | 2011-05-24 01:51:47 +0200 |
---|---|---|
committer | Jannis Harder <harder@informatik.uni-luebeck.de> | 2011-05-24 01:51:47 +0200 |
commit | 102299d0ffc15a08167f6eab8b9813c2f7dcda3b (patch) | |
tree | b7a82e10dff01742fd68b0ede985e0fa4bc44be8 /src/jrummikub/control | |
parent | 9290db240a10d107801a568e57d742a36052ccc0 (diff) | |
download | JRummikub-102299d0ffc15a08167f6eab8b9813c2f7dcda3b.tar JRummikub-102299d0ffc15a08167f6eab8b9813c2f7dcda3b.zip |
Fixed invalid moves without laying out stones and cleaned up rule
checks
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@259 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub/control')
-rw-r--r-- | src/jrummikub/control/RoundControl.java | 105 |
1 files changed, 42 insertions, 63 deletions
diff --git a/src/jrummikub/control/RoundControl.java b/src/jrummikub/control/RoundControl.java index a69b890..072aa7f 100644 --- a/src/jrummikub/control/RoundControl.java +++ b/src/jrummikub/control/RoundControl.java @@ -108,85 +108,64 @@ public class RoundControl { } } - /** - * after a legal move - * - * @return win or no win - */ - private boolean postLegalMove() { - roundState.setTable(clonedTable); + private boolean laidOutEnough() { + List<StoneSet> newSets = tableSetDifference(roundState.getTable(), + clonedTable); - if (roundState.getActivePlayer().getHand().getSize() == 0) { - win(); - return true; + int totalValue = 0; + for (StoneSet set : newSets) { + totalValue += set.classify().getSecond(); } - return false; - } - private boolean notLaidOutYet(Set<Stone> tableDiff) { - boolean win = false; - if (tableSetDifference(clonedTable, roundState.getTable()).isEmpty()) { - // laid sthg out and didn't change table - List<StoneSet> newSets = tableSetDifference(roundState.getTable(), - clonedTable); + return totalValue >= roundState.getGameSettings() + .getInitialMeldThreshold(); + } - int totalValue = 0; - for (StoneSet set : newSets) { - totalValue += set.classify().getSecond(); + private void endOfTurn() { + checkTurn(); + roundState.nextPlayer(); + prepareTurn(); + } + + private void checkTurn() { + if (!clonedTable.isValid()) { + rejectMove(); + return; + } + if (!roundState.getActivePlayer().getLaidOut()) { + // Player touched forbidden stones + if (!tableSetDifference(clonedTable, roundState.getTable()).isEmpty()) { + rejectMove(); + return; } - - if (totalValue >= roundState.getGameSettings() - .getInitialMeldThreshold()) { - - roundState.getActivePlayer().setLaidOut(true); - win = postLegalMove(); - return win; - } else { - // deal penalty, reset - roundState.getGameHeap().putBack(tableDiff); - dealPenalty(tableDiff.size()); - return win; + if (!laidOutEnough()) { + rejectMove(); + return; } - } else { - // deal penalty, reset - roundState.getGameHeap().putBack(tableDiff); - dealPenalty(tableDiff.size()); - return win; } - } - - private void endOfTurn() { Set<Stone> tableDiff = tableDifference(roundState.getTable(), clonedTable); + + roundState.setTable(clonedTable); if (tableDiff.isEmpty()) { // Player hasn't made a move - if (clonedTable.isValid()) { - roundState.setTable(clonedTable); - } dealStone(); } else { - // Player has made a move - if (!clonedTable.isValid()) { - // deal penalty, reset - roundState.getGameHeap().putBack(tableDiff); - dealPenalty(tableDiff.size()); - } else { - if (roundState.getActivePlayer().getLaidOut()) { - // Player has laid out - if (postLegalMove()) { - return; - } - } else { - // Player hasn't laid out - if (notLaidOutYet(tableDiff)) { - return; - } - } + roundState.getActivePlayer().setLaidOut(true); + if (roundState.getActivePlayer().getHand().getSize() == 0) { + win(); } } - roundState.nextPlayer(); - prepareTurn(); + } + + private void rejectMove() { + Set<Stone> tableDiff = tableDifference(roundState.getTable(), + clonedTable); + // deal penalty, reset + roundState.getGameHeap().putBack(tableDiff); + dealPenalty(tableDiff.size()); + } static Set<Stone> tableDifference(ITable oldTable, ITable newTable) { |