diff options
author | Bennet Gerlach <bennet_gerlach@web.de> | 2011-06-18 16:41:55 +0200 |
---|---|---|
committer | Bennet Gerlach <bennet_gerlach@web.de> | 2011-06-18 16:41:55 +0200 |
commit | 0ada4609a0ebc24915dfa904e62bfe6b322fa120 (patch) | |
tree | 5b0c292b4621017c1fb73e182de81dceb2007c37 /src/jrummikub | |
parent | ac3c13c50b87abfc6e4959fabd5107990d1eb417 (diff) | |
download | JRummikub-0ada4609a0ebc24915dfa904e62bfe6b322fa120.tar JRummikub-0ada4609a0ebc24915dfa904e62bfe6b322fa120.zip |
Fixed bug in AI (threw Internal AI Error, stones in hand weren't
solved)
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@464 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub')
-rw-r--r-- | src/jrummikub/ai/TurnLogic.java | 68 |
1 files changed, 25 insertions, 43 deletions
diff --git a/src/jrummikub/ai/TurnLogic.java b/src/jrummikub/ai/TurnLogic.java index 81391a7..8440425 100644 --- a/src/jrummikub/ai/TurnLogic.java +++ b/src/jrummikub/ai/TurnLogic.java @@ -101,10 +101,8 @@ public class TurnLogic { for (int i = 0; i < jokerIDs.size(); i++) { StoneState left = stones.get(jokerIDs.get(i)); - HashSet<Integer> leftLeftGroup = new HashSet<Integer>( - left.leftGroup); - HashSet<Integer> leftLeftRun = new HashSet<Integer>( - left.leftRun); + HashSet<Integer> leftLeftGroup = new HashSet<Integer>(left.leftGroup); + HashSet<Integer> leftLeftRun = new HashSet<Integer>(left.leftRun); leftLeftGroup.remove(null); leftLeftRun.remove(null); int runID, groupID; @@ -216,8 +214,8 @@ public class TurnLogic { public boolean isInterested(HashSet<Integer> changes) { return !(Collections.disjoint(changes, leftRun) && Collections.disjoint(changes, rightRun) - && Collections.disjoint(changes, leftGroup) && Collections - .disjoint(changes, rightGroup)); + && Collections.disjoint(changes, leftGroup) && Collections.disjoint( + changes, rightGroup)); } public <T extends Comparable<T>> boolean lessThan(T a, T b) { @@ -285,8 +283,7 @@ public class TurnLogic { if (!other.runNeighbor(this) || !other.rightRun.contains(id)) { leftRun.remove(i); changed = true; - } else if (other.rightRun.size() == 1 - && other.onTable == Boolean.TRUE) { + } else if (other.rightRun.size() == 1 && other.onTable == Boolean.TRUE) { changed |= leftRun.retainAll(Arrays.asList(i)); changed |= onTable != Boolean.TRUE; onTable = true; @@ -306,8 +303,7 @@ public class TurnLogic { if (!this.runNeighbor(other) || !other.leftRun.contains(id)) { rightRun.remove(i); changed = true; - } else if (other.leftRun.size() == 1 - && other.onTable == Boolean.TRUE) { + } else if (other.leftRun.size() == 1 && other.onTable == Boolean.TRUE) { changed |= rightRun.retainAll(Arrays.asList(i)); changed |= onTable != Boolean.TRUE; onTable = true; @@ -324,8 +320,7 @@ public class TurnLogic { relevantChanges.retainAll(changes); for (int i : relevantChanges) { StoneState other = top.stones.get(i); - if (!other.groupNeighbor(this) - || !other.rightGroup.contains(id)) { + if (!other.groupNeighbor(this) || !other.rightGroup.contains(id)) { leftGroup.remove(i); changed = true; } else if (other.rightGroup.size() == 1 @@ -350,8 +345,7 @@ public class TurnLogic { if (!this.groupNeighbor(other) || !other.leftGroup.contains(id)) { rightGroup.remove(i); changed = true; - } else if (other.leftGroup.size() == 1 - && other.onTable == Boolean.TRUE) { + } else if (other.leftGroup.size() == 1 && other.onTable == Boolean.TRUE) { changed |= rightGroup.retainAll(Arrays.asList(i)); changed |= onTable != Boolean.TRUE; onTable = true; @@ -407,9 +401,8 @@ public class TurnLogic { private boolean checkLonelyStone() { boolean changed = false; @SuppressWarnings("unchecked") - List<HashSet<Integer>> sets = Arrays.<HashSet<Integer>> asList( - leftGroup, rightGroup, leftRun, rightRun, leftGroup, - rightGroup, leftRun); + List<HashSet<Integer>> sets = Arrays.<HashSet<Integer>> asList(leftGroup, + rightGroup, leftRun, rightRun, leftGroup, rightGroup, leftRun); for (int i = 0; i < 4; i++) { if (isNullSet(sets.get(i)) && isNullSet(sets.get(i + 1)) && isNullSet(sets.get(i + 2))) { @@ -443,8 +436,8 @@ public class TurnLogic { private boolean checkStoneCanBeOnTable() throws Contradiction { boolean changed = false; - if (leftGroup.isEmpty() || rightGroup.isEmpty() - || leftRun.isEmpty() || rightRun.isEmpty()) { + if (leftGroup.isEmpty() || rightGroup.isEmpty() || leftRun.isEmpty() + || rightRun.isEmpty()) { if (onTable == Boolean.TRUE) { throw new Contradiction(); } @@ -472,23 +465,14 @@ public class TurnLogic { } public boolean isSolved() { - boolean solved = false; if (onTable == Boolean.FALSE) { - return solved; + return true; } if (onTable == null || color == null || value == null) { - return solved; - } - if (leftRun.size() > 1 || rightRun.size() > 1 - || leftGroup.size() > 1 || rightGroup.size() > 1) { - return solved; + return false; } - solved = bothGoupAndRun(); - return solved; - } - - private boolean bothGoupAndRun() { - if (!((isNullSet(leftRun) && isNullSet(rightRun)) || (isNullSet(leftGroup) && isNullSet(rightGroup)))) { + if (leftRun.size() > 1 || rightRun.size() > 1 || leftGroup.size() > 1 + || rightGroup.size() > 1) { return false; } return true; @@ -524,11 +508,11 @@ public class TurnLogic { * Creates new turn logic * * @param settings - * the game settings + * the game settings * @param tableStones - * all stones on the table + * all stones on the table * @param handStones - * all stones on the hand + * all stones on the hand */ public TurnLogic(GameSettings settings, Collection<Stone> tableStones, Collection<Stone> handStones) { @@ -557,18 +541,17 @@ public class TurnLogic { @Override public int compare(Pair<Stone, Boolean> o1, Pair<Stone, Boolean> o2) { int cmp; - cmp = ((Boolean) o1.getFirst().isJoker()).compareTo(o2 - .getFirst().isJoker()); + cmp = ((Boolean) o1.getFirst().isJoker()).compareTo(o2.getFirst() + .isJoker()); if (cmp != 0) { return -cmp; } - cmp = (o1.getFirst().getColor()).compareTo(o2.getFirst() - .getColor()); + cmp = (o1.getFirst().getColor()).compareTo(o2.getFirst().getColor()); if (cmp != 0) { return cmp; } - cmp = ((Integer) o1.getFirst().getValue()).compareTo(o2 - .getFirst().getValue()); + cmp = ((Integer) o1.getFirst().getValue()).compareTo(o2.getFirst() + .getValue()); return cmp; } }); @@ -635,8 +618,7 @@ public class TurnLogic { ArrayList<Stone> setStones = new ArrayList<Stone>(); while (true) { setStones.add(inputStones.get(stone.id)); - if (isNullSet(stone.rightRun) - && isNullSet(stone.rightGroup)) { + if (isNullSet(stone.rightRun) && isNullSet(stone.rightGroup)) { break; } Integer rightRunID = stone.rightRun.iterator().next(); |