Fixed metrics in AI code

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@515 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Jannis Harder 2011-06-20 23:52:03 +02:00
parent a33b0a22ac
commit 1ba3c97583

View file

@ -448,7 +448,8 @@ public class TurnLogic {
checkGroupRunExclusive(); checkGroupRunExclusive();
changed |= checkJoker(); changed |= checkJokerColor();
changed |= checkJokerValue();
return changed; return changed;
} }
@ -529,7 +530,7 @@ public class TurnLogic {
} }
} }
private boolean checkJoker() { private boolean checkJokerValue() {
boolean changed = false; boolean changed = false;
if (this.value == null) { if (this.value == null) {
if (isSingleNonNullSet(leftGroup)) { if (isSingleNonNullSet(leftGroup)) {
@ -550,6 +551,11 @@ public class TurnLogic {
} }
changed |= this.value != null; changed |= this.value != null;
} }
return changed;
}
private boolean checkJokerColor() {
boolean changed = false;
if (this.color == null) { if (this.color == null) {
if (isSingleNonNullSet(leftRun)) { if (isSingleNonNullSet(leftRun)) {
this.color = top.stones.get(leftRun.iterator().next()).color; this.color = top.stones.get(leftRun.iterator().next()).color;
@ -558,7 +564,6 @@ public class TurnLogic {
} }
changed |= this.color != null; changed |= this.color != null;
} }
return changed; return changed;
} }
@ -593,11 +598,6 @@ public class TurnLogic {
return (double) value; return (double) value;
} }
public int getSize() {
return leftGroup.size() + rightGroup.size() + leftRun.size()
+ rightRun.size();
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public boolean needsJoker(boolean side) { public boolean needsJoker(boolean side) {
if (onTable != Boolean.TRUE) { if (onTable != Boolean.TRUE) {
@ -681,17 +681,11 @@ public class TurnLogic {
} }
}); });
System.out.println("---");
ArrayList<Stone> handStones2 = new ArrayList<Stone>();
int i = 0; int i = 0;
for (Pair<Stone, Boolean> pair : sortedStones) { for (Pair<Stone, Boolean> pair : sortedStones) {
top.add(new StoneState(i++, pair.getFirst(), pair.getSecond())); top.add(new StoneState(i++, pair.getFirst(), pair.getSecond()));
inputStones.add(pair.getFirst()); 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 { 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++) { for (int i = 0; i < stoneCount; i++) {
StoneState stone = top.stones.get(i); StoneState stone = top.stones.get(i);
if (stone.leftRun.size() > 1) { if (stone.leftRun.size() > 1) {
replace();
branchLeftRun(i, stone); branchLeftRun(i, stone);
return; return;
} }
if (stone.rightRun.size() > 1) { if (stone.rightRun.size() > 1) {
replace();
branchRightRun(i, stone); branchRightRun(i, stone);
return; return;
} }
if (stone.leftGroup.size() > 1) { if (stone.leftGroup.size() > 1) {
replace();
branchLeftGroup(i, stone); branchLeftGroup(i, stone);
return; return;
} }
if (stone.rightGroup.size() > 1) { if (stone.rightGroup.size() > 1) {
replace();
branchRightGroup(i, stone); branchRightGroup(i, stone);
return; return;
} }
if (stone.onTable == null) { if (stone.onTable == null) {
replace();
branchOnHand(i); branchOnHand(i);
return; return;
} }
@ -852,12 +827,10 @@ public class TurnLogic {
for (int i = 0; i < stoneCount; i++) { for (int i = 0; i < stoneCount; i++) {
StoneState stone = top.stones.get(i); StoneState stone = top.stones.get(i);
if (stone.color == null) { if (stone.color == null) {
replace();
branchColor(i); branchColor(i);
return; return;
} }
if (stone.value == null) { if (stone.value == null) {
replace();
branchValue(i); branchValue(i);
return; return;
} }
@ -867,6 +840,7 @@ public class TurnLogic {
} }
private void branchValue(int i) { private void branchValue(int i) {
replace();
for (int value = 1; value <= settings.getHighestValue(); value++) { for (int value = 1; value <= settings.getHighestValue(); value++) {
State newState = new State(top); State newState = new State(top);
newState.stones.get(i).value = value; newState.stones.get(i).value = value;
@ -876,6 +850,7 @@ public class TurnLogic {
} }
private void branchColor(int i) { private void branchColor(int i) {
replace();
for (StoneColor color : stoneColors) { for (StoneColor color : stoneColors) {
State newState = new State(top); State newState = new State(top);
newState.stones.get(i).color = color; newState.stones.get(i).color = color;
@ -885,6 +860,7 @@ public class TurnLogic {
} }
private void branchRightGroup(int i, StoneState stone) { private void branchRightGroup(int i, StoneState stone) {
replace();
for (Integer id : stone.rightGroup) { for (Integer id : stone.rightGroup) {
State newState = new State(top); State newState = new State(top);
newState.stones.get(i).rightGroup.clear(); newState.stones.get(i).rightGroup.clear();
@ -895,6 +871,7 @@ public class TurnLogic {
} }
private void branchLeftGroup(int i, StoneState stone) { private void branchLeftGroup(int i, StoneState stone) {
replace();
for (Integer id : stone.leftGroup) { for (Integer id : stone.leftGroup) {
State newState = new State(top); State newState = new State(top);
newState.stones.get(i).leftGroup.clear(); newState.stones.get(i).leftGroup.clear();
@ -905,6 +882,7 @@ public class TurnLogic {
} }
private void branchRightRun(int i, StoneState stone) { private void branchRightRun(int i, StoneState stone) {
replace();
for (Integer id : stone.rightRun) { for (Integer id : stone.rightRun) {
State newState = new State(top); State newState = new State(top);
newState.stones.get(i).rightRun.clear(); newState.stones.get(i).rightRun.clear();
@ -915,6 +893,7 @@ public class TurnLogic {
} }
private void branchLeftRun(int i, StoneState stone) { private void branchLeftRun(int i, StoneState stone) {
replace();
for (Integer id : stone.leftRun) { for (Integer id : stone.leftRun) {
State newState = new State(top); State newState = new State(top);
newState.stones.get(i).leftRun.clear(); newState.stones.get(i).leftRun.clear();
@ -925,6 +904,7 @@ public class TurnLogic {
} }
private void branchOnHand(int i) { private void branchOnHand(int i) {
replace();
State newState = new State(top); State newState = new State(top);
newState.stones.get(i).onTable = true; newState.stones.get(i).onTable = true;
newState.changedStones.add(i); newState.changedStones.add(i);