From 3ffad8597290f91d21c2a2ba7657bbbc16ab1582 Mon Sep 17 00:00:00 2001 From: Jannis Harder Date: Tue, 14 Jun 2011 21:05:15 +0200 Subject: Implemented initial meld test using new AI git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@441 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/model/Hand.java | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) (limited to 'src/jrummikub/model') 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 implements IHand { } @Override - protected Pair fixInvalidDrop(Stone stone, Position pos, - Direction dir) { + protected Pair fixInvalidDrop(Stone stone, + Position pos, Direction dir) { double x = pos.getX(); double y = pos.getY(); @@ -56,9 +59,11 @@ public class Hand extends StoneTray implements IHand { return new Pair(new Position(0, y), RIGHT); } else { if (getFreeRowSpace((int) y) == 0) { - return new Pair(new Position(0, y + 1), RIGHT); + return new Pair(new Position(0, y + 1), + RIGHT); } else { - return new Pair(new Position(WIDTH - 1, y), LEFT); + return new Pair( + new Position(WIDTH - 1, y), LEFT); } } } @@ -80,29 +85,23 @@ public class Hand extends StoneTray implements IHand { @Override public boolean isInitialMeldPossible(GameSettings settings) { - AIUtil aiUtil = new AIUtil(settings); + List handStones = new ArrayList(); - List stones = new ArrayList(); - - for (Iterator> iter = this.iterator(); iter.hasNext();) { - stones.add(iter.next().getFirst()); + for (Pair entry : this) { + handStones.add(entry.getFirst()); } - Pair, Integer>, Integer> stoneCounts = AIUtil - .countStones(stones); - - Pair, Integer> result = aiUtil.findSetsWithTotalPoints( - settings.getInitialMeldThreshold(), stoneCounts.getFirst(), - stoneCounts.getSecond()); - - return (result.getSecond() >= settings.getInitialMeldThreshold()); + TurnLogic turnLogic = new TurnLogic(settings, + Collections. emptyList(), handStones); + return turnLogic.solve(); } @Override public int getIdenticalStoneCount() { List stones = new ArrayList(); - for (Iterator> iter = this.iterator(); iter.hasNext();) { + for (Iterator> iter = this.iterator(); iter + .hasNext();) { stones.add(iter.next().getFirst()); } -- cgit v1.2.3