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
This commit is contained in:
parent
ac3c13c50b
commit
0ada4609a0
1 changed files with 25 additions and 43 deletions
|
@ -101,10 +101,8 @@ public class TurnLogic {
|
||||||
for (int i = 0; i < jokerIDs.size(); i++) {
|
for (int i = 0; i < jokerIDs.size(); i++) {
|
||||||
StoneState left = stones.get(jokerIDs.get(i));
|
StoneState left = stones.get(jokerIDs.get(i));
|
||||||
|
|
||||||
HashSet<Integer> leftLeftGroup = new HashSet<Integer>(
|
HashSet<Integer> leftLeftGroup = new HashSet<Integer>(left.leftGroup);
|
||||||
left.leftGroup);
|
HashSet<Integer> leftLeftRun = new HashSet<Integer>(left.leftRun);
|
||||||
HashSet<Integer> leftLeftRun = new HashSet<Integer>(
|
|
||||||
left.leftRun);
|
|
||||||
leftLeftGroup.remove(null);
|
leftLeftGroup.remove(null);
|
||||||
leftLeftRun.remove(null);
|
leftLeftRun.remove(null);
|
||||||
int runID, groupID;
|
int runID, groupID;
|
||||||
|
@ -216,8 +214,8 @@ public class TurnLogic {
|
||||||
public boolean isInterested(HashSet<Integer> changes) {
|
public boolean isInterested(HashSet<Integer> changes) {
|
||||||
return !(Collections.disjoint(changes, leftRun)
|
return !(Collections.disjoint(changes, leftRun)
|
||||||
&& Collections.disjoint(changes, rightRun)
|
&& Collections.disjoint(changes, rightRun)
|
||||||
&& Collections.disjoint(changes, leftGroup) && Collections
|
&& Collections.disjoint(changes, leftGroup) && Collections.disjoint(
|
||||||
.disjoint(changes, rightGroup));
|
changes, rightGroup));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends Comparable<T>> boolean lessThan(T a, T b) {
|
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)) {
|
if (!other.runNeighbor(this) || !other.rightRun.contains(id)) {
|
||||||
leftRun.remove(i);
|
leftRun.remove(i);
|
||||||
changed = true;
|
changed = true;
|
||||||
} else if (other.rightRun.size() == 1
|
} else if (other.rightRun.size() == 1 && other.onTable == Boolean.TRUE) {
|
||||||
&& other.onTable == Boolean.TRUE) {
|
|
||||||
changed |= leftRun.retainAll(Arrays.asList(i));
|
changed |= leftRun.retainAll(Arrays.asList(i));
|
||||||
changed |= onTable != Boolean.TRUE;
|
changed |= onTable != Boolean.TRUE;
|
||||||
onTable = true;
|
onTable = true;
|
||||||
|
@ -306,8 +303,7 @@ public class TurnLogic {
|
||||||
if (!this.runNeighbor(other) || !other.leftRun.contains(id)) {
|
if (!this.runNeighbor(other) || !other.leftRun.contains(id)) {
|
||||||
rightRun.remove(i);
|
rightRun.remove(i);
|
||||||
changed = true;
|
changed = true;
|
||||||
} else if (other.leftRun.size() == 1
|
} else if (other.leftRun.size() == 1 && other.onTable == Boolean.TRUE) {
|
||||||
&& other.onTable == Boolean.TRUE) {
|
|
||||||
changed |= rightRun.retainAll(Arrays.asList(i));
|
changed |= rightRun.retainAll(Arrays.asList(i));
|
||||||
changed |= onTable != Boolean.TRUE;
|
changed |= onTable != Boolean.TRUE;
|
||||||
onTable = true;
|
onTable = true;
|
||||||
|
@ -324,8 +320,7 @@ public class TurnLogic {
|
||||||
relevantChanges.retainAll(changes);
|
relevantChanges.retainAll(changes);
|
||||||
for (int i : relevantChanges) {
|
for (int i : relevantChanges) {
|
||||||
StoneState other = top.stones.get(i);
|
StoneState other = top.stones.get(i);
|
||||||
if (!other.groupNeighbor(this)
|
if (!other.groupNeighbor(this) || !other.rightGroup.contains(id)) {
|
||||||
|| !other.rightGroup.contains(id)) {
|
|
||||||
leftGroup.remove(i);
|
leftGroup.remove(i);
|
||||||
changed = true;
|
changed = true;
|
||||||
} else if (other.rightGroup.size() == 1
|
} else if (other.rightGroup.size() == 1
|
||||||
|
@ -350,8 +345,7 @@ public class TurnLogic {
|
||||||
if (!this.groupNeighbor(other) || !other.leftGroup.contains(id)) {
|
if (!this.groupNeighbor(other) || !other.leftGroup.contains(id)) {
|
||||||
rightGroup.remove(i);
|
rightGroup.remove(i);
|
||||||
changed = true;
|
changed = true;
|
||||||
} else if (other.leftGroup.size() == 1
|
} else if (other.leftGroup.size() == 1 && other.onTable == Boolean.TRUE) {
|
||||||
&& other.onTable == Boolean.TRUE) {
|
|
||||||
changed |= rightGroup.retainAll(Arrays.asList(i));
|
changed |= rightGroup.retainAll(Arrays.asList(i));
|
||||||
changed |= onTable != Boolean.TRUE;
|
changed |= onTable != Boolean.TRUE;
|
||||||
onTable = true;
|
onTable = true;
|
||||||
|
@ -407,9 +401,8 @@ public class TurnLogic {
|
||||||
private boolean checkLonelyStone() {
|
private boolean checkLonelyStone() {
|
||||||
boolean changed = false;
|
boolean changed = false;
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
List<HashSet<Integer>> sets = Arrays.<HashSet<Integer>> asList(
|
List<HashSet<Integer>> sets = Arrays.<HashSet<Integer>> asList(leftGroup,
|
||||||
leftGroup, rightGroup, leftRun, rightRun, leftGroup,
|
rightGroup, leftRun, rightRun, leftGroup, rightGroup, leftRun);
|
||||||
rightGroup, leftRun);
|
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
if (isNullSet(sets.get(i)) && isNullSet(sets.get(i + 1))
|
if (isNullSet(sets.get(i)) && isNullSet(sets.get(i + 1))
|
||||||
&& isNullSet(sets.get(i + 2))) {
|
&& isNullSet(sets.get(i + 2))) {
|
||||||
|
@ -443,8 +436,8 @@ public class TurnLogic {
|
||||||
|
|
||||||
private boolean checkStoneCanBeOnTable() throws Contradiction {
|
private boolean checkStoneCanBeOnTable() throws Contradiction {
|
||||||
boolean changed = false;
|
boolean changed = false;
|
||||||
if (leftGroup.isEmpty() || rightGroup.isEmpty()
|
if (leftGroup.isEmpty() || rightGroup.isEmpty() || leftRun.isEmpty()
|
||||||
|| leftRun.isEmpty() || rightRun.isEmpty()) {
|
|| rightRun.isEmpty()) {
|
||||||
if (onTable == Boolean.TRUE) {
|
if (onTable == Boolean.TRUE) {
|
||||||
throw new Contradiction();
|
throw new Contradiction();
|
||||||
}
|
}
|
||||||
|
@ -472,23 +465,14 @@ public class TurnLogic {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSolved() {
|
public boolean isSolved() {
|
||||||
boolean solved = false;
|
|
||||||
if (onTable == Boolean.FALSE) {
|
if (onTable == Boolean.FALSE) {
|
||||||
return solved;
|
return true;
|
||||||
}
|
}
|
||||||
if (onTable == null || color == null || value == null) {
|
if (onTable == null || color == null || value == null) {
|
||||||
return solved;
|
return false;
|
||||||
}
|
}
|
||||||
if (leftRun.size() > 1 || rightRun.size() > 1
|
if (leftRun.size() > 1 || rightRun.size() > 1 || leftGroup.size() > 1
|
||||||
|| leftGroup.size() > 1 || rightGroup.size() > 1) {
|
|| rightGroup.size() > 1) {
|
||||||
return solved;
|
|
||||||
}
|
|
||||||
solved = bothGoupAndRun();
|
|
||||||
return solved;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean bothGoupAndRun() {
|
|
||||||
if (!((isNullSet(leftRun) && isNullSet(rightRun)) || (isNullSet(leftGroup) && isNullSet(rightGroup)))) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -524,11 +508,11 @@ public class TurnLogic {
|
||||||
* Creates new turn logic
|
* Creates new turn logic
|
||||||
*
|
*
|
||||||
* @param settings
|
* @param settings
|
||||||
* the game settings
|
* the game settings
|
||||||
* @param tableStones
|
* @param tableStones
|
||||||
* all stones on the table
|
* all stones on the table
|
||||||
* @param handStones
|
* @param handStones
|
||||||
* all stones on the hand
|
* all stones on the hand
|
||||||
*/
|
*/
|
||||||
public TurnLogic(GameSettings settings, Collection<Stone> tableStones,
|
public TurnLogic(GameSettings settings, Collection<Stone> tableStones,
|
||||||
Collection<Stone> handStones) {
|
Collection<Stone> handStones) {
|
||||||
|
@ -557,18 +541,17 @@ public class TurnLogic {
|
||||||
@Override
|
@Override
|
||||||
public int compare(Pair<Stone, Boolean> o1, Pair<Stone, Boolean> o2) {
|
public int compare(Pair<Stone, Boolean> o1, Pair<Stone, Boolean> o2) {
|
||||||
int cmp;
|
int cmp;
|
||||||
cmp = ((Boolean) o1.getFirst().isJoker()).compareTo(o2
|
cmp = ((Boolean) o1.getFirst().isJoker()).compareTo(o2.getFirst()
|
||||||
.getFirst().isJoker());
|
.isJoker());
|
||||||
if (cmp != 0) {
|
if (cmp != 0) {
|
||||||
return -cmp;
|
return -cmp;
|
||||||
}
|
}
|
||||||
cmp = (o1.getFirst().getColor()).compareTo(o2.getFirst()
|
cmp = (o1.getFirst().getColor()).compareTo(o2.getFirst().getColor());
|
||||||
.getColor());
|
|
||||||
if (cmp != 0) {
|
if (cmp != 0) {
|
||||||
return cmp;
|
return cmp;
|
||||||
}
|
}
|
||||||
cmp = ((Integer) o1.getFirst().getValue()).compareTo(o2
|
cmp = ((Integer) o1.getFirst().getValue()).compareTo(o2.getFirst()
|
||||||
.getFirst().getValue());
|
.getValue());
|
||||||
return cmp;
|
return cmp;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -635,8 +618,7 @@ public class TurnLogic {
|
||||||
ArrayList<Stone> setStones = new ArrayList<Stone>();
|
ArrayList<Stone> setStones = new ArrayList<Stone>();
|
||||||
while (true) {
|
while (true) {
|
||||||
setStones.add(inputStones.get(stone.id));
|
setStones.add(inputStones.get(stone.id));
|
||||||
if (isNullSet(stone.rightRun)
|
if (isNullSet(stone.rightRun) && isNullSet(stone.rightGroup)) {
|
||||||
&& isNullSet(stone.rightGroup)) {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Integer rightRunID = stone.rightRun.iterator().next();
|
Integer rightRunID = stone.rightRun.iterator().next();
|
||||||
|
|
Reference in a new issue