Ca. 150 Zeilen überflüssigen Code entfernt

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@463 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Ida Massow 2011-06-18 16:19:20 +02:00
parent bc835d499f
commit ac3c13c50b
6 changed files with 339 additions and 416 deletions

View file

@ -11,6 +11,7 @@ import jrummikub.util.MockEvent;
import jrummikub.util.MockEvent1; import jrummikub.util.MockEvent1;
import jrummikub.util.MockEvent2; import jrummikub.util.MockEvent2;
/** */
public class MockConnectionControl implements IConnectionControl { public class MockConnectionControl implements IConnectionControl {
/** */ /** */
public String nickname; public String nickname;

View file

@ -18,6 +18,10 @@ import jrummikub.view.ISettingsPanel;
import jrummikub.view.ISettingsPanel.SettingsMode; import jrummikub.view.ISettingsPanel.SettingsMode;
import jrummikub.view.IView; import jrummikub.view.IView;
/**
* Abstract class for network game controls inbetween choosing and starting a
* game
*/
public abstract class AbstractGameBeginControl { public abstract class AbstractGameBeginControl {
protected List<Connection> connections = new ArrayList<Connection>(); protected List<Connection> connections = new ArrayList<Connection>();
protected GameData gameData; protected GameData gameData;
@ -25,6 +29,18 @@ public abstract class AbstractGameBeginControl {
protected IView view; protected IView view;
protected Event backEvent = new Event(); protected Event backEvent = new Event();
/**
* Create a new game begin control
*
* @param connection
* connection control for mesages and events
* @param view
* the view
* @param gameData
* game data of chosen game
* @param settingsMode
* mode of settings panel
*/
public AbstractGameBeginControl(IConnectionControl connection, IView view, public AbstractGameBeginControl(IConnectionControl connection, IView view,
final GameData gameData, SettingsMode settingsMode) { final GameData gameData, SettingsMode settingsMode) {
this.connectionControl = connection; this.connectionControl = connection;
@ -35,8 +51,29 @@ public abstract class AbstractGameBeginControl {
view.getSettingsPanel().enableAddPlayerButton(false); view.getSettingsPanel().enableAddPlayerButton(false);
updateSettingsPanel(); updateSettingsPanel();
connections.add(view.getSettingsPanel().getBackEvent() addViewListeners(view, gameData);
.add(new IListener() {
connections.add(connectionControl.getChangeColorEvent().add(
new IListener2<String, Color>() {
@Override
public void handle(String sender, Color color) {
List<PlayerSettings> players = gameData
.getGameSettings().getPlayerList();
for (PlayerSettings s : players) {
if (s.getName().equals(sender)
&& s.getType() == Type.NETWORK) {
s.setColor(color);
break;
}
}
updateSettingsPanel();
}
}));
}
private void addViewListeners(IView view, final GameData gameData) {
connections.add(view.getSettingsPanel().getBackEvent().add(
new IListener() {
@Override @Override
public void handle() { public void handle() {
goBack(); goBack();
@ -62,26 +99,16 @@ public abstract class AbstractGameBeginControl {
updateSettingsPanel(); updateSettingsPanel();
} }
})); }));
connections.add(connectionControl.getChangeColorEvent().add(
new IListener2<String, Color>() {
@Override
public void handle(String sender, Color color) {
List<PlayerSettings> players = gameData
.getGameSettings().getPlayerList();
for (PlayerSettings s : players) {
if (s.getName().equals(sender)
&& s.getType() == Type.NETWORK) {
s.setColor(color);
break;
}
}
updateSettingsPanel();
}
}));
} }
protected abstract void goBack(); protected abstract void goBack();
/**
* The back event is emitted when the player wants to go back to the
* previous control and panel
*
* @return the event
*/
public Event getBackEvent() { public Event getBackEvent() {
return backEvent; return backEvent;
} }
@ -96,8 +123,8 @@ public abstract class AbstractGameBeginControl {
protected void updateSettingsPanel() { protected void updateSettingsPanel() {
view.getSettingsPanel().setGameSettings(gameData.getGameSettings()); view.getSettingsPanel().setGameSettings(gameData.getGameSettings());
Set<Color> colors = new HashSet<Color>( Set<Color> colors = new HashSet<Color>(Arrays
Arrays.asList(ISettingsPanel.PLAYER_COLORS)); .asList(ISettingsPanel.PLAYER_COLORS));
for (PlayerSettings player : gameData.getGameSettings().getPlayerList()) { for (PlayerSettings player : gameData.getGameSettings().getPlayerList()) {
colors.remove(player.getColor()); colors.remove(player.getColor());

View file

@ -323,20 +323,25 @@ class ConnectionControl implements IConnectionControl {
if (!currentGame.getGameID().equals(uuid)) { if (!currentGame.getGameID().equals(uuid)) {
return; return;
} }
if (messageType.equals("game_join")) { messagesDuringGame(extension, sender, messageType);
gameJoinEvent.emit(sender); }
} else if (messageType.equals("game_leave")) { }
gameLeaveEvent.emit(sender);
} else if (messageType.equals("game_join_ack")) { private void messagesDuringGame(DefaultPacketExtension extension,
gameJoinAckEvent String sender, String messageType) {
.emit(Boolean.valueOf(extension.getValue("ack"))); if (messageType.equals("game_join")) {
} else if (messageType.equals("change_color")) { gameJoinEvent.emit(sender);
changeColorEvent.emit(sender, (Color) Base64 } else if (messageType.equals("game_leave")) {
.decodeToObject(extension.getValue("color"))); gameLeaveEvent.emit(sender);
} else { } else if (messageType.equals("game_join_ack")) {
System.err.println("Received unrecognized message of type '" gameJoinAckEvent
+ messageType + "'"); .emit(Boolean.valueOf(extension.getValue("ack")));
} } else if (messageType.equals("change_color")) {
changeColorEvent.emit(sender, (Color) Base64
.decodeToObject(extension.getValue("color")));
} else {
System.err.println("Received unrecognized message of type '"
+ messageType + "'");
} }
} }

View file

@ -85,17 +85,9 @@ public class AIControl extends AbstractTurnControl {
List<Stone> tableStones = new ArrayList<Stone>(); List<Stone> tableStones = new ArrayList<Stone>();
List<Stone> handStones = new ArrayList<Stone>(); List<Stone> handStones = new ArrayList<Stone>();
for (Pair<Stone, Position> entry : turnInfo.getHand()) { addHandStones(handStones);
handStones.add(entry.getFirst());
}
if (turnInfo.getLaidOut()) { addTableStones(tableStones);
for (Pair<StoneSet, Position> entry : turnInfo.getTable()) {
for (Stone stone : entry.getFirst()) {
tableStones.add(stone);
}
}
}
logic = new TurnLogic(settings, tableStones, handStones); logic = new TurnLogic(settings, tableStones, handStones);
@ -133,6 +125,22 @@ public class AIControl extends AbstractTurnControl {
} }
private void addHandStones(List<Stone> handStones) {
for (Pair<Stone, Position> entry : turnInfo.getHand()) {
handStones.add(entry.getFirst());
}
}
private void addTableStones(List<Stone> tableStones) {
if (turnInfo.getLaidOut()) {
for (Pair<StoneSet, Position> entry : turnInfo.getTable()) {
for (Stone stone : entry.getFirst()) {
tableStones.add(stone);
}
}
}
}
private void executeTurn() { private void executeTurn() {
if (turnDone) { if (turnDone) {
return; return;
@ -143,25 +151,7 @@ public class AIControl extends AbstractTurnControl {
if (result != null) { if (result != null) {
if (turnInfo.getLaidOut()) { if (turnInfo.getLaidOut()) {
outerLoop: for (Iterator<Pair<StoneSet, Position>> it = turnInfo doNotMoveExistingSets(result);
.getTable().iterator(); it.hasNext();) {
Pair<StoneSet, Position> pair = it.next();
setSearch: for (Iterator<StoneSet> it2 = result.iterator(); it2
.hasNext();) {
StoneSet set = it2.next();
if (set.getSize() != pair.getFirst().getSize()) {
continue;
}
for (int i = 0; i < set.getSize(); i++) {
if (set.get(i) != pair.getFirst().get(i)) {
continue setSearch;
}
}
it2.remove();
continue outerLoop;
}
it.remove();
}
} }
for (StoneSet set : result) { for (StoneSet set : result) {
@ -178,6 +168,29 @@ public class AIControl extends AbstractTurnControl {
emitEndOfTurn(); emitEndOfTurn();
} }
private void doNotMoveExistingSets(List<StoneSet> result) {
outerLoop: for (Iterator<Pair<StoneSet, Position>> it = turnInfo
.getTable().iterator(); it.hasNext();) {
Pair<StoneSet, Position> pair = it.next();
setSearch: for (Iterator<StoneSet> it2 = result.iterator(); it2
.hasNext();) {
StoneSet set = it2.next();
if (set.getSize() != pair.getFirst().getSize()) {
continue;
}
for (int i = 0; i < set.getSize(); i++) {
if (set.get(i) != pair.getFirst().get(i)) {
continue setSearch;
}
}
it2.remove();
continue outerLoop;
}
it.remove();
}
}
/** /**
* Get the factory for the base AI control * Get the factory for the base AI control
* *

View file

@ -38,7 +38,7 @@ public class AIControlTest {
@Before @Before
public void setUp() { public void setUp() {
aiControl = TurnControlFactory.getFactory(Type.COMPUTER).create(); aiControl = TurnControlFactory.getFactory(Type.COMPUTER).create();
((AIControl)aiControl).useBackgroundThread = false; ((AIControl) aiControl).useBackgroundThread = false;
gameSettings = new GameSettings(); gameSettings = new GameSettings();
playerSettings = new PlayerSettings("ROBOT_01", Color.GRAY); playerSettings = new PlayerSettings("ROBOT_01", Color.GRAY);
player = new Player(playerSettings); player = new Player(playerSettings);
@ -73,6 +73,7 @@ public class AIControlTest {
/** /**
* @throws InterruptedException * @throws InterruptedException
* if timeout
*/ */
@Test(timeout = 10000) @Test(timeout = 10000)
public void testTurnZeroNoRedealing() throws InterruptedException { public void testTurnZeroNoRedealing() throws InterruptedException {
@ -86,6 +87,7 @@ public class AIControlTest {
/** /**
* @throws InterruptedException * @throws InterruptedException
* if timeout
*/ */
@Test(timeout = 10000) @Test(timeout = 10000)
public void testTurnZeroNotMelding() throws InterruptedException { public void testTurnZeroNotMelding() throws InterruptedException {
@ -101,6 +103,7 @@ public class AIControlTest {
/** /**
* @throws InterruptedException * @throws InterruptedException
* if timeout
*/ */
@Test(timeout = 10000) @Test(timeout = 10000)
public void testNormalTurnMelding() throws InterruptedException { public void testNormalTurnMelding() throws InterruptedException {

View file

@ -37,6 +37,7 @@ import org.junit.Test;
* Tests for {@link HumanTurnControl} * Tests for {@link HumanTurnControl}
*/ */
public class TurnControlTest { public class TurnControlTest {
@SuppressWarnings("serial")
static class AccessibleTable extends Table { static class AccessibleTable extends Table {
StoneSet[] getSetArray() { StoneSet[] getSetArray() {
return objects.keySet().toArray(new StoneSet[0]); return objects.keySet().toArray(new StoneSet[0]);
@ -75,6 +76,28 @@ public class TurnControlTest {
MockTable mockTable; MockTable mockTable;
MockHand mockHand; MockHand mockHand;
boolean eventFired; boolean eventFired;
Stone blueOne = new Stone(1, BLUE);
Stone redOne = new Stone(1, RED);
Stone blackOne = new Stone(1, BLACK);
Stone blueTwo = new Stone(2, BLUE);
Stone blueThree = new Stone(3, BLUE);
Stone blueFour = new Stone(4, BLUE);
Stone redTwo = new Stone(2, RED);
Stone redThree = new Stone(3, RED);
Stone redFour = new Stone(4, RED);
Stone blackTwo = new Stone(2, BLACK);
Stone blackThree = new Stone(3, BLACK);
Stone blackFour = new Stone(4, BLACK);
Stone blackFive = new Stone(5, BLACK);
Stone redJoker = new Stone(RED);
Stone blackJoker = new Stone(BLACK);
Stone orange10 = new Stone(10, StoneColor.ORANGE);
Stone blue4a = new Stone(4, StoneColor.BLUE);
Stone black5 = new Stone(5, StoneColor.BLACK);
Stone orange13 = new Stone(13, StoneColor.ORANGE);
Stone red11 = new Stone(11, StoneColor.RED);
Stone black10 = new Stone(10, StoneColor.BLACK);
Stone black13 = new Stone(13, StoneColor.BLACK);
private void checkTableDisplay(ITable table) { private void checkTableDisplay(ITable table) {
Iterator<Pair<StoneSet, Position>> stoneSetsView = mockView.tablePanel.stoneSets Iterator<Pair<StoneSet, Position>> stoneSetsView = mockView.tablePanel.stoneSets
@ -110,8 +133,8 @@ 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 ITurnControl.TurnInfo(mockTable, testControl.setup(new ITurnControl.TurnInfo(mockTable, mockPlayer
mockPlayer.getHand(), mockPlayer.getLaidOut(), TurnMode.NORMAL_TURN), .getHand(), mockPlayer.getLaidOut(), TurnMode.NORMAL_TURN),
new GameSettings(), mockView); new GameSettings(), mockView);
} }
@ -130,14 +153,14 @@ public class TurnControlTest {
mockView.bottomPanelType = BottomPanelType.START_TURN_PANEL; mockView.bottomPanelType = BottomPanelType.START_TURN_PANEL;
List<Pair<Stone, Position>> stones = Arrays.asList( List<Pair<Stone, Position>> stones = Arrays.asList(
new Pair<Stone, Position>(new Stone(RED), new Position(0, 0)), new Pair<Stone, Position>(redJoker, new Position(0, 0)),
new Pair<Stone, Position>(new Stone(BLACK), new Position(1, 0))); new Pair<Stone, Position>(blackJoker, new Position(1, 0)));
mockHand.iterable = stones; mockHand.iterable = stones;
testControl = new HumanTurnControl(mockTimer); testControl = new HumanTurnControl(mockTimer);
testControl.setup(new ITurnControl.TurnInfo(mockTable, testControl.setup(new ITurnControl.TurnInfo(mockTable, mockPlayer
mockPlayer.getHand(), mockPlayer.getLaidOut(), TurnMode.NORMAL_TURN), .getHand(), mockPlayer.getLaidOut(), TurnMode.NORMAL_TURN),
new GameSettings(), mockView); new GameSettings(), mockView);
testControl.startTurn(); testControl.startTurn();
@ -215,19 +238,15 @@ public class TurnControlTest {
public void selectStoneInHand() { public void selectStoneInHand() {
testControl.startTurn(); testControl.startTurn();
Stone firstStone = new Stone(StoneColor.RED);
// Select first stone // Select first stone
mockView.handPanel.stoneClickEvent.emit(firstStone, false); mockView.handPanel.stoneClickEvent.emit(redJoker, false);
assertCollection(Arrays.asList(firstStone)); assertCollection(Arrays.asList(redJoker));
// Select second stone // Select second stone
Stone secondStone = new Stone(StoneColor.BLACK); mockView.handPanel.stoneClickEvent.emit(blackJoker, false);
mockView.handPanel.stoneClickEvent.emit(secondStone, false);
assertCollection(Arrays.asList(secondStone));
assertCollection(Arrays.asList(blackJoker));
} }
/** */ /** */
@ -235,23 +254,20 @@ public class TurnControlTest {
public void collectStoneInHand() { public void collectStoneInHand() {
testControl.startTurn(); testControl.startTurn();
Stone firstStone = new Stone(StoneColor.RED);
// Select first stone // Select first stone
mockView.handPanel.stoneClickEvent.emit(firstStone, true); mockView.handPanel.stoneClickEvent.emit(redJoker, true);
assertCollection(Arrays.asList(firstStone)); assertCollection(Arrays.asList(redJoker));
// Select second stone // Select second stone
Stone secondStone = new Stone(StoneColor.BLACK); mockView.handPanel.stoneClickEvent.emit(blackJoker, true);
mockView.handPanel.stoneClickEvent.emit(secondStone, true);
assertCollection(Arrays.asList(firstStone, secondStone)); assertCollection(Arrays.asList(redJoker, blackJoker));
// De-select first stone // De-select first stone
mockView.handPanel.stoneClickEvent.emit(firstStone, true); mockView.handPanel.stoneClickEvent.emit(redJoker, true);
assertCollection(Arrays.asList(secondStone)); assertCollection(Arrays.asList(blackJoker));
} }
/** */ /** */
@ -259,16 +275,13 @@ public class TurnControlTest {
public void deselectStoneInCollection() { public void deselectStoneInCollection() {
testControl.startTurn(); testControl.startTurn();
Stone firstStone = new Stone(StoneColor.RED); mockView.handPanel.stoneClickEvent.emit(redJoker, true);
Stone secondStone = new Stone(StoneColor.BLACK); mockView.handPanel.stoneClickEvent.emit(blackJoker, true);
mockView.handPanel.stoneClickEvent.emit(firstStone, true); mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(redJoker,
mockView.handPanel.stoneClickEvent.emit(secondStone, true);
mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(firstStone,
false); false);
assertCollection(Arrays.asList(secondStone)); assertCollection(Arrays.asList(blackJoker));
} }
/** */ /** */
@ -276,16 +289,13 @@ public class TurnControlTest {
public void reorderCollection() { public void reorderCollection() {
testControl.startTurn(); testControl.startTurn();
Stone firstStone = new Stone(StoneColor.RED); mockView.handPanel.stoneClickEvent.emit(redJoker, true);
Stone secondStone = new Stone(StoneColor.BLACK); mockView.handPanel.stoneClickEvent.emit(blackJoker, true);
mockView.handPanel.stoneClickEvent.emit(firstStone, true); mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(
mockView.handPanel.stoneClickEvent.emit(secondStone, true); blackJoker, true);
mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(firstStone, assertCollection(Arrays.asList(redJoker, blackJoker));
true);
assertCollection(Arrays.asList(secondStone, firstStone));
} }
/** */ /** */
@ -293,16 +303,13 @@ public class TurnControlTest {
public void deselectWholeCollection() { public void deselectWholeCollection() {
testControl.startTurn(); testControl.startTurn();
Stone firstStone = new Stone(StoneColor.RED); mockView.handPanel.stoneClickEvent.emit(redJoker, true);
Stone secondStone = new Stone(StoneColor.BLACK); mockView.handPanel.stoneClickEvent.emit(blackJoker, true);
mockView.handPanel.stoneClickEvent.emit(firstStone, true); mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(redJoker,
mockView.handPanel.stoneClickEvent.emit(secondStone, true);
mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(firstStone,
true); true);
mockView.tablePanel.stoneCollectionPanel.setClickEvent.emit(firstStone, mockView.tablePanel.stoneCollectionPanel.setClickEvent.emit(redJoker,
true); true);
assertCollection(new ArrayList<Stone>()); assertCollection(new ArrayList<Stone>());
@ -313,19 +320,13 @@ public class TurnControlTest {
public void selectStoneOnTable() { public void selectStoneOnTable() {
testControl.startTurn(); testControl.startTurn();
Stone firstStone = new Stone(StoneColor.RED);
// Select first stone // Select first stone
mockView.tablePanel.stoneClickEvent.emit(firstStone, false); mockView.tablePanel.stoneClickEvent.emit(redJoker, false);
assertCollection(Arrays.asList(redJoker));
assertCollection(Arrays.asList(firstStone));
// Select second stone // Select second stone
Stone secondStone = new Stone(StoneColor.BLACK); mockView.tablePanel.stoneClickEvent.emit(blackJoker, false);
mockView.tablePanel.stoneClickEvent.emit(secondStone, false); assertCollection(Arrays.asList(blackJoker));
assertCollection(Arrays.asList(secondStone));
} }
/** */ /** */
@ -333,23 +334,17 @@ public class TurnControlTest {
public void collectStoneOnTable() { public void collectStoneOnTable() {
testControl.startTurn(); testControl.startTurn();
Stone firstStone = new Stone(StoneColor.RED);
// Select first stone // Select first stone
mockView.tablePanel.stoneClickEvent.emit(firstStone, true); mockView.tablePanel.stoneClickEvent.emit(redJoker, true);
assertCollection(Arrays.asList(redJoker));
assertCollection(Arrays.asList(firstStone));
// Select second stone // Select second stone
Stone secondStone = new Stone(StoneColor.BLACK); mockView.tablePanel.stoneClickEvent.emit(blackJoker, true);
mockView.tablePanel.stoneClickEvent.emit(secondStone, true); assertCollection(Arrays.asList(redJoker, blackJoker));
assertCollection(Arrays.asList(firstStone, secondStone));
// De-select first stone // De-select first stone
mockView.tablePanel.stoneClickEvent.emit(firstStone, true); mockView.tablePanel.stoneClickEvent.emit(redJoker, true);
assertCollection(Arrays.asList(blackJoker));
assertCollection(Arrays.asList(secondStone));
} }
/** */ /** */
@ -357,22 +352,18 @@ public class TurnControlTest {
public void selectSetOnTable() { public void selectSetOnTable() {
testControl.startTurn(); testControl.startTurn();
Stone stone1 = new Stone(StoneColor.RED); StoneSet set1 = new StoneSet(Arrays.asList(redJoker, blackJoker));
Stone stone2 = new Stone(StoneColor.BLACK); StoneSet set2 = new StoneSet(Arrays.asList(redOne, blackOne));
StoneSet set1 = new StoneSet(Arrays.asList(stone1, stone2));
Stone stone3 = new Stone(1, StoneColor.RED);
Stone stone4 = new Stone(1, StoneColor.BLACK);
StoneSet set2 = new StoneSet(Arrays.asList(stone3, stone4));
mockTable.findStoneSet.put(stone1, set1); mockTable.findStoneSet.put(redJoker, set1);
mockTable.findStoneSet.put(stone4, set2); mockTable.findStoneSet.put(blackOne, set2);
mockView.tablePanel.stoneClickEvent.emit(stone1, false); mockView.tablePanel.stoneClickEvent.emit(redJoker, false);
mockView.tablePanel.setClickEvent.emit(stone1, false); mockView.tablePanel.setClickEvent.emit(redJoker, false);
assertCollection(Arrays.asList(stone1, stone2)); assertCollection(Arrays.asList(redJoker, blackJoker));
mockView.tablePanel.stoneClickEvent.emit(stone4, false); mockView.tablePanel.stoneClickEvent.emit(blackOne, false);
mockView.tablePanel.setClickEvent.emit(stone4, false); mockView.tablePanel.setClickEvent.emit(blackOne, false);
assertCollection(Arrays.asList(stone3, stone4)); assertCollection(Arrays.asList(redOne, blackOne));
} }
/** */ /** */
@ -380,22 +371,18 @@ public class TurnControlTest {
public void collectSetOnTable() { public void collectSetOnTable() {
testControl.startTurn(); testControl.startTurn();
Stone stone1 = new Stone(StoneColor.RED); StoneSet set1 = new StoneSet(Arrays.asList(redJoker, blackJoker));
Stone stone2 = new Stone(StoneColor.BLACK); StoneSet set2 = new StoneSet(Arrays.asList(redOne, blackOne));
StoneSet set1 = new StoneSet(Arrays.asList(stone1, stone2));
Stone stone3 = new Stone(1, StoneColor.RED);
Stone stone4 = new Stone(1, StoneColor.BLACK);
StoneSet set2 = new StoneSet(Arrays.asList(stone3, stone4));
mockTable.findStoneSet.put(stone1, set1); mockTable.findStoneSet.put(redJoker, set1);
mockTable.findStoneSet.put(stone4, set2); mockTable.findStoneSet.put(blackOne, set2);
mockView.tablePanel.stoneClickEvent.emit(stone1, true); mockView.tablePanel.stoneClickEvent.emit(redJoker, true);
mockView.tablePanel.setClickEvent.emit(stone1, true); mockView.tablePanel.setClickEvent.emit(redJoker, true);
assertCollection(Arrays.asList(stone1, stone2)); assertCollection(Arrays.asList(redJoker, blackJoker));
mockView.tablePanel.stoneClickEvent.emit(stone4, true); mockView.tablePanel.stoneClickEvent.emit(blackOne, true);
mockView.tablePanel.setClickEvent.emit(stone4, true); mockView.tablePanel.setClickEvent.emit(blackOne, true);
assertCollection(Arrays.asList(stone1, stone2, stone3, stone4)); assertCollection(Arrays.asList(redJoker, blackJoker, redOne, blackOne));
} }
/** */ /** */
@ -403,20 +390,16 @@ public class TurnControlTest {
public void rangeSelectOnTableReverse() { public void rangeSelectOnTableReverse() {
testControl.startTurn(); testControl.startTurn();
Stone stone1 = new Stone(1, StoneColor.RED); StoneSet set1 = new StoneSet(Arrays.asList(redOne, redTwo, redThree,
Stone stone2 = new Stone(2, StoneColor.RED); redFour));
Stone stone3 = new Stone(3, StoneColor.RED);
Stone stone4 = new Stone(4, StoneColor.RED);
StoneSet set1 = new StoneSet(Arrays.asList(stone1, stone2, stone3, stone4));
mockTable.findStoneSet.put(stone1, set1); mockTable.findStoneSet.put(redOne, set1);
mockTable.findStoneSet.put(stone3, set1); mockTable.findStoneSet.put(redThree, set1);
mockView.tablePanel.stoneClickEvent.emit(stone3, false); mockView.tablePanel.stoneClickEvent.emit(redThree, false);
mockView.tablePanel.rangeClickEvent.emit(stone1, true); mockView.tablePanel.rangeClickEvent.emit(redOne, true);
assertCollection(Arrays.asList(stone1, stone2, stone3));
assertCollection(Arrays.asList(redOne, redTwo, redThree));
} }
/** */ /** */
@ -424,20 +407,17 @@ public class TurnControlTest {
public void rangeSelectOnTable() { public void rangeSelectOnTable() {
testControl.startTurn(); testControl.startTurn();
Stone stone1 = new Stone(1, StoneColor.RED);
Stone stone2 = new Stone(2, StoneColor.RED);
Stone stone3 = new Stone(3, StoneColor.RED);
Stone stone4 = new Stone(4, StoneColor.RED); Stone stone4 = new Stone(4, StoneColor.RED);
StoneSet set1 = new StoneSet(Arrays.asList(stone1, stone2, stone3, stone4)); StoneSet set1 = new StoneSet(Arrays.asList(redOne, redTwo, redThree,
stone4));
mockTable.findStoneSet.put(stone1, set1); mockTable.findStoneSet.put(redOne, set1);
mockTable.findStoneSet.put(stone3, set1); mockTable.findStoneSet.put(redThree, set1);
mockView.tablePanel.stoneClickEvent.emit(stone1, false); mockView.tablePanel.stoneClickEvent.emit(redOne, false);
mockView.tablePanel.rangeClickEvent.emit(stone3, true); mockView.tablePanel.rangeClickEvent.emit(redThree, true);
assertCollection(Arrays.asList(stone1, stone2, stone3));
assertCollection(Arrays.asList(redOne, redTwo, redThree));
} }
/** */ /** */
@ -445,23 +425,18 @@ public class TurnControlTest {
public void rangeCollectOnTable() { public void rangeCollectOnTable() {
testControl.startTurn(); testControl.startTurn();
Stone extraStone = new Stone(StoneColor.RED); StoneSet set1 = new StoneSet(Arrays.asList(redOne, redTwo, redThree,
redFour));
Stone stone1 = new Stone(1, StoneColor.RED); mockTable.findStoneSet.put(redOne, set1);
Stone stone2 = new Stone(2, StoneColor.RED); mockTable.findStoneSet.put(redThree, set1);
Stone stone3 = new Stone(3, StoneColor.RED);
Stone stone4 = new Stone(4, StoneColor.RED);
StoneSet set1 = new StoneSet(Arrays.asList(stone1, stone2, stone3, stone4));
mockTable.findStoneSet.put(stone1, set1); mockView.tablePanel.stoneClickEvent.emit(redJoker, false);
mockTable.findStoneSet.put(stone3, set1);
mockView.tablePanel.stoneClickEvent.emit(extraStone, false); mockView.tablePanel.stoneClickEvent.emit(redOne, true);
mockView.tablePanel.rangeClickEvent.emit(redThree, false);
mockView.tablePanel.stoneClickEvent.emit(stone1, true); assertCollection(Arrays.asList(redJoker, redOne, redTwo, redThree));
mockView.tablePanel.rangeClickEvent.emit(stone3, false);
assertCollection(Arrays.asList(extraStone, stone1, stone2, stone3));
} }
/** */ /** */
@ -469,24 +444,19 @@ public class TurnControlTest {
public void rangeFailSelect() { public void rangeFailSelect() {
testControl.startTurn(); testControl.startTurn();
Stone stone1 = new Stone(1, StoneColor.RED); StoneSet set1 = new StoneSet(Arrays.asList(redOne));
Stone stone2 = new Stone(2, StoneColor.RED); StoneSet set2 = new StoneSet(Arrays.asList(redTwo));
StoneSet set1 = new StoneSet(Arrays.asList(stone1));
StoneSet set2 = new StoneSet(Arrays.asList(stone2));
mockTable.findStoneSet.put(stone1, set1); mockTable.findStoneSet.put(redOne, set1);
mockTable.findStoneSet.put(stone2, set2); mockTable.findStoneSet.put(redTwo, set2);
// Select first stone // Select first stone
mockView.tablePanel.stoneClickEvent.emit(stone1, false); mockView.tablePanel.stoneClickEvent.emit(redOne, false);
assertCollection(Arrays.asList(redOne));
assertCollection(Arrays.asList(stone1));
// Select second stone // Select second stone
mockView.tablePanel.rangeClickEvent.emit(stone2, false); mockView.tablePanel.rangeClickEvent.emit(redTwo, false);
assertCollection(Arrays.asList(redOne, redTwo));
assertCollection(Arrays.asList(stone1, stone2));
} }
/** */ /** */
@ -494,23 +464,19 @@ public class TurnControlTest {
public void rangeFailCollect() { public void rangeFailCollect() {
testControl.startTurn(); testControl.startTurn();
Stone stone1 = new Stone(1, StoneColor.RED); StoneSet set1 = new StoneSet(Arrays.asList(redOne));
Stone stone2 = new Stone(2, StoneColor.RED); StoneSet set2 = new StoneSet(Arrays.asList(redTwo));
StoneSet set1 = new StoneSet(Arrays.asList(stone1));
StoneSet set2 = new StoneSet(Arrays.asList(stone2));
mockTable.findStoneSet.put(stone1, set1); mockTable.findStoneSet.put(redOne, set1);
mockTable.findStoneSet.put(stone2, set2); mockTable.findStoneSet.put(redTwo, set2);
// Select first stone // Select first stone
mockView.tablePanel.stoneClickEvent.emit(stone1, true); mockView.tablePanel.stoneClickEvent.emit(redOne, true);
assertCollection(Arrays.asList(redOne));
assertCollection(Arrays.asList(stone1));
// Select second stone // Select second stone
mockView.tablePanel.rangeClickEvent.emit(stone2, true); mockView.tablePanel.rangeClickEvent.emit(redTwo, true);
assertCollection(Arrays.asList(redOne, redTwo));
assertCollection(Arrays.asList(stone1, stone2));
} }
/** */ /** */
@ -518,19 +484,15 @@ public class TurnControlTest {
public void rangeSelectOnHandReverse() { public void rangeSelectOnHandReverse() {
testControl.startTurn(); testControl.startTurn();
Stone stone1 = new Stone(1, StoneColor.RED); mockHand.drop(redOne, new Position(0, 0));
Stone stone2 = new Stone(2, StoneColor.RED); mockHand.drop(redTwo, new Position(1.5f, 0));
Stone stone3 = new Stone(3, StoneColor.RED); mockHand.drop(redThree, new Position(0, 1));
Stone stone4 = new Stone(4, StoneColor.RED); mockHand.drop(redFour, new Position(1, 1));
mockHand.drop(stone1, new Position(0, 0));
mockHand.drop(stone2, new Position(1.5f, 0));
mockHand.drop(stone3, new Position(0, 1));
mockHand.drop(stone4, new Position(1, 1));
mockView.handPanel.stoneClickEvent.emit(stone3, false); mockView.handPanel.stoneClickEvent.emit(redThree, false);
mockView.handPanel.rangeClickEvent.emit(stone1, true); mockView.handPanel.rangeClickEvent.emit(redOne, true);
assertCollection(Arrays.asList(stone1, stone2, stone3)); assertCollection(Arrays.asList(redOne, redTwo, redThree));
} }
/** */ /** */
@ -538,19 +500,15 @@ public class TurnControlTest {
public void rangeSelectOnHand() { public void rangeSelectOnHand() {
testControl.startTurn(); testControl.startTurn();
Stone stone1 = new Stone(1, StoneColor.RED); mockHand.drop(redOne, new Position(0, 0));
Stone stone2 = new Stone(2, StoneColor.RED); mockHand.drop(redTwo, new Position(1.5f, 0));
Stone stone3 = new Stone(3, StoneColor.RED); mockHand.drop(redThree, new Position(0, 1));
Stone stone4 = new Stone(4, StoneColor.RED); mockHand.drop(redFour, new Position(1, 1));
mockHand.drop(stone1, new Position(0, 0));
mockHand.drop(stone2, new Position(1.5f, 0));
mockHand.drop(stone3, new Position(0, 1));
mockHand.drop(stone4, new Position(1, 1));
mockView.handPanel.stoneClickEvent.emit(stone1, false); mockView.handPanel.stoneClickEvent.emit(redOne, false);
mockView.handPanel.rangeClickEvent.emit(stone3, true); mockView.handPanel.rangeClickEvent.emit(redThree, true);
assertCollection(Arrays.asList(stone1, stone2, stone3)); assertCollection(Arrays.asList(redOne, redTwo, redThree));
} }
/** */ /** */
@ -558,22 +516,16 @@ public class TurnControlTest {
public void rangeCollectOnHand() { public void rangeCollectOnHand() {
testControl.startTurn(); testControl.startTurn();
Stone extraStone = new Stone(StoneColor.RED); mockHand.drop(redOne, new Position(0, 0));
mockHand.drop(redTwo, new Position(1.5f, 0));
mockHand.drop(redThree, new Position(0, 1));
mockHand.drop(redFour, new Position(1, 1));
Stone stone1 = new Stone(1, StoneColor.RED); mockView.handPanel.stoneClickEvent.emit(redJoker, false);
Stone stone2 = new Stone(2, StoneColor.RED);
Stone stone3 = new Stone(3, StoneColor.RED);
Stone stone4 = new Stone(4, StoneColor.RED);
mockHand.drop(stone1, new Position(0, 0));
mockHand.drop(stone2, new Position(1.5f, 0));
mockHand.drop(stone3, new Position(0, 1));
mockHand.drop(stone4, new Position(1, 1));
mockView.handPanel.stoneClickEvent.emit(extraStone, false); mockView.handPanel.stoneClickEvent.emit(redOne, true);
mockView.handPanel.rangeClickEvent.emit(redThree, false);
mockView.handPanel.stoneClickEvent.emit(stone1, true); assertCollection(Arrays.asList(redJoker, redOne, redTwo, redThree));
mockView.handPanel.rangeClickEvent.emit(stone3, false);
assertCollection(Arrays.asList(extraStone, stone1, stone2, stone3));
} }
/** */ /** */
@ -581,21 +533,18 @@ public class TurnControlTest {
public void rangeFailSelectHand() { public void rangeFailSelectHand() {
testControl.startTurn(); testControl.startTurn();
Stone stone1 = new Stone(1, StoneColor.RED); StoneSet set1 = new StoneSet(Arrays.asList(redOne));
Stone stone2 = new Stone(2, StoneColor.RED); mockTable.findStoneSet.put(redOne, set1);
StoneSet set1 = new StoneSet(Arrays.asList(stone1)); mockHand.drop(redTwo, new Position(0, 0));
mockTable.findStoneSet.put(stone1, set1);
mockHand.drop(stone2, new Position(0, 0));
// Select first stone // Select first stone
mockView.tablePanel.stoneClickEvent.emit(stone1, false); mockView.tablePanel.stoneClickEvent.emit(redOne, false);
assertCollection(Arrays.asList(stone1)); assertCollection(Arrays.asList(redOne));
// Select second stone // Select second stone
mockView.handPanel.rangeClickEvent.emit(stone2, false); mockView.handPanel.rangeClickEvent.emit(redTwo, false);
assertCollection(Arrays.asList(stone1, stone2));
assertCollection(Arrays.asList(redOne, redTwo));
} }
/** */ /** */
@ -603,20 +552,16 @@ public class TurnControlTest {
public void rangeFailCollectHand() { public void rangeFailCollectHand() {
testControl.startTurn(); testControl.startTurn();
Stone stone1 = new Stone(1, StoneColor.RED); StoneSet set1 = new StoneSet(Arrays.asList(redOne));
Stone stone2 = new Stone(2, StoneColor.RED); mockTable.findStoneSet.put(redOne, set1);
StoneSet set1 = new StoneSet(Arrays.asList(stone1)); mockHand.drop(redTwo, new Position(0, 0));
mockTable.findStoneSet.put(stone1, set1);
mockHand.drop(stone2, new Position(0, 0));
// Select first stone // Select first stone
mockView.tablePanel.stoneClickEvent.emit(stone1, false); mockView.tablePanel.stoneClickEvent.emit(redOne, false);
assertCollection(Arrays.asList(redOne));
assertCollection(Arrays.asList(stone1));
// Select second stone // Select second stone
mockView.handPanel.rangeClickEvent.emit(stone2, true); mockView.handPanel.rangeClickEvent.emit(redTwo, true);
assertCollection(Arrays.asList(redOne, redTwo));
assertCollection(Arrays.asList(stone1, stone2));
} }
private void assertCollection(List<Stone> expected) { private void assertCollection(List<Stone> expected) {
@ -631,27 +576,15 @@ 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 ITurnControl.TurnInfo(table, mockPlayer.getHand(), turnControl.setup(new ITurnControl.TurnInfo(table,
mockPlayer.getLaidOut(), TurnMode.NORMAL_TURN), new GameSettings(), mockPlayer.getHand(), mockPlayer.getLaidOut(),
mockView); TurnMode.NORMAL_TURN), new GameSettings(), mockView);
turnControl.startTurn(); turnControl.startTurn();
Stone blueOne = new Stone(1, BLUE);
Stone redOne = new Stone(1, RED); StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne,
Stone blackOne = new Stone(1, BLACK); blackOne, redTwo, redThree, redFour, blackTwo, blackThree));
Stone blueTwo = new Stone(2, BLUE); StoneSet oldSet2 = new StoneSet(Arrays.asList(blueTwo, blackFour,
Stone blueThree = new Stone(3, BLUE); blackFive));
Stone blueFour = new Stone(4, BLUE);
Stone redTwo = new Stone(2, RED);
Stone redThree = new Stone(3, RED);
Stone redFour = new Stone(4, RED);
Stone blackTwo = new Stone(2, BLACK);
Stone blackThree = new Stone(3, BLACK);
Stone blackFour = new Stone(4, BLACK);
Stone blackFive = new Stone(5, BLACK);
StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne, blackOne,
redTwo, redThree, redFour, blackTwo, blackThree));
StoneSet oldSet2 = new StoneSet(
Arrays.asList(blueTwo, blackFour, blackFive));
table.drop(oldSet1, new Position(0, 0)); table.drop(oldSet1, new Position(0, 0));
table.drop(oldSet2, new Position(0, 0)); table.drop(oldSet2, new Position(0, 0));
mockHand.drop(blueThree, new Position(0, 0)); mockHand.drop(blueThree, new Position(0, 0));
@ -750,27 +683,14 @@ 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 ITurnControl.TurnInfo(table, mockPlayer.getHand(), turnControl.setup(new ITurnControl.TurnInfo(table,
mockPlayer.getLaidOut(), TurnMode.NORMAL_TURN), new GameSettings(), mockPlayer.getHand(), mockPlayer.getLaidOut(),
mockView); TurnMode.NORMAL_TURN), new GameSettings(), mockView);
turnControl.startTurn(); turnControl.startTurn();
Stone blueOne = new Stone(1, BLUE); StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne,
Stone redOne = new Stone(1, RED); blackOne, redTwo, redThree, redFour, blackTwo, blackThree));
Stone blackOne = new Stone(1, BLACK); StoneSet oldSet2 = new StoneSet(Arrays.asList(blueTwo, blackFour,
Stone blueTwo = new Stone(2, BLUE); blackFive));
Stone blueThree = new Stone(3, BLUE);
Stone blueFour = new Stone(4, BLUE);
Stone redTwo = new Stone(2, RED);
Stone redThree = new Stone(3, RED);
Stone redFour = new Stone(4, RED);
Stone blackTwo = new Stone(2, BLACK);
Stone blackThree = new Stone(3, BLACK);
Stone blackFour = new Stone(4, BLACK);
Stone blackFive = new Stone(5, BLACK);
StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne, blackOne,
redTwo, redThree, redFour, blackTwo, blackThree));
StoneSet oldSet2 = new StoneSet(
Arrays.asList(blueTwo, blackFour, blackFive));
table.drop(oldSet1, new Position(0, 0)); table.drop(oldSet1, new Position(0, 0));
table.drop(oldSet2, new Position(0, 0)); table.drop(oldSet2, new Position(0, 0));
mockHand.drop(blueThree, new Position(0, 0)); mockHand.drop(blueThree, new Position(0, 0));
@ -869,27 +789,14 @@ 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 ITurnControl.TurnInfo(table, mockPlayer.getHand(), turnControl.setup(new ITurnControl.TurnInfo(table,
mockPlayer.getLaidOut(), TurnMode.NORMAL_TURN), new GameSettings(), mockPlayer.getHand(), mockPlayer.getLaidOut(),
mockView); TurnMode.NORMAL_TURN), new GameSettings(), mockView);
turnControl.startTurn(); turnControl.startTurn();
Stone blueOne = new Stone(1, BLUE); StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne,
Stone redOne = new Stone(1, RED); blackOne, redTwo, redThree, redFour, blackTwo, blackThree));
Stone blackOne = new Stone(1, BLACK); StoneSet oldSet2 = new StoneSet(Arrays.asList(blueTwo, blackFour,
Stone blueTwo = new Stone(2, BLUE); blackFive));
Stone blueThree = new Stone(3, BLUE);
Stone blueFour = new Stone(4, BLUE);
Stone redTwo = new Stone(2, RED);
Stone redThree = new Stone(3, RED);
Stone redFour = new Stone(4, RED);
Stone blackTwo = new Stone(2, BLACK);
Stone blackThree = new Stone(3, BLACK);
Stone blackFour = new Stone(4, BLACK);
Stone blackFive = new Stone(5, BLACK);
StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne, blackOne,
redTwo, redThree, redFour, blackTwo, blackThree));
StoneSet oldSet2 = new StoneSet(
Arrays.asList(blueTwo, blackFour, blackFive));
table.drop(oldSet1, new Position(0, 0)); table.drop(oldSet1, new Position(0, 0));
table.drop(oldSet2, new Position(0, 0)); table.drop(oldSet2, new Position(0, 0));
mockHand.drop(blueThree, new Position(0, 0)); mockHand.drop(blueThree, new Position(0, 0));
@ -962,28 +869,15 @@ public class TurnControlTest {
public void testSortByGroups() { public void testSortByGroups() {
testControl.startTurn(); testControl.startTurn();
Stone red1 = new Stone(1, StoneColor.RED); mockHand.drop(redOne, new Position(0, 0));
Stone blue2 = new Stone(2, StoneColor.BLUE); mockHand.drop(blueTwo, new Position(0, 0));
Stone red4 = new Stone(4, StoneColor.RED); mockHand.drop(redFour, new Position(0, 0));
Stone red3 = new Stone(3, StoneColor.RED); mockHand.drop(redThree, new Position(0, 0));
Stone orange10 = new Stone(10, StoneColor.ORANGE);
Stone blue1 = new Stone(1, StoneColor.BLUE);
Stone blue4 = new Stone(4, StoneColor.BLUE);
Stone blue4a = new Stone(4, StoneColor.BLUE);
Stone joker = new Stone(StoneColor.BLACK);
Stone black5 = new Stone(5, StoneColor.BLACK);
Stone orange13 = new Stone(13, StoneColor.ORANGE);
Stone red11 = new Stone(11, StoneColor.RED);
Stone black10 = new Stone(10, StoneColor.BLACK);
mockHand.drop(red1, new Position(0, 0));
mockHand.drop(blue2, new Position(0, 0));
mockHand.drop(red4, new Position(0, 0));
mockHand.drop(red3, new Position(0, 0));
mockHand.drop(orange10, new Position(0, 0)); mockHand.drop(orange10, new Position(0, 0));
mockHand.drop(blue1, new Position(0, 0)); mockHand.drop(blueOne, new Position(0, 0));
mockHand.drop(blue4, new Position(0, 0)); mockHand.drop(blueFour, new Position(0, 0));
mockHand.drop(blue4a, new Position(0, 0)); mockHand.drop(blue4a, new Position(0, 0));
mockHand.drop(joker, new Position(0, 0)); mockHand.drop(blackJoker, new Position(0, 0));
mockHand.drop(black5, new Position(0, 0)); mockHand.drop(black5, new Position(0, 0));
mockHand.drop(orange13, new Position(0, 0)); mockHand.drop(orange13, new Position(0, 0));
mockHand.drop(red11, new Position(0, 0)); mockHand.drop(red11, new Position(0, 0));
@ -993,28 +887,28 @@ public class TurnControlTest {
List<Pair<Stone, Position>> stones = new ArrayList<Pair<Stone, Position>>( List<Pair<Stone, Position>> stones = new ArrayList<Pair<Stone, Position>>(
mockHand.stones); mockHand.stones);
Collections Collections.sort(stones,
.sort(stones, new HumanTurnControl.HandStonePositionComparator()); new HumanTurnControl.HandStonePositionComparator());
assertEquals(stones.size(), 13); assertEquals(stones.size(), 13);
assertSame(stones.get(0).getFirst(), blue1); assertSame(stones.get(0).getFirst(), blueOne);
assertSame(stones.get(1).getFirst(), red1); assertSame(stones.get(1).getFirst(), redOne);
assertSame(stones.get(2).getFirst(), blue2); assertSame(stones.get(2).getFirst(), blueTwo);
assertSame(stones.get(3).getFirst(), red3); assertSame(stones.get(3).getFirst(), redThree);
assertTrue(stones.get(4).getFirst() == blue4 assertTrue(stones.get(4).getFirst() == blueFour
|| stones.get(4).getFirst() == blue4a); || stones.get(4).getFirst() == blue4a);
assertTrue(stones.get(5).getFirst() == blue4 assertTrue(stones.get(5).getFirst() == blueFour
|| stones.get(5).getFirst() == blue4a); || stones.get(5).getFirst() == blue4a);
assertSame(stones.get(6).getFirst(), red4); assertSame(stones.get(6).getFirst(), redFour);
assertSame(stones.get(7).getFirst(), black5); assertSame(stones.get(7).getFirst(), black5);
assertSame(stones.get(8).getFirst(), black10); assertSame(stones.get(8).getFirst(), black10);
assertSame(stones.get(9).getFirst(), orange10); assertSame(stones.get(9).getFirst(), orange10);
assertSame(stones.get(10).getFirst(), red11); assertSame(stones.get(10).getFirst(), red11);
assertSame(stones.get(11).getFirst(), orange13); assertSame(stones.get(11).getFirst(), orange13);
assertSame(stones.get(12).getFirst(), joker); assertSame(stones.get(12).getFirst(), blackJoker);
checkHandDisplay(mockHand); checkHandDisplay(mockHand);
} }
@ -1024,28 +918,15 @@ public class TurnControlTest {
public void testSortByRuns() { public void testSortByRuns() {
testControl.startTurn(); testControl.startTurn();
Stone red1 = new Stone(1, StoneColor.RED); mockHand.drop(redOne, new Position(0, 0));
Stone blue2 = new Stone(2, StoneColor.BLUE); mockHand.drop(blueTwo, new Position(0, 0));
Stone red4 = new Stone(4, StoneColor.RED); mockHand.drop(redFour, new Position(0, 0));
Stone red3 = new Stone(3, StoneColor.RED); mockHand.drop(redThree, new Position(0, 0));
Stone orange10 = new Stone(10, StoneColor.ORANGE);
Stone blue1 = new Stone(1, StoneColor.BLUE);
Stone blue4 = new Stone(4, StoneColor.BLUE);
Stone blue4a = new Stone(4, StoneColor.BLUE);
Stone joker = new Stone(StoneColor.BLACK);
Stone black5 = new Stone(5, StoneColor.BLACK);
Stone orange13 = new Stone(13, StoneColor.ORANGE);
Stone red11 = new Stone(11, StoneColor.RED);
Stone black10 = new Stone(10, StoneColor.BLACK);
mockHand.drop(red1, new Position(0, 0));
mockHand.drop(blue2, new Position(0, 0));
mockHand.drop(red4, new Position(0, 0));
mockHand.drop(red3, new Position(0, 0));
mockHand.drop(orange10, new Position(0, 0)); mockHand.drop(orange10, new Position(0, 0));
mockHand.drop(blue1, new Position(0, 0)); mockHand.drop(blueOne, new Position(0, 0));
mockHand.drop(blue4, new Position(0, 0)); mockHand.drop(blueFour, new Position(0, 0));
mockHand.drop(blue4a, new Position(0, 0)); mockHand.drop(blue4a, new Position(0, 0));
mockHand.drop(joker, new Position(0, 0)); mockHand.drop(blackJoker, new Position(0, 0));
mockHand.drop(black5, new Position(0, 0)); mockHand.drop(black5, new Position(0, 0));
mockHand.drop(orange13, new Position(0, 0)); mockHand.drop(orange13, new Position(0, 0));
mockHand.drop(red11, new Position(0, 0)); mockHand.drop(red11, new Position(0, 0));
@ -1055,8 +936,8 @@ public class TurnControlTest {
List<Pair<Stone, Position>> stones = new ArrayList<Pair<Stone, Position>>( List<Pair<Stone, Position>> stones = new ArrayList<Pair<Stone, Position>>(
mockHand.stones); mockHand.stones);
Collections Collections.sort(stones,
.sort(stones, new HumanTurnControl.HandStonePositionComparator()); new HumanTurnControl.HandStonePositionComparator());
assertEquals(stones.size(), 13); assertEquals(stones.size(), 13);
@ -1064,19 +945,19 @@ public class TurnControlTest {
assertSame(stones.get(1).getFirst(), black10); assertSame(stones.get(1).getFirst(), black10);
assertSame(stones.get(2).getFirst(), orange10); assertSame(stones.get(2).getFirst(), orange10);
assertSame(stones.get(3).getFirst(), orange13); assertSame(stones.get(3).getFirst(), orange13);
assertSame(stones.get(4).getFirst(), blue1); assertSame(stones.get(4).getFirst(), blueOne);
assertSame(stones.get(5).getFirst(), blue2); assertSame(stones.get(5).getFirst(), blueTwo);
assertTrue(stones.get(6).getFirst() == blue4 assertTrue(stones.get(6).getFirst() == blueFour
|| stones.get(6).getFirst() == blue4a); || stones.get(6).getFirst() == blue4a);
assertTrue(stones.get(7).getFirst() == blue4 assertTrue(stones.get(7).getFirst() == blueFour
|| stones.get(7).getFirst() == blue4a); || stones.get(7).getFirst() == blue4a);
assertSame(stones.get(8).getFirst(), red1); assertSame(stones.get(8).getFirst(), redOne);
assertSame(stones.get(9).getFirst(), red3); assertSame(stones.get(9).getFirst(), redThree);
assertSame(stones.get(10).getFirst(), red4); assertSame(stones.get(10).getFirst(), redFour);
assertSame(stones.get(11).getFirst(), red11); assertSame(stones.get(11).getFirst(), red11);
assertSame(stones.get(12).getFirst(), joker); assertSame(stones.get(12).getFirst(), blackJoker);
checkHandDisplay(mockHand); checkHandDisplay(mockHand);
} }
@ -1086,21 +967,18 @@ public class TurnControlTest {
public void testDropHandValid() { public void testDropHandValid() {
testControl.startTurn(); testControl.startTurn();
Stone firstStone = new Stone(StoneColor.RED); mockHand.drop(redJoker, new Position(0, 0));
Stone secondStone = new Stone(StoneColor.BLACK); mockHand.drop(blackJoker, new Position(1, 0));
mockHand.drop(firstStone, new Position(0, 0)); mockView.handPanel.stoneClickEvent.emit(redJoker, true);
mockHand.drop(secondStone, new Position(1, 0)); mockView.handPanel.stoneClickEvent.emit(blackJoker, true);
mockView.handPanel.stoneClickEvent.emit(firstStone, true);
mockView.handPanel.stoneClickEvent.emit(secondStone, true);
mockView.handPanel.clickEvent.emit(new Position(2, 0.25f)); mockView.handPanel.clickEvent.emit(new Position(2, 0.25f));
assertCollection(new ArrayList<Stone>()); assertCollection(new ArrayList<Stone>());
Set<Stone> expected = new HashSet<Stone>(Arrays.asList(firstStone, Set<Stone> expected = new HashSet<Stone>(Arrays.asList(redJoker,
secondStone)); blackJoker));
assertEquals(expected, mockHand.pickups); assertEquals(expected, mockHand.pickups);
Set<Stone> handStones = new HashSet<Stone>(); Set<Stone> handStones = new HashSet<Stone>();
@ -1116,23 +994,19 @@ public class TurnControlTest {
public void testDropHandInvalid() { public void testDropHandInvalid() {
testControl.startTurn(); testControl.startTurn();
Stone firstStone = new Stone(StoneColor.RED); mockHand.drop(redJoker, new Position(0, 0));
Stone secondStone = new Stone(StoneColor.BLACK); mockHand.drop(black13, new Position(1, 0));
Stone thirdStone = new Stone(13, StoneColor.BLACK);
mockHand.drop(firstStone, new Position(0, 0)); mockView.handPanel.stoneClickEvent.emit(redJoker, true);
mockHand.drop(thirdStone, new Position(1, 0)); mockView.tablePanel.stoneClickEvent.emit(blackJoker, true);
mockView.handPanel.stoneClickEvent.emit(black13, true);
mockView.handPanel.stoneClickEvent.emit(firstStone, true);
mockView.tablePanel.stoneClickEvent.emit(secondStone, true);
mockView.handPanel.stoneClickEvent.emit(thirdStone, true);
mockView.handPanel.clickEvent.emit(new Position(2, 0.25f)); mockView.handPanel.clickEvent.emit(new Position(2, 0.25f));
assertCollection(Arrays.asList(secondStone)); assertCollection(Arrays.asList(blackJoker));
Set<Stone> expected = new HashSet<Stone>(Arrays.asList(firstStone, Set<Stone> expected = new HashSet<Stone>(Arrays.asList(redJoker,
thirdStone)); black13));
assertEquals(expected, mockHand.pickups); assertEquals(expected, mockHand.pickups);
Set<Stone> handStones = new HashSet<Stone>(); Set<Stone> handStones = new HashSet<Stone>();