summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/ai/fdsolver/Constraints.java
diff options
context:
space:
mode:
authorJannis Harder <harder@informatik.uni-luebeck.de>2011-06-14 17:48:22 +0200
committerJannis Harder <harder@informatik.uni-luebeck.de>2011-06-14 17:48:22 +0200
commit7568f3782466531fe04fc14a40dc4d3a393c1fb9 (patch)
tree7778b598da5b698c35189234fe3a9dd58ae82913 /src/jrummikub/ai/fdsolver/Constraints.java
parent79767f762e39eac3a0247b9ee75b24258790e0de (diff)
downloadJRummikub-7568f3782466531fe04fc14a40dc4d3a393c1fb9.tar
JRummikub-7568f3782466531fe04fc14a40dc4d3a393c1fb9.zip
Added TurnLogic with rule variables and constraints
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@436 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub/ai/fdsolver/Constraints.java')
-rw-r--r--src/jrummikub/ai/fdsolver/Constraints.java56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/jrummikub/ai/fdsolver/Constraints.java b/src/jrummikub/ai/fdsolver/Constraints.java
new file mode 100644
index 0000000..0885d2a
--- /dev/null
+++ b/src/jrummikub/ai/fdsolver/Constraints.java
@@ -0,0 +1,56 @@
+package jrummikub.ai.fdsolver;
+
+import java.util.List;
+
+import jrummikub.ai.fdsolver.constraint.Filter;
+import jrummikub.ai.fdsolver.constraint.FilterConstraint;
+import jrummikub.ai.fdsolver.constraint.IfConstraint;
+import jrummikub.ai.fdsolver.constraint.IndexConstraint;
+import jrummikub.ai.fdsolver.constraint.LessThan;
+import jrummikub.ai.fdsolver.constraint.OffsetConstraint;
+import jrummikub.ai.fdsolver.constraint.SameConstraint;
+import jrummikub.ai.fdsolver.constraint.SumConstraint;
+
+public class Constraints {
+ public static Constraint when(Var<Boolean> cond, Constraint c) {
+ return new IfConstraint(false, cond, c);
+ }
+
+ public static Constraint unless(Var<Boolean> cond, Constraint c) {
+ return new IfConstraint(true, cond, c);
+ }
+
+
+ public static <T> Constraint index(Var<T> target, Var<Integer> index, List<Var<T>> list) {
+ return new IndexConstraint<T>(target, index, list);
+ }
+
+ public static <T> Constraint constant(Var<T> target, final T constant) {
+ return new FilterConstraint<T>(new Filter<T>() {
+ @Override
+ public boolean accept(T value) {
+ return value.equals(constant);
+ }
+ }, target);
+ }
+
+ public static Constraint offset(int offset, Var<Integer> x, Var<Integer> y) {
+ return new OffsetConstraint(offset, x, y);
+ }
+
+ public static <T> Constraint same(Var<T> x, Var<T> y) {
+ return new SameConstraint<T>(x, y);
+ }
+
+ public static Constraint sum(Var<Integer> x, Var<Integer> y, Var<Integer> z) {
+ return new SumConstraint(x, y, z);
+ }
+
+ public static <T extends Comparable<T>> Constraint lessThan(Var<T> x, Var<T> y) {
+ return new LessThan<T>(false, x, y);
+ }
+
+ public static <T extends Comparable<T>> Constraint lessThanEq(Var<T> x, Var<T> y) {
+ return new LessThan<T>(true, x, y);
+ }
+}