Implement tableDifference (and fix test...)

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@144 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Matthias Schiffer 2011-05-05 16:48:17 +02:00
parent f5075789fa
commit 7ee737f0d3
2 changed files with 19 additions and 6 deletions

View file

@ -1,5 +1,6 @@
package jrummikub.control; package jrummikub.control;
import java.util.HashSet;
import java.util.Set; import java.util.Set;
import jrummikub.model.IGameState; import jrummikub.model.IGameState;
@ -7,7 +8,9 @@ import jrummikub.model.IHand;
import jrummikub.model.ITable; import jrummikub.model.ITable;
import jrummikub.model.Position; import jrummikub.model.Position;
import jrummikub.model.Stone; import jrummikub.model.Stone;
import jrummikub.model.StoneSet;
import jrummikub.util.IListener; import jrummikub.util.IListener;
import jrummikub.util.Pair;
import jrummikub.view.IView; import jrummikub.view.IView;
public class RoundControl { public class RoundControl {
@ -52,10 +55,8 @@ public class RoundControl {
for (int i = 0; i < gameState.getPlayerCount(); i++) { for (int i = 0; i < gameState.getPlayerCount(); i++) {
IHand hand = gameState.getPlayer(i).getHand(); IHand hand = gameState.getPlayer(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(gameState.getGameHeap().drawStone(), new Position(j, 0));
0)); hand.drop(gameState.getGameHeap().drawStone(), new Position(j, 1));
hand.drop(gameState.getGameHeap().drawStone(), new Position(j,
1));
} }
} }
} }
@ -65,7 +66,20 @@ public class RoundControl {
} }
static Set<Stone> tableDifference(ITable oldTable, ITable newTable) { static Set<Stone> tableDifference(ITable oldTable, ITable newTable) {
return null; Set<Stone> ret = new HashSet<Stone>();
for (Pair<StoneSet, Position> entry : newTable) {
for (Stone stone : entry.getFirst()) {
ret.add(stone);
}
}
for (Pair<StoneSet, Position> entry : oldTable) {
for (Stone stone : entry.getFirst()) {
ret.remove(stone);
}
}
return ret;
} }
private void resetTable() { private void resetTable() {

View file

@ -227,7 +227,6 @@ public class RoundControlTest {
newTable.drop(newSet2, new Position(0, 0)); newTable.drop(newSet2, new Position(0, 0));
Set<Stone> expectedStones = new HashSet<Stone>(); Set<Stone> expectedStones = new HashSet<Stone>();
expectedStones.add(blueTwo);
expectedStones.add(blueThree); expectedStones.add(blueThree);
expectedStones.add(blueFour); expectedStones.add(blueFour);