5Q3SORE3SJYL2W7UQLQPK2XQAHQJ4CHN7FYJTYXDR2M7MPXEPABQC
ZUIY422H4XJARH5I366XA4WXHY72VFMGJJPL4T6BIXBH6OHY4USAC
PBRYNWYOTORTAAYHMNGLU5KNAS4T5FCSEIWM656VQ7IZJ6P7NQ3QC
F2NSN45RYCMFIJ4WVEKRTCORP2IEFSAWH3XNRAT2I55CNSBK6DUAC
PUEVD5LHJH2GUKOBNHZTGYW6YTIBZGE7AMAHPDMMGSCUQFULII2AC
JFVDXTQS6OZQWXXRQ3I4HC7BBFXWQUWQO56C7AXQ35PMWUQI2MKAC
KZKRGZBWLSKWVN6ZKDGGK6W6EAQLMSKUEJBVMMZ2UD3TZERZKS7QC
COS2T3FPTP6JB7UANIDCGVTW5T7HEAOSTNWI6JNVL6K3I6EOWJNQC
U3DDUM6PNGQS3342RSZVDTLLZNS55EPHFVI36GWXHAJ23P5PVPDQC
var $elm$core$Platform$Cmd$batch = _Platform_batch;
var $elm$core$Platform$Cmd$none = $elm$core$Platform$Cmd$batch(_List_Nil);
var $author$project$Queens$init = function (flags) {
return _Utils_Tuple2(
{fixedQueens: $elm$core$Set$empty, id: 1, size: 8, solutionQueens: $elm$core$Set$empty, status: $elm$core$Maybe$Nothing},
$elm$core$Platform$Cmd$none);
};
var $elm$core$Platform$Sub$batch = _Platform_batch;
var $elm$core$Platform$Sub$none = $elm$core$Platform$Sub$batch(_List_Nil);
var $author$project$Queens$subscriptions = function (model) {
return $elm$core$Platform$Sub$none;
};
});
var $elm$core$List$filter = F2(
function (isGood, list) {
return A3(
$elm$core$List$foldr,
F2(
function (x, xs) {
return isGood(x) ? A2($elm$core$List$cons, x, xs) : xs;
}),
_List_Nil,
list);
});
var $elm$core$Dict$foldl = F3(
function (func, acc, dict) {
foldl:
while (true) {
if (dict.$ === 'RBEmpty_elm_builtin') {
return acc;
} else {
var key = dict.b;
var value = dict.c;
var left = dict.d;
var right = dict.e;
var $temp$func = func,
$temp$acc = A3(
func,
key,
value,
A3($elm$core$Dict$foldl, func, acc, left)),
$temp$dict = right;
func = $temp$func;
acc = $temp$acc;
dict = $temp$dict;
continue foldl;
}
}
var $elm$core$Dict$filter = F2(
function (isGood, dict) {
return A3(
$elm$core$Dict$foldl,
F3(
function (k, v, d) {
return A2(isGood, k, v) ? A3($elm$core$Dict$insert, k, v, d) : d;
}),
$elm$core$Dict$empty,
dict);
});
var $elm$core$Set$filter = F2(
function (isGood, _v0) {
var dict = _v0.a;
return $elm$core$Set$Set_elm_builtin(
A2(
$elm$core$Dict$filter,
F2(
function (key, _v1) {
return isGood(key);
}),
dict));
});
var $elm$core$Set$insert = F2(
function (key, _v0) {
var dict = _v0.a;
return $elm$core$Set$Set_elm_builtin(
A3($elm$core$Dict$insert, key, _Utils_Tuple0, dict));
});
var $elm$core$Set$fromList = function (list) {
return A3($elm$core$List$foldl, $elm$core$Set$insert, $elm$core$Set$empty, list);
};
};
var $elm$json$Json$Decode$field = _Json_decodeField;
var $elm$json$Json$Decode$int = _Json_decodeInt;
var $elm$json$Json$Decode$list = _Json_decodeList;
var $elm$core$Basics$negate = function (n) {
return -n;
};
var $author$project$Queens$solutionDecoder = function () {
var listToTuple = function (l) {
if (l.b && l.b.b) {
var x = l.a;
var _v1 = l.b;
var y = _v1.a;
var xs = _v1.b;
return _Utils_Tuple2(x, y);
} else {
return _Utils_Tuple2(-1, -1);
}
};
return A2(
$elm$json$Json$Decode$field,
'queens',
$elm$json$Json$Decode$list(
A2(
$elm$json$Json$Decode$map,
listToTuple,
$elm$json$Json$Decode$list($elm$json$Json$Decode$int))));
}();
var $author$project$Queens$formatQueen = function (_v0) {
var i = _v0.a;
var j = _v0.b;
return '&queen=' + ($elm$core$String$fromInt(i) + (':' + $elm$core$String$fromInt(j)));
};
var $author$project$Queens$solveUrl = function (m) {
return 'solve?id=1&size=' + ($elm$core$String$fromInt(m.size) + A3(
$elm$core$List$foldl,
$elm$core$Basics$append,
'',
A2(
$elm$core$List$map,
$author$project$Queens$formatQueen,
$elm$core$Set$toList(m.fixedQueens))));
};
var $author$project$Queens$requestSolution = function (m) {
return $elm$http$Http$get(
{
expect: A2($elm$http$Http$expectJson, $author$project$Queens$ReceivedSolution, $author$project$Queens$solutionDecoder),
url: $author$project$Queens$solveUrl(m)
});
};
var $author$project$Queens$init = function (flags) {
var model = {fixedQueens: $elm$core$Set$empty, id: 1, size: 8, solutionQueens: $elm$core$Set$empty, status: $elm$core$Maybe$Nothing};
return _Utils_Tuple2(
model,
$author$project$Queens$requestSolution(model));
};
var $elm$core$Platform$Sub$batch = _Platform_batch;
var $elm$core$Platform$Sub$none = $elm$core$Platform$Sub$batch(_List_Nil);
var $author$project$Queens$subscriptions = function (model) {
return $elm$core$Platform$Sub$none;
};
var $author$project$Queens$Solved = {$: 'Solved'};
var $author$project$Queens$Unsolvable = {$: 'Unsolvable'};
var $elm$core$List$filter = F2(
function (isGood, list) {
return A3(
$elm$core$List$foldr,
F2(
function (x, xs) {
return isGood(x) ? A2($elm$core$List$cons, x, xs) : xs;
}),
_List_Nil,
list);
});
var $elm$core$Dict$foldl = F3(
function (func, acc, dict) {
foldl:
while (true) {
if (dict.$ === 'RBEmpty_elm_builtin') {
return acc;
} else {
var key = dict.b;
var value = dict.c;
var left = dict.d;
var right = dict.e;
var $temp$func = func,
$temp$acc = A3(
func,
key,
value,
A3($elm$core$Dict$foldl, func, acc, left)),
$temp$dict = right;
func = $temp$func;
acc = $temp$acc;
dict = $temp$dict;
continue foldl;
}
}
});
var $elm$core$Dict$filter = F2(
function (isGood, dict) {
return A3(
$elm$core$Dict$foldl,
F3(
function (k, v, d) {
return A2(isGood, k, v) ? A3($elm$core$Dict$insert, k, v, d) : d;
}),
$elm$core$Dict$empty,
dict);
});
var $elm$core$Set$filter = F2(
function (isGood, _v0) {
var dict = _v0.a;
return $elm$core$Set$Set_elm_builtin(
A2(
$elm$core$Dict$filter,
F2(
function (key, _v1) {
return isGood(key);
}),
dict));
});
var $elm$core$Set$insert = F2(
function (key, _v0) {
var dict = _v0.a;
return $elm$core$Set$Set_elm_builtin(
A3($elm$core$Dict$insert, key, _Utils_Tuple0, dict));
});
var $elm$core$Set$fromList = function (list) {
return A3($elm$core$List$foldl, $elm$core$Set$insert, $elm$core$Set$empty, list);
var $elm$json$Json$Decode$field = _Json_decodeField;
var $elm$json$Json$Decode$int = _Json_decodeInt;
var $elm$json$Json$Decode$list = _Json_decodeList;
var $elm$core$Basics$negate = function (n) {
return -n;
};
var $author$project$Queens$solutionDecoder = function () {
var listToTuple = function (l) {
if (l.b && l.b.b) {
var x = l.a;
var _v1 = l.b;
var y = _v1.a;
var xs = _v1.b;
return _Utils_Tuple2(x, y);
} else {
return _Utils_Tuple2(-1, -1);
}
};
return A2(
$elm$json$Json$Decode$field,
'queens',
$elm$json$Json$Decode$list(
A2(
$elm$json$Json$Decode$map,
listToTuple,
$elm$json$Json$Decode$list($elm$json$Json$Decode$int))));
}();
var formatQueen = function (_v3) {
var i = _v3.a;
var j = _v3.b;
return '&queen=' + ($elm$core$String$fromInt(i) + (':' + $elm$core$String$fromInt(j)));
};
var solveUrl = function (m) {
return 'solve?id=1&size=' + ($elm$core$String$fromInt(m.size) + A3(
$elm$core$List$foldl,
$elm$core$Basics$append,
'',
A2(
$elm$core$List$map,
formatQueen,
$elm$core$Set$toList(m.fixedQueens))));
};
var requestSolution = function (m) {
return $elm$http$Http$get(
{
expect: A2($elm$http$Http$expectJson, $author$project$Queens$ReceivedSolution, $author$project$Queens$solutionDecoder),
url: solveUrl(m)
});
};
var $author$project$Queens$isAttacked = F2(
function (queens, square) {
var isAttackedBy = F2(
function (_v1, _v2) {
var qX = _v1.a;
var qY = _v1.b;
var sX = _v2.a;
var sY = _v2.b;
return (_Utils_eq(qX, sX) && _Utils_eq(qY, sY)) ? false : (_Utils_eq(qX, sX) ? true : (_Utils_eq(qY, sY) ? true : ((_Utils_eq(qX - qY, sX - sY) || _Utils_eq(qY + qX, sY + sX)) ? true : false)));
});
if (!queens.b) {
return false;
} else {
var x = queens.a;
var xs = queens.b;
return A2(isAttackedBy, x, square) || A2($author$project$Queens$isAttacked, xs, square);
}
});
$elm$svg$Svg$Attributes$x(
$elm$core$String$fromInt(i * w)),
$elm$svg$Svg$Attributes$y(
$elm$core$String$fromInt(j * w)),
$elm$svg$Svg$Attributes$width(
$elm$core$String$fromInt(w)),
$elm$svg$Svg$Attributes$height(
$elm$core$String$fromInt(w)),
$elm$svg$Svg$Attributes$fill(
(A2($elm$core$Basics$modBy, 2, i + j) === 1) ? 'lightblue' : 'white'),
$elm$svg$Svg$Events$onClick(
A2($author$project$Queens$AddQueen, i, j))
]),
_List_Nil);
A2(
$elm$svg$Svg$rect,
_List_fromArray(
[
$elm$svg$Svg$Attributes$x(
$elm$core$String$fromInt(i * w)),
$elm$svg$Svg$Attributes$y(
$elm$core$String$fromInt(j * w)),
$elm$svg$Svg$Attributes$width(
$elm$core$String$fromInt(w)),
$elm$svg$Svg$Attributes$height(
$elm$core$String$fromInt(w)),
$elm$svg$Svg$Attributes$fill(
(A2($elm$core$Basics$modBy, 2, i + j) === 1) ? 'lightblue' : 'white'),
$elm$svg$Svg$Events$onClick(
A2($author$project$Queens$AddQueen, i, j))
]),
_List_Nil),
A2(
$author$project$Queens$isAttacked,
$elm$core$Set$toList(model.fixedQueens),
_Utils_Tuple2(i, j)) ? A2(
$elm$svg$Svg$foreignObject,
_List_fromArray(
[
$elm$svg$Svg$Attributes$width(
$elm$core$String$fromInt(w)),
$elm$svg$Svg$Attributes$height(
$elm$core$String$fromInt(w)),
$elm$svg$Svg$Attributes$x(
$elm$core$String$fromInt(i * w)),
$elm$svg$Svg$Attributes$y(
$elm$core$String$fromInt(j * w))
]),
_List_fromArray(
[
A2(
$elm$html$Html$img,
_List_fromArray(
[
$elm$html$Html$Attributes$width(w),
$elm$html$Html$Attributes$height(w),
$elm$html$Html$Attributes$src('static/attacked.svg')
]),
_List_Nil)
])) : A2($elm$svg$Svg$svg, _List_Nil, _List_Nil)
]));
( { id = 1
, fixedQueens = Set.empty
, solutionQueens = Set.empty
, size = 8
, status = Nothing
}
, Cmd.none
)
let
model =
{ id = 1
, fixedQueens = Set.empty
, solutionQueens = Set.empty
, size = 8
, status = Nothing
}
in
( model, requestSolution model )
solveUrl m =
"solve?id=1&size="
++ String.fromInt m.size
++ (List.foldl (++) "" <| List.map formatQueen (Set.toList m.fixedQueens))
formatQueen (i,j) = "&queen=" ++ String.fromInt i ++ ":" ++ String.fromInt j
requestSolution m =
Http.get
{ url = solveUrl m
, expect = Http.expectJson ReceivedSolution solutionDecoder
}
let
solveUrl m =
"solve?id=1&size="
++ String.fromInt m.size
++ (List.foldl (++) "" <| List.map formatQueen (Set.toList m.fixedQueens))
formatQueen (i,j) = "&queen=" ++ String.fromInt i ++ ":" ++ String.fromInt j
requestSolution m =
Http.get
{ url = solveUrl m
, expect = Http.expectJson ReceivedSolution solutionDecoder
}
in
isAttacked : List (Int, Int) -> (Int, Int) -> Bool
isAttacked queens square =
let
isAttackedBy (qX, qY) (sX, sY) =
if qX == sX && qY == sY
then False
else if qX == sX
then True
else if qY == sY
then True
else if qX - qY == sX - sY || qY + qX == sY + sX
then True
else False
in
case queens of
[] -> False
(x::xs) -> isAttackedBy x square || isAttacked xs square
square (i,j) = Svg.rect
[ Attr.x <| String.fromInt (i * w)
, Attr.y <| String.fromInt (j * w)
, Attr.width <| String.fromInt w
, Attr.height <| String.fromInt w
, Attr.fill <| if modBy 2 (i+j) == 1 then "lightblue" else "white"
, Events.onClick (AddQueen i j)
]
[]
square (i,j) =
Svg.g
[]
[ Svg.rect
[ Attr.x <| String.fromInt (i * w)
, Attr.y <| String.fromInt (j * w)
, Attr.width <| String.fromInt w
, Attr.height <| String.fromInt w
, Attr.fill <| if modBy 2 (i+j) == 1 then "lightblue" else "white"
, Events.onClick (AddQueen i j)
]
[]
, if isAttacked (Set.toList model.fixedQueens) (i, j)
then
Svg.foreignObject
[ Attr.width <| String.fromInt w
, Attr.height <| String.fromInt w
, Attr.x <| String.fromInt (i * w)
, Attr.y <| String.fromInt (j * w)
]
(
[ img
[ HAttr.width w
, HAttr.height w
, src "static/attacked.svg"
]
[]
]
)
else
Svg.svg [] []
]