Added Javadoc comments to private methods in the model
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@522 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
0b1151e6af
commit
b0a89642b7
8 changed files with 175 additions and 80 deletions
|
@ -50,8 +50,8 @@ public class GameSettings implements Serializable {
|
||||||
totalTime = 60;
|
totalTime = 60;
|
||||||
noLimits = false;
|
noLimits = false;
|
||||||
seeHandSize = false;
|
seeHandSize = false;
|
||||||
stoneColors = new HashSet<StoneColor>(Arrays.asList(BLACK, BLUE,
|
stoneColors = new HashSet<StoneColor>(Arrays.asList(BLACK, BLUE, ORANGE,
|
||||||
ORANGE, RED));
|
RED));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -67,7 +67,7 @@ public class GameSettings implements Serializable {
|
||||||
* Sets the initial meld threshold
|
* Sets the initial meld threshold
|
||||||
*
|
*
|
||||||
* @param value
|
* @param value
|
||||||
* the value to set
|
* the value to set
|
||||||
*/
|
*/
|
||||||
public void setInitialMeldThreshold(int value) {
|
public void setInitialMeldThreshold(int value) {
|
||||||
initialMeldThreshold = value;
|
initialMeldThreshold = value;
|
||||||
|
@ -86,7 +86,7 @@ public class GameSettings implements Serializable {
|
||||||
* Sets the points counted for a joker
|
* Sets the points counted for a joker
|
||||||
*
|
*
|
||||||
* @param value
|
* @param value
|
||||||
* the value to set
|
* the value to set
|
||||||
*/
|
*/
|
||||||
public void setJokerPoints(int value) {
|
public void setJokerPoints(int value) {
|
||||||
jokerPoints = value;
|
jokerPoints = value;
|
||||||
|
@ -105,7 +105,7 @@ public class GameSettings implements Serializable {
|
||||||
* Sets the number of jokers in game
|
* Sets the number of jokers in game
|
||||||
*
|
*
|
||||||
* @param value
|
* @param value
|
||||||
* how many jokers will be used
|
* how many jokers will be used
|
||||||
*/
|
*/
|
||||||
public void setJokerNumber(int value) {
|
public void setJokerNumber(int value) {
|
||||||
jokerNumber = value;
|
jokerNumber = value;
|
||||||
|
@ -133,7 +133,7 @@ public class GameSettings implements Serializable {
|
||||||
* Set the highest stone value in use
|
* Set the highest stone value in use
|
||||||
*
|
*
|
||||||
* @param highestValue
|
* @param highestValue
|
||||||
* highest stone value
|
* highest stone value
|
||||||
*/
|
*/
|
||||||
public void setHighestValue(int highestValue) {
|
public void setHighestValue(int highestValue) {
|
||||||
this.highestValue = highestValue;
|
this.highestValue = highestValue;
|
||||||
|
@ -152,7 +152,7 @@ public class GameSettings implements Serializable {
|
||||||
* Set the number of sets of stones in use
|
* Set the number of sets of stones in use
|
||||||
*
|
*
|
||||||
* @param stoneSets
|
* @param stoneSets
|
||||||
* sets of stones in use
|
* sets of stones in use
|
||||||
*/
|
*/
|
||||||
public void setStoneSetNumber(int stoneSets) {
|
public void setStoneSetNumber(int stoneSets) {
|
||||||
this.stoneSetNumber = stoneSets;
|
this.stoneSetNumber = stoneSets;
|
||||||
|
@ -171,7 +171,7 @@ public class GameSettings implements Serializable {
|
||||||
* Setter for the time for a turn
|
* Setter for the time for a turn
|
||||||
*
|
*
|
||||||
* @param totalTime
|
* @param totalTime
|
||||||
* for a turn
|
* for a turn
|
||||||
*/
|
*/
|
||||||
public void setTotalTime(int totalTime) {
|
public void setTotalTime(int totalTime) {
|
||||||
this.totalTime = totalTime;
|
this.totalTime = totalTime;
|
||||||
|
@ -186,24 +186,35 @@ public class GameSettings implements Serializable {
|
||||||
return noLimits;
|
return noLimits;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean doSeeHandSize() {
|
/**
|
||||||
|
* Returns the visibility of the hand size
|
||||||
|
*
|
||||||
|
* @return whether the hand size is visible
|
||||||
|
*/
|
||||||
|
public boolean getSeeHandSize() {
|
||||||
return seeHandSize;
|
return seeHandSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set whether the hand size is visible
|
||||||
|
*
|
||||||
|
* @param see
|
||||||
|
* whether the hand size is visible
|
||||||
|
*/
|
||||||
|
public void setSeeHandSize(boolean see) {
|
||||||
|
seeHandSize = see;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set whether "No-Limits" rules are used
|
* Set whether "No-Limits" rules are used
|
||||||
*
|
*
|
||||||
* @param noLimits
|
* @param noLimits
|
||||||
* use no limit rules
|
* use no limit rules
|
||||||
*/
|
*/
|
||||||
public void setNoLimits(boolean noLimits) {
|
public void setNoLimits(boolean noLimits) {
|
||||||
this.noLimits = noLimits;
|
this.noLimits = noLimits;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSeeHandSize(boolean see) {
|
|
||||||
seeHandSize = see;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get stone colors used
|
* Get stone colors used
|
||||||
*
|
*
|
||||||
|
@ -217,7 +228,7 @@ public class GameSettings implements Serializable {
|
||||||
* Set stone colors used
|
* Set stone colors used
|
||||||
*
|
*
|
||||||
* @param stoneColors
|
* @param stoneColors
|
||||||
* used stone colors
|
* used stone colors
|
||||||
*/
|
*/
|
||||||
public void setStoneColors(Set<StoneColor> stoneColors) {
|
public void setStoneColors(Set<StoneColor> stoneColors) {
|
||||||
this.stoneColors = new HashSet<StoneColor>(stoneColors);
|
this.stoneColors = new HashSet<StoneColor>(stoneColors);
|
||||||
|
@ -236,7 +247,7 @@ public class GameSettings implements Serializable {
|
||||||
* Set number of stones dealt at game start
|
* Set number of stones dealt at game start
|
||||||
*
|
*
|
||||||
* @param number
|
* @param number
|
||||||
* how many Stones will be dealt initially
|
* how many Stones will be dealt initially
|
||||||
*/
|
*/
|
||||||
public void setNumberOfStonesDealt(int number) {
|
public void setNumberOfStonesDealt(int number) {
|
||||||
numberOfStonesDealt = number;
|
numberOfStonesDealt = number;
|
||||||
|
@ -264,7 +275,7 @@ public class GameSettings implements Serializable {
|
||||||
* @return total number of stones
|
* @return total number of stones
|
||||||
*/
|
*/
|
||||||
public int getTotalStones() {
|
public int getTotalStones() {
|
||||||
return getHighestValue() * getStoneSetNumber()
|
return getHighestValue() * getStoneSetNumber() * getStoneColors().size()
|
||||||
* getStoneColors().size() + getJokerNumber();
|
+ getJokerNumber();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,13 @@ public class GameState implements Serializable {
|
||||||
return scores;
|
return scores;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether players have won
|
||||||
|
*
|
||||||
|
* @param points the player's points
|
||||||
|
* @param wins the number of wins per player
|
||||||
|
* @return whether a player has won
|
||||||
|
*/
|
||||||
private Boolean[] getWinners(Integer[] points, int[] wins) {
|
private Boolean[] getWinners(Integer[] points, int[] wins) {
|
||||||
int playerCount = scores.get(0).getPoints().size();
|
int playerCount = scores.get(0).getPoints().size();
|
||||||
int maxWins = 0, maxPoints = 0;
|
int maxWins = 0, maxPoints = 0;
|
||||||
|
|
|
@ -47,8 +47,8 @@ public class Hand extends StoneTray<Stone> implements IHand {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Pair<Position, Direction> fixInvalidDrop(Stone stone,
|
protected Pair<Position, Direction> fixInvalidDrop(Stone stone, Position pos,
|
||||||
Position pos, Direction dir) {
|
Direction dir) {
|
||||||
double x = pos.getX();
|
double x = pos.getX();
|
||||||
double y = pos.getY();
|
double y = pos.getY();
|
||||||
|
|
||||||
|
@ -59,11 +59,9 @@ public class Hand extends StoneTray<Stone> implements IHand {
|
||||||
return new Pair<Position, Direction>(new Position(0, y), RIGHT);
|
return new Pair<Position, Direction>(new Position(0, y), RIGHT);
|
||||||
} else {
|
} else {
|
||||||
if (getFreeRowSpace((int) y) == 0) {
|
if (getFreeRowSpace((int) y) == 0) {
|
||||||
return new Pair<Position, Direction>(new Position(0, y + 1),
|
return new Pair<Position, Direction>(new Position(0, y + 1), RIGHT);
|
||||||
RIGHT);
|
|
||||||
} else {
|
} else {
|
||||||
return new Pair<Position, Direction>(
|
return new Pair<Position, Direction>(new Position(WIDTH - 1, y), LEFT);
|
||||||
new Position(WIDTH - 1, y), LEFT);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,8 +94,14 @@ public class Hand extends StoneTray<Stone> implements IHand {
|
||||||
turnLogic.needIntialMeldThreshold();
|
turnLogic.needIntialMeldThreshold();
|
||||||
return turnLogic.solve();
|
return turnLogic.solve();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Increments the count of a stone in the list of all stones
|
||||||
|
*
|
||||||
|
* @param stones
|
||||||
|
* all stones and their respective numbers
|
||||||
|
* @param stone
|
||||||
|
*/
|
||||||
private static void incrementStoneCount(
|
private static void incrementStoneCount(
|
||||||
TreeMap<Pair<Integer, StoneColor>, Integer> stones,
|
TreeMap<Pair<Integer, StoneColor>, Integer> stones,
|
||||||
Pair<Integer, StoneColor> stone) {
|
Pair<Integer, StoneColor> stone) {
|
||||||
|
@ -108,6 +112,9 @@ public class Hand extends StoneTray<Stone> implements IHand {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The measure to compare the stones by
|
||||||
|
*/
|
||||||
private final static Comparator<Pair<Integer, StoneColor>> comparator = new Comparator<Pair<Integer, StoneColor>>() {
|
private final static Comparator<Pair<Integer, StoneColor>> comparator = new Comparator<Pair<Integer, StoneColor>>() {
|
||||||
@Override
|
@Override
|
||||||
public int compare(Pair<Integer, StoneColor> o1,
|
public int compare(Pair<Integer, StoneColor> o1,
|
||||||
|
@ -120,7 +127,7 @@ public class Hand extends StoneTray<Stone> implements IHand {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Counts the numbers of stones
|
* Counts the numbers of stones
|
||||||
*
|
*
|
||||||
|
@ -152,8 +159,7 @@ public class Hand extends StoneTray<Stone> implements IHand {
|
||||||
public int getIdenticalStoneCount() {
|
public int getIdenticalStoneCount() {
|
||||||
List<Stone> stones = new ArrayList<Stone>();
|
List<Stone> stones = new ArrayList<Stone>();
|
||||||
|
|
||||||
for (Iterator<Pair<Stone, Position>> iter = this.iterator(); iter
|
for (Iterator<Pair<Stone, Position>> iter = this.iterator(); iter.hasNext();) {
|
||||||
.hasNext();) {
|
|
||||||
stones.add(iter.next().getFirst());
|
stones.add(iter.next().getFirst());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -96,6 +96,11 @@ public interface IRoundState extends Serializable {
|
||||||
*/
|
*/
|
||||||
public void setActivePlayerNumber(int i);
|
public void setActivePlayerNumber(int i);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the game state
|
||||||
|
*
|
||||||
|
* @return the game state
|
||||||
|
*/
|
||||||
public GameState getGameState();
|
public GameState getGameState();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -21,6 +21,8 @@ public class RoundState implements IRoundState {
|
||||||
*
|
*
|
||||||
* @param gameSettings
|
* @param gameSettings
|
||||||
* the game settings
|
* the game settings
|
||||||
|
* @param gameState
|
||||||
|
* the game state
|
||||||
*/
|
*/
|
||||||
public RoundState(GameSettings gameSettings, GameState gameState) {
|
public RoundState(GameSettings gameSettings, GameState gameState) {
|
||||||
this.gameSettings = gameSettings;
|
this.gameSettings = gameSettings;
|
||||||
|
|
|
@ -23,7 +23,7 @@ public class StoneSet implements Iterable<Stone>, Sizeable, Serializable {
|
||||||
* Create a new single stone stone set
|
* Create a new single stone stone set
|
||||||
*
|
*
|
||||||
* @param stone
|
* @param stone
|
||||||
* single stone of the set
|
* single stone of the set
|
||||||
*/
|
*/
|
||||||
public StoneSet(Stone stone) {
|
public StoneSet(Stone stone) {
|
||||||
stones = new ArrayList<Stone>(Collections.singletonList(stone));
|
stones = new ArrayList<Stone>(Collections.singletonList(stone));
|
||||||
|
@ -33,7 +33,7 @@ public class StoneSet implements Iterable<Stone>, Sizeable, Serializable {
|
||||||
* Create a stone set from a list of stones
|
* Create a stone set from a list of stones
|
||||||
*
|
*
|
||||||
* @param stones
|
* @param stones
|
||||||
* list of stones to build a set of
|
* list of stones to build a set of
|
||||||
*/
|
*/
|
||||||
public StoneSet(List<Stone> stones) {
|
public StoneSet(List<Stone> stones) {
|
||||||
this.stones = new ArrayList<Stone>(stones);
|
this.stones = new ArrayList<Stone>(stones);
|
||||||
|
@ -53,7 +53,7 @@ public class StoneSet implements Iterable<Stone>, Sizeable, Serializable {
|
||||||
* Test for rule conflict within the StoneSet
|
* Test for rule conflict within the StoneSet
|
||||||
*
|
*
|
||||||
* @param settings
|
* @param settings
|
||||||
* GameSettings
|
* GameSettings
|
||||||
*
|
*
|
||||||
* @return true when the set is valid according to the rules
|
* @return true when the set is valid according to the rules
|
||||||
*/
|
*/
|
||||||
|
@ -62,13 +62,13 @@ public class StoneSet implements Iterable<Stone>, Sizeable, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for rule conflict within the StoneSet and determine whether the set
|
* Test for rule conflict within the StoneSet and determine whether the set is
|
||||||
* is a group or a run
|
* a group or a run
|
||||||
*
|
*
|
||||||
* @param settings
|
* @param settings
|
||||||
* GameSettings
|
* GameSettings
|
||||||
*
|
*
|
||||||
* @return GROUP or RUN for valid sets, INVALID otherwise
|
* @return GROUP or RUN for valid sets, INVALID otherwise and the points
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public Pair<Type, Integer> classify(GameSettings settings) {
|
public Pair<Type, Integer> classify(GameSettings settings) {
|
||||||
|
@ -84,7 +84,7 @@ public class StoneSet implements Iterable<Stone>, Sizeable, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nonJoker == -1) {
|
if (nonJoker == -1) {
|
||||||
return classifyJokersOnly(settings, nonJoker);
|
return classifyJokersOnly(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
int runScore = isValidRun(nonJoker, settings);
|
int runScore = isValidRun(nonJoker, settings);
|
||||||
|
@ -99,8 +99,15 @@ public class StoneSet implements Iterable<Stone>, Sizeable, Serializable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Pair<Type, Integer> classifyJokersOnly(GameSettings settings,
|
/**
|
||||||
int nonJoker) {
|
* Test for rule conflict within a StoneSet with jokers only and determine
|
||||||
|
* whether the set is a group or a run
|
||||||
|
*
|
||||||
|
* @param settings
|
||||||
|
* the game settings
|
||||||
|
* @return GROUP or RUN for valid sets, INVALID otherwise and the points
|
||||||
|
*/
|
||||||
|
private Pair<Type, Integer> classifyJokersOnly(GameSettings settings) {
|
||||||
if (stones.size() > settings.getHighestValue()
|
if (stones.size() > settings.getHighestValue()
|
||||||
&& stones.size() > settings.getStoneColors().size()
|
&& stones.size() > settings.getStoneColors().size()
|
||||||
&& !settings.isNoLimits()) {
|
&& !settings.isNoLimits()) {
|
||||||
|
@ -126,8 +133,10 @@ public class StoneSet implements Iterable<Stone>, Sizeable, Serializable {
|
||||||
* Test for rule conflict within the StoneSet, assuming we have a run
|
* Test for rule conflict within the StoneSet, assuming we have a run
|
||||||
*
|
*
|
||||||
* @param referencePosition
|
* @param referencePosition
|
||||||
* position of stone used as reference (any non-joker stone)
|
* position of stone used as reference (any non-joker stone)
|
||||||
* @param settings
|
* @param settings
|
||||||
|
* the game settings
|
||||||
|
* @return the set's points
|
||||||
*/
|
*/
|
||||||
private int isValidRun(int referencePosition, GameSettings settings) {
|
private int isValidRun(int referencePosition, GameSettings settings) {
|
||||||
StoneColor runColor = stones.get(referencePosition).getColor();
|
StoneColor runColor = stones.get(referencePosition).getColor();
|
||||||
|
@ -167,7 +176,12 @@ public class StoneSet implements Iterable<Stone>, Sizeable, Serializable {
|
||||||
/**
|
/**
|
||||||
* Test for rule conflict within the StoneSet, assuming we have a group
|
* Test for rule conflict within the StoneSet, assuming we have a group
|
||||||
*
|
*
|
||||||
|
* @param value
|
||||||
|
* the value of the stones (all have the same in a group)
|
||||||
|
*
|
||||||
* @param settings
|
* @param settings
|
||||||
|
* the game settings
|
||||||
|
* @return the set's points
|
||||||
*/
|
*/
|
||||||
private int isValidGroup(int value, GameSettings settings) {
|
private int isValidGroup(int value, GameSettings settings) {
|
||||||
if (stones.size() > settings.getStoneColors().size()) {
|
if (stones.size() > settings.getStoneColors().size()) {
|
||||||
|
@ -195,7 +209,7 @@ public class StoneSet implements Iterable<Stone>, Sizeable, Serializable {
|
||||||
* Stone Sets
|
* Stone Sets
|
||||||
*
|
*
|
||||||
* @param position
|
* @param position
|
||||||
* Splitting {@link Position}
|
* Splitting {@link Position}
|
||||||
* @return A pair of StoneSets, one for each split part
|
* @return A pair of StoneSets, one for each split part
|
||||||
*/
|
*/
|
||||||
public Pair<StoneSet, StoneSet> splitAt(int position) {
|
public Pair<StoneSet, StoneSet> splitAt(int position) {
|
||||||
|
@ -205,8 +219,7 @@ public class StoneSet implements Iterable<Stone>, Sizeable, Serializable {
|
||||||
return new Pair<StoneSet, StoneSet>(this, null);
|
return new Pair<StoneSet, StoneSet>(this, null);
|
||||||
}
|
}
|
||||||
StoneSet firstSet = new StoneSet(stones.subList(0, position));
|
StoneSet firstSet = new StoneSet(stones.subList(0, position));
|
||||||
StoneSet secondSet = new StoneSet(stones.subList(position,
|
StoneSet secondSet = new StoneSet(stones.subList(position, stones.size()));
|
||||||
stones.size()));
|
|
||||||
return new Pair<StoneSet, StoneSet>(firstSet, secondSet);
|
return new Pair<StoneSet, StoneSet>(firstSet, secondSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,7 +227,7 @@ public class StoneSet implements Iterable<Stone>, Sizeable, Serializable {
|
||||||
* Joins StoneSet to another StoneSet and returns the resulting new StoneSet
|
* Joins StoneSet to another StoneSet and returns the resulting new StoneSet
|
||||||
*
|
*
|
||||||
* @param other
|
* @param other
|
||||||
* StoneSet to be joined to active StoneSet
|
* StoneSet to be joined to active StoneSet
|
||||||
* @return the combined StoneSet
|
* @return the combined StoneSet
|
||||||
*/
|
*/
|
||||||
public StoneSet join(StoneSet other) {
|
public StoneSet join(StoneSet other) {
|
||||||
|
@ -237,7 +250,7 @@ public class StoneSet implements Iterable<Stone>, Sizeable, Serializable {
|
||||||
* Returns the i-th stone of the set (starting with 0)
|
* Returns the i-th stone of the set (starting with 0)
|
||||||
*
|
*
|
||||||
* @param i
|
* @param i
|
||||||
* number of the stone to return
|
* number of the stone to return
|
||||||
* @return the i-th stone
|
* @return the i-th stone
|
||||||
*/
|
*/
|
||||||
public Stone get(int i) {
|
public Stone get(int i) {
|
||||||
|
|
|
@ -31,6 +31,17 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Subroutine to "drop" to consider and determine the direction the objects
|
||||||
|
* dropped one collides with position-wise evade in
|
||||||
|
*
|
||||||
|
* @param object
|
||||||
|
* the object to add to Hand
|
||||||
|
* @param position
|
||||||
|
* {@link Position} to put the object
|
||||||
|
* @param direction
|
||||||
|
* the direction the other stones evade in
|
||||||
|
*/
|
||||||
private void drop(E object, Position position, Direction direction) {
|
private void drop(E object, Position position, Direction direction) {
|
||||||
Pair<Position, Direction> update = fixInvalidDrop(object, position,
|
Pair<Position, Direction> update = fixInvalidDrop(object, position,
|
||||||
direction);
|
direction);
|
||||||
|
@ -42,6 +53,16 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
|
||||||
dropUnchecked(object, position, direction);
|
dropUnchecked(object, position, direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Subroutine to "drop" to execute the actual drop
|
||||||
|
*
|
||||||
|
* @param object
|
||||||
|
* the object to add to Hand
|
||||||
|
* @param position
|
||||||
|
* {@link Position} to put the object
|
||||||
|
* @param direction
|
||||||
|
* the direction the other stones evade in
|
||||||
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private void dropUnchecked(E object, Position position, Direction direction) {
|
private void dropUnchecked(E object, Position position, Direction direction) {
|
||||||
objects.put(object, new Pair<E, Position>(object, position));
|
objects.put(object, new Pair<E, Position>(object, position));
|
||||||
|
@ -62,23 +83,22 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
|
||||||
Position newPosition = null;
|
Position newPosition = null;
|
||||||
// Move object to avoid overlap
|
// Move object to avoid overlap
|
||||||
switch (newDirection) {
|
switch (newDirection) {
|
||||||
case TOP:
|
case TOP:
|
||||||
newPosition = new Position(currentPosition.getX(), position.getY()
|
newPosition = new Position(currentPosition.getX(), position.getY()
|
||||||
- currentObject.getHeight());
|
- currentObject.getHeight());
|
||||||
break;
|
break;
|
||||||
case BOTTOM:
|
case BOTTOM:
|
||||||
newPosition = new Position(currentPosition.getX(), position.getY()
|
newPosition = new Position(currentPosition.getX(), position.getY()
|
||||||
+ object.getHeight());
|
+ object.getHeight());
|
||||||
break;
|
break;
|
||||||
case LEFT:
|
case LEFT:
|
||||||
newPosition = new Position(
|
newPosition = new Position(position.getX() - currentObject.getWidth(),
|
||||||
position.getX() - currentObject.getWidth(),
|
currentPosition.getY());
|
||||||
currentPosition.getY());
|
break;
|
||||||
break;
|
case RIGHT:
|
||||||
case RIGHT:
|
newPosition = new Position(position.getX() + object.getWidth(),
|
||||||
newPosition = new Position(position.getX() + object.getWidth(),
|
currentPosition.getY());
|
||||||
currentPosition.getY());
|
break;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
objects.remove(currentObject);
|
objects.remove(currentObject);
|
||||||
|
@ -102,6 +122,16 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static method for determining a less or equal relation considering a small
|
||||||
|
* fuzziness
|
||||||
|
*
|
||||||
|
* @param d
|
||||||
|
* the value to be less or equal
|
||||||
|
* @param e
|
||||||
|
* than the other one
|
||||||
|
* @return if d is less or equal e
|
||||||
|
*/
|
||||||
private static boolean lessOrEqual(double d, double e) {
|
private static boolean lessOrEqual(double d, double e) {
|
||||||
if (-0.000001 < e && e < 0.000001) {
|
if (-0.000001 < e && e < 0.000001) {
|
||||||
return (d < e + 0.000001);
|
return (d < e + 0.000001);
|
||||||
|
@ -115,7 +145,20 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
|
||||||
return d < e;
|
return d < e;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Tests whether two objects overlap **/
|
/**
|
||||||
|
* Tests whether two objects overlap
|
||||||
|
*
|
||||||
|
* @param object1
|
||||||
|
* first object
|
||||||
|
* @param position1
|
||||||
|
* first object's position
|
||||||
|
* @param object2
|
||||||
|
* second object
|
||||||
|
* @param position2
|
||||||
|
* second object's position
|
||||||
|
*
|
||||||
|
* @return whether they overlap
|
||||||
|
**/
|
||||||
private boolean objectsOverlap(E object1, Position position1, E object2,
|
private boolean objectsOverlap(E object1, Position position1, E object2,
|
||||||
Position position2) {
|
Position position2) {
|
||||||
// Tests if position is left of, above ... the current object
|
// Tests if position is left of, above ... the current object
|
||||||
|
@ -134,6 +177,17 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the direction to move the object in
|
||||||
|
*
|
||||||
|
* @param object
|
||||||
|
* the object
|
||||||
|
* @param position
|
||||||
|
* the object's position
|
||||||
|
* @param blocking
|
||||||
|
* the object thats blocking
|
||||||
|
* @return the direction
|
||||||
|
*/
|
||||||
private Direction getMoveDirection(E object, Position position,
|
private Direction getMoveDirection(E object, Position position,
|
||||||
Pair<E, Position> blocking) {
|
Pair<E, Position> blocking) {
|
||||||
boolean isVertical = getMoveOrientation(object, position, blocking);
|
boolean isVertical = getMoveOrientation(object, position, blocking);
|
||||||
|
@ -161,6 +215,13 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
|
||||||
/**
|
/**
|
||||||
* Will the object be moved horizontally or vertically
|
* Will the object be moved horizontally or vertically
|
||||||
*
|
*
|
||||||
|
* @param object
|
||||||
|
* the object
|
||||||
|
* @param position
|
||||||
|
* the objects position
|
||||||
|
* @param blocking
|
||||||
|
* the object thats blocking
|
||||||
|
*
|
||||||
* @return boolean vertical movement
|
* @return boolean vertical movement
|
||||||
*/
|
*/
|
||||||
private boolean getMoveOrientation(E object, Position position,
|
private boolean getMoveOrientation(E object, Position position,
|
||||||
|
@ -177,16 +238,9 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
|
||||||
double overlapBottom = Math.min(objectBottom, blockingBottom);
|
double overlapBottom = Math.min(objectBottom, blockingBottom);
|
||||||
double overlapTop = Math.max(position.getY(), blocking.getSecond().getY());
|
double overlapTop = Math.max(position.getY(), blocking.getSecond().getY());
|
||||||
double overlapY = overlapBottom - overlapTop;
|
double overlapY = overlapBottom - overlapTop;
|
||||||
// vertical or horizontal Shift
|
|
||||||
// TODO magic factor
|
|
||||||
return overlapX > overlapY;
|
return overlapX > overlapY;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see jrummikub.model.IStoneTray#getPosition(E)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public Position getPosition(E object) {
|
public Position getPosition(E object) {
|
||||||
Pair<E, Position> entry = objects.get(object);
|
Pair<E, Position> entry = objects.get(object);
|
||||||
|
@ -206,21 +260,11 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
|
||||||
return objects.values().iterator();
|
return objects.values().iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see jrummikub.model.IStoneTray#pickUp(E)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public boolean pickUp(E object) {
|
public boolean pickUp(E object) {
|
||||||
return null != objects.remove(object);
|
return null != objects.remove(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see jrummikub.model.IStoneTray#clone()
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public IStoneTray<E> clone() {
|
public IStoneTray<E> clone() {
|
||||||
|
|
|
@ -46,6 +46,13 @@ public class Table extends StoneTray<StoneSet> implements ITable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds {@link StoneInfo}
|
||||||
|
*
|
||||||
|
* @param stone
|
||||||
|
* the stone
|
||||||
|
* @return the info
|
||||||
|
*/
|
||||||
private StoneInfo findStoneInfo(Stone stone) {
|
private StoneInfo findStoneInfo(Stone stone) {
|
||||||
// Find the set of the stone
|
// Find the set of the stone
|
||||||
StoneInfo info;
|
StoneInfo info;
|
||||||
|
|
Reference in a new issue