diff options
| author | Tom Harley | 2020-01-23 13:03:25 +0000 |
|---|---|---|
| committer | Tom Harley | 2020-01-23 13:03:25 +0000 |
| commit | f3d375722130e448802c046af2d75f66a06de498 (patch) | |
| tree | 0c82bd620be0401c6b9ba69c3314dfe0d9522eae /src/order-moves.eprime.m4 | |
| download | machinarium-master.tar.gz machinarium-master.zip | |
Diffstat (limited to 'src/order-moves.eprime.m4')
| -rw-r--r-- | src/order-moves.eprime.m4 | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/src/order-moves.eprime.m4 b/src/order-moves.eprime.m4 new file mode 100644 index 0000000..3bdc65e --- /dev/null +++ b/src/order-moves.eprime.m4 @@ -0,0 +1,76 @@ +language ESSENCE' 1.0 + +given initial_grid : matrix indexed by [int(1..n),int(1..n)] of int(0,1) + +letting fig = flatten(initial_grid) +letting spaces = (n * n) - sum(fig) + +find order : matrix indexed by [int(1..spaces)] of int(1..n*n) +find moves : matrix indexed by [int(1..spaces-1)] of int(-1,1,-n,n) + +ifdef(`optimise_moves', `dnl +find chdir : matrix indexed by [int(2..spaces-1)] of int(0,1) + +minimising sum(chdir) +')dnl + +such that + +ifdef(`optimise_moves', `dnl +forAll i: int(2..spaces-1) . + chdir[i] = 1 <-> moves[i-1] != moves[i], +')dnl + +allDiff(order), + +ifdef(`fill_all', `dnl +forAll i: int(1..n*n) . + fig[i] = 0 <-> exists j: int(1..spaces) . order[j] = i, +', `dnl +forAll i: int(1..spaces) . + fig[order[i]] != 1, +')dnl + +ifdef(`no_block_moves', `dnl +forAll i: int(1..spaces-1) . + fig[order[i] + moves[i]] != 1, +')dnl + +ifdef(`no_repeat_moves', `dnl +forAll i: int(2..spaces-1) . + forAll j: int(1..i-1) . + order[i] + moves[i] != order[j], +')dnl + +forAll i: int(1..spaces-1) . + order[i] + moves[i] = order[i+1], + +forAll i: int(1..spaces-1) . +ifdef(`up_down_bounds', `dnl + ((order[i] <= n) -> (moves[i] != -n)) /\ + ((order[i] > n * n - n) -> (moves[i] != n)) /\ +')dnl + ((order[i] % n = 1) -> (moves[i] != -1)) /\ + ((order[i] % n = 0) -> (moves[i] != 1)) /\ +true, + +ifdef(`opposite_move_check', `dnl +forAll i: int(2..spaces-1) . + moves[i] != -moves[i-1], + +')dnl +forAll i: int(2..spaces-1) . + (moves[i] = moves[i-1]) \/ + (fig[order[i] + moves[i-1]] = 1) \/ + (exists j: int(1..i-1) . order[i] + moves[i-1] = order[j]) \/ + (moves[i-1] = -n /\ order[i] <= n) \/ +ifdef(`throw_exception', `dnl + (moves[i-1] = n /\ order[i] > n * n - 1) \/ +', `dnl + (moves[i-1] = n /\ order[i] > n * n - n) \/ +')dnl + (moves[i-1] = -1 /\ order[i] % n = 1) \/ + (moves[i-1] = 1 /\ order[i] % n = 0) \/ +false, + +true |
