model vollständig dukumentiert
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@546 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
5e3ce21569
commit
e4e66240bf
2 changed files with 28 additions and 13 deletions
|
@ -47,8 +47,8 @@ public class Hand extends StoneTray<Stone> implements IHand {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Pair<Position, Direction> fixInvalidDrop(Stone stone, Position pos,
|
protected Pair<Position, Direction> fixInvalidDrop(Stone stone,
|
||||||
Direction dir) {
|
Position pos, Direction dir) {
|
||||||
double x = pos.getX();
|
double x = pos.getX();
|
||||||
double y = pos.getY();
|
double y = pos.getY();
|
||||||
|
|
||||||
|
@ -59,9 +59,11 @@ 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), RIGHT);
|
return new Pair<Position, Direction>(new Position(0, y + 1),
|
||||||
|
RIGHT);
|
||||||
} else {
|
} else {
|
||||||
return new Pair<Position, Direction>(new Position(WIDTH - 1, y), LEFT);
|
return new Pair<Position, Direction>(
|
||||||
|
new Position(WIDTH - 1, y), LEFT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -99,8 +101,9 @@ public class Hand extends StoneTray<Stone> implements IHand {
|
||||||
* Increments the count of a stone in the list of all stones
|
* Increments the count of a stone in the list of all stones
|
||||||
*
|
*
|
||||||
* @param stones
|
* @param stones
|
||||||
* all stones and their respective numbers
|
* all stones and their respective numbers
|
||||||
* @param stone
|
* @param stone
|
||||||
|
* the start stone
|
||||||
*/
|
*/
|
||||||
private static void incrementStoneCount(
|
private static void incrementStoneCount(
|
||||||
TreeMap<Pair<Integer, StoneColor>, Integer> stones,
|
TreeMap<Pair<Integer, StoneColor>, Integer> stones,
|
||||||
|
@ -132,7 +135,7 @@ public class Hand extends StoneTray<Stone> implements IHand {
|
||||||
* Counts the numbers of stones
|
* Counts the numbers of stones
|
||||||
*
|
*
|
||||||
* @param stones
|
* @param stones
|
||||||
* the stones to count
|
* the stones to count
|
||||||
* @return the numbers for all stones
|
* @return the numbers for all stones
|
||||||
*/
|
*/
|
||||||
private static Pair<TreeMap<Pair<Integer, StoneColor>, Integer>, Integer> countStones(
|
private static Pair<TreeMap<Pair<Integer, StoneColor>, Integer>, Integer> countStones(
|
||||||
|
@ -159,7 +162,8 @@ 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.hasNext();) {
|
for (Iterator<Pair<Stone, Position>> iter = this.iterator(); iter
|
||||||
|
.hasNext();) {
|
||||||
stones.add(iter.next().getFirst());
|
stones.add(iter.next().getFirst());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ public class Table extends StoneTray<StoneSet> implements ITable {
|
||||||
* Constructor for a table
|
* Constructor for a table
|
||||||
*
|
*
|
||||||
* @param settings
|
* @param settings
|
||||||
* GameSettings
|
* GameSettings
|
||||||
*/
|
*/
|
||||||
public Table(GameSettings settings) {
|
public Table(GameSettings settings) {
|
||||||
gameSettings = settings;
|
gameSettings = settings;
|
||||||
|
@ -35,7 +35,7 @@ public class Table extends StoneTray<StoneSet> implements ITable {
|
||||||
* Removes {@link Stone} from the Table
|
* Removes {@link Stone} from the Table
|
||||||
*
|
*
|
||||||
* @param stone
|
* @param stone
|
||||||
* stone to pick up
|
* stone to pick up
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void pickUpStone(Stone stone) {
|
public void pickUpStone(Stone stone) {
|
||||||
|
@ -50,7 +50,7 @@ public class Table extends StoneTray<StoneSet> implements ITable {
|
||||||
* Finds {@link StoneInfo}
|
* Finds {@link StoneInfo}
|
||||||
*
|
*
|
||||||
* @param stone
|
* @param stone
|
||||||
* the stone
|
* the stone
|
||||||
* @return the info
|
* @return the info
|
||||||
*/
|
*/
|
||||||
private StoneInfo findStoneInfo(Stone stone) {
|
private StoneInfo findStoneInfo(Stone stone) {
|
||||||
|
@ -89,11 +89,22 @@ public class Table extends StoneTray<StoneSet> implements ITable {
|
||||||
return info.set;
|
return info.set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Splits a stone set at a specified position
|
||||||
|
*
|
||||||
|
* @param set
|
||||||
|
* the stone set to split
|
||||||
|
* @param setPosition
|
||||||
|
* the set's position on the table
|
||||||
|
* @param stonePosition
|
||||||
|
* the stone after which splitting should occur
|
||||||
|
*/
|
||||||
private void splitSet(StoneSet set, Position setPosition, int stonePosition) {
|
private void splitSet(StoneSet set, Position setPosition, int stonePosition) {
|
||||||
pickUp(set);
|
pickUp(set);
|
||||||
|
|
||||||
Pair<StoneSet, StoneSet> firstSplit = set.splitAt(stonePosition);
|
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 leftSet = firstSplit.getFirst();
|
||||||
StoneSet rightSet = secondSplit.getSecond();
|
StoneSet rightSet = secondSplit.getSecond();
|
||||||
|
@ -101,8 +112,8 @@ public class Table extends StoneTray<StoneSet> implements ITable {
|
||||||
if (set.classify(gameSettings).getFirst() == StoneSet.Type.RUN) {
|
if (set.classify(gameSettings).getFirst() == StoneSet.Type.RUN) {
|
||||||
Position leftPosition, rightPosition;
|
Position leftPosition, rightPosition;
|
||||||
leftPosition = setPosition;
|
leftPosition = setPosition;
|
||||||
rightPosition = new Position(setPosition.getX() + stonePosition + 1,
|
rightPosition = new Position(
|
||||||
setPosition.getY());
|
setPosition.getX() + stonePosition + 1, setPosition.getY());
|
||||||
|
|
||||||
drop(leftSet, leftPosition);
|
drop(leftSet, leftPosition);
|
||||||
drop(rightSet, rightPosition);
|
drop(rightSet, rightPosition);
|
||||||
|
|
Reference in a new issue