Tested and implemented scoring

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@272 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Jannis Harder 2011-05-25 15:51:34 +02:00
parent e3b5a0790d
commit 157bd4f606
8 changed files with 283 additions and 29 deletions

View file

@ -29,10 +29,11 @@ import jrummikub.model.MockTable;
import jrummikub.model.PlayerSettings;
import jrummikub.model.Position;
import jrummikub.model.RoundState;
import jrummikub.model.Score;
import jrummikub.model.Stone;
import jrummikub.model.StoneSet;
import jrummikub.model.Table;
import jrummikub.util.IListener;
import jrummikub.util.IListener1;
import jrummikub.util.Pair;
import jrummikub.view.MockView;
@ -47,12 +48,13 @@ public class RoundControlTest {
private MockRoundState testRoundState;
private RoundControl testRound;
private MockTable testTable;
private GameSettings gameSettings;
private IRoundState roundState;
private RoundControl roundControl;
private boolean roundEnded;
private Score roundScore;
/**
* For each test create a round control initialized by a mock model and view
@ -68,7 +70,7 @@ public class RoundControlTest {
testTable.sets.add(testRoundState.table.sets.get(0));
testRoundState.table.clonedTable = testTable;
roundEnded = false;
gameSettings = new GameSettings();
gameSettings.getPlayerList().add(new PlayerSettings("Ida", Color.RED));
@ -154,14 +156,13 @@ public class RoundControlTest {
assertEquals(0, roundState.getTable().getSize());
assertEquals(14 + 6, hand.getSize());
}
/** */
@Test
public void laidOutValidUnchanged() {
roundControl.startRound();
view.startTurnEvent.emit();
IHand hand = roundState.getActivePlayer().getHand();
assertFalse(roundState.getActivePlayer().getLaidOut());
@ -589,13 +590,13 @@ public class RoundControlTest {
@Test
public void testWinning() {
testRound.getEndOfRoundEvent().add(new IListener() {
testRound.getEndOfRoundEvent().add(new IListener1<Score>() {
@Override
public void handle() {
public void handle(Score roundScore) {
roundEnded = true;
}
});
testRound.startRound();
MockTable oldTable = testRoundState.table;
testTable.valid = true;
@ -622,7 +623,9 @@ public class RoundControlTest {
view.tablePanel.clickEvent.emit(new Position(0, 0));
testRoundState.players.get(0).hand = new Hand(gameSettings);
for (int i = 0; i < 4; i++) {
testRoundState.players.get(i).hand = new Hand(gameSettings);
}
resetTurnStart();
assertFalse(roundEnded);
@ -714,32 +717,126 @@ public class RoundControlTest {
assertTrue(vanishedSets.isEmpty());
assertEquals(1, newSets.size());
}
/** */
@Test
public void heapIsEmpty() {
roundControl.getEndOfRoundEvent().add(new IListener() {
roundControl.getEndOfRoundEvent().add(new IListener1<Score>() {
@Override
public void handle() {
public void handle(Score roundScore) {
roundEnded = true;
}
});
roundState.getGameHeap().drawStones(106 - 14 * 4 - 1);
roundControl.startRound();
IPlayer player1 = roundState.getActivePlayer();
view.startTurnEvent.emit();
view.playerPanel.endTurnEvent.emit(); // player 1 draws a card here
assertSame(player1, roundState.getActivePlayer());
for (int i = 0; i < 4; i++) {
view.startTurnEvent.emit();
view.playerPanel.endTurnEvent.emit();
}
assertTrue(roundEnded);
}
/** */
@Test
public void testScore() {
testRound.getEndOfRoundEvent().add(new IListener1<Score>() {
@Override
public void handle(Score score) {
roundEnded = true;
roundScore = score;
}
});
testRound.startRound();
for (int i = 0; i < 4; i++) {
testRoundState.players.get(i).hand = new Hand(gameSettings);
}
testRoundState.players.get(0).laidOut = true;
testRoundState.players.get(0).hand.drop(new Stone(1, RED),
new Position(0, 0));
testRoundState.players.get(0).hand.drop(new Stone(2, RED),
new Position(0, 0));
testRoundState.players.get(1).laidOut = true;
testRoundState.players.get(1).hand.drop(new Stone(RED), new Position(0,
0));
testRoundState.players.get(2).laidOut = false;
testRoundState.players.get(2).hand.drop(new Stone(9, RED),
new Position(0, 0));
testRoundState.players.get(2).hand.drop(new Stone(10, RED),
new Position(0, 0));
testRoundState.players.get(2).hand.drop(new Stone(11, RED),
new Position(0, 0));
testRoundState.players.get(3).laidOut = true;
testRound.endOfRound();
assertTrue(roundEnded);
for (int i = 0; i < 4; i++) {
assertTrue(roundScore.getWinners().get(i) == (i == 3));
}
assertEquals(-3, (int) roundScore.getPoints().get(0));
assertEquals(-50, (int) roundScore.getPoints().get(1));
assertEquals(-200, (int) roundScore.getPoints().get(2));
assertEquals(253, (int) roundScore.getPoints().get(3));
}
/** */
@Test
public void testScoreWhenHeapEmpty() {
testRound.getEndOfRoundEvent().add(new IListener1<Score>() {
@Override
public void handle(Score score) {
roundEnded = true;
roundScore = score;
}
});
testRound.startRound();
for (int i = 0; i < 4; i++) {
testRoundState.players.get(i).hand = new Hand(gameSettings);
}
testRoundState.players.get(0).laidOut = true;
testRoundState.players.get(0).hand.drop(new Stone(1, RED),
new Position(0, 0));
testRoundState.players.get(0).hand.drop(new Stone(2, RED),
new Position(0, 0));
testRoundState.players.get(1).laidOut = true;
testRoundState.players.get(1).hand.drop(new Stone(3, RED),
new Position(0, 0));
testRoundState.players.get(2).laidOut = true;
testRoundState.players.get(2).hand.drop(new Stone(3, BLUE),
new Position(0, 0));
testRoundState.players.get(3).laidOut = false;
testRoundState.players.get(3).hand.drop(new Stone(13, RED),
new Position(0, 0));
testRound.endOfRound();
assertTrue(roundEnded);
assertFalse(roundScore.getWinners().get(0));
assertTrue(roundScore.getWinners().get(1));
assertTrue(roundScore.getWinners().get(2));
assertFalse(roundScore.getWinners().get(3));
assertEquals(-3, (int) roundScore.getPoints().get(0));
assertEquals(-3, (int) roundScore.getPoints().get(1));
assertEquals(-3, (int) roundScore.getPoints().get(2));
assertEquals(-100, (int) roundScore.getPoints().get(3));
}
}