Implemented initial meld test using new AI
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@441 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
751d5a3aa9
commit
3ffad85972
6 changed files with 164 additions and 26 deletions
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue