Skip to content
Snippets Groups Projects
Commit 37221d3d authored by Michael Leuschel's avatar Michael Leuschel
Browse files

add new queens visualisations

parent 92facf33
No related branches found
No related tags found
No related merge requests found
MACHINE QueensWithEvents
CONSTANTS n
PROPERTIES
n : NATURAL &
n < 121
DEFINITIONS
SET_PREF_TIME_OUT == 6000;
SET_PREF_CLPFD == TRUE;
SET_PREF_MAX_INITIALISATIONS == 121;
SET_PREF_MAX_OPERATIONS == 10;
MAX_OPERATIONS_SetQueen == 1000;
MAX_OPERATIONS_ChangeQueen == 1000;
MAX_OPERATIONS_SolveAny == 4;
is_attacked(q1) == q1:dom(queens) &
#q2.(q2:dom(queens) & q2 /= q1 &
(no_attack(q1,q2,queens) => queens(q1) = queens(q2)));
pos_is_attacked(q1,q1row) ==
#q2.(q2:dom(queens) & q2 /= q1 &
(no_attack_pos(q1,q1row,q2,queens(q2)) => q1row = queens(q2)));
no_attack(q1,q2,board) == no_attack_pos(q1,board(q1),q2,board(q2));
no_attack_pos(q1,q1row,q2,q2row) == (q1row+q2-q1 /= q2row & q1row-q2+q1 /= q2row);
Solution(board) == (
board : perm(1..n) /* for each column the row in which the queen is in */
&
!(q1,q2).(q1:1..n & q2:2..n & q2>q1 => no_attack(q1,q2,board) )
)
VARIABLES queens
INVARIANT
queens : (1..n) +-> (1..n)
INITIALISATION
queens := {}
OPERATIONS
Solve = ANY solution WHERE
Solution(solution) &
!x.(x:dom(queens) => solution(x)=queens(x))
THEN
queens := solution
END;
SolveFuzzy = ANY solution WHERE
Solution(solution) &
!x.(x:dom(queens) => solution(x):{queens(x)-1,queens(x),queens(x)+1})
THEN
queens := solution
END;
SetQueen(i,j) = SELECT i:1..n & j:1..n & i /: dom(queens) THEN
queens(i) := j
END;
ChangeQueen(i,j) = SELECT i:1..n & j:1..n & i : dom(queens) & j /= queens(i) THEN
queens(i) := j
END;
TryQueen(i,j) = PRE i:1..n & j:1..n THEN
IF i /: dom(queens) THEN
SELECT i:1..n & j:1..n & i /: dom(queens) THEN
queens(i) := j
END ELSE
SELECT i:1..n & j:1..n & i : dom(queens) & j /= queens(i) THEN
queens(i) := j
END
END
END;
r<--Get(yy) = PRE yy:dom(queens) THEN r:= queens(yy) END
END
\ No newline at end of file
{
"svg":"queens_120.svg",
"items": [
{
"for": {"from":1, "to":120},
"id": "svgQueen%0",
"attr": "visibility",
"value" : "IF %0:dom(queens) THEN \"visible\" ELSE \"hidden\" END"
},
{
"for": {"from":1, "to":120},
"id": "svgQueen%0",
"attr": "y",
"value" :"IF %0:dom(queens) THEN 45*queens(%0)-45 ELSE 0 END"
},
{
"for": {"from":1, "to":120},
"id": "svgQueen%0",
"attr": "fill",
"value" : "IF is_attacked(%0) & %0:dom(queens) THEN \"red\" ELSE \"black\" END"
},
{
"for": {"from":1, "to":120},
"id": "gTiles%0",
"attr": "visibility",
"value" : "IF %0<=n THEN \"visible\" ELSE \"hidden\" END"
}
],
"events": [
{
"for": {"from":1, "to":120},
"repeat": [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,
41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,
61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,
81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,
101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120],
"id": "tile%1x%0",
"event": "TryQueen",
"predicates" : ["i=%1","j=%0"]
}
]
}
This diff is collapsed.
{
"svg":"queens_20.svg",
"items": [
{
"for": {"from":1, "to":20},
"id": "svgQueen%0",
"attr": "visibility",
"value" : "IF %0:dom(queens) THEN \"visible\" ELSE \"hidden\" END"
},
{
"for": {"from":1, "to":20},
"id": "svgQueen%0",
"attr": "y",
"value" :"IF %0:dom(queens) THEN 45*queens(%0)-45 ELSE 0 END"
},
{
"for": {"from":1, "to":20},
"id": "svgQueen%0",
"attr": "fill",
"value" : "IF is_attacked(%0) & %0:dom(queens) THEN \"red\" ELSE \"black\" END"
},
{
"for": {"from":1, "to":20},
"id": "gTiles%0",
"attr": "visibility",
"value" : "IF %0<=n THEN \"visible\" ELSE \"hidden\" END"
}
],
"events": [
{
"repeat": [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20],
"for": {"from":1, "to":20},
"id": "tile%1x%0",
"event": "TryQueen",
"predicates" : ["i=%1","j=%0"]
}
]
}
This diff is collapsed.
{
"svg":"queens_8.svg",
"items": [
{
"for": {"from":1, "to":8},
"id": "svgQueen%0",
"attr": "visibility",
"value" : "IF %0:dom(queens) THEN \"visible\" ELSE \"hidden\" END"
},
{
"for": {"from":1, "to":8},
"id": "svgQueen%0",
"attr": "y",
"value" :"IF %0:dom(queens) THEN 45*queens(%0)-45 ELSE 0 END"
},
{
"for": {"from":1, "to":8},
"id": "svgQueen%0",
"attr": "fill",
"value" : "IF is_attacked(%0) & %0:dom(queens) THEN \"red\" ELSE \"black\" END"
},
{
"for": {"from":1, "to":8},
"id": "gTiles%0",
"attr": "visibility",
"value" : "IF %0<=n THEN \"visible\" ELSE \"hidden\" END"
}
],
"events": [
{
"id": "tile%0x%1",
"event": "TryQueen",
"predicates" : ["i=%0","j=%1"],
"repeat": [
["1", "1"], ["1", "2"], ["1", "3"],["1", "4"], ["1", "5"], ["1", "6"], ["1", "7"], ["1", "8"],
["2", "1"], ["2", "2"], ["2", "3"],["2", "4"], ["2", "5"], ["2", "6"], ["2", "7"], ["2", "8"],
["3", "1"], ["3", "2"], ["3", "3"],["3", "4"], ["3", "5"], ["3", "6"], ["3", "7"], ["3", "8"],
["4", "1"], ["4", "2"], ["4", "3"],["4", "4"], ["4", "5"], ["4", "6"], ["4", "7"], ["4", "8"],
["5", "1"], ["5", "2"], ["5", "3"],["5", "4"], ["5", "5"], ["5", "6"], ["5", "7"], ["5", "8"],
["6", "1"], ["6", "2"], ["6", "3"],["6", "4"], ["6", "5"], ["6", "6"], ["6", "7"], ["6", "8"],
["7", "1"], ["7", "2"], ["7", "3"],["7", "4"], ["7", "5"], ["7", "6"], ["7", "7"], ["7", "8"],
["8", "1"], ["8", "2"], ["8", "3"],["8", "4"], ["8", "5"], ["8", "6"], ["8", "7"], ["8", "8"]
]
}
]
}
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment