Removed AIUtil
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@449 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
47bf19036e
commit
5a4d1ccb12
3 changed files with 57 additions and 346 deletions
|
@ -5,12 +5,12 @@ import static jrummikub.model.StoneTray.Direction.RIGHT;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import jrummikub.ai.TurnLogic;
|
||||
import jrummikub.control.AIUtil;
|
||||
import jrummikub.util.Pair;
|
||||
|
||||
/** Class managing a {@link Player}'s {@link Stone}s */
|
||||
|
@ -96,6 +96,57 @@ public class Hand extends StoneTray<Stone> implements IHand {
|
|||
turnLogic.needIntialMeldThreshold();
|
||||
return turnLogic.solve();
|
||||
}
|
||||
|
||||
|
||||
private static void incrementStoneCount(
|
||||
TreeMap<Pair<Integer, StoneColor>, Integer> stones,
|
||||
Pair<Integer, StoneColor> stone) {
|
||||
if (stones.containsKey(stone)) {
|
||||
stones.put(stone, stones.get(stone) + 1);
|
||||
} else {
|
||||
stones.put(stone, 1);
|
||||
}
|
||||
}
|
||||
|
||||
private final static Comparator<Pair<Integer, StoneColor>> comparator = new Comparator<Pair<Integer, StoneColor>>() {
|
||||
@Override
|
||||
public int compare(Pair<Integer, StoneColor> o1,
|
||||
Pair<Integer, StoneColor> o2) {
|
||||
int firstComparison = o1.getFirst().compareTo(o2.getFirst());
|
||||
if (firstComparison != 0) {
|
||||
return -firstComparison;
|
||||
} else {
|
||||
return o1.getSecond().compareTo(o2.getSecond());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Counts the numbers of stones
|
||||
*
|
||||
* @param stones
|
||||
* the stones to count
|
||||
* @return the numbers for all stones
|
||||
*/
|
||||
private static Pair<TreeMap<Pair<Integer, StoneColor>, Integer>, Integer> countStones(
|
||||
List<Stone> stones) {
|
||||
int jokerCount = 0;
|
||||
TreeMap<Pair<Integer, StoneColor>, Integer> stoneCounts = new TreeMap<Pair<Integer, StoneColor>, Integer>(
|
||||
comparator);
|
||||
|
||||
for (Stone stone : stones) {
|
||||
if (stone.isJoker()) {
|
||||
jokerCount++;
|
||||
} else {
|
||||
Pair<Integer, StoneColor> key = new Pair<Integer, StoneColor>(
|
||||
stone.getValue(), stone.getColor());
|
||||
|
||||
incrementStoneCount(stoneCounts, key);
|
||||
}
|
||||
}
|
||||
return new Pair<TreeMap<Pair<Integer, StoneColor>, Integer>, Integer>(
|
||||
stoneCounts, jokerCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIdenticalStoneCount() {
|
||||
|
@ -106,8 +157,7 @@ public class Hand extends StoneTray<Stone> implements IHand {
|
|||
stones.add(iter.next().getFirst());
|
||||
}
|
||||
|
||||
Pair<TreeMap<Pair<Integer, StoneColor>, Integer>, Integer> stoneCounts = AIUtil
|
||||
.countStones(stones);
|
||||
Pair<TreeMap<Pair<Integer, StoneColor>, Integer>, Integer> stoneCounts = countStones(stones);
|
||||
|
||||
int pairCount = 0;
|
||||
|
||||
|
|
Reference in a new issue