diff options
Diffstat (limited to 'src/jrummikub/ai/TurnLogic.java')
-rw-r--r-- | src/jrummikub/ai/TurnLogic.java | 50 |
1 files changed, 45 insertions, 5 deletions
diff --git a/src/jrummikub/ai/TurnLogic.java b/src/jrummikub/ai/TurnLogic.java index 1ce752c..e736361 100644 --- a/src/jrummikub/ai/TurnLogic.java +++ b/src/jrummikub/ai/TurnLogic.java @@ -32,11 +32,15 @@ public class TurnLogic { private GameSettings settings; private int stoneCount; private int maxSetSize; + private int maxHandPoints; private Var<Boolean> trueVar; + private Var<Integer> totalPoints; private List<Var<Boolean>> onTable = new ArrayList<Var<Boolean>>(); + private List<Var<Integer>> pointsValue = new ArrayList<Var<Integer>>(); + private List<Var<Integer>> stoneValue = new ArrayList<Var<Integer>>(); private List<Var<Integer>> leftStoneValue = new ArrayList<Var<Integer>>(); private List<Var<Integer>> rightStoneValue = new ArrayList<Var<Integer>>(); @@ -76,6 +80,7 @@ public class TurnLogic { trueVar = solver.makeVar(true); + maxHandPoints = 0; int i = 0; for (Stone stone : tableStones) { addStone(i, true, stone); @@ -89,6 +94,19 @@ public class TurnLogic { for (i = 0; i < stoneCount; i++) { addConstraints(i); } + + totalPoints = solver.makeRangeVar(settings.getInitialMeldThreshold(), + maxHandPoints); + + List<Var<Integer>> points = new ArrayList<Var<Integer>>(); + + for (Var<Integer> var : pointsValue) { + if (var != null) { + points.add(var); + } + } + + add(sum(totalPoints, points)); } private void addStone(int i, boolean table, Stone stone) { @@ -100,9 +118,22 @@ public class TurnLogic { isJoker.add(stone.isJoker()); if (stone.isJoker()) { stoneValue.add(solver.makeRangeVar(1, settings.getHighestValue())); + if (table) { + pointsValue.add(null); + } else { + pointsValue.add(solver.makeRangeVar(0, + settings.getHighestValue())); + maxHandPoints += settings.getHighestValue(); + } stoneColor.add(solver.makeVar(settings.getStoneColors())); } else { stoneValue.add(solver.makeVar(stone.getValue())); + if (table) { + pointsValue.add(null); + } else { + pointsValue.add(solver.makeVar(0, stone.getValue())); + maxHandPoints += stone.getValue(); + } stoneColor.add(solver.makeVar(stone.getColor())); } @@ -282,6 +313,13 @@ public class TurnLogic { add(unless(onTable.get(i), constant(stoneColor.get(i), StoneColor.RED))); } + + // initial meld points + if (pointsValue.get(i) != null) { + add(when(onTable.get(i), + same(stoneValue.get(i), pointsValue.get(i)))); + add(unless(onTable.get(i), constant(pointsValue.get(i), 0))); + } } public boolean solve() { @@ -342,10 +380,12 @@ public class TurnLogic { System.out.print("[" + stoneColor.get(i).getValue().toString().substring(0, 1) + stoneValue.get(i).getValue() + "]"); - // + "," + leftNeighbor.get(i).getValue() + - // hasLeftNeighbor.get(i).getValue() + lowCount.get(i).getValue() + "," - // + rightNeighbor.get(i).getValue() + - // hasRightNeighbor.get(i).getValue() + highCount.get(i).getValue() + - // "]"); + /* + * + "," + leftNeighbor.get(i).getValue() + + * hasLeftNeighbor.get(i).getValue() + lowCount.get(i).getValue() + "," + * + rightNeighbor.get(i).getValue() + + * hasRightNeighbor.get(i).getValue() + highCount.get(i).getValue() + + * "]"); + */ } } |