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
This commit is contained in:
parent
9290db240a
commit
102299d0ff
2 changed files with 114 additions and 65 deletions
|
@ -108,25 +108,7 @@ public class RoundControl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private boolean laidOutEnough() {
|
||||||
* after a legal move
|
|
||||||
*
|
|
||||||
* @return win or no win
|
|
||||||
*/
|
|
||||||
private boolean postLegalMove() {
|
|
||||||
roundState.setTable(clonedTable);
|
|
||||||
|
|
||||||
if (roundState.getActivePlayer().getHand().getSize() == 0) {
|
|
||||||
win();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
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(),
|
List<StoneSet> newSets = tableSetDifference(roundState.getTable(),
|
||||||
clonedTable);
|
clonedTable);
|
||||||
|
|
||||||
|
@ -135,58 +117,55 @@ public class RoundControl {
|
||||||
totalValue += set.classify().getSecond();
|
totalValue += set.classify().getSecond();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (totalValue >= roundState.getGameSettings()
|
return totalValue >= roundState.getGameSettings()
|
||||||
.getInitialMeldThreshold()) {
|
.getInitialMeldThreshold();
|
||||||
|
|
||||||
roundState.getActivePlayer().setLaidOut(true);
|
|
||||||
win = postLegalMove();
|
|
||||||
return win;
|
|
||||||
} else {
|
|
||||||
// deal penalty, reset
|
|
||||||
roundState.getGameHeap().putBack(tableDiff);
|
|
||||||
dealPenalty(tableDiff.size());
|
|
||||||
return win;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// deal penalty, reset
|
|
||||||
roundState.getGameHeap().putBack(tableDiff);
|
|
||||||
dealPenalty(tableDiff.size());
|
|
||||||
return win;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void endOfTurn() {
|
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 (!laidOutEnough()) {
|
||||||
|
rejectMove();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
Set<Stone> tableDiff = tableDifference(roundState.getTable(),
|
Set<Stone> tableDiff = tableDifference(roundState.getTable(),
|
||||||
clonedTable);
|
clonedTable);
|
||||||
|
|
||||||
|
roundState.setTable(clonedTable);
|
||||||
|
|
||||||
if (tableDiff.isEmpty()) {
|
if (tableDiff.isEmpty()) {
|
||||||
// Player hasn't made a move
|
// Player hasn't made a move
|
||||||
if (clonedTable.isValid()) {
|
|
||||||
roundState.setTable(clonedTable);
|
|
||||||
}
|
|
||||||
dealStone();
|
dealStone();
|
||||||
} else {
|
} else {
|
||||||
// Player has made a move
|
roundState.getActivePlayer().setLaidOut(true);
|
||||||
if (!clonedTable.isValid()) {
|
if (roundState.getActivePlayer().getHand().getSize() == 0) {
|
||||||
|
win();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void rejectMove() {
|
||||||
|
Set<Stone> tableDiff = tableDifference(roundState.getTable(),
|
||||||
|
clonedTable);
|
||||||
// deal penalty, reset
|
// deal penalty, reset
|
||||||
roundState.getGameHeap().putBack(tableDiff);
|
roundState.getGameHeap().putBack(tableDiff);
|
||||||
dealPenalty(tableDiff.size());
|
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.nextPlayer();
|
|
||||||
prepareTurn();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Set<Stone> tableDifference(ITable oldTable, ITable newTable) {
|
static Set<Stone> tableDifference(ITable oldTable, ITable newTable) {
|
||||||
|
|
|
@ -131,6 +131,7 @@ public class RoundControlTest {
|
||||||
assertFalse(roundState
|
assertFalse(roundState
|
||||||
.getNthNextPlayer(roundState.getPlayerCount() - 1).getLaidOut());
|
.getNthNextPlayer(roundState.getPlayerCount() - 1).getLaidOut());
|
||||||
assertEquals(0, roundState.getTable().getSize());
|
assertEquals(0, roundState.getTable().getSize());
|
||||||
|
assertEquals(14 + 6, hand.getSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Threshold=30 */
|
/** Threshold=30 */
|
||||||
|
@ -177,6 +178,7 @@ public class RoundControlTest {
|
||||||
assertFalse(roundState
|
assertFalse(roundState
|
||||||
.getNthNextPlayer(roundState.getPlayerCount() - 1).getLaidOut());
|
.getNthNextPlayer(roundState.getPlayerCount() - 1).getLaidOut());
|
||||||
assertEquals(0, roundState.getTable().getSize());
|
assertEquals(0, roundState.getTable().getSize());
|
||||||
|
assertEquals(14 + 9, hand.getSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Threshold=30 */
|
/** Threshold=30 */
|
||||||
|
@ -246,6 +248,7 @@ public class RoundControlTest {
|
||||||
assertFalse(roundState
|
assertFalse(roundState
|
||||||
.getNthNextPlayer(roundState.getPlayerCount() - 1).getLaidOut());
|
.getNthNextPlayer(roundState.getPlayerCount() - 1).getLaidOut());
|
||||||
assertEquals(2, roundState.getTable().getSize());
|
assertEquals(2, roundState.getTable().getSize());
|
||||||
|
assertEquals(14 + 6, hand.getSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Threshold=30 */
|
/** Threshold=30 */
|
||||||
|
@ -318,6 +321,69 @@ public class RoundControlTest {
|
||||||
assertFalse(roundState
|
assertFalse(roundState
|
||||||
.getNthNextPlayer(roundState.getPlayerCount() - 1).getLaidOut());
|
.getNthNextPlayer(roundState.getPlayerCount() - 1).getLaidOut());
|
||||||
assertEquals(2, roundState.getTable().getSize());
|
assertEquals(2, roundState.getTable().getSize());
|
||||||
|
assertEquals(14 + 7, hand.getSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void laidOutJustChangedTable() {
|
||||||
|
MockGameSettings gameSettings = new MockGameSettings();
|
||||||
|
RoundState roundState = new RoundState(gameSettings);
|
||||||
|
RoundControl roundControl = new RoundControl(roundState, view);
|
||||||
|
roundControl.startRound();
|
||||||
|
view.startTurnEvent.emit();
|
||||||
|
// Fake Turn to put stones on the table
|
||||||
|
Stone blueFour = new Stone(4, BLUE);
|
||||||
|
Stone blackFour = new Stone(4, BLACK);
|
||||||
|
Stone redFour = new Stone(4, RED);
|
||||||
|
Stone orangeFour = new Stone(4, ORANGE);
|
||||||
|
|
||||||
|
Stone blueFive = new Stone(5, BLUE);
|
||||||
|
Stone blueSix = new Stone(6, BLUE);
|
||||||
|
Stone blueSeven = new Stone(7, BLUE);
|
||||||
|
|
||||||
|
IHand hand = roundState.getActivePlayer().getHand();
|
||||||
|
hand.drop(blueFive, new Position(0, 0));
|
||||||
|
hand.drop(blueSix, new Position(0, 0));
|
||||||
|
hand.drop(blueSeven, new Position(0, 0));
|
||||||
|
|
||||||
|
hand.drop(redFour, new Position(0, 0));
|
||||||
|
hand.drop(blueFour, new Position(0, 0));
|
||||||
|
hand.drop(blackFour, new Position(0, 0));
|
||||||
|
hand.drop(orangeFour, new Position(0, 0));
|
||||||
|
|
||||||
|
view.handPanel.stoneClickEvent.emit(redFour, false);
|
||||||
|
view.handPanel.stoneClickEvent.emit(blueFour, true);
|
||||||
|
view.handPanel.stoneClickEvent.emit(blackFour, true);
|
||||||
|
view.handPanel.stoneClickEvent.emit(orangeFour, true);
|
||||||
|
|
||||||
|
view.tablePanel.clickEvent.emit(new Position(0, 0));
|
||||||
|
|
||||||
|
view.handPanel.stoneClickEvent.emit(blueFive, false);
|
||||||
|
view.handPanel.stoneClickEvent.emit(blueSix, true);
|
||||||
|
view.handPanel.stoneClickEvent.emit(blueSeven, true);
|
||||||
|
|
||||||
|
view.tablePanel.clickEvent.emit(new Position(0, 0));
|
||||||
|
|
||||||
|
view.playerPanel.endTurnEvent.emit();
|
||||||
|
assertEquals(2, roundState.getTable().getSize());
|
||||||
|
view.startTurnEvent.emit();
|
||||||
|
|
||||||
|
hand = roundState.getActivePlayer().getHand();
|
||||||
|
|
||||||
|
view.tablePanel.stoneClickEvent.emit(blueFour, false);
|
||||||
|
view.tablePanel.stoneClickEvent.emit(blueFive, true);
|
||||||
|
view.tablePanel.stoneClickEvent.emit(blueSix, true);
|
||||||
|
view.tablePanel.stoneClickEvent.emit(blueSeven, true);
|
||||||
|
|
||||||
|
assertFalse(roundState.getActivePlayer().getLaidOut());
|
||||||
|
|
||||||
|
view.tablePanel.clickEvent.emit(new Position(0, 0));
|
||||||
|
|
||||||
|
view.playerPanel.endTurnEvent.emit();
|
||||||
|
assertFalse(roundState
|
||||||
|
.getNthNextPlayer(roundState.getPlayerCount() - 1).getLaidOut());
|
||||||
|
assertEquals(2, roundState.getTable().getSize());
|
||||||
|
assertEquals(14 + 3, hand.getSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Threshold=30 */
|
/** Threshold=30 */
|
||||||
|
@ -365,6 +431,7 @@ public class RoundControlTest {
|
||||||
assertTrue(roundState.getNthNextPlayer(roundState.getPlayerCount() - 1)
|
assertTrue(roundState.getNthNextPlayer(roundState.getPlayerCount() - 1)
|
||||||
.getLaidOut());
|
.getLaidOut());
|
||||||
assertEquals(2, roundState.getTable().getSize());
|
assertEquals(2, roundState.getTable().getSize());
|
||||||
|
assertEquals(14, hand.getSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** */
|
/** */
|
||||||
|
@ -408,6 +475,7 @@ public class RoundControlTest {
|
||||||
/** */
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testTableValidHandChanged() {
|
public void testTableValidHandChanged() {
|
||||||
|
testRoundState.players.get(0).setLaidOut(true);
|
||||||
testRound.startRound();
|
testRound.startRound();
|
||||||
MockTable oldTable = testRoundState.table;
|
MockTable oldTable = testRoundState.table;
|
||||||
testTable.valid = true;
|
testTable.valid = true;
|
||||||
|
@ -453,6 +521,7 @@ public class RoundControlTest {
|
||||||
/** */
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testTableValidHandUnchanged() {
|
public void testTableValidHandUnchanged() {
|
||||||
|
testRoundState.players.get(0).setLaidOut(true);
|
||||||
testRound.startRound();
|
testRound.startRound();
|
||||||
MockTable oldTable = testRoundState.table;
|
MockTable oldTable = testRoundState.table;
|
||||||
testTable.valid = true;
|
testTable.valid = true;
|
||||||
|
@ -473,6 +542,7 @@ public class RoundControlTest {
|
||||||
/** */
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testTableInvalidHandUnchanged() {
|
public void testTableInvalidHandUnchanged() {
|
||||||
|
testRoundState.players.get(1).setLaidOut(true);
|
||||||
testRound.startRound();
|
testRound.startRound();
|
||||||
MockTable oldTable = testRoundState.table;
|
MockTable oldTable = testRoundState.table;
|
||||||
testTable.valid = false;
|
testTable.valid = false;
|
||||||
|
@ -484,7 +554,7 @@ public class RoundControlTest {
|
||||||
view.getPlayerPanel().endTurnEvent.emit();
|
view.getPlayerPanel().endTurnEvent.emit();
|
||||||
|
|
||||||
assertNull(testRoundState.setTable);
|
assertNull(testRoundState.setTable);
|
||||||
assertEquals(14 + 1, testRoundState.players.get(0).hand.getSize());
|
assertEquals(14 + 3, testRoundState.players.get(0).hand.getSize());
|
||||||
assertEquals(1, testRoundState.activePlayer);
|
assertEquals(1, testRoundState.activePlayer);
|
||||||
|
|
||||||
checkTurnStartSetUp();
|
checkTurnStartSetUp();
|
||||||
|
|
Reference in a new issue