summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIda Massow <massow@informatik.uni-luebeck.de>2011-05-16 22:24:11 +0200
committerIda Massow <massow@informatik.uni-luebeck.de>2011-05-16 22:24:11 +0200
commit46cf40c44ff87e51e4ad6165b4371d61df3f21eb (patch)
tree84927d20c572b7bf6b3d5158402d86c67fa9ee1e
parenta4f5beb00598f577598a0e39e4e1099d9ea6e1e6 (diff)
downloadJRummikub-46cf40c44ff87e51e4ad6165b4371d61df3f21eb.tar
JRummikub-46cf40c44ff87e51e4ad6165b4371d61df3f21eb.zip
Test und implementierung von tableSetDifference, getestet und alles :-)
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@246 72836036-5685-4462-b002-a69064685172
-rw-r--r--src/jrummikub/control/RoundControl.java24
-rw-r--r--test/jrummikub/control/RoundControlTest.java55
2 files changed, 74 insertions, 5 deletions
diff --git a/src/jrummikub/control/RoundControl.java b/src/jrummikub/control/RoundControl.java
index dad2e30..c46d402 100644
--- a/src/jrummikub/control/RoundControl.java
+++ b/src/jrummikub/control/RoundControl.java
@@ -33,9 +33,9 @@ public class RoundControl {
* Create a new RoundControl using the given gameState and view
*
* @param gameState
- * initial game state
+ * initial game state
* @param view
- * view used for user interaction
+ * view used for user interaction
*/
public RoundControl(IGameState gameState, IView view) {
this.gameState = gameState;
@@ -99,14 +99,17 @@ public class RoundControl {
for (int i = 0; i < gameState.getPlayerCount(); i++) {
IHand hand = gameState.getNthNextPlayer(i).getHand();
for (int j = 0; j < 7; j++) {
- hand.drop(gameState.getGameHeap().drawStone(), new Position(j, 0));
- hand.drop(gameState.getGameHeap().drawStone(), new Position(j, 1));
+ hand.drop(gameState.getGameHeap().drawStone(), new Position(j,
+ 0));
+ hand.drop(gameState.getGameHeap().drawStone(), new Position(j,
+ 1));
}
}
}
private void endOfTurn() {
- Set<Stone> tableDiff = tableDifference(gameState.getTable(), clonedTable);
+ Set<Stone> tableDiff = tableDifference(gameState.getTable(),
+ clonedTable);
if (!tableDiff.isEmpty()) { // Player has made a move
if (clonedTable.isValid()) {
@@ -145,7 +148,18 @@ public class RoundControl {
ret.remove(stone);
}
}
+ return ret;
+ }
+ static List<StoneSet> tableSetDifference(ITable oldTable, ITable newTable) {
+ List<StoneSet> ret = new ArrayList<StoneSet>();
+
+ for (Pair<StoneSet, Position> entry : newTable) {
+ ret.add(entry.getFirst());
+ }
+ for (Pair<StoneSet, Position> entry : oldTable) {
+ ret.remove(entry.getFirst());
+ }
return ret;
}
diff --git a/test/jrummikub/control/RoundControlTest.java b/test/jrummikub/control/RoundControlTest.java
index dba3ae9..1be11e4 100644
--- a/test/jrummikub/control/RoundControlTest.java
+++ b/test/jrummikub/control/RoundControlTest.java
@@ -2,6 +2,7 @@ package jrummikub.control;
import static jrummikub.model.StoneColor.BLACK;
import static jrummikub.model.StoneColor.BLUE;
+import static jrummikub.model.StoneColor.ORANGE;
import static jrummikub.model.StoneColor.RED;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -13,15 +14,18 @@ import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.List;
import java.util.Set;
import jrummikub.model.Hand;
import jrummikub.model.IHand;
+import jrummikub.model.ITable;
import jrummikub.model.MockGameState;
import jrummikub.model.MockTable;
import jrummikub.model.Position;
import jrummikub.model.Stone;
import jrummikub.model.StoneSet;
+import jrummikub.model.Table;
import jrummikub.util.Pair;
import jrummikub.view.MockView;
@@ -276,4 +280,55 @@ public class RoundControlTest {
assertTrue(expectedStones.containsAll(stones));
assertTrue(stones.containsAll(expectedStones));
}
+
+ @Test
+ public void testTableSetDifference() {
+ ITable oldTable = new Table();
+ Stone blueOne = new Stone(1, BLUE);
+ Stone redOne = new Stone(1, RED);
+ Stone blackOne = new Stone(1, BLACK);
+ Stone orangeOne = new Stone(1, ORANGE);
+ Stone blueTwo = new Stone(2, BLUE);
+ Stone blueThree = new Stone(3, BLUE);
+ Stone blueFour = new Stone(4, BLUE);
+ StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne,
+ blackOne, orangeOne));
+ StoneSet oldSet2 = new StoneSet(Arrays.asList(blueTwo, blueThree,
+ blueFour));
+ oldTable.drop(oldSet1, new Position(0, 0));
+ oldTable.drop(oldSet2, new Position(0, 0));
+ ITable newTable = (Table) oldTable.clone();
+ List<StoneSet> newSets = RoundControl.tableSetDifference(oldTable,
+ newTable);
+ List<StoneSet> vanishedSets = RoundControl.tableSetDifference(newTable,
+ oldTable);
+
+ assertTrue(newSets.isEmpty());
+ assertTrue(vanishedSets.isEmpty());
+
+ newTable.pickUp(oldSet2);
+ newTable.drop(oldSet2.join(new StoneSet(new Stone(5, BLUE))),
+ new Position(0, 0));
+ newSets = RoundControl.tableSetDifference(oldTable, newTable);
+ vanishedSets = RoundControl.tableSetDifference(newTable, oldTable);
+
+ assertFalse(newSets.isEmpty());
+ assertFalse(vanishedSets.isEmpty());
+ assertEquals(1, newSets.size());
+ assertEquals(1, vanishedSets.size());
+
+ Stone redTwo = new Stone(2, RED);
+ Stone redThree = new Stone(3, RED);
+ Stone redFour = new Stone(4, RED);
+ StoneSet oldSet3 = new StoneSet(
+ Arrays.asList(redTwo, redThree, redFour));
+ ITable newTable2 = (Table) oldTable.clone();
+ newTable2.drop(oldSet3, new Position(0, 0));
+ newSets = RoundControl.tableSetDifference(oldTable, newTable2);
+ vanishedSets = RoundControl.tableSetDifference(newTable2, oldTable);
+
+ assertFalse(newSets.isEmpty());
+ assertTrue(vanishedSets.isEmpty());
+ assertEquals(1, newSets.size());
+ }
}