diff options
author | Jannis Harder <harder@informatik.uni-luebeck.de> | 2011-06-14 21:05:15 +0200 |
---|---|---|
committer | Jannis Harder <harder@informatik.uni-luebeck.de> | 2011-06-14 21:05:15 +0200 |
commit | 3ffad8597290f91d21c2a2ba7657bbbc16ab1582 (patch) | |
tree | f2d4847afdebfc3778b70cca751f81ea4678b5e1 /src/jrummikub/model | |
parent | 751d5a3aa98461bf27f2a21a157e72f8da89406a (diff) | |
download | JRummikub-3ffad8597290f91d21c2a2ba7657bbbc16ab1582.tar JRummikub-3ffad8597290f91d21c2a2ba7657bbbc16ab1582.zip |
Implemented initial meld test using new AI
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@441 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub/model')
-rw-r--r-- | src/jrummikub/model/Hand.java | 37 |
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()); } |