summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mock/jrummikub/model/MockHand.java4
-rw-r--r--mock/jrummikub/model/MockPlayer.java2
-rw-r--r--src/jrummikub/model/Hand.java6
-rw-r--r--src/jrummikub/model/IHand.java2
-rw-r--r--test/jrummikub/model/HandTest.java123
5 files changed, 131 insertions, 6 deletions
diff --git a/mock/jrummikub/model/MockHand.java b/mock/jrummikub/model/MockHand.java
index c69ae7b..c3caf42 100644
--- a/mock/jrummikub/model/MockHand.java
+++ b/mock/jrummikub/model/MockHand.java
@@ -82,4 +82,8 @@ public class MockHand implements IHand {
// TODO Auto-generated method stub
return 0;
}
+
+ public boolean isInitialMeldPossible() {
+ return false;
+ }
}
diff --git a/mock/jrummikub/model/MockPlayer.java b/mock/jrummikub/model/MockPlayer.java
index 19c7014..81b22f5 100644
--- a/mock/jrummikub/model/MockPlayer.java
+++ b/mock/jrummikub/model/MockPlayer.java
@@ -5,7 +5,7 @@ package jrummikub.model;
*/
public class MockPlayer implements IPlayer {
/** */
- public Hand hand;
+ public IHand hand;
/** */
public PlayerSettings playerSettings;
/** */
diff --git a/src/jrummikub/model/Hand.java b/src/jrummikub/model/Hand.java
index 35ea49f..724a48e 100644
--- a/src/jrummikub/model/Hand.java
+++ b/src/jrummikub/model/Hand.java
@@ -74,4 +74,10 @@ public class Hand extends StoneTray<Stone> implements IHand {
return points;
}
+
+ @Override
+ public boolean isInitialMeldPossible() {
+ // TODO Auto-generated method stub
+ throw new Error("not implemented");
+ }
}
diff --git a/src/jrummikub/model/IHand.java b/src/jrummikub/model/IHand.java
index ec49489..a58c7be 100644
--- a/src/jrummikub/model/IHand.java
+++ b/src/jrummikub/model/IHand.java
@@ -27,4 +27,6 @@ public interface IHand extends IStoneTray<Stone> {
* @return points
*/
int getStonePoints();
+
+ public abstract boolean isInitialMeldPossible();
}
diff --git a/test/jrummikub/model/HandTest.java b/test/jrummikub/model/HandTest.java
index 5be48d6..5aa662c 100644
--- a/test/jrummikub/model/HandTest.java
+++ b/test/jrummikub/model/HandTest.java
@@ -1,9 +1,14 @@
package jrummikub.model;
-import static jrummikub.model.StoneColor.*;
+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.assertTrue;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import org.junit.Before;
@@ -14,7 +19,7 @@ import org.junit.Test;
*/
public class HandTest {
- Hand hand;
+ IHand hand;
/** */
@Before
@@ -104,14 +109,14 @@ public class HandTest {
}
Stone newStone = new Stone(RED);
hand.drop(newStone, new Position(12.5f, 1));
-
+
for (int i = 0; i < 13; i++) {
assertEquals(new Position(i, 1), hand.getPosition(rowStones.get(i)));
}
assertEquals(new Position(13, 1), hand.getPosition(newStone));
assertEquals(new Position(0, 2), hand.getPosition(rowStones.get(13)));
}
-
+
/** */
@Test
public void testCountPoints() {
@@ -123,7 +128,115 @@ public class HandTest {
hand.drop(stone1, new Position(0, 0));
hand.drop(stone2, new Position(0, 0));
hand.drop(stone3, new Position(0, 0));
-
+
assertEquals(56, hand.getStonePoints());
}
+
+ private void testInitialMeld(boolean possible, List<Stone> handStones) {
+ for (Stone stone : handStones) {
+ hand.drop(stone, new Position(0, 0));
+ }
+ assertTrue(possible == hand.isInitialMeldPossible());
+ }
+
+ /** */
+ @Test
+ public void testNoValid() {
+ testInitialMeld(false, Arrays.asList(new Stone(8, RED), new Stone(9,
+ RED), new Stone(10, RED), new Stone(12, RED),
+ new Stone(13, RED)));
+ testInitialMeld(false, Arrays.asList(new Stone(10, RED), new Stone(10,
+ BLACK), new Stone(11, RED), new Stone(11, BLACK)));
+ testInitialMeld(false, Arrays.asList(new Stone(10, RED), new Stone(10,
+ RED), new Stone(10, BLACK), new Stone(11, RED), new Stone(11,
+ BLACK)));
+
+ testInitialMeld(false, Arrays.asList(new Stone(10, RED), new Stone(11,
+ BLACK), new Stone(12, RED)));
+ }
+
+ /** */
+ @Test
+ public void testNotEnoughPoints() {
+ testInitialMeld(false, Arrays.asList(new Stone(8, RED), new Stone(9,
+ RED), new Stone(10, RED)));
+ testInitialMeld(false, Arrays.asList(new Stone(1, RED), new Stone(2,
+ RED), new Stone(3, RED), new Stone(4, RED)));
+ testInitialMeld(false, Arrays.asList(new Stone(1, RED), new Stone(2,
+ RED), new Stone(3, RED), new Stone(1, BLACK), new Stone(2,
+ BLACK), new Stone(3, BLACK)));
+ }
+
+ /** */
+ @Test
+ public void testNotEnoughPointsWithJoker() {
+ testInitialMeld(false, Arrays.asList(new Stone(8, RED), new Stone(9,
+ RED), new Stone(RED), new Stone(3, BLACK)));
+ testInitialMeld(false, Arrays.asList(new Stone(4, RED), new Stone(5,
+ RED), new Stone(4, BLACK), new Stone(5, BLACK), new Stone(RED)));
+ }
+
+ /** */
+ @Test
+ public void testNotEnoughPointsWithTwoJokers() {
+ testInitialMeld(false, Arrays.asList(new Stone(1, RED), new Stone(2,
+ BLUE), new Stone(3, BLACK), new Stone(RED), new Stone(BLACK)));
+ testInitialMeld(false, Arrays.asList(new Stone(8, RED), new Stone(RED),
+ new Stone(BLACK)));
+ }
+
+ /** */
+ @Test
+ public void testValid() {
+ testInitialMeld(true, Arrays.asList(new Stone(11, RED), new Stone(12,
+ RED), new Stone(13, RED)));
+ testInitialMeld(true, Arrays.asList(new Stone(4, RED),
+ new Stone(5, RED), new Stone(6, RED), new Stone(5, ORANGE),
+ new Stone(5, BLACK), new Stone(5, BLUE)));
+ testInitialMeld(true, Arrays.asList(new Stone(10, RED), new Stone(10,
+ BLACK), new Stone(10, ORANGE)));
+ }
+
+ /** */
+ @Test
+ public void testValidWithJoker() {
+ testInitialMeld(true, Arrays.asList(new Stone(11, RED), new Stone(RED),
+ new Stone(13, RED)));
+ testInitialMeld(true, Arrays.asList(new Stone(10, RED),
+ new Stone(BLACK), new Stone(10, ORANGE)));
+ testInitialMeld(true, Arrays.asList(new Stone(4, RED),
+ new Stone(5, RED), new Stone(6, RED), new Stone(5, BLACK),
+ new Stone(5, BLUE), new Stone(RED)));
+ }
+
+ /** */
+ @Test
+ public void testValidWithTwoJokers() {
+ testInitialMeld(true, Arrays.asList(new Stone(9, RED), new Stone(RED),
+ new Stone(BLACK)));
+ }
+
+ /** */
+ @Test
+ public void testValidHuge() {
+ List<Stone> stones = new ArrayList<Stone>();
+ for (int i = 1; i <= 10; i++) {
+ stones.add(new Stone(i, RED));
+ stones.add(new Stone(i, BLACK));
+ }
+ testInitialMeld(true, stones);
+ }
+
+ /** */
+ @Test
+ public void testInvalidHuge() {
+ testInitialMeld(false, Arrays.asList(new Stone(1, RED), new Stone(2,
+ RED), new Stone(4, RED), new Stone(6, RED), new Stone(8, RED),
+ new Stone(10, RED), new Stone(13, RED), new Stone(1, BLACK),
+ new Stone(2, BLACK), new Stone(4, BLACK), new Stone(5, BLACK),
+ new Stone(8, BLACK), new Stone(9, BLACK), new Stone(12, BLACK),
+ new Stone(3, BLUE), new Stone(5, BLUE), new Stone(7, BLUE),
+ new Stone(11, BLUE), new Stone(RED)));
+ }
+
}