Always operate on cloned hands in the turn controls

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@380 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Matthias Schiffer 2011-06-07 00:23:00 +02:00
parent c59332950b
commit af3661fea0
11 changed files with 157 additions and 84 deletions

View file

@ -42,4 +42,9 @@ public class MockPlayer implements IPlayer {
public void setLaidOut(boolean laidOut) { public void setLaidOut(boolean laidOut) {
this.laidOut = laidOut; this.laidOut = laidOut;
} }
@Override
public void setHand(IHand hand) {
this.hand = hand;
}
} }

View file

@ -36,6 +36,7 @@ public class RoundControl {
IRoundState roundState; IRoundState roundState;
private IView view; private IView view;
private ITable clonedTable; private ITable clonedTable;
IHand clonedHand;
private Event restartRoundEvent = new Event(); private Event restartRoundEvent = new Event();
private Event1<Score> endOfRoundEvent = new Event1<Score>(); private Event1<Score> endOfRoundEvent = new Event1<Score>();
private List<Connection> connections = new ArrayList<Connection>(); private List<Connection> connections = new ArrayList<Connection>();
@ -84,6 +85,7 @@ public class RoundControl {
boolean isHuman = roundState.getActivePlayer().getPlayerSettings() boolean isHuman = roundState.getActivePlayer().getPlayerSettings()
.getTurnControlType() == HUMAN; .getTurnControlType() == HUMAN;
clonedTable = (ITable) roundState.getTable().clone(); clonedTable = (ITable) roundState.getTable().clone();
clonedHand = (IHand) roundState.getActivePlayer().getHand().clone();
view.setBottomPanel(isHuman ? BottomPanelType.START_TURN_PANEL view.setBottomPanel(isHuman ? BottomPanelType.START_TURN_PANEL
: BottomPanelType.COMPUTER_HAND_PANEL); : BottomPanelType.COMPUTER_HAND_PANEL);
@ -109,7 +111,7 @@ public class RoundControl {
if (roundState.getTurnNumber() < 1) { if (roundState.getTurnNumber() < 1) {
turnMode = TurnMode.INSPECT_ONLY; turnMode = TurnMode.INSPECT_ONLY;
if (roundState.getActivePlayer().getHand().getIdenticalStoneCount() >= 3) { if (clonedHand.getIdenticalStoneCount() >= 3) {
turnMode = TurnMode.MAY_REDEAL; turnMode = TurnMode.MAY_REDEAL;
} }
} }
@ -120,8 +122,9 @@ public class RoundControl {
turnControl = TurnControlFactory.getFactory( turnControl = TurnControlFactory.getFactory(
roundState.getActivePlayer().getPlayerSettings().getTurnControlType()) roundState.getActivePlayer().getPlayerSettings().getTurnControlType())
.create(); .create();
turnControl.setup(roundState.getGameSettings(), turnControl.setup(new ITurnControl.TurnInfo(clonedTable, clonedHand,
roundState.getActivePlayer(), clonedTable, view, turnMode); roundState.getActivePlayer().getLaidOut(), turnMode), roundState
.getGameSettings(), view);
turnControl.getEndOfTurnEvent().add(new IListener() { turnControl.getEndOfTurnEvent().add(new IListener() {
@Override @Override
public void handle() { public void handle() {
@ -189,6 +192,8 @@ public class RoundControl {
} }
private void checkTurn() { private void checkTurn() {
roundState.getActivePlayer().setHand(clonedHand);
if (!clonedTable.isValid()) { if (!clonedTable.isValid()) {
rejectMove(); rejectMove();
return; return;

View file

@ -1,8 +1,6 @@
package jrummikub.control.turn; package jrummikub.control.turn;
import jrummikub.model.GameSettings; import jrummikub.model.GameSettings;
import jrummikub.model.IPlayer;
import jrummikub.model.ITable;
import jrummikub.util.Event; import jrummikub.util.Event;
import jrummikub.util.IEvent; import jrummikub.util.IEvent;
import jrummikub.view.IView; import jrummikub.view.IView;
@ -14,11 +12,9 @@ public abstract class AbstractTurnControl implements ITurnControl {
protected Event endOfTurnEvent = new Event(); protected Event endOfTurnEvent = new Event();
protected Event redealEvent = new Event(); protected Event redealEvent = new Event();
protected TurnInfo turnInfo;
protected GameSettings settings; protected GameSettings settings;
protected IPlayer player;
protected ITable table;
protected IView view; protected IView view;
protected TurnMode turnMode;
@Override @Override
public IEvent getEndOfTurnEvent() { public IEvent getEndOfTurnEvent() {
@ -31,13 +27,10 @@ public abstract class AbstractTurnControl implements ITurnControl {
} }
@Override @Override
public void setup(GameSettings settings, IPlayer player, ITable table, public void setup(TurnInfo info, GameSettings settings, IView view) {
IView view, TurnMode turnMode) { turnInfo = info;
this.settings = settings; this.settings = settings;
this.player = player;
this.table = table;
this.view = view; this.view = view;
this.turnMode = turnMode;
} }
} }

View file

@ -63,7 +63,7 @@ public class BaseAIControl extends AbstractTurnControl {
} }
private void compute() { private void compute() {
switch (turnMode) { switch (turnInfo.getTurnMode()) {
case MAY_REDEAL: case MAY_REDEAL:
emitRedeal(); emitRedeal();
break; break;
@ -77,14 +77,14 @@ public class BaseAIControl extends AbstractTurnControl {
} }
private Stone findMatchingStone(Stone target) { private Stone findMatchingStone(Stone target) {
for (Pair<Stone, Position> entry : player.getHand()) { for (Pair<Stone, Position> entry : turnInfo.getHand()) {
Stone stone = entry.getFirst(); Stone stone = entry.getFirst();
if (stone.getValue() == target.getValue() if (stone.getValue() == target.getValue()
&& stone.getColor() == target.getColor()) { && stone.getColor() == target.getColor()) {
return stone; return stone;
} }
} }
for (Pair<Stone, Position> entry : player.getHand()) { for (Pair<Stone, Position> entry : turnInfo.getHand()) {
Stone stone = entry.getFirst(); Stone stone = entry.getFirst();
if (stone.isJoker()) { if (stone.isJoker()) {
return stone; return stone;
@ -95,14 +95,14 @@ public class BaseAIControl extends AbstractTurnControl {
private Stone pickUpMatchingStone(Stone target) { private Stone pickUpMatchingStone(Stone target) {
Stone match = findMatchingStone(target); Stone match = findMatchingStone(target);
player.getHand().pickUp(match); turnInfo.getHand().pickUp(match);
return match; return match;
} }
private void turn() { private void turn() {
List<Stone> stones = new ArrayList<Stone>(); List<Stone> stones = new ArrayList<Stone>();
for (Pair<Stone, Position> entry : player.getHand()) { for (Pair<Stone, Position> entry : turnInfo.getHand()) {
stones.add(entry.getFirst()); stones.add(entry.getFirst());
} }
@ -115,7 +115,7 @@ public class BaseAIControl extends AbstractTurnControl {
Math.max(30, settings.getInitialMeldThreshold() * 2), Math.max(30, settings.getInitialMeldThreshold() * 2),
counts.getFirst(), counts.getSecond()); counts.getFirst(), counts.getSecond());
if (!player.getLaidOut() if (!turnInfo.getLaidOut()
&& result.getSecond() < settings.getInitialMeldThreshold()) { && result.getSecond() < settings.getInitialMeldThreshold()) {
emitEndOfTurn(); emitEndOfTurn();
return; return;
@ -126,7 +126,7 @@ public class BaseAIControl extends AbstractTurnControl {
for (Stone stone : set) { for (Stone stone : set) {
handStones.add(pickUpMatchingStone(stone)); handStones.add(pickUpMatchingStone(stone));
} }
table.drop(new StoneSet(handStones), new Position( turnInfo.getTable().drop(new StoneSet(handStones), new Position(
(float) Math.random() * 30 - 15, (float) Math.random() * 6 - 3)); (float) Math.random() * 30 - 15, (float) Math.random() * 6 - 3));
} }
@ -148,7 +148,7 @@ public class BaseAIControl extends AbstractTurnControl {
private void emitEndOfTurn() { private void emitEndOfTurn() {
long timeElapsed = System.currentTimeMillis() - startTime; long timeElapsed = System.currentTimeMillis() - startTime;
long timeNeeded = Math.min((long) (1000 + Math.random() long timeNeeded = Math.min((long) (1000 + Math.random()
* player.getHand().getSize() * 100), 50000); * turnInfo.getHand().getSize() * 100), 50000);
long waitTime = timeNeeded - timeElapsed; long waitTime = timeNeeded - timeElapsed;
if (waitTime > 0) { if (waitTime > 0) {

View file

@ -73,11 +73,11 @@ public class HumanTurnControl extends AbstractTurnControl {
addHandPanelHandlers(); addHandPanelHandlers();
addStoneCollectionHandlers(); addStoneCollectionHandlers();
if (turnMode == TurnMode.NORMAL_TURN) { if (turnInfo.getTurnMode() == TurnMode.NORMAL_TURN) {
addTablePanelHandlers(); addTablePanelHandlers();
} }
view.getHandPanel().setStones(player.getHand().clone()); view.getHandPanel().setStones(turnInfo.getHand().clone());
view.getHandPanel().resetCurrentRow(); view.getHandPanel().resetCurrentRow();
view.setBottomPanel(BottomPanelType.HUMAN_HAND_PANEL); view.setBottomPanel(BottomPanelType.HUMAN_HAND_PANEL);
@ -227,7 +227,7 @@ public class HumanTurnControl extends AbstractTurnControl {
private void handClick(Position pos) { private void handClick(Position pos) {
List<Stone> handStones = new ArrayList<Stone>(); List<Stone> handStones = new ArrayList<Stone>();
for (Stone s : selectedStones) { for (Stone s : selectedStones) {
if (player.getHand().pickUp(s)) { if (turnInfo.getHand().pickUp(s)) {
handStones.add(s); handStones.add(s);
} }
} }
@ -236,28 +236,28 @@ public class HumanTurnControl extends AbstractTurnControl {
for (Stone s : handStones) { for (Stone s : handStones) {
double x = Math.max(0, double x = Math.max(0,
Math.min(13, pos.getX() - handStones.size() / 2.0f + i)); Math.min(13, pos.getX() - handStones.size() / 2.0f + i));
player.getHand().drop(s, turnInfo.getHand().drop(s,
new Position(x, (float) Math.floor(pos.getY()))); new Position(x, (float) Math.floor(pos.getY())));
selectedStones.remove(s); selectedStones.remove(s);
i++; i++;
} }
view.setSelectedStones(selectedStones); view.setSelectedStones(selectedStones);
view.getHandPanel().setStones(player.getHand()); view.getHandPanel().setStones(turnInfo.getHand());
} }
private void sortStones(Comparator<Stone> comparator) { private void sortStones(Comparator<Stone> comparator) {
List<Stone> stones = new ArrayList<Stone>(); List<Stone> stones = new ArrayList<Stone>();
for (Pair<Stone, Position> entry : player.getHand()) { for (Pair<Stone, Position> entry : turnInfo.getHand()) {
stones.add(entry.getFirst()); stones.add(entry.getFirst());
} }
for (Stone stone : stones) { for (Stone stone : stones) {
player.getHand().pickUp(stone); turnInfo.getHand().pickUp(stone);
} }
Collections.sort(stones, comparator); Collections.sort(stones, comparator);
int x = 0, y = 0; int x = 0, y = 0;
for (Stone stone : stones) { for (Stone stone : stones) {
player.getHand().drop(stone, new Position(x, y)); turnInfo.getHand().drop(stone, new Position(x, y));
x++; x++;
if (x >= Hand.WIDTH) { if (x >= Hand.WIDTH) {
x = 0; x = 0;
@ -265,7 +265,7 @@ public class HumanTurnControl extends AbstractTurnControl {
} }
} }
view.getHandPanel().setStones(player.getHand()); view.getHandPanel().setStones(turnInfo.getHand());
} }
private void sortByRuns() { private void sortByRuns() {
@ -306,8 +306,8 @@ public class HumanTurnControl extends AbstractTurnControl {
private void pickUpSelectedStones() { private void pickUpSelectedStones() {
for (Stone stone : selectedStones) { for (Stone stone : selectedStones) {
player.getHand().pickUp(stone); turnInfo.getHand().pickUp(stone);
table.pickUpStone(stone); turnInfo.getTable().pickUpStone(stone);
} }
} }
@ -317,12 +317,12 @@ public class HumanTurnControl extends AbstractTurnControl {
} }
pickUpSelectedStones(); pickUpSelectedStones();
table.drop(new StoneSet(selectedStones), new Position(position.getX() turnInfo.getTable().drop(new StoneSet(selectedStones), new Position(position.getX()
- selectedStones.size() * 0.5f, position.getY() - 0.5f)); - selectedStones.size() * 0.5f, position.getY() - 0.5f));
selectedStones.clear(); selectedStones.clear();
view.getTablePanel().setStoneSets(table); view.getTablePanel().setStoneSets(turnInfo.getTable());
view.getHandPanel().setStones(player.getHand()); view.getHandPanel().setStones(turnInfo.getHand());
view.setSelectedStones(selectedStones); view.setSelectedStones(selectedStones);
} }
@ -330,7 +330,7 @@ public class HumanTurnControl extends AbstractTurnControl {
if (!collect) { if (!collect) {
selectedStones.clear(); selectedStones.clear();
} }
StoneSet selectedSet = table.findStoneSet(stone); StoneSet selectedSet = turnInfo.getTable().findStoneSet(stone);
for (Stone setStone : selectedSet) { for (Stone setStone : selectedSet) {
selectedStones.remove(setStone); selectedStones.remove(setStone);
selectedStones.add(setStone); selectedStones.add(setStone);
@ -344,8 +344,8 @@ public class HumanTurnControl extends AbstractTurnControl {
return; return;
} }
Stone lastStone = selectedStones.get(selectedStones.size() - 1); Stone lastStone = selectedStones.get(selectedStones.size() - 1);
StoneSet lastSet = table.findStoneSet(lastStone); StoneSet lastSet = turnInfo.getTable().findStoneSet(lastStone);
StoneSet selectedSet = table.findStoneSet(stone); StoneSet selectedSet = turnInfo.getTable().findStoneSet(stone);
if (lastSet != selectedSet) { if (lastSet != selectedSet) {
stoneClick(stone, true); stoneClick(stone, true);
return; return;
@ -376,13 +376,13 @@ public class HumanTurnControl extends AbstractTurnControl {
return; return;
} }
Stone lastStone = selectedStones.get(selectedStones.size() - 1); Stone lastStone = selectedStones.get(selectedStones.size() - 1);
StoneSet lastSet = table.findStoneSet(lastStone); StoneSet lastSet = turnInfo.getTable().findStoneSet(lastStone);
if (lastSet != null) { if (lastSet != null) {
stoneClick(stone, true); stoneClick(stone, true);
return; return;
} }
List<Pair<Stone, Position>> handPairs = new ArrayList<Pair<Stone, Position>>(); List<Pair<Stone, Position>> handPairs = new ArrayList<Pair<Stone, Position>>();
for (Pair<Stone, Position> entry : player.getHand()) { for (Pair<Stone, Position> entry : turnInfo.getHand()) {
handPairs.add(entry); handPairs.add(entry);
} }
@ -410,7 +410,7 @@ public class HumanTurnControl extends AbstractTurnControl {
private void connectorClick(StoneSet set, boolean right) { private void connectorClick(StoneSet set, boolean right) {
List<Stone> stones = new LinkedList<Stone>(); List<Stone> stones = new LinkedList<Stone>();
Position pos = table.getPosition(set); Position pos = turnInfo.getTable().getPosition(set);
for (Stone stone : set) { for (Stone stone : set) {
stones.add(stone); stones.add(stone);
} }
@ -421,24 +421,24 @@ public class HumanTurnControl extends AbstractTurnControl {
pickUpSelectedStones(); pickUpSelectedStones();
StoneSet newSet = null; StoneSet newSet = null;
for (Stone stone : stones) { for (Stone stone : stones) {
newSet = table.findStoneSet(stone); newSet = turnInfo.getTable().findStoneSet(stone);
if (newSet != null) { if (newSet != null) {
break; break;
} }
} }
if (newSet != null) { if (newSet != null) {
Position newPos = table.getPosition(newSet); Position newPos = turnInfo.getTable().getPosition(newSet);
table.pickUp(newSet); turnInfo.getTable().pickUp(newSet);
if (right) { if (right) {
StoneSet joinedSet = newSet.join(new StoneSet(selectedStones)); StoneSet joinedSet = newSet.join(new StoneSet(selectedStones));
table.drop(joinedSet, newPos); turnInfo.getTable().drop(joinedSet, newPos);
} else { } else {
StoneSet joinedSet = new StoneSet(selectedStones).join(newSet); StoneSet joinedSet = new StoneSet(selectedStones).join(newSet);
table.drop(joinedSet, new Position(newPos.getX() turnInfo.getTable().drop(joinedSet, new Position(newPos.getX()
- selectedStones.size(), newPos.getY())); - selectedStones.size(), newPos.getY()));
} }
} else { } else {
table.drop( turnInfo.getTable().drop(
new StoneSet(selectedStones), new StoneSet(selectedStones),
new Position(pos.getX() new Position(pos.getX()
+ (set.getSize() - selectedStones.size()) * 0.5f, + (set.getSize() - selectedStones.size()) * 0.5f,
@ -447,8 +447,8 @@ public class HumanTurnControl extends AbstractTurnControl {
selectedStones.clear(); selectedStones.clear();
view.getTablePanel().setStoneSets(table); view.getTablePanel().setStoneSets(turnInfo.getTable());
view.getHandPanel().setStones(player.getHand()); view.getHandPanel().setStones(turnInfo.getHand());
view.setSelectedStones(selectedStones); view.setSelectedStones(selectedStones);
} }

View file

@ -1,7 +1,7 @@
package jrummikub.control.turn; package jrummikub.control.turn;
import jrummikub.model.GameSettings; import jrummikub.model.GameSettings;
import jrummikub.model.IPlayer; import jrummikub.model.IHand;
import jrummikub.model.ITable; import jrummikub.model.ITable;
import jrummikub.util.IEvent; import jrummikub.util.IEvent;
import jrummikub.view.IView; import jrummikub.view.IView;
@ -14,19 +14,15 @@ public interface ITurnControl {
/** /**
* Start the turn * Start the turn
* *
* @param info
* the current turn state
*
* @param settings * @param settings
* the game settings * the game settings
* @param player
* the active player
* @param table
* current table
* @param view * @param view
* view for user interaction. * view for user interaction.
* @param turnMode
* whether it is turn zero and if one may redeal
*/ */
public void setup(GameSettings settings, IPlayer player, ITable table, public void setup(TurnInfo info, GameSettings settings, IView view);
IView view, TurnMode turnMode);
/** /**
* Get the event that is emitted when the turn is over * Get the event that is emitted when the turn is over
@ -45,6 +41,71 @@ public interface ITurnControl {
/** /**
* Start the turn * Start the turn
*/ */
public abstract void startTurn(); public void startTurn();
/**
* The TurnInfo class encapsulates all information concerning the current turn
*/
public class TurnInfo {
private ITable table;
private IHand hand;
private boolean hasLaidOut;
private TurnMode turnMode;
/**
* Creates a new TurnInfo instance
*
* @param table
* the current table
* @param hand
* the current player's hand
* @param hasLaidOut
* has the player laid out yet?
* @param turnMode
* the turn mode
*/
public TurnInfo(ITable table, IHand hand, boolean hasLaidOut,
TurnMode turnMode) {
this.table = table;
this.hand = hand;
this.hasLaidOut = hasLaidOut;
this.turnMode = turnMode;
}
/**
* Gets the current table
*
* @return the table
*/
public ITable getTable() {
return table;
}
/**
* Gets the current player's hand
*
* @return the hand
*/
public IHand getHand() {
return hand;
}
/**
* Returns if the current player has laid out yet
*
* @return if the player has laid out
*/
public boolean getLaidOut() {
return hasLaidOut;
}
/**
* Gets the current turn's mode
*
* @return the turn mode
*/
public TurnMode getTurnMode() {
return turnMode;
}
}
} }

View file

@ -12,6 +12,13 @@ public interface IPlayer {
*/ */
public IHand getHand(); public IHand getHand();
/**
* Set the current hand of the player
*
* @param hand the new hand
*/
public void setHand(IHand hand);
/** /**
* Has the player laid out yet? * Has the player laid out yet?
* *

View file

@ -24,6 +24,11 @@ public class Player implements IPlayer {
return hand; return hand;
} }
@Override
public void setHand(IHand hand) {
this.hand = hand;
}
@Override @Override
public boolean getLaidOut() { public boolean getLaidOut() {
return laidOut; return laidOut;

View file

@ -147,7 +147,7 @@ public class RoundControlTest {
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(); IHand hand = roundControl.clonedHand;
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));
@ -177,7 +177,7 @@ public class RoundControlTest {
} }
view.startTurnEvent.emit(); view.startTurnEvent.emit();
IHand hand = roundState.getActivePlayer().getHand(); IHand hand = roundControl.clonedHand;
assertFalse(roundState.getActivePlayer().getLaidOut()); assertFalse(roundState.getActivePlayer().getLaidOut());
@ -202,7 +202,7 @@ public class RoundControlTest {
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(); IHand hand = roundControl.clonedHand;
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));
@ -255,7 +255,7 @@ public class RoundControlTest {
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(); IHand hand = roundControl.clonedHand;
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));
@ -286,7 +286,7 @@ public class RoundControlTest {
Stone redNine = new Stone(9, RED); Stone redNine = new Stone(9, RED);
Stone redTen = new Stone(10, RED); Stone redTen = new Stone(10, RED);
hand = roundState.getActivePlayer().getHand(); hand = roundControl.clonedHand;
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));
@ -326,7 +326,7 @@ public class RoundControlTest {
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(); IHand hand = roundControl.clonedHand;
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));
@ -358,7 +358,7 @@ public class RoundControlTest {
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 = roundControl.clonedHand;
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));
@ -400,7 +400,7 @@ public class RoundControlTest {
Stone blueSix = new Stone(6, BLUE); Stone blueSix = new Stone(6, BLUE);
Stone blueSeven = new Stone(7, BLUE); Stone blueSeven = new Stone(7, BLUE);
IHand hand = roundState.getActivePlayer().getHand(); IHand hand = roundControl.clonedHand;
hand.drop(blueFive, new Position(0, 0)); hand.drop(blueFive, new Position(0, 0));
hand.drop(blueSix, new Position(0, 0)); hand.drop(blueSix, new Position(0, 0));
hand.drop(blueSeven, new Position(0, 0)); hand.drop(blueSeven, new Position(0, 0));
@ -427,7 +427,7 @@ public class RoundControlTest {
assertEquals(2, roundState.getTable().getSize()); assertEquals(2, roundState.getTable().getSize());
view.startTurnEvent.emit(); view.startTurnEvent.emit();
hand = roundState.getActivePlayer().getHand(); hand = roundControl.clonedHand;
view.tablePanel.stoneClickEvent.emit(blueFour, false); view.tablePanel.stoneClickEvent.emit(blueFour, false);
view.tablePanel.stoneClickEvent.emit(blueFive, true); view.tablePanel.stoneClickEvent.emit(blueFive, true);
@ -464,7 +464,7 @@ public class RoundControlTest {
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(); IHand hand = roundControl.clonedHand;
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));
@ -573,7 +573,7 @@ public class RoundControlTest {
view.startTurnEvent.emit(); view.startTurnEvent.emit();
assertSame(BottomPanelType.HUMAN_HAND_PANEL, view.bottomPanelType); assertSame(BottomPanelType.HUMAN_HAND_PANEL, view.bottomPanelType);
IHand hand = testRoundState.players.get(0).hand; IHand hand = testRound.clonedHand;
Stone stone = hand.iterator().next().getFirst(); Stone stone = hand.iterator().next().getFirst();
hand.pickUp(stone); hand.pickUp(stone);
testTable.drop(new StoneSet(stone), new Position(0, 0)); testTable.drop(new StoneSet(stone), new Position(0, 0));
@ -658,7 +658,7 @@ public class RoundControlTest {
view.startTurnEvent.emit(); view.startTurnEvent.emit();
assertSame(BottomPanelType.HUMAN_HAND_PANEL, view.bottomPanelType); assertSame(BottomPanelType.HUMAN_HAND_PANEL, view.bottomPanelType);
IHand hand = testRoundState.players.get(0).hand; IHand hand = testRound.clonedHand;
Stone blueEight = new Stone(8, BLUE); Stone blueEight = new Stone(8, BLUE);
Stone blackEight = new Stone(8, BLACK); Stone blackEight = new Stone(8, BLACK);
@ -680,6 +680,7 @@ public class RoundControlTest {
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
testRoundState.players.get(i).hand = new Hand(); testRoundState.players.get(i).hand = new Hand();
} }
testRound.clonedHand = (IHand) testRoundState.players.get(3).hand.clone();
resetTurnStart(); resetTurnStart();
assertFalse(roundEnded); assertFalse(roundEnded);
@ -952,6 +953,7 @@ public class RoundControlTest {
hand.drop(new Stone(i / 2, RED), new Position(0, 0)); hand.drop(new Stone(i / 2, RED), new Position(0, 0));
} }
testRoundState.players.get(0).hand = hand; testRoundState.players.get(0).hand = hand;
testRound.clonedHand = (IHand) hand.clone();
view.startTurnEvent.emit(); view.startTurnEvent.emit();
assertEquals(view.playerPanel.turnMode, TurnMode.MAY_REDEAL); assertEquals(view.playerPanel.turnMode, TurnMode.MAY_REDEAL);
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {

View file

@ -75,7 +75,7 @@ public class BaseAIControlTest {
*/ */
@Test(timeout = 10000) @Test(timeout = 10000)
public void testTurnZeroRedealing() throws InterruptedException { public void testTurnZeroRedealing() throws InterruptedException {
aiControl.setup(gameSettings, player, table, view, TurnMode.MAY_REDEAL); aiControl.setup(new ITurnControl.TurnInfo(table, player.getHand(), player.getLaidOut(), TurnMode.MAY_REDEAL), gameSettings, view);
aiControl.startTurn(); aiControl.startTurn();
while (!redealt) { while (!redealt) {
Thread.sleep(100); Thread.sleep(100);
@ -89,7 +89,7 @@ public class BaseAIControlTest {
*/ */
@Test(timeout = 10000) @Test(timeout = 10000)
public void testTurnZeroNotMelding() throws InterruptedException { public void testTurnZeroNotMelding() throws InterruptedException {
aiControl.setup(gameSettings, player, table, view, TurnMode.INSPECT_ONLY); aiControl.setup(new ITurnControl.TurnInfo(table, player.getHand(), player.getLaidOut(), TurnMode.INSPECT_ONLY), gameSettings, view);
aiControl.startTurn(); aiControl.startTurn();
while (!turnEnded) { while (!turnEnded) {
Thread.sleep(100); Thread.sleep(100);
@ -103,7 +103,7 @@ public class BaseAIControlTest {
*/ */
@Test(timeout = 10000) @Test(timeout = 10000)
public void testNormalTurnMelding() throws InterruptedException { public void testNormalTurnMelding() throws InterruptedException {
aiControl.setup(gameSettings, player, table, view, TurnMode.NORMAL_TURN); aiControl.setup(new ITurnControl.TurnInfo(table, player.getHand(), player.getLaidOut(), TurnMode.NORMAL_TURN), gameSettings, view);
aiControl.startTurn(); aiControl.startTurn();
while (!turnEnded) { while (!turnEnded) {
Thread.sleep(100); Thread.sleep(100);

View file

@ -110,8 +110,7 @@ public class TurnControlTest {
mockPlayer = new MockPlayer(null, null); mockPlayer = new MockPlayer(null, null);
mockPlayer.hand = mockHand; mockPlayer.hand = mockHand;
testControl = new HumanTurnControl(mockTimer); testControl = new HumanTurnControl(mockTimer);
testControl.setup(new GameSettings(), mockPlayer, mockTable, mockView, testControl.setup(new ITurnControl.TurnInfo(mockTable, mockPlayer.getHand(), mockPlayer.getLaidOut(), TurnMode.NORMAL_TURN), new GameSettings(), mockView);
TurnMode.NORMAL_TURN);
} }
/** */ /** */
@ -135,8 +134,7 @@ public class TurnControlTest {
mockHand.iterable = stones; mockHand.iterable = stones;
testControl = new HumanTurnControl(mockTimer); testControl = new HumanTurnControl(mockTimer);
testControl.setup(new GameSettings(), mockPlayer, mockTable, mockView, testControl.setup(new ITurnControl.TurnInfo(mockTable, mockPlayer.getHand(), mockPlayer.getLaidOut(), TurnMode.NORMAL_TURN), new GameSettings(), mockView);
TurnMode.NORMAL_TURN);
testControl.startTurn(); testControl.startTurn();
int i = 0; int i = 0;
@ -629,8 +627,7 @@ public class TurnControlTest {
public void testAddLeft() { public void testAddLeft() {
AccessibleTable table = new AccessibleTable(); AccessibleTable table = new AccessibleTable();
HumanTurnControl turnControl = new HumanTurnControl(mockTimer); HumanTurnControl turnControl = new HumanTurnControl(mockTimer);
turnControl.setup(new GameSettings(), mockPlayer, table, mockView, turnControl.setup(new ITurnControl.TurnInfo(table, mockPlayer.getHand(), mockPlayer.getLaidOut(), TurnMode.NORMAL_TURN), new GameSettings(), mockView);
TurnMode.NORMAL_TURN);
turnControl.startTurn(); turnControl.startTurn();
Stone blueOne = new Stone(1, BLUE); Stone blueOne = new Stone(1, BLUE);
Stone redOne = new Stone(1, RED); Stone redOne = new Stone(1, RED);
@ -747,8 +744,7 @@ public class TurnControlTest {
public void testAddRight() { public void testAddRight() {
AccessibleTable table = new AccessibleTable(); AccessibleTable table = new AccessibleTable();
HumanTurnControl turnControl = new HumanTurnControl(mockTimer); HumanTurnControl turnControl = new HumanTurnControl(mockTimer);
turnControl.setup(new GameSettings(), mockPlayer, table, mockView, turnControl.setup(new ITurnControl.TurnInfo(table, mockPlayer.getHand(), mockPlayer.getLaidOut(), TurnMode.NORMAL_TURN), new GameSettings(), mockView);
TurnMode.NORMAL_TURN);
turnControl.startTurn(); turnControl.startTurn();
Stone blueOne = new Stone(1, BLUE); Stone blueOne = new Stone(1, BLUE);
Stone redOne = new Stone(1, RED); Stone redOne = new Stone(1, RED);
@ -865,8 +861,7 @@ public class TurnControlTest {
public void testAddNewSet() { public void testAddNewSet() {
AccessibleTable table = new AccessibleTable(); AccessibleTable table = new AccessibleTable();
HumanTurnControl turnControl = new HumanTurnControl(mockTimer); HumanTurnControl turnControl = new HumanTurnControl(mockTimer);
turnControl.setup(new GameSettings(), mockPlayer, table, mockView, turnControl.setup(new ITurnControl.TurnInfo(table, mockPlayer.getHand(), mockPlayer.getLaidOut(), TurnMode.NORMAL_TURN), new GameSettings(), mockView);
TurnMode.NORMAL_TURN);
turnControl.startTurn(); turnControl.startTurn();
Stone blueOne = new Stone(1, BLUE); Stone blueOne = new Stone(1, BLUE);
Stone redOne = new Stone(1, RED); Stone redOne = new Stone(1, RED);