summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/model
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub/model')
-rw-r--r--src/jrummikub/model/Hand.java37
1 files changed, 18 insertions, 19 deletions
diff --git a/src/jrummikub/model/Hand.java b/src/jrummikub/model/Hand.java
index 681241a..c656afd 100644
--- a/src/jrummikub/model/Hand.java
+++ b/src/jrummikub/model/Hand.java
@@ -1,12 +1,15 @@
package jrummikub.model;
-import static jrummikub.model.StoneTray.Direction.*;
+import static jrummikub.model.StoneTray.Direction.LEFT;
+import static jrummikub.model.StoneTray.Direction.RIGHT;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.TreeMap;
+import jrummikub.ai.TurnLogic;
import jrummikub.control.AIUtil;
import jrummikub.util.Pair;
@@ -44,8 +47,8 @@ public class Hand extends StoneTray<Stone> implements IHand {
}
@Override
- protected Pair<Position, Direction> fixInvalidDrop(Stone stone, Position pos,
- Direction dir) {
+ protected Pair<Position, Direction> fixInvalidDrop(Stone stone,
+ Position pos, Direction dir) {
double x = pos.getX();
double y = pos.getY();
@@ -56,9 +59,11 @@ public class Hand extends StoneTray<Stone> implements IHand {
return new Pair<Position, Direction>(new Position(0, y), RIGHT);
} else {
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 {
- return new Pair<Position, Direction>(new Position(WIDTH - 1, y), LEFT);
+ return new Pair<Position, Direction>(
+ new Position(WIDTH - 1, y), LEFT);
}
}
}
@@ -80,29 +85,23 @@ public class Hand extends StoneTray<Stone> implements IHand {
@Override
public boolean isInitialMeldPossible(GameSettings settings) {
- AIUtil aiUtil = new AIUtil(settings);
+ List<Stone> handStones = new ArrayList<Stone>();
- List<Stone> stones = new ArrayList<Stone>();
-
- for (Iterator<Pair<Stone, Position>> iter = this.iterator(); iter.hasNext();) {
- stones.add(iter.next().getFirst());
+ for (Pair<Stone, Position> entry : this) {
+ handStones.add(entry.getFirst());
}
- Pair<TreeMap<Pair<Integer, StoneColor>, Integer>, Integer> stoneCounts = AIUtil
- .countStones(stones);
-
- Pair<List<StoneSet>, Integer> result = aiUtil.findSetsWithTotalPoints(
- settings.getInitialMeldThreshold(), stoneCounts.getFirst(),
- stoneCounts.getSecond());
-
- return (result.getSecond() >= settings.getInitialMeldThreshold());
+ TurnLogic turnLogic = new TurnLogic(settings,
+ Collections.<Stone> emptyList(), handStones);
+ return turnLogic.solve();
}
@Override
public int getIdenticalStoneCount() {
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());
}