Tests für Sets mit mehr Farben, mehr Values, ...
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@332 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
d66d73ea8f
commit
f22ff5f0f1
12 changed files with 308 additions and 186 deletions
|
@ -23,7 +23,7 @@ public class RoundState implements IRoundState {
|
|||
public RoundState(GameSettings gameSettings) {
|
||||
this.gameSettings = gameSettings;
|
||||
|
||||
table = new Table();
|
||||
table = new Table(gameSettings);
|
||||
players = new ArrayList<Player>();
|
||||
|
||||
for (PlayerSettings playerSettings : gameSettings.getPlayerList()) {
|
||||
|
|
|
@ -9,5 +9,13 @@ public enum StoneColor {
|
|||
/** */
|
||||
BLUE,
|
||||
/** */
|
||||
RED
|
||||
RED,
|
||||
/** */
|
||||
GREEN,
|
||||
/** */
|
||||
VIOLET,
|
||||
/** */
|
||||
BROWN,
|
||||
/** */
|
||||
WHITE
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package jrummikub.model;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
|
@ -24,21 +23,25 @@ public class StoneHeap {
|
|||
* */
|
||||
public StoneHeap(GameSettings gameSettings) {
|
||||
heap = new ArrayList<Stone>();
|
||||
for (int i = 1; i <= 13; i++) {
|
||||
for (int i = 1; i <= gameSettings.getHighestCard(); i++) {
|
||||
for (int j = 0; j < gameSettings.getStoneSetNumber(); j++) {
|
||||
for (StoneColor c : EnumSet.allOf(StoneColor.class)) {
|
||||
for (StoneColor c : gameSettings.getStoneColors()) {
|
||||
heap.add(new Stone(i, c));
|
||||
}
|
||||
}
|
||||
}
|
||||
// Joker
|
||||
|
||||
ArrayList<StoneColor> jokerColors = new ArrayList<StoneColor>(Arrays.asList(StoneColor.values()));
|
||||
|
||||
StoneColor temp = jokerColors.get(1);
|
||||
jokerColors.set(1, jokerColors.get(3));
|
||||
jokerColors.set(3, temp);
|
||||
|
||||
|
||||
ArrayList<StoneColor> jokerColors = new ArrayList<StoneColor>(
|
||||
Arrays.asList(StoneColor.values()));
|
||||
jokerColors.retainAll(gameSettings.getStoneColors());
|
||||
|
||||
if (jokerColors.size() >= 4) {
|
||||
StoneColor temp = jokerColors.get(1);
|
||||
jokerColors.set(1, jokerColors.get(3));
|
||||
jokerColors.set(3, temp);
|
||||
}
|
||||
|
||||
int jokersLeft = gameSettings.getJokerNumber();
|
||||
done: while (true) {
|
||||
for (StoneColor c : jokerColors) {
|
||||
|
|
|
@ -51,8 +51,8 @@ public class StoneSet implements Iterable<Stone>, Sizeable {
|
|||
*
|
||||
* @return true when the set is valid according to the rules
|
||||
*/
|
||||
public boolean isValid() {
|
||||
return classify().getFirst() != INVALID;
|
||||
public boolean isValid(GameSettings settings) {
|
||||
return classify(settings).getFirst() != INVALID;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -62,7 +62,7 @@ public class StoneSet implements Iterable<Stone>, Sizeable {
|
|||
* @return GROUP or RUN for valid sets, INVALID otherwise
|
||||
*/
|
||||
|
||||
public Pair<Type, Integer> classify() {
|
||||
public Pair<Type, Integer> classify(GameSettings settings) {
|
||||
if (stones.size() < 3) {
|
||||
return new Pair<Type, Integer>(INVALID, 0);
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import jrummikub.util.Pair;
|
|||
/** Class administering the {@link Stone}s on the game-Table */
|
||||
|
||||
public class Table extends StoneTray<StoneSet> implements ITable {
|
||||
private GameSettings gameSettings;
|
||||
|
||||
private static class StoneInfo {
|
||||
StoneSet set;
|
||||
|
@ -18,11 +19,15 @@ public class Table extends StoneTray<StoneSet> implements ITable {
|
|||
}
|
||||
}
|
||||
|
||||
public Table(GameSettings settings) {
|
||||
gameSettings = settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes {@link Stone} from the Table
|
||||
*
|
||||
* @param stone
|
||||
* stone to pick up
|
||||
* stone to pick up
|
||||
*/
|
||||
@Override
|
||||
public void pickUpStone(Stone stone) {
|
||||
|
@ -69,21 +74,21 @@ public class Table extends StoneTray<StoneSet> implements ITable {
|
|||
return info.set;
|
||||
}
|
||||
|
||||
private void splitSet(StoneSet set, Position setPosition,
|
||||
int stonePosition) {
|
||||
private void splitSet(StoneSet set, Position setPosition, int stonePosition) {
|
||||
pickUp(set);
|
||||
|
||||
Pair<StoneSet, StoneSet> firstSplit = set.splitAt(stonePosition);
|
||||
Pair<StoneSet, StoneSet> secondSplit = firstSplit.getSecond().splitAt(1);
|
||||
Pair<StoneSet, StoneSet> secondSplit = firstSplit.getSecond()
|
||||
.splitAt(1);
|
||||
|
||||
StoneSet leftSet = firstSplit.getFirst();
|
||||
StoneSet rightSet = secondSplit.getSecond();
|
||||
|
||||
if (set.classify().getFirst() == StoneSet.Type.RUN) {
|
||||
if (set.classify(gameSettings).getFirst() == StoneSet.Type.RUN) {
|
||||
Position leftPosition, rightPosition;
|
||||
leftPosition = setPosition;
|
||||
rightPosition = new Position(setPosition.getX() + stonePosition + 1,
|
||||
setPosition.getY());
|
||||
rightPosition = new Position(
|
||||
setPosition.getX() + stonePosition + 1, setPosition.getY());
|
||||
|
||||
drop(leftSet, leftPosition);
|
||||
drop(rightSet, rightPosition);
|
||||
|
@ -105,7 +110,7 @@ public class Table extends StoneTray<StoneSet> implements ITable {
|
|||
@Override
|
||||
public boolean isValid() {
|
||||
for (Pair<StoneSet, Position> i : this) {
|
||||
if (!i.getFirst().isValid()) {
|
||||
if (!i.getFirst().isValid(gameSettings)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue