summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/ai
diff options
context:
space:
mode:
authorJannis Harder <harder@informatik.uni-luebeck.de>2011-06-17 22:12:41 +0200
committerJannis Harder <harder@informatik.uni-luebeck.de>2011-06-17 22:12:41 +0200
commit47bf19036e049787fa7742f5ff72a08a0c9e887c (patch)
tree0858aef8cc91af311a1c8505d69411d116da83ba /src/jrummikub/ai
parenta07e723242da4fbdd00cee2d86a46f4db70bc87a (diff)
downloadJRummikub-47bf19036e049787fa7742f5ff72a08a0c9e887c.tar
JRummikub-47bf19036e049787fa7742f5ff72a08a0c9e887c.zip
Use new AI for computer players
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@448 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub/ai')
-rw-r--r--src/jrummikub/ai/TurnLogic.java20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/jrummikub/ai/TurnLogic.java b/src/jrummikub/ai/TurnLogic.java
index 01a3d59..b9e2a2a 100644
--- a/src/jrummikub/ai/TurnLogic.java
+++ b/src/jrummikub/ai/TurnLogic.java
@@ -27,9 +27,10 @@ public class TurnLogic {
private State top;
private volatile boolean abort = false;
+ private volatile boolean autoAbort = false;
private int neededPoints = 0;
- private double neededScore = Double.NEGATIVE_INFINITY;
+ private double neededScore = 0;
@SuppressWarnings("serial")
private static class Contradiction extends Throwable {
@@ -548,6 +549,10 @@ public class TurnLogic {
public List<StoneSet> getResult() {
State result = bestState;
+ if (result == null) {
+ return null;
+ }
+
ArrayList<StoneSet> outputSets = new ArrayList<StoneSet>();
for (int i = 0; i < stoneCount; i++) {
@@ -560,9 +565,6 @@ public class TurnLogic {
&& isNullSet(stone.rightGroup)) {
break;
}
- /* System.out.println("--");
- System.out.println(stone.rightRun);
- System.out.println(stone.rightGroup); */
Integer rightRunID = stone.rightRun.iterator().next();
Integer rightGroupID = stone.rightGroup.iterator().next();
@@ -600,7 +602,7 @@ public class TurnLogic {
}
public double optimize() {
- while (solve()) {
+ while (!autoAbort && solve()) {
neededScore = top.getScore();
}
return neededScore;
@@ -688,4 +690,12 @@ public class TurnLogic {
// This should never happen
throw new Error("Internal AI error");
}
+
+ public void autoAbort() {
+ if (bestState != null) {
+ abort = true;
+ }
+ autoAbort = true;
+
+ }
}