summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJannis Harder <harder@informatik.uni-luebeck.de>2011-06-20 23:52:03 +0200
committerJannis Harder <harder@informatik.uni-luebeck.de>2011-06-20 23:52:03 +0200
commit1ba3c9758394f551aa913df52852c19e7e6c6187 (patch)
tree4eebd17aa66363f903d6734db49c5e0c11c394f0 /src
parenta33b0a22acf13a79aba9c205ec320f671b426958 (diff)
downloadJRummikub-1ba3c9758394f551aa913df52852c19e7e6c6187.tar
JRummikub-1ba3c9758394f551aa913df52852c19e7e6c6187.zip
Fixed metrics in AI code
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@515 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src')
-rw-r--r--src/jrummikub/ai/TurnLogic.java50
1 files changed, 15 insertions, 35 deletions
diff --git a/src/jrummikub/ai/TurnLogic.java b/src/jrummikub/ai/TurnLogic.java
index b3ac3cd..e31f5ea 100644
--- a/src/jrummikub/ai/TurnLogic.java
+++ b/src/jrummikub/ai/TurnLogic.java
@@ -448,7 +448,8 @@ public class TurnLogic {
checkGroupRunExclusive();
- changed |= checkJoker();
+ changed |= checkJokerColor();
+ changed |= checkJokerValue();
return changed;
}
@@ -529,7 +530,7 @@ public class TurnLogic {
}
}
- private boolean checkJoker() {
+ private boolean checkJokerValue() {
boolean changed = false;
if (this.value == null) {
if (isSingleNonNullSet(leftGroup)) {
@@ -550,6 +551,11 @@ public class TurnLogic {
}
changed |= this.value != null;
}
+ return changed;
+ }
+
+ private boolean checkJokerColor() {
+ boolean changed = false;
if (this.color == null) {
if (isSingleNonNullSet(leftRun)) {
this.color = top.stones.get(leftRun.iterator().next()).color;
@@ -558,7 +564,6 @@ public class TurnLogic {
}
changed |= this.color != null;
}
-
return changed;
}
@@ -593,11 +598,6 @@ public class TurnLogic {
return (double) value;
}
- public int getSize() {
- return leftGroup.size() + rightGroup.size() + leftRun.size()
- + rightRun.size();
- }
-
@SuppressWarnings("unchecked")
public boolean needsJoker(boolean side) {
if (onTable != Boolean.TRUE) {
@@ -681,17 +681,11 @@ public class TurnLogic {
}
});
- System.out.println("---");
- ArrayList<Stone> handStones2 = new ArrayList<Stone>();
int i = 0;
for (Pair<Stone, Boolean> pair : sortedStones) {
top.add(new StoneState(i++, pair.getFirst(), pair.getSecond()));
inputStones.add(pair.getFirst());
- if (!pair.getSecond()) {
- handStones2.add(pair.getFirst());
- }
}
- System.out.println(handStones2);
}
/**
@@ -807,44 +801,25 @@ public class TurnLogic {
}
private void branch() throws Contradiction {
-
- ArrayList<Integer> indices = new ArrayList<Integer>();
- for (int i = 0; i < stoneCount; i++) {
- indices.add(i);
- }
- Collections.sort(indices, new Comparator<Integer>() {
- @Override
- public int compare(Integer o1, Integer o2) {
- Integer size1 = top.stones.get(o1).getSize();
- Integer size2 = top.stones.get(o2).getSize();
- return size1.compareTo(size2);
- }
- });
-
for (int i = 0; i < stoneCount; i++) {
StoneState stone = top.stones.get(i);
if (stone.leftRun.size() > 1) {
- replace();
branchLeftRun(i, stone);
return;
}
if (stone.rightRun.size() > 1) {
- replace();
branchRightRun(i, stone);
return;
}
if (stone.leftGroup.size() > 1) {
- replace();
branchLeftGroup(i, stone);
return;
}
if (stone.rightGroup.size() > 1) {
- replace();
branchRightGroup(i, stone);
return;
}
if (stone.onTable == null) {
- replace();
branchOnHand(i);
return;
}
@@ -852,12 +827,10 @@ public class TurnLogic {
for (int i = 0; i < stoneCount; i++) {
StoneState stone = top.stones.get(i);
if (stone.color == null) {
- replace();
branchColor(i);
return;
}
if (stone.value == null) {
- replace();
branchValue(i);
return;
}
@@ -867,6 +840,7 @@ public class TurnLogic {
}
private void branchValue(int i) {
+ replace();
for (int value = 1; value <= settings.getHighestValue(); value++) {
State newState = new State(top);
newState.stones.get(i).value = value;
@@ -876,6 +850,7 @@ public class TurnLogic {
}
private void branchColor(int i) {
+ replace();
for (StoneColor color : stoneColors) {
State newState = new State(top);
newState.stones.get(i).color = color;
@@ -885,6 +860,7 @@ public class TurnLogic {
}
private void branchRightGroup(int i, StoneState stone) {
+ replace();
for (Integer id : stone.rightGroup) {
State newState = new State(top);
newState.stones.get(i).rightGroup.clear();
@@ -895,6 +871,7 @@ public class TurnLogic {
}
private void branchLeftGroup(int i, StoneState stone) {
+ replace();
for (Integer id : stone.leftGroup) {
State newState = new State(top);
newState.stones.get(i).leftGroup.clear();
@@ -905,6 +882,7 @@ public class TurnLogic {
}
private void branchRightRun(int i, StoneState stone) {
+ replace();
for (Integer id : stone.rightRun) {
State newState = new State(top);
newState.stones.get(i).rightRun.clear();
@@ -915,6 +893,7 @@ public class TurnLogic {
}
private void branchLeftRun(int i, StoneState stone) {
+ replace();
for (Integer id : stone.leftRun) {
State newState = new State(top);
newState.stones.get(i).leftRun.clear();
@@ -925,6 +904,7 @@ public class TurnLogic {
}
private void branchOnHand(int i) {
+ replace();
State newState = new State(top);
newState.stones.get(i).onTable = true;
newState.changedStones.add(i);