Rauskommen fertig und getestet

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@256 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Ida Massow 2011-05-21 15:51:36 +02:00
parent cb3f9cc011
commit 7354002de5
13 changed files with 324 additions and 181 deletions

View file

@ -13,7 +13,7 @@ public class MockPlayer implements IPlayer {
/** /**
* @param playerSettings * @param playerSettings
* the player settings * the player settings
*/ */
public MockPlayer(PlayerSettings playerSettings) { public MockPlayer(PlayerSettings playerSettings) {
hand = new Hand(); hand = new Hand();
@ -35,4 +35,9 @@ public class MockPlayer implements IPlayer {
public PlayerSettings getPlayerSettings() { public PlayerSettings getPlayerSettings() {
return playerSettings; return playerSettings;
} }
@Override
public void setLaidOut(boolean laidOut) {
this.laidOut = laidOut;
}
} }

View file

@ -19,7 +19,7 @@ public class MockRoundState implements IRoundState {
/** */ /** */
public StoneHeap gameHeap; public StoneHeap gameHeap;
/** */ /** */
public GameSettings gameSettings; public IGameSettings gameSettings;
/** */ /** */
public MockRoundState() { public MockRoundState() {
@ -32,6 +32,7 @@ public class MockRoundState implements IRoundState {
activePlayer = 0; activePlayer = 0;
gameHeap = new StoneHeap(); gameHeap = new StoneHeap();
gameSettings = new GameSettings(); gameSettings = new GameSettings();
gameSettings.setInitialMeldThreshold(30);
} }
@Override @Override
@ -71,7 +72,7 @@ public class MockRoundState implements IRoundState {
} }
@Override @Override
public GameSettings getGameSettings() { public IGameSettings getGameSettings() {
return gameSettings; return gameSettings;
} }
} }

View file

@ -23,7 +23,7 @@ public class MockTable implements ITable {
@Override @Override
public void pickUpStone(Stone stone) { public void pickUpStone(Stone stone) {
// TODO Auto-generated method stub // TODO: Auto-generated method stub
} }
@Override @Override

View file

@ -6,6 +6,7 @@ import javax.swing.UIManager;
import jrummikub.control.GameControl; import jrummikub.control.GameControl;
import jrummikub.model.GameSettings; import jrummikub.model.GameSettings;
import jrummikub.model.IGameSettings;
import jrummikub.model.PlayerSettings; import jrummikub.model.PlayerSettings;
import jrummikub.view.impl.View; import jrummikub.view.impl.View;
@ -28,7 +29,7 @@ public class JRummikub {
} catch (Exception e) { } catch (Exception e) {
} }
GameSettings gameSettings = new GameSettings(); IGameSettings gameSettings = new GameSettings();
gameSettings.getPlayerList().add(new PlayerSettings("Ida", Color.RED)); gameSettings.getPlayerList().add(new PlayerSettings("Ida", Color.RED));
gameSettings.getPlayerList().add( gameSettings.getPlayerList().add(
new PlayerSettings("Matthias", Color.YELLOW)); new PlayerSettings("Matthias", Color.YELLOW));

View file

@ -1,6 +1,6 @@
package jrummikub.control; package jrummikub.control;
import jrummikub.model.GameSettings; import jrummikub.model.IGameSettings;
import jrummikub.model.RoundState; import jrummikub.model.RoundState;
import jrummikub.util.IListener; import jrummikub.util.IListener;
import jrummikub.view.IView; import jrummikub.view.IView;
@ -9,7 +9,7 @@ import jrummikub.view.IView;
* Controls a Game, at some point including all Rounds, starts new Rounds * Controls a Game, at some point including all Rounds, starts new Rounds
*/ */
public class GameControl { public class GameControl {
private GameSettings gameSettings; private IGameSettings gameSettings;
private IView view; private IView view;
private RoundControl roundControl; private RoundControl roundControl;
@ -21,7 +21,7 @@ public class GameControl {
* @param view * @param view
* the view * the view
*/ */
public GameControl(GameSettings gameSettings, IView view) { public GameControl(IGameSettings gameSettings, IView view) {
this.gameSettings = gameSettings; this.gameSettings = gameSettings;
this.view = view; this.view = view;

View file

@ -23,7 +23,7 @@ import jrummikub.view.IView;
* Controller that manages a single round of rummikub * Controller that manages a single round of rummikub
*/ */
public class RoundControl { public class RoundControl {
private IRoundState gameState; private IRoundState roundState;
private IView view; private IView view;
private ITable clonedTable; private ITable clonedTable;
private Event endRoundEvent = new Event(); private Event endRoundEvent = new Event();
@ -37,8 +37,8 @@ public class RoundControl {
* @param view * @param view
* view used for user interaction * view used for user interaction
*/ */
public RoundControl(IRoundState gameState, IView view) { public RoundControl(IRoundState roundState, IView view) {
this.gameState = gameState; this.roundState = roundState;
this.view = view; this.view = view;
} }
@ -69,20 +69,21 @@ public class RoundControl {
} }
private void prepareTurn() { private void prepareTurn() {
clonedTable = (ITable) gameState.getTable().clone(); clonedTable = (ITable) roundState.getTable().clone();
view.enableStartTurnPanel(true); view.enableStartTurnPanel(true);
view.getTablePanel().setStoneSets(clonedTable); view.getTablePanel().setStoneSets(clonedTable);
view.setCurrentPlayerName(gameState.getActivePlayer().getPlayerSettings().getName()); view.setCurrentPlayerName(roundState.getActivePlayer()
.getPlayerSettings().getName());
view.getTablePanel().setLeftPlayerName( view.getTablePanel().setLeftPlayerName(
gameState.getNthNextPlayer(1).getPlayerSettings().getName()); roundState.getNthNextPlayer(1).getPlayerSettings().getName());
view.getTablePanel().setTopPlayerName( view.getTablePanel().setTopPlayerName(
gameState.getNthNextPlayer(2).getPlayerSettings().getName()); roundState.getNthNextPlayer(2).getPlayerSettings().getName());
view.getTablePanel().setRightPlayerName( view.getTablePanel().setRightPlayerName(
gameState.getNthNextPlayer(3).getPlayerSettings().getName()); roundState.getNthNextPlayer(3).getPlayerSettings().getName());
} }
private void startTurn() { private void startTurn() {
TurnControl turnControl = new TurnControl(gameState.getActivePlayer() TurnControl turnControl = new TurnControl(roundState.getActivePlayer()
.getHand(), clonedTable, view); .getHand(), clonedTable, view);
connections.add(turnControl.getEndOfTurnEvent().add(new IListener() { connections.add(turnControl.getEndOfTurnEvent().add(new IListener() {
@ -96,42 +97,95 @@ public class RoundControl {
} }
void deal() { void deal() {
for (int i = 0; i < gameState.getPlayerCount(); i++) { for (int i = 0; i < roundState.getPlayerCount(); i++) {
IHand hand = gameState.getNthNextPlayer(i).getHand(); IHand hand = roundState.getNthNextPlayer(i).getHand();
for (int j = 0; j < 7; j++) { for (int j = 0; j < 7; j++) {
hand.drop(gameState.getGameHeap().drawStone(), new Position(j, hand.drop(roundState.getGameHeap().drawStone(), new Position(j,
0)); 0));
hand.drop(gameState.getGameHeap().drawStone(), new Position(j, hand.drop(roundState.getGameHeap().drawStone(), new Position(j,
1)); 1));
} }
} }
} }
/**
* 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(),
clonedTable);
int totalValue = 0;
for (StoneSet set : newSets) {
totalValue += set.classify().getSecond();
}
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;
}
} else {
// deal penalty, reset
roundState.getGameHeap().putBack(tableDiff);
dealPenalty(tableDiff.size());
return win;
}
}
private void endOfTurn() { private void endOfTurn() {
Set<Stone> tableDiff = tableDifference(gameState.getTable(), Set<Stone> tableDiff = tableDifference(roundState.getTable(),
clonedTable); clonedTable);
if (!tableDiff.isEmpty()) { // Player has made a move if (tableDiff.isEmpty()) {
// Player hasn't made a move
if (clonedTable.isValid()) { if (clonedTable.isValid()) {
gameState.setTable(clonedTable); roundState.setTable(clonedTable);
if (gameState.getActivePlayer().getHand().getSize() == 0) {
win();
return;
}
} else {
gameState.getGameHeap().putBack(tableDiff);
dealPenalty(tableDiff.size());
} }
} else { // Player hasn't made a move
if (clonedTable.isValid()) {
gameState.setTable(clonedTable);
}
dealStone(); 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.nextPlayer();
gameState.nextPlayer();
prepareTurn(); prepareTurn();
} }
@ -164,7 +218,7 @@ public class RoundControl {
} }
void dealStones(int count) { void dealStones(int count) {
IHand hand = gameState.getActivePlayer().getHand(); IHand hand = roundState.getActivePlayer().getHand();
int rowCount = hand.getRowCount(); int rowCount = hand.getRowCount();
for (int i = 0; i < count; ++i) { for (int i = 0; i < count; ++i) {
@ -172,7 +226,7 @@ public class RoundControl {
rowCount++; rowCount++;
} }
hand.drop(gameState.getGameHeap().drawStone(), new Position( hand.drop(roundState.getGameHeap().drawStone(), new Position(
Hand.WIDTH - 1, rowCount - 1)); Hand.WIDTH - 1, rowCount - 1));
} }
} }

View file

@ -6,7 +6,7 @@ import java.util.List;
/** /**
* The overall game settings * The overall game settings
*/ */
public class GameSettings { public class GameSettings implements IGameSettings {
private List<PlayerSettings> players = new ArrayList<PlayerSettings>(); private List<PlayerSettings> players = new ArrayList<PlayerSettings>();
private int initialMeldThreshold; private int initialMeldThreshold;
@ -18,30 +18,26 @@ public class GameSettings {
initialMeldThreshold = 30; initialMeldThreshold = 30;
} }
/** /* (non-Javadoc)
* Returns the list containing the settings of all players * @see jrummikub.model.IGameSettings#getPlayerList()
*
* @return the player settings list
*/ */
@Override
public List<PlayerSettings> getPlayerList() { public List<PlayerSettings> getPlayerList() {
return players; return players;
} }
/** /* (non-Javadoc)
* Sets the initial meld threshold * @see jrummikub.model.IGameSettings#setInitialMeldThreshold(int)
*
* @param value
* the value to set
*/ */
@Override
public void setInitialMeldThreshold(int value) { public void setInitialMeldThreshold(int value) {
initialMeldThreshold = value; initialMeldThreshold = value;
} }
/** /* (non-Javadoc)
* Returns the initial meld threshold * @see jrummikub.model.IGameSettings#getInitialMeldThreshold()
*
* @return the threshold
*/ */
@Override
public int getInitialMeldThreshold() { public int getInitialMeldThreshold() {
return initialMeldThreshold; return initialMeldThreshold;
} }

View file

@ -25,4 +25,10 @@ public interface IPlayer {
* @return the player settings * @return the player settings
*/ */
public PlayerSettings getPlayerSettings(); public PlayerSettings getPlayerSettings();
/**
* Set if the player laid out
*
*/
void setLaidOut(boolean laidOut);
} }

View file

@ -10,7 +10,7 @@ public interface IRoundState {
* *
* @return The game settings * @return The game settings
*/ */
public GameSettings getGameSettings(); public IGameSettings getGameSettings();
/** /**
* Get the current {@link Table} * Get the current {@link Table}

View file

@ -10,7 +10,7 @@ public class Player implements IPlayer {
* Create a new player with a given name and color * Create a new player with a given name and color
* *
* @param settings * @param settings
* the player settings * the player settings
*/ */
public Player(PlayerSettings settings) { public Player(PlayerSettings settings) {
this.settings = settings; this.settings = settings;
@ -29,6 +29,11 @@ public class Player implements IPlayer {
return laidOut; return laidOut;
} }
@Override
public void setLaidOut(boolean laidOut) {
this.laidOut = laidOut;
}
@Override @Override
public PlayerSettings getPlayerSettings() { public PlayerSettings getPlayerSettings() {
return settings; return settings;

View file

@ -5,7 +5,7 @@ import java.util.List;
/** Class managing the overall and momentary RoundState */ /** Class managing the overall and momentary RoundState */
public class RoundState implements IRoundState { public class RoundState implements IRoundState {
private GameSettings gameSettings; private IGameSettings gameSettings;
private ITable table; private ITable table;
private List<Player> players; private List<Player> players;
@ -18,7 +18,7 @@ public class RoundState implements IRoundState {
* @param gameSettings * @param gameSettings
* the game settings * the game settings
*/ */
public RoundState(GameSettings gameSettings) { public RoundState(IGameSettings gameSettings) {
this.gameSettings = gameSettings; this.gameSettings = gameSettings;
table = new Table(); table = new Table();
@ -68,7 +68,7 @@ public class RoundState implements IRoundState {
} }
@Override @Override
public GameSettings getGameSettings() { public IGameSettings getGameSettings() {
return gameSettings; return gameSettings;
} }
} }

View file

@ -20,6 +20,7 @@ import java.util.Set;
import jrummikub.model.Hand; import jrummikub.model.Hand;
import jrummikub.model.IHand; import jrummikub.model.IHand;
import jrummikub.model.ITable; import jrummikub.model.ITable;
import jrummikub.model.MockGameSettings;
import jrummikub.model.MockRoundState; import jrummikub.model.MockRoundState;
import jrummikub.model.MockTable; import jrummikub.model.MockTable;
import jrummikub.model.Position; import jrummikub.model.Position;
@ -99,215 +100,274 @@ public class RoundControlTest {
view.displayStartTurnPanel = false; view.displayStartTurnPanel = false;
} }
// TODO: evt. Mock round/gaestate zwecks hargecodeter player, dann wer weiß,
// wie wir sonst an Player rankommen
// laidOut test cases // laidOut test cases
/** */ /** Threshold=30 */
@Test @Test
public void laidOutValidTooFew() { public void laidOutValidTooFew() {
MockGameSettings gameSettings = new MockGameSettings();
RoundState roundState = new RoundState(null); RoundState roundState = new RoundState(gameSettings);
RoundControl roundControl = new RoundControl(roundState, view); RoundControl roundControl = new RoundControl(roundState, view);
roundControl.startRound(); roundControl.startRound();
IHand hand = roundState.getActivePlayer().getHand(); view.startTurnEvent.emit();
Stone blueOne = new Stone(1, BLUE); Stone blueOne = new Stone(1, BLUE);
Stone blueTwo = new Stone(2, BLUE); Stone blueTwo = new Stone(2, BLUE);
Stone blueThree = new Stone(3, BLUE); Stone blueThree = new Stone(3, BLUE);
IHand hand = roundState.getActivePlayer().getHand();
hand.drop(blueOne, new Position(0, 0)); hand.drop(blueOne, new Position(0, 0));
hand.drop(blueTwo, new Position(0, 0)); hand.drop(blueTwo, new Position(0, 0));
hand.drop(blueThree, new Position(0, 0)); hand.drop(blueThree, new Position(0, 0));
assertFalse(roundState.getActivePlayer().getLaidOut()); assertFalse(roundState.getActivePlayer().getLaidOut());
hand.pickUp(blueOne); view.handPanel.stoneClickEvent.emit(blueOne, false);
hand.pickUp(blueTwo); view.handPanel.stoneClickEvent.emit(blueTwo, true);
hand.pickUp(blueThree); view.handPanel.stoneClickEvent.emit(blueThree, true);
roundState.getTable().drop( view.tablePanel.clickEvent.emit(new Position(0, 0));
new StoneSet(Arrays.asList(blueOne, blueTwo, blueThree)),
new Position(0, 0));
view.playerPanel.endTurnEvent.emit(); view.playerPanel.endTurnEvent.emit();
assertTrue(roundState.getNthNextPlayer(roundState.getPlayerCount() - 1) assertFalse(roundState
.getLaidOut()); .getNthNextPlayer(roundState.getPlayerCount() - 1).getLaidOut());
assertEquals(0, roundState.getTable().getSize());
} }
/** */ /** Threshold=30 */
@Test @Test
public void laidOutInvalidEnough() { public void laidOutInvalidEnough() {
RoundState roundState = new RoundState(null); MockGameSettings gameSettings = new MockGameSettings();
RoundState roundState = new RoundState(gameSettings);
RoundControl roundControl = new RoundControl(roundState, view); RoundControl roundControl = new RoundControl(roundState, view);
roundControl.startRound(); roundControl.startRound();
IHand hand = roundState.getActivePlayer().getHand(); view.startTurnEvent.emit();
Stone blueOne = new Stone(1, BLUE); Stone blueOne = new Stone(1, BLUE);
Stone blueTwo = new Stone(2, BLUE); Stone blueTwo = new Stone(2, BLUE);
Stone blueThree = new Stone(3, BLUE); Stone blueThree = new Stone(3, BLUE);
Stone redEight = new Stone(8, RED); IHand hand = roundState.getActivePlayer().getHand();
Stone redNine = new Stone(9, RED);
Stone redTen = new Stone(10, RED);
Stone orangeOne = new Stone(1, ORANGE);
hand.drop(blueOne, new Position(0, 0)); hand.drop(blueOne, new Position(0, 0));
hand.drop(blueTwo, new Position(0, 0)); hand.drop(blueTwo, new Position(0, 0));
hand.drop(blueThree, new Position(0, 0)); hand.drop(blueThree, new Position(0, 0));
hand.drop(redEight, new Position(0, 0)); view.handPanel.stoneClickEvent.emit(blueOne, false);
hand.drop(redNine, new Position(0, 0)); view.handPanel.stoneClickEvent.emit(blueTwo, true);
view.handPanel.stoneClickEvent.emit(blueThree, true);
view.tablePanel.clickEvent.emit(new Position(0, 0));
Stone blueTen = new Stone(10, BLUE);
Stone redTen = new Stone(10, RED);
Stone blueEleven = new Stone(11, BLUE);
assertFalse(roundState.getActivePlayer().getLaidOut());
hand.drop(blueTen, new Position(0, 0));
hand.drop(redTen, new Position(0, 0)); hand.drop(redTen, new Position(0, 0));
hand.drop(blueEleven, new Position(0, 0));
hand.drop(orangeOne, new Position(0, 0)); view.handPanel.stoneClickEvent.emit(blueTen, false);
view.handPanel.stoneClickEvent.emit(redTen, true);
view.handPanel.stoneClickEvent.emit(blueEleven, true);
hand.pickUp(orangeOne); view.tablePanel.clickEvent.emit(new Position(0, 0));
hand.pickUp(blueTwo);
hand.pickUp(blueThree);
roundState.getTable().drop(
new StoneSet(Arrays.asList(orangeOne, blueTwo, blueThree)),
new Position(0, 0));
hand.pickUp(redEight);
hand.pickUp(redNine);
hand.pickUp(redTen);
roundState.getTable().drop(
new StoneSet(Arrays.asList(redEight, redNine, redTen)),
new Position(0, 0));
view.playerPanel.endTurnEvent.emit(); view.playerPanel.endTurnEvent.emit();
assertTrue(roundState.getNthNextPlayer(roundState.getPlayerCount() - 1) assertFalse(roundState
.getLaidOut()); .getNthNextPlayer(roundState.getPlayerCount() - 1).getLaidOut());
assertEquals(0, roundState.getTable().getSize());
} }
/** */ /** Threshold=30 */
@Test @Test
public void laidOutTooFewChangedTable() { public void laidOutTooFewChangedTable() {
RoundState roundState = new RoundState(null); MockGameSettings gameSettings = new MockGameSettings();
RoundState roundState = new RoundState(gameSettings);
RoundControl roundControl = new RoundControl(roundState, view); RoundControl roundControl = new RoundControl(roundState, view);
roundControl.startRound(); roundControl.startRound();
IHand hand = roundState.getActivePlayer().getHand(); view.startTurnEvent.emit();
// Fake Turn to put stones on the table
Stone redEight = new Stone(8, RED);
Stone redNine = new Stone(9, RED);
Stone redTen = new Stone(10, RED);
hand.drop(redEight, new Position(0, 0));
hand.drop(redNine, new Position(0, 0));
hand.drop(redTen, new Position(0, 0));
Stone blueSeven = new Stone(7, BLUE); Stone blueSeven = new Stone(7, BLUE);
Stone blackSeven = new Stone(7, BLACK); Stone blackSeven = new Stone(7, BLACK);
Stone redSeven = new Stone(7, RED); Stone redSeven = new Stone(7, RED);
Stone orangeSeven = new Stone(7, ORANGE); Stone orangeSeven = new Stone(7, ORANGE);
StoneSet sevenSet = new StoneSet(Arrays.asList(blueSeven, blackSeven, Stone blueOne = new Stone(1, BLUE);
redSeven, orangeSeven)); Stone blueTwo = new Stone(2, BLUE);
Stone blueThree = new Stone(3, BLUE);
roundState.getTable().drop(sevenSet, new Position(0, 0)); IHand hand = roundState.getActivePlayer().getHand();
hand.pickUp(redEight); hand.drop(blueOne, new Position(0, 0));
hand.pickUp(redNine); hand.drop(blueTwo, new Position(0, 0));
hand.pickUp(redTen); hand.drop(blueThree, new Position(0, 0));
roundState.getTable().pickUpStone(redSeven);
roundState.getTable() hand.drop(redSeven, new Position(0, 0));
.drop(new StoneSet(Arrays.asList(redSeven, redEight, redNine, hand.drop(blueSeven, new Position(0, 0));
redTen)), new Position(0, 0)); hand.drop(blackSeven, new Position(0, 0));
hand.drop(orangeSeven, new Position(0, 0));
view.handPanel.stoneClickEvent.emit(redSeven, false);
view.handPanel.stoneClickEvent.emit(blueSeven, true);
view.handPanel.stoneClickEvent.emit(blackSeven, true);
view.handPanel.stoneClickEvent.emit(orangeSeven, true);
view.tablePanel.clickEvent.emit(new Position(0, 0));
view.handPanel.stoneClickEvent.emit(blueOne, false);
view.handPanel.stoneClickEvent.emit(blueTwo, true);
view.handPanel.stoneClickEvent.emit(blueThree, true);
view.tablePanel.clickEvent.emit(new Position(0, 0));
view.playerPanel.endTurnEvent.emit(); view.playerPanel.endTurnEvent.emit();
assertTrue(roundState.getNthNextPlayer(roundState.getPlayerCount() - 1) assertEquals(2, roundState.getTable().getSize());
.getLaidOut()); view.startTurnEvent.emit();
Stone redEight = new Stone(8, RED);
Stone redNine = new Stone(9, RED);
Stone redTen = new Stone(10, RED);
hand = roundState.getActivePlayer().getHand();
hand.drop(redEight, new Position(0, 0));
hand.drop(redNine, new Position(0, 0));
hand.drop(redTen, new Position(0, 0));
view.tablePanel.stoneClickEvent.emit(redSeven, false);
view.handPanel.stoneClickEvent.emit(redEight, true);
view.handPanel.stoneClickEvent.emit(redNine, true);
view.handPanel.stoneClickEvent.emit(redTen, 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());
} }
/** */ /** Threshold=30 */
@Test @Test
public void laidOutEnoughChangedTable() { public void laidOutEnoughChangedTable() {
RoundState roundState = new RoundState(null); MockGameSettings gameSettings = new MockGameSettings();
RoundState roundState = new RoundState(gameSettings);
RoundControl roundControl = new RoundControl(roundState, view); RoundControl roundControl = new RoundControl(roundState, view);
roundControl.startRound(); roundControl.startRound();
view.startTurnEvent.emit();
// Fake Turn to put stones on the table
Stone blueSeven = new Stone(7, BLUE);
Stone blackSeven = new Stone(7, BLACK);
Stone redSeven = new Stone(7, RED);
Stone orangeSeven = new Stone(7, ORANGE);
Stone blueOne = new Stone(1, BLUE);
Stone blueTwo = new Stone(2, BLUE);
Stone blueThree = new Stone(3, BLUE);
IHand hand = roundState.getActivePlayer().getHand(); IHand hand = roundState.getActivePlayer().getHand();
hand.drop(blueOne, new Position(0, 0));
hand.drop(blueTwo, new Position(0, 0));
hand.drop(blueThree, new Position(0, 0));
hand.drop(redSeven, new Position(0, 0));
hand.drop(blueSeven, new Position(0, 0));
hand.drop(blackSeven, new Position(0, 0));
hand.drop(orangeSeven, new Position(0, 0));
view.handPanel.stoneClickEvent.emit(redSeven, false);
view.handPanel.stoneClickEvent.emit(blueSeven, true);
view.handPanel.stoneClickEvent.emit(blackSeven, true);
view.handPanel.stoneClickEvent.emit(orangeSeven, true);
view.tablePanel.clickEvent.emit(new Position(0, 0));
view.handPanel.stoneClickEvent.emit(blueOne, false);
view.handPanel.stoneClickEvent.emit(blueTwo, true);
view.handPanel.stoneClickEvent.emit(blueThree, true);
view.tablePanel.clickEvent.emit(new Position(0, 0));
view.playerPanel.endTurnEvent.emit();
assertEquals(2, roundState.getTable().getSize());
view.startTurnEvent.emit();
Stone redEight = new Stone(8, RED); Stone redEight = new Stone(8, RED);
Stone redNine = new Stone(9, RED); Stone redNine = new Stone(9, RED);
Stone redTen = new Stone(10, RED); Stone redTen = new Stone(10, RED);
Stone redEleven = new Stone(11, RED); Stone redEleven = new Stone(11, RED);
hand = roundState.getActivePlayer().getHand();
hand.drop(redEight, new Position(0, 0)); hand.drop(redEight, new Position(0, 0));
hand.drop(redNine, new Position(0, 0)); hand.drop(redNine, new Position(0, 0));
hand.drop(redTen, new Position(0, 0)); hand.drop(redTen, new Position(0, 0));
hand.drop(redEleven, new Position(0, 0)); hand.drop(redEleven, new Position(0, 0));
view.tablePanel.stoneClickEvent.emit(redSeven, false);
view.handPanel.stoneClickEvent.emit(redEight, true);
view.handPanel.stoneClickEvent.emit(redNine, true);
view.handPanel.stoneClickEvent.emit(redTen, true);
view.handPanel.stoneClickEvent.emit(redEleven, 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());
}
/** Threshold=30 */
@Test
public void laidOutValid() {
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 blueSeven = new Stone(7, BLUE); Stone blueSeven = new Stone(7, BLUE);
Stone blackSeven = new Stone(7, BLACK); Stone blackSeven = new Stone(7, BLACK);
Stone redSeven = new Stone(7, RED); Stone redSeven = new Stone(7, RED);
Stone orangeSeven = new Stone(7, ORANGE); Stone orangeSeven = new Stone(7, ORANGE);
StoneSet sevenSet = new StoneSet(Arrays.asList(blueSeven, blackSeven,
redSeven, orangeSeven));
roundState.getTable().drop(sevenSet, new Position(0, 0));
hand.pickUp(redEight);
hand.pickUp(redNine);
hand.pickUp(redTen);
hand.pickUp(redEleven);
roundState.getTable().pickUpStone(redSeven);
roundState.getTable().drop(
new StoneSet(Arrays.asList(redSeven, redEight, redNine, redTen,
redEleven)), new Position(0, 0));
view.playerPanel.endTurnEvent.emit();
assertTrue(roundState.getNthNextPlayer(roundState.getPlayerCount() - 1)
.getLaidOut());
}
/** */
@Test
public void laidOutValid() {
RoundState roundState = new RoundState(null);
RoundControl roundControl = new RoundControl(roundState, view);
roundControl.startRound();
IHand hand = roundState.getActivePlayer().getHand();
Stone blueOne = new Stone(1, BLUE); Stone blueOne = new Stone(1, BLUE);
Stone blueTwo = new Stone(2, BLUE); Stone blueTwo = new Stone(2, BLUE);
Stone blueThree = new Stone(3, BLUE); Stone blueThree = new Stone(3, BLUE);
Stone redEight = new Stone(8, RED); IHand hand = roundState.getActivePlayer().getHand();
Stone redNine = new Stone(9, RED);
Stone redTen = new Stone(10, RED);
hand.drop(blueOne, new Position(0, 0)); hand.drop(blueOne, new Position(0, 0));
hand.drop(blueTwo, new Position(0, 0)); hand.drop(blueTwo, new Position(0, 0));
hand.drop(blueThree, new Position(0, 0)); hand.drop(blueThree, new Position(0, 0));
hand.drop(redEight, new Position(0, 0)); hand.drop(redSeven, new Position(0, 0));
hand.drop(redNine, new Position(0, 0)); hand.drop(blueSeven, new Position(0, 0));
hand.drop(redTen, new Position(0, 0)); hand.drop(blackSeven, new Position(0, 0));
hand.drop(orangeSeven, new Position(0, 0));
assertFalse(roundState.getActivePlayer().getLaidOut()); view.handPanel.stoneClickEvent.emit(redSeven, false);
view.handPanel.stoneClickEvent.emit(blueSeven, true);
view.handPanel.stoneClickEvent.emit(blackSeven, true);
view.handPanel.stoneClickEvent.emit(orangeSeven, true);
hand.pickUp(blueOne); view.tablePanel.clickEvent.emit(new Position(0, 0));
hand.pickUp(blueTwo);
hand.pickUp(blueThree);
roundState.getTable().drop( view.handPanel.stoneClickEvent.emit(blueOne, false);
new StoneSet(Arrays.asList(blueOne, blueTwo, blueThree)), view.handPanel.stoneClickEvent.emit(blueTwo, true);
new Position(0, 0)); view.handPanel.stoneClickEvent.emit(blueThree, true);
hand.pickUp(redEight); view.tablePanel.clickEvent.emit(new Position(0, 0));
hand.pickUp(redNine);
hand.pickUp(redTen);
roundState.getTable().drop(
new StoneSet(Arrays.asList(redEight, redNine, redTen)),
new Position(0, 0));
view.playerPanel.endTurnEvent.emit(); view.playerPanel.endTurnEvent.emit();
assertTrue(roundState.getNthNextPlayer(roundState.getPlayerCount() - 1) assertTrue(roundState.getNthNextPlayer(roundState.getPlayerCount() - 1)
.getLaidOut()); .getLaidOut());
assertEquals(2, roundState.getTable().getSize());
} }
/** */ /** */
@ -444,12 +504,27 @@ public class RoundControlTest {
view.startTurnEvent.emit(); view.startTurnEvent.emit();
assertFalse(view.displayStartTurnPanel); assertFalse(view.displayStartTurnPanel);
IHand hand = testRoundState.players.get(0).hand; IHand hand = testRoundState.players.get(0).hand;
Stone stone = hand.iterator().next().getFirst();
hand.pickUp(stone); Stone blueEight = new Stone(8, BLUE);
testTable.drop(new StoneSet(stone), new Position(0, 0)); Stone blackEight = new Stone(8, BLACK);
Stone redEight = new Stone(8, RED);
Stone orangeEight = new Stone(8, ORANGE);
hand.drop(redEight, new Position(0, 0));
hand.drop(blueEight, new Position(0, 0));
hand.drop(blackEight, new Position(0, 0));
hand.drop(orangeEight, new Position(0, 0));
view.handPanel.stoneClickEvent.emit(redEight, false);
view.handPanel.stoneClickEvent.emit(blueEight, true);
view.handPanel.stoneClickEvent.emit(blackEight, true);
view.handPanel.stoneClickEvent.emit(orangeEight, true);
view.tablePanel.clickEvent.emit(new Position(0, 0));
testRoundState.players.get(0).hand = new Hand(); testRoundState.players.get(0).hand = new Hand();
resetTurnStart(); resetTurnStart();
view.getPlayerPanel().endTurnEvent.emit(); view.playerPanel.endTurnEvent.emit();
assertTrue(view.displayWinPanel); assertTrue(view.displayWinPanel);
} }

View file

@ -11,7 +11,7 @@ import org.junit.Test;
* Test class for {@link RoundState} * Test class for {@link RoundState}
*/ */
public class RoundStateTest { public class RoundStateTest {
private GameSettings settings = new GameSettings(); private IGameSettings settings = new GameSettings();
private IRoundState testRound; private IRoundState testRound;
/** */ /** */