summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/model/Table.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub/model/Table.java')
-rw-r--r--src/jrummikub/model/Table.java36
1 files changed, 20 insertions, 16 deletions
diff --git a/src/jrummikub/model/Table.java b/src/jrummikub/model/Table.java
index 71ce27c..a763bef 100644
--- a/src/jrummikub/model/Table.java
+++ b/src/jrummikub/model/Table.java
@@ -10,24 +10,25 @@ public class Table extends StoneTray<StoneSet> implements ITable {
StoneSet set;
Position setPosition;
int stonePosition;
+
public StoneInfo(StoneSet set, Position setPosition, int stonePosition) {
this.set = set;
this.setPosition = setPosition;
this.stonePosition = stonePosition;
}
}
-
+
/**
* Removes {@link Stone} from the Table
*
* @param stone
- * stone to pick up
+ * stone to pick up
*/
@Override
- public void pickUpStone(Stone stone) {
+ public Pair<StoneSet, StoneSet> pickUpStone(Stone stone) {
StoneInfo info = findStoneInfo(stone);
-
- splitSet(info.set, info.setPosition, info.stonePosition);
+
+ return splitSet(info.set, info.setPosition, info.stonePosition);
}
private StoneInfo findStoneInfo(Stone stone) {
@@ -55,7 +56,7 @@ public class Table extends StoneTray<StoneSet> implements ITable {
}
return info;
}
-
+
@Override
public StoneSet findStoneSet(Stone stone) {
StoneInfo info = findStoneInfo(stone);
@@ -64,28 +65,29 @@ public class Table extends StoneTray<StoneSet> implements ITable {
}
return info.set;
}
-
-
- private void splitSet(StoneSet set, Position setPosition, int stonePosition) {
+ private Pair<StoneSet, StoneSet> splitSet(StoneSet set, Position setPosition,
+ int stonePosition) {
pickUp(set);
-
+
Pair<StoneSet, StoneSet> firstSplit = set.splitAt(stonePosition);
Pair<StoneSet, StoneSet> secondSplit = firstSplit.getSecond().splitAt(1);
-
+
StoneSet leftSet = firstSplit.getFirst();
StoneSet rightSet = secondSplit.getSecond();
-
+
if (set.classify() == StoneSet.Type.RUN) {
Position leftPosition, rightPosition;
leftPosition = setPosition;
- rightPosition = new Position(setPosition.getX() + stonePosition, setPosition.getY());
-
+ rightPosition = new Position(setPosition.getX() + stonePosition,
+ setPosition.getY());
+
drop(leftSet, leftPosition);
drop(rightSet, rightPosition);
} else {
- Position newPosition = new Position(setPosition.getX() + 0.5f, setPosition.getY());
-
+ Position newPosition = new Position(setPosition.getX() + 0.5f,
+ setPosition.getY());
+
if (leftSet == null) {
drop(rightSet, newPosition);
} else if (rightSet == null) {
@@ -94,6 +96,8 @@ public class Table extends StoneTray<StoneSet> implements ITable {
drop(leftSet.join(rightSet), newPosition);
}
}
+
+ return new Pair<StoneSet, StoneSet>(leftSet, rightSet);
}
/** Tests the Table for rule conflicts by checking all the {@link StoneSet} */