code vs. zombies 100%
This commit is contained in:
10
code_vs_zombies/.gitignore
vendored
Normal file
10
code_vs_zombies/.gitignore
vendored
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
/bower_components/
|
||||||
|
/node_modules/
|
||||||
|
/.pulp-cache/
|
||||||
|
/output/
|
||||||
|
/generated-docs/
|
||||||
|
/.psc-package/
|
||||||
|
/.psc*
|
||||||
|
/.purs*
|
||||||
|
/.psa*
|
||||||
|
/.spago
|
||||||
27
code_vs_zombies/.vscode/tasks.json
vendored
Normal file
27
code_vs_zombies/.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
||||||
|
// for the documentation about the tasks.json format
|
||||||
|
"version": "2.0.0",
|
||||||
|
"tasks": [
|
||||||
|
{
|
||||||
|
"label": "build_purescript",
|
||||||
|
"type": "shell",
|
||||||
|
"command": "spago bundle-app",
|
||||||
|
"presentation": {
|
||||||
|
"echo": true,
|
||||||
|
"focus": true,
|
||||||
|
"reveal": "silent"
|
||||||
|
},
|
||||||
|
"group": {
|
||||||
|
"kind": "build",
|
||||||
|
"isDefault": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "build_purescript_old",
|
||||||
|
"type": "shell",
|
||||||
|
"command": "spago bundle-app && sed -i \"$ d\" index.js && uglifyjs index.js --compress --mangle --output index.js",
|
||||||
|
"group": "build"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
797
code_vs_zombies/index.js
Normal file
797
code_vs_zombies/index.js
Normal file
@@ -0,0 +1,797 @@
|
|||||||
|
// Generated by purs bundle 0.13.6
|
||||||
|
var PS = {};
|
||||||
|
(function($PS) {
|
||||||
|
// Generated by purs version 0.13.6
|
||||||
|
"use strict";
|
||||||
|
$PS["Control.Semigroupoid"] = $PS["Control.Semigroupoid"] || {};
|
||||||
|
var exports = $PS["Control.Semigroupoid"];
|
||||||
|
var Semigroupoid = function (compose) {
|
||||||
|
this.compose = compose;
|
||||||
|
};
|
||||||
|
var semigroupoidFn = new Semigroupoid(function (f) {
|
||||||
|
return function (g) {
|
||||||
|
return function (x) {
|
||||||
|
return f(g(x));
|
||||||
|
};
|
||||||
|
};
|
||||||
|
});
|
||||||
|
var compose = function (dict) {
|
||||||
|
return dict.compose;
|
||||||
|
};
|
||||||
|
exports["compose"] = compose;
|
||||||
|
exports["semigroupoidFn"] = semigroupoidFn;
|
||||||
|
})(PS);
|
||||||
|
(function($PS) {
|
||||||
|
// Generated by purs version 0.13.6
|
||||||
|
"use strict";
|
||||||
|
$PS["Control.Category"] = $PS["Control.Category"] || {};
|
||||||
|
var exports = $PS["Control.Category"];
|
||||||
|
var Control_Semigroupoid = $PS["Control.Semigroupoid"];
|
||||||
|
var Category = function (Semigroupoid0, identity) {
|
||||||
|
this.Semigroupoid0 = Semigroupoid0;
|
||||||
|
this.identity = identity;
|
||||||
|
};
|
||||||
|
var identity = function (dict) {
|
||||||
|
return dict.identity;
|
||||||
|
};
|
||||||
|
var categoryFn = new Category(function () {
|
||||||
|
return Control_Semigroupoid.semigroupoidFn;
|
||||||
|
}, function (x) {
|
||||||
|
return x;
|
||||||
|
});
|
||||||
|
exports["identity"] = identity;
|
||||||
|
exports["categoryFn"] = categoryFn;
|
||||||
|
})(PS);
|
||||||
|
(function(exports) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// Array size ------------------------------------------------------------------
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
exports.length = function (xs) {
|
||||||
|
return xs.length;
|
||||||
|
};
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// Indexed operations ----------------------------------------------------------
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
exports.indexImpl = function (just) {
|
||||||
|
return function (nothing) {
|
||||||
|
return function (xs) {
|
||||||
|
return function (i) {
|
||||||
|
return i < 0 || i >= xs.length ? nothing : just(xs[i]);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// Sorting ---------------------------------------------------------------------
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
exports.sortImpl = function (f) {
|
||||||
|
return function (l) {
|
||||||
|
return l.slice().sort(function (x, y) {
|
||||||
|
return f(x)(y);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.drop = function (n) {
|
||||||
|
return function (l) {
|
||||||
|
return n < 1 ? l : l.slice(n);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
})(PS["Data.Array"] = PS["Data.Array"] || {});
|
||||||
|
(function($PS) {
|
||||||
|
// Generated by purs version 0.13.6
|
||||||
|
"use strict";
|
||||||
|
$PS["Data.Maybe"] = $PS["Data.Maybe"] || {};
|
||||||
|
var exports = $PS["Data.Maybe"];
|
||||||
|
var Control_Category = $PS["Control.Category"];
|
||||||
|
var Nothing = (function () {
|
||||||
|
function Nothing() {
|
||||||
|
|
||||||
|
};
|
||||||
|
Nothing.value = new Nothing();
|
||||||
|
return Nothing;
|
||||||
|
})();
|
||||||
|
var Just = (function () {
|
||||||
|
function Just(value0) {
|
||||||
|
this.value0 = value0;
|
||||||
|
};
|
||||||
|
Just.create = function (value0) {
|
||||||
|
return new Just(value0);
|
||||||
|
};
|
||||||
|
return Just;
|
||||||
|
})();
|
||||||
|
var maybe = function (v) {
|
||||||
|
return function (v1) {
|
||||||
|
return function (v2) {
|
||||||
|
if (v2 instanceof Nothing) {
|
||||||
|
return v;
|
||||||
|
};
|
||||||
|
if (v2 instanceof Just) {
|
||||||
|
return v1(v2.value0);
|
||||||
|
};
|
||||||
|
throw new Error("Failed pattern match at Data.Maybe (line 217, column 1 - line 217, column 51): " + [ v.constructor.name, v1.constructor.name, v2.constructor.name ]);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
var fromMaybe = function (a) {
|
||||||
|
return maybe(a)(Control_Category.identity(Control_Category.categoryFn));
|
||||||
|
};
|
||||||
|
exports["Nothing"] = Nothing;
|
||||||
|
exports["Just"] = Just;
|
||||||
|
exports["fromMaybe"] = fromMaybe;
|
||||||
|
})(PS);
|
||||||
|
(function($PS) {
|
||||||
|
// Generated by purs version 0.13.6
|
||||||
|
"use strict";
|
||||||
|
$PS["Data.Ordering"] = $PS["Data.Ordering"] || {};
|
||||||
|
var exports = $PS["Data.Ordering"];
|
||||||
|
var LT = (function () {
|
||||||
|
function LT() {
|
||||||
|
|
||||||
|
};
|
||||||
|
LT.value = new LT();
|
||||||
|
return LT;
|
||||||
|
})();
|
||||||
|
var GT = (function () {
|
||||||
|
function GT() {
|
||||||
|
|
||||||
|
};
|
||||||
|
GT.value = new GT();
|
||||||
|
return GT;
|
||||||
|
})();
|
||||||
|
var EQ = (function () {
|
||||||
|
function EQ() {
|
||||||
|
|
||||||
|
};
|
||||||
|
EQ.value = new EQ();
|
||||||
|
return EQ;
|
||||||
|
})();
|
||||||
|
exports["LT"] = LT;
|
||||||
|
exports["GT"] = GT;
|
||||||
|
exports["EQ"] = EQ;
|
||||||
|
})(PS);
|
||||||
|
(function($PS) {
|
||||||
|
// Generated by purs version 0.13.6
|
||||||
|
"use strict";
|
||||||
|
$PS["Data.Array"] = $PS["Data.Array"] || {};
|
||||||
|
var exports = $PS["Data.Array"];
|
||||||
|
var $foreign = $PS["Data.Array"];
|
||||||
|
var Data_Maybe = $PS["Data.Maybe"];
|
||||||
|
var Data_Ordering = $PS["Data.Ordering"];
|
||||||
|
var sortBy = function (comp) {
|
||||||
|
return function (xs) {
|
||||||
|
var comp$prime = function (x) {
|
||||||
|
return function (y) {
|
||||||
|
var v = comp(x)(y);
|
||||||
|
if (v instanceof Data_Ordering.GT) {
|
||||||
|
return 1;
|
||||||
|
};
|
||||||
|
if (v instanceof Data_Ordering.EQ) {
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
if (v instanceof Data_Ordering.LT) {
|
||||||
|
return -1 | 0;
|
||||||
|
};
|
||||||
|
throw new Error("Failed pattern match at Data.Array (line 702, column 15 - line 705, column 13): " + [ v.constructor.name ]);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
return $foreign.sortImpl(comp$prime)(xs);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
var index = $foreign.indexImpl(Data_Maybe.Just.create)(Data_Maybe.Nothing.value);
|
||||||
|
var head = function (xs) {
|
||||||
|
return index(xs)(0);
|
||||||
|
};
|
||||||
|
exports["head"] = head;
|
||||||
|
exports["sortBy"] = sortBy;
|
||||||
|
exports["length"] = $foreign.length;
|
||||||
|
exports["drop"] = $foreign.drop;
|
||||||
|
})(PS);
|
||||||
|
(function(exports) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var refEq = function (r1) {
|
||||||
|
return function (r2) {
|
||||||
|
return r1 === r2;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
exports.eqIntImpl = refEq;
|
||||||
|
})(PS["Data.Eq"] = PS["Data.Eq"] || {});
|
||||||
|
(function($PS) {
|
||||||
|
// Generated by purs version 0.13.6
|
||||||
|
"use strict";
|
||||||
|
$PS["Data.Eq"] = $PS["Data.Eq"] || {};
|
||||||
|
var exports = $PS["Data.Eq"];
|
||||||
|
var $foreign = $PS["Data.Eq"];
|
||||||
|
var Eq = function (eq) {
|
||||||
|
this.eq = eq;
|
||||||
|
};
|
||||||
|
var eqInt = new Eq($foreign.eqIntImpl);
|
||||||
|
exports["eqInt"] = eqInt;
|
||||||
|
})(PS);
|
||||||
|
(function(exports) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
exports.foldrArray = function (f) {
|
||||||
|
return function (init) {
|
||||||
|
return function (xs) {
|
||||||
|
var acc = init;
|
||||||
|
var len = xs.length;
|
||||||
|
for (var i = len - 1; i >= 0; i--) {
|
||||||
|
acc = f(xs[i])(acc);
|
||||||
|
}
|
||||||
|
return acc;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.foldlArray = function (f) {
|
||||||
|
return function (init) {
|
||||||
|
return function (xs) {
|
||||||
|
var acc = init;
|
||||||
|
var len = xs.length;
|
||||||
|
for (var i = 0; i < len; i++) {
|
||||||
|
acc = f(acc)(xs[i]);
|
||||||
|
}
|
||||||
|
return acc;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
})(PS["Data.Foldable"] = PS["Data.Foldable"] || {});
|
||||||
|
(function(exports) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
exports.arrayMap = function (f) {
|
||||||
|
return function (arr) {
|
||||||
|
var l = arr.length;
|
||||||
|
var result = new Array(l);
|
||||||
|
for (var i = 0; i < l; i++) {
|
||||||
|
result[i] = f(arr[i]);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
})(PS["Data.Functor"] = PS["Data.Functor"] || {});
|
||||||
|
(function($PS) {
|
||||||
|
// Generated by purs version 0.13.6
|
||||||
|
"use strict";
|
||||||
|
$PS["Data.Functor"] = $PS["Data.Functor"] || {};
|
||||||
|
var exports = $PS["Data.Functor"];
|
||||||
|
var $foreign = $PS["Data.Functor"];
|
||||||
|
var Control_Semigroupoid = $PS["Control.Semigroupoid"];
|
||||||
|
var Functor = function (map) {
|
||||||
|
this.map = map;
|
||||||
|
};
|
||||||
|
var map = function (dict) {
|
||||||
|
return dict.map;
|
||||||
|
};
|
||||||
|
var functorFn = new Functor(Control_Semigroupoid.compose(Control_Semigroupoid.semigroupoidFn));
|
||||||
|
var functorArray = new Functor($foreign.arrayMap);
|
||||||
|
exports["map"] = map;
|
||||||
|
exports["functorFn"] = functorFn;
|
||||||
|
exports["functorArray"] = functorArray;
|
||||||
|
})(PS);
|
||||||
|
(function($PS) {
|
||||||
|
// Generated by purs version 0.13.6
|
||||||
|
"use strict";
|
||||||
|
$PS["Data.Monoid"] = $PS["Data.Monoid"] || {};
|
||||||
|
var exports = $PS["Data.Monoid"];
|
||||||
|
var Monoid = function (Semigroup0, mempty) {
|
||||||
|
this.Semigroup0 = Semigroup0;
|
||||||
|
this.mempty = mempty;
|
||||||
|
};
|
||||||
|
var mempty = function (dict) {
|
||||||
|
return dict.mempty;
|
||||||
|
};
|
||||||
|
exports["Monoid"] = Monoid;
|
||||||
|
exports["mempty"] = mempty;
|
||||||
|
})(PS);
|
||||||
|
(function(exports) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
exports.boolConj = function (b1) {
|
||||||
|
return function (b2) {
|
||||||
|
return b1 && b2;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.boolDisj = function (b1) {
|
||||||
|
return function (b2) {
|
||||||
|
return b1 || b2;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.boolNot = function (b) {
|
||||||
|
return !b;
|
||||||
|
};
|
||||||
|
})(PS["Data.HeytingAlgebra"] = PS["Data.HeytingAlgebra"] || {});
|
||||||
|
(function($PS) {
|
||||||
|
// Generated by purs version 0.13.6
|
||||||
|
"use strict";
|
||||||
|
$PS["Data.HeytingAlgebra"] = $PS["Data.HeytingAlgebra"] || {};
|
||||||
|
var exports = $PS["Data.HeytingAlgebra"];
|
||||||
|
var $foreign = $PS["Data.HeytingAlgebra"];
|
||||||
|
var HeytingAlgebra = function (conj, disj, ff, implies, not, tt) {
|
||||||
|
this.conj = conj;
|
||||||
|
this.disj = disj;
|
||||||
|
this.ff = ff;
|
||||||
|
this.implies = implies;
|
||||||
|
this.not = not;
|
||||||
|
this.tt = tt;
|
||||||
|
};
|
||||||
|
var not = function (dict) {
|
||||||
|
return dict.not;
|
||||||
|
};
|
||||||
|
var ff = function (dict) {
|
||||||
|
return dict.ff;
|
||||||
|
};
|
||||||
|
var disj = function (dict) {
|
||||||
|
return dict.disj;
|
||||||
|
};
|
||||||
|
var heytingAlgebraBoolean = new HeytingAlgebra($foreign.boolConj, $foreign.boolDisj, false, function (a) {
|
||||||
|
return function (b) {
|
||||||
|
return disj(heytingAlgebraBoolean)(not(heytingAlgebraBoolean)(a))(b);
|
||||||
|
};
|
||||||
|
}, $foreign.boolNot, true);
|
||||||
|
exports["ff"] = ff;
|
||||||
|
exports["disj"] = disj;
|
||||||
|
exports["heytingAlgebraBoolean"] = heytingAlgebraBoolean;
|
||||||
|
})(PS);
|
||||||
|
(function($PS) {
|
||||||
|
// Generated by purs version 0.13.6
|
||||||
|
"use strict";
|
||||||
|
$PS["Data.Semigroup"] = $PS["Data.Semigroup"] || {};
|
||||||
|
var exports = $PS["Data.Semigroup"];
|
||||||
|
var Semigroup = function (append) {
|
||||||
|
this.append = append;
|
||||||
|
};
|
||||||
|
var append = function (dict) {
|
||||||
|
return dict.append;
|
||||||
|
};
|
||||||
|
exports["Semigroup"] = Semigroup;
|
||||||
|
exports["append"] = append;
|
||||||
|
})(PS);
|
||||||
|
(function($PS) {
|
||||||
|
// Generated by purs version 0.13.6
|
||||||
|
"use strict";
|
||||||
|
$PS["Data.Monoid.Disj"] = $PS["Data.Monoid.Disj"] || {};
|
||||||
|
var exports = $PS["Data.Monoid.Disj"];
|
||||||
|
var Data_HeytingAlgebra = $PS["Data.HeytingAlgebra"];
|
||||||
|
var Data_Monoid = $PS["Data.Monoid"];
|
||||||
|
var Data_Semigroup = $PS["Data.Semigroup"];
|
||||||
|
var Disj = function (x) {
|
||||||
|
return x;
|
||||||
|
};
|
||||||
|
var semigroupDisj = function (dictHeytingAlgebra) {
|
||||||
|
return new Data_Semigroup.Semigroup(function (v) {
|
||||||
|
return function (v1) {
|
||||||
|
return Data_HeytingAlgebra.disj(dictHeytingAlgebra)(v)(v1);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
|
var monoidDisj = function (dictHeytingAlgebra) {
|
||||||
|
return new Data_Monoid.Monoid(function () {
|
||||||
|
return semigroupDisj(dictHeytingAlgebra);
|
||||||
|
}, Data_HeytingAlgebra.ff(dictHeytingAlgebra));
|
||||||
|
};
|
||||||
|
exports["Disj"] = Disj;
|
||||||
|
exports["monoidDisj"] = monoidDisj;
|
||||||
|
})(PS);
|
||||||
|
(function($PS) {
|
||||||
|
// Generated by purs version 0.13.6
|
||||||
|
"use strict";
|
||||||
|
$PS["Data.Newtype"] = $PS["Data.Newtype"] || {};
|
||||||
|
var exports = $PS["Data.Newtype"];
|
||||||
|
var Data_Functor = $PS["Data.Functor"];
|
||||||
|
var Data_Monoid_Disj = $PS["Data.Monoid.Disj"];
|
||||||
|
var Newtype = function (unwrap, wrap) {
|
||||||
|
this.unwrap = unwrap;
|
||||||
|
this.wrap = wrap;
|
||||||
|
};
|
||||||
|
var wrap = function (dict) {
|
||||||
|
return dict.wrap;
|
||||||
|
};
|
||||||
|
var unwrap = function (dict) {
|
||||||
|
return dict.unwrap;
|
||||||
|
};
|
||||||
|
var newtypeDisj = new Newtype(function (v) {
|
||||||
|
return v;
|
||||||
|
}, Data_Monoid_Disj.Disj);
|
||||||
|
var alaF = function (dictFunctor) {
|
||||||
|
return function (dictFunctor1) {
|
||||||
|
return function (dictNewtype) {
|
||||||
|
return function (dictNewtype1) {
|
||||||
|
return function (v) {
|
||||||
|
return function (f) {
|
||||||
|
var $96 = Data_Functor.map(dictFunctor1)(unwrap(dictNewtype1));
|
||||||
|
var $97 = Data_Functor.map(dictFunctor)(wrap(dictNewtype));
|
||||||
|
return function ($98) {
|
||||||
|
return $96(f($97($98)));
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
exports["alaF"] = alaF;
|
||||||
|
exports["newtypeDisj"] = newtypeDisj;
|
||||||
|
})(PS);
|
||||||
|
(function($PS) {
|
||||||
|
// Generated by purs version 0.13.6
|
||||||
|
"use strict";
|
||||||
|
$PS["Data.Foldable"] = $PS["Data.Foldable"] || {};
|
||||||
|
var exports = $PS["Data.Foldable"];
|
||||||
|
var $foreign = $PS["Data.Foldable"];
|
||||||
|
var Data_Functor = $PS["Data.Functor"];
|
||||||
|
var Data_Monoid = $PS["Data.Monoid"];
|
||||||
|
var Data_Monoid_Disj = $PS["Data.Monoid.Disj"];
|
||||||
|
var Data_Newtype = $PS["Data.Newtype"];
|
||||||
|
var Data_Semigroup = $PS["Data.Semigroup"];
|
||||||
|
var Foldable = function (foldMap, foldl, foldr) {
|
||||||
|
this.foldMap = foldMap;
|
||||||
|
this.foldl = foldl;
|
||||||
|
this.foldr = foldr;
|
||||||
|
};
|
||||||
|
var foldr = function (dict) {
|
||||||
|
return dict.foldr;
|
||||||
|
};
|
||||||
|
var foldMapDefaultR = function (dictFoldable) {
|
||||||
|
return function (dictMonoid) {
|
||||||
|
return function (f) {
|
||||||
|
return foldr(dictFoldable)(function (x) {
|
||||||
|
return function (acc) {
|
||||||
|
return Data_Semigroup.append(dictMonoid.Semigroup0())(f(x))(acc);
|
||||||
|
};
|
||||||
|
})(Data_Monoid.mempty(dictMonoid));
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
var foldableArray = new Foldable(function (dictMonoid) {
|
||||||
|
return foldMapDefaultR(foldableArray)(dictMonoid);
|
||||||
|
}, $foreign.foldlArray, $foreign.foldrArray);
|
||||||
|
var foldMap = function (dict) {
|
||||||
|
return dict.foldMap;
|
||||||
|
};
|
||||||
|
var any = function (dictFoldable) {
|
||||||
|
return function (dictHeytingAlgebra) {
|
||||||
|
return Data_Newtype.alaF(Data_Functor.functorFn)(Data_Functor.functorFn)(Data_Newtype.newtypeDisj)(Data_Newtype.newtypeDisj)(Data_Monoid_Disj.Disj)(foldMap(dictFoldable)(Data_Monoid_Disj.monoidDisj(dictHeytingAlgebra)));
|
||||||
|
};
|
||||||
|
};
|
||||||
|
exports["any"] = any;
|
||||||
|
exports["foldableArray"] = foldableArray;
|
||||||
|
})(PS);
|
||||||
|
(function(exports) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
exports.fromNumberImpl = function (just) {
|
||||||
|
return function (nothing) {
|
||||||
|
return function (n) {
|
||||||
|
/* jshint bitwise: false */
|
||||||
|
return (n | 0) === n ? just(n) : nothing;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.toNumber = function (n) {
|
||||||
|
return n;
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.pow = function (x) {
|
||||||
|
return function (y) {
|
||||||
|
/* jshint bitwise: false */
|
||||||
|
return Math.pow(x,y) | 0;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
})(PS["Data.Int"] = PS["Data.Int"] || {});
|
||||||
|
(function($PS) {
|
||||||
|
// Generated by purs version 0.13.6
|
||||||
|
"use strict";
|
||||||
|
$PS["Data.Int"] = $PS["Data.Int"] || {};
|
||||||
|
var exports = $PS["Data.Int"];
|
||||||
|
var $foreign = $PS["Data.Int"];
|
||||||
|
var Data_Maybe = $PS["Data.Maybe"];
|
||||||
|
var fromNumber = $foreign.fromNumberImpl(Data_Maybe.Just.create)(Data_Maybe.Nothing.value);
|
||||||
|
exports["fromNumber"] = fromNumber;
|
||||||
|
exports["toNumber"] = $foreign.toNumber;
|
||||||
|
exports["pow"] = $foreign.pow;
|
||||||
|
})(PS);
|
||||||
|
(function(exports) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var unsafeCompareImpl = function (lt) {
|
||||||
|
return function (eq) {
|
||||||
|
return function (gt) {
|
||||||
|
return function (x) {
|
||||||
|
return function (y) {
|
||||||
|
return x < y ? lt : x === y ? eq : gt;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
exports.ordIntImpl = unsafeCompareImpl;
|
||||||
|
})(PS["Data.Ord"] = PS["Data.Ord"] || {});
|
||||||
|
(function($PS) {
|
||||||
|
// Generated by purs version 0.13.6
|
||||||
|
"use strict";
|
||||||
|
$PS["Data.Ord"] = $PS["Data.Ord"] || {};
|
||||||
|
var exports = $PS["Data.Ord"];
|
||||||
|
var $foreign = $PS["Data.Ord"];
|
||||||
|
var Data_Eq = $PS["Data.Eq"];
|
||||||
|
var Data_Ordering = $PS["Data.Ordering"];
|
||||||
|
var Ord = function (Eq0, compare) {
|
||||||
|
this.Eq0 = Eq0;
|
||||||
|
this.compare = compare;
|
||||||
|
};
|
||||||
|
var ordInt = new Ord(function () {
|
||||||
|
return Data_Eq.eqInt;
|
||||||
|
}, $foreign.ordIntImpl(Data_Ordering.LT.value)(Data_Ordering.EQ.value)(Data_Ordering.GT.value));
|
||||||
|
var compare = function (dict) {
|
||||||
|
return dict.compare;
|
||||||
|
};
|
||||||
|
exports["compare"] = compare;
|
||||||
|
exports["ordInt"] = ordInt;
|
||||||
|
})(PS);
|
||||||
|
(function(exports) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
exports.showIntImpl = function (n) {
|
||||||
|
return n.toString();
|
||||||
|
};
|
||||||
|
})(PS["Data.Show"] = PS["Data.Show"] || {});
|
||||||
|
(function($PS) {
|
||||||
|
// Generated by purs version 0.13.6
|
||||||
|
"use strict";
|
||||||
|
$PS["Data.Show"] = $PS["Data.Show"] || {};
|
||||||
|
var exports = $PS["Data.Show"];
|
||||||
|
var $foreign = $PS["Data.Show"];
|
||||||
|
var Show = function (show) {
|
||||||
|
this.show = show;
|
||||||
|
};
|
||||||
|
var showInt = new Show($foreign.showIntImpl);
|
||||||
|
var show = function (dict) {
|
||||||
|
return dict.show;
|
||||||
|
};
|
||||||
|
exports["Show"] = Show;
|
||||||
|
exports["show"] = show;
|
||||||
|
exports["showInt"] = showInt;
|
||||||
|
})(PS);
|
||||||
|
(function(exports) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
exports.log = function (s) {
|
||||||
|
return function () {
|
||||||
|
console.log(s);
|
||||||
|
return {};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
})(PS["Effect.Console"] = PS["Effect.Console"] || {});
|
||||||
|
(function($PS) {
|
||||||
|
// Generated by purs version 0.13.6
|
||||||
|
"use strict";
|
||||||
|
$PS["Effect.Console"] = $PS["Effect.Console"] || {};
|
||||||
|
var exports = $PS["Effect.Console"];
|
||||||
|
var $foreign = $PS["Effect.Console"];
|
||||||
|
exports["log"] = $foreign.log;
|
||||||
|
})(PS);
|
||||||
|
(function(exports) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
// module Math
|
||||||
|
|
||||||
|
exports.abs = Math.abs;
|
||||||
|
|
||||||
|
exports.sqrt = Math.sqrt;
|
||||||
|
})(PS["Math"] = PS["Math"] || {});
|
||||||
|
(function($PS) {
|
||||||
|
// Generated by purs version 0.13.6
|
||||||
|
"use strict";
|
||||||
|
$PS["Math"] = $PS["Math"] || {};
|
||||||
|
var exports = $PS["Math"];
|
||||||
|
var $foreign = $PS["Math"];
|
||||||
|
exports["abs"] = $foreign.abs;
|
||||||
|
exports["sqrt"] = $foreign.sqrt;
|
||||||
|
})(PS);
|
||||||
|
(function($PS) {
|
||||||
|
// Generated by purs version 0.13.6
|
||||||
|
"use strict";
|
||||||
|
$PS["Range"] = $PS["Range"] || {};
|
||||||
|
var exports = $PS["Range"];
|
||||||
|
var Data_Show = $PS["Data.Show"];
|
||||||
|
var Pos = (function () {
|
||||||
|
function Pos(value0, value1) {
|
||||||
|
this.value0 = value0;
|
||||||
|
this.value1 = value1;
|
||||||
|
};
|
||||||
|
Pos.create = function (value0) {
|
||||||
|
return function (value1) {
|
||||||
|
return new Pos(value0, value1);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
return Pos;
|
||||||
|
})();
|
||||||
|
var showPos = new Data_Show.Show(function (v) {
|
||||||
|
return Data_Show.show(Data_Show.showInt)(v.value0) + (" " + Data_Show.show(Data_Show.showInt)(v.value1));
|
||||||
|
});
|
||||||
|
exports["Pos"] = Pos;
|
||||||
|
exports["showPos"] = showPos;
|
||||||
|
})(PS);
|
||||||
|
(function($PS) {
|
||||||
|
// Generated by purs version 0.13.6
|
||||||
|
"use strict";
|
||||||
|
$PS["Lib"] = $PS["Lib"] || {};
|
||||||
|
var exports = $PS["Lib"];
|
||||||
|
var Data_Int = $PS["Data.Int"];
|
||||||
|
var Data_Maybe = $PS["Data.Maybe"];
|
||||||
|
var $$Math = $PS["Math"];
|
||||||
|
var Range = $PS["Range"];
|
||||||
|
var toPos = function (p) {
|
||||||
|
return new Range.Pos(p.x, p.y);
|
||||||
|
};
|
||||||
|
var sqrt = function (x) {
|
||||||
|
return Data_Maybe.fromMaybe(0)(Data_Int.fromNumber($$Math.sqrt(Data_Int.toNumber(x))));
|
||||||
|
};
|
||||||
|
var abs = function (x) {
|
||||||
|
return Data_Maybe.fromMaybe(0)(Data_Int.fromNumber($$Math.abs(Data_Int.toNumber(x))));
|
||||||
|
};
|
||||||
|
var dist = function (v) {
|
||||||
|
return function (v1) {
|
||||||
|
var b2 = Data_Int.pow(abs(v1.value1 - v.value1 | 0))(2);
|
||||||
|
var a2 = Data_Int.pow(abs(v1.value0 - v.value0 | 0))(2);
|
||||||
|
return sqrt(a2 + b2 | 0);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
exports["dist"] = dist;
|
||||||
|
exports["toPos"] = toPos;
|
||||||
|
})(PS);
|
||||||
|
(function(exports) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
exports.parseInput = function() {
|
||||||
|
var inputs = readline().split(' ');
|
||||||
|
var x = parseInt(inputs[0]);
|
||||||
|
var y = parseInt(inputs[1]);
|
||||||
|
var humanCount = parseInt(readline());
|
||||||
|
var humans = []
|
||||||
|
for (let i = 0; i < humanCount; i++) {
|
||||||
|
var inputs = readline().split(' ');
|
||||||
|
var humanId = parseInt(inputs[0]);
|
||||||
|
var humanX = parseInt(inputs[1]);
|
||||||
|
var humanY = parseInt(inputs[2]);
|
||||||
|
humans.push({
|
||||||
|
id: humanId,
|
||||||
|
x: humanX,
|
||||||
|
y: humanY,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
var zombieCount = parseInt(readline());
|
||||||
|
var zombies = []
|
||||||
|
for (let i = 0; i < zombieCount; i++) {
|
||||||
|
var inputs = readline().split(' ');
|
||||||
|
var zombieId = parseInt(inputs[0]);
|
||||||
|
var zombieX = parseInt(inputs[1]);
|
||||||
|
var zombieY = parseInt(inputs[2]);
|
||||||
|
var zombieXNext = parseInt(inputs[3]);
|
||||||
|
var zombieYNext = parseInt(inputs[4]);
|
||||||
|
zombies.push({
|
||||||
|
id: zombieId,
|
||||||
|
x: zombieX,
|
||||||
|
y: zombieY,
|
||||||
|
nextX: zombieXNext,
|
||||||
|
nextY: zombieYNext,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
player: { x, y },
|
||||||
|
humanCount,
|
||||||
|
zombieCount,
|
||||||
|
humans,
|
||||||
|
zombies,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
})(PS["Reader"] = PS["Reader"] || {});
|
||||||
|
(function($PS) {
|
||||||
|
// Generated by purs version 0.13.6
|
||||||
|
"use strict";
|
||||||
|
$PS["Reader"] = $PS["Reader"] || {};
|
||||||
|
var exports = $PS["Reader"];
|
||||||
|
var $foreign = $PS["Reader"];
|
||||||
|
exports["parseInput"] = $foreign.parseInput;
|
||||||
|
})(PS);
|
||||||
|
(function($PS) {
|
||||||
|
// Generated by purs version 0.13.6
|
||||||
|
"use strict";
|
||||||
|
$PS["Main"] = $PS["Main"] || {};
|
||||||
|
var exports = $PS["Main"];
|
||||||
|
var Data_Array = $PS["Data.Array"];
|
||||||
|
var Data_Foldable = $PS["Data.Foldable"];
|
||||||
|
var Data_Functor = $PS["Data.Functor"];
|
||||||
|
var Data_HeytingAlgebra = $PS["Data.HeytingAlgebra"];
|
||||||
|
var Data_Maybe = $PS["Data.Maybe"];
|
||||||
|
var Data_Ord = $PS["Data.Ord"];
|
||||||
|
var Data_Show = $PS["Data.Show"];
|
||||||
|
var Effect_Console = $PS["Effect.Console"];
|
||||||
|
var Lib = $PS["Lib"];
|
||||||
|
var Range = $PS["Range"];
|
||||||
|
var Reader = $PS["Reader"];
|
||||||
|
var loop$prime = function (player) {
|
||||||
|
return function (humans) {
|
||||||
|
return function (target) {
|
||||||
|
var targetAlive = (function () {
|
||||||
|
if (target instanceof Data_Maybe.Just) {
|
||||||
|
return Data_Foldable.any(Data_Foldable.foldableArray)(Data_HeytingAlgebra.heytingAlgebraBoolean)(function (h) {
|
||||||
|
return h.x === target.value0.value0 && h.y === target.value0.value1;
|
||||||
|
})(humans);
|
||||||
|
};
|
||||||
|
if (target instanceof Data_Maybe.Nothing) {
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
throw new Error("Failed pattern match at Main (line 44, column 23 - line 46, column 29): " + [ target.constructor.name ]);
|
||||||
|
})();
|
||||||
|
var playerPos = Lib.toPos(player);
|
||||||
|
var nearestHuman = Data_Array.sortBy(function (h1) {
|
||||||
|
return function (h2) {
|
||||||
|
return Data_Ord.compare(Data_Ord.ordInt)(Lib.dist(Lib.toPos(h1))(playerPos))(Lib.dist(Lib.toPos(h2))(playerPos));
|
||||||
|
};
|
||||||
|
})(humans);
|
||||||
|
var sndHuman = (function () {
|
||||||
|
var $5 = Data_Array.length(nearestHuman) > 1;
|
||||||
|
if ($5) {
|
||||||
|
return Data_Array.drop(1)(nearestHuman);
|
||||||
|
};
|
||||||
|
return nearestHuman;
|
||||||
|
})();
|
||||||
|
var target$prime = (function () {
|
||||||
|
if (target instanceof Data_Maybe.Just) {
|
||||||
|
if (targetAlive) {
|
||||||
|
return [ target.value0 ];
|
||||||
|
};
|
||||||
|
return Data_Functor.map(Data_Functor.functorArray)(Lib.toPos)(sndHuman);
|
||||||
|
};
|
||||||
|
if (target instanceof Data_Maybe.Nothing) {
|
||||||
|
var $9 = Data_Array.length(nearestHuman) === 2;
|
||||||
|
if ($9) {
|
||||||
|
return Data_Functor.map(Data_Functor.functorArray)(Lib.toPos)(sndHuman);
|
||||||
|
};
|
||||||
|
return Data_Functor.map(Data_Functor.functorArray)(Lib.toPos)(nearestHuman);
|
||||||
|
};
|
||||||
|
throw new Error("Failed pattern match at Main (line 27, column 19 - line 29, column 103): " + [ target.constructor.name ]);
|
||||||
|
})();
|
||||||
|
var pos = (function () {
|
||||||
|
var v = Data_Array.head(target$prime);
|
||||||
|
if (v instanceof Data_Maybe.Just) {
|
||||||
|
return v.value0;
|
||||||
|
};
|
||||||
|
if (v instanceof Data_Maybe.Nothing) {
|
||||||
|
return new Range.Pos(6000, 6000);
|
||||||
|
};
|
||||||
|
throw new Error("Failed pattern match at Main (line 31, column 15 - line 33, column 37): " + [ v.constructor.name ]);
|
||||||
|
})();
|
||||||
|
return function __do() {
|
||||||
|
Effect_Console.log(Data_Show.show(Range.showPos)(pos))();
|
||||||
|
return loop(new Data_Maybe.Just(pos))();
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
var loop = function (target) {
|
||||||
|
return function __do() {
|
||||||
|
var input = Reader.parseInput();
|
||||||
|
return loop$prime(input.player)(input.humans)(target)();
|
||||||
|
};
|
||||||
|
};
|
||||||
|
var main = loop(Data_Maybe.Nothing.value);
|
||||||
|
exports["main"] = main;
|
||||||
|
exports["loop"] = loop;
|
||||||
|
exports["loop'"] = loop$prime;
|
||||||
|
})(PS);
|
||||||
|
PS["Main"].main();
|
||||||
128
code_vs_zombies/packages.dhall
Normal file
128
code_vs_zombies/packages.dhall
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
{-
|
||||||
|
Welcome to your new Dhall package-set!
|
||||||
|
|
||||||
|
Below are instructions for how to edit this file for most use
|
||||||
|
cases, so that you don't need to know Dhall to use it.
|
||||||
|
|
||||||
|
## Warning: Don't Move This Top-Level Comment!
|
||||||
|
|
||||||
|
Due to how `dhall format` currently works, this comment's
|
||||||
|
instructions cannot appear near corresponding sections below
|
||||||
|
because `dhall format` will delete the comment. However,
|
||||||
|
it will not delete a top-level comment like this one.
|
||||||
|
|
||||||
|
## Use Cases
|
||||||
|
|
||||||
|
Most will want to do one or both of these options:
|
||||||
|
1. Override/Patch a package's dependency
|
||||||
|
2. Add a package not already in the default package set
|
||||||
|
|
||||||
|
This file will continue to work whether you use one or both options.
|
||||||
|
Instructions for each option are explained below.
|
||||||
|
|
||||||
|
### Overriding/Patching a package
|
||||||
|
|
||||||
|
Purpose:
|
||||||
|
- Change a package's dependency to a newer/older release than the
|
||||||
|
default package set's release
|
||||||
|
- Use your own modified version of some dependency that may
|
||||||
|
include new API, changed API, removed API by
|
||||||
|
using your custom git repo of the library rather than
|
||||||
|
the package set's repo
|
||||||
|
|
||||||
|
Syntax:
|
||||||
|
Replace the overrides' "{=}" (an empty record) with the following idea
|
||||||
|
The "//" or "⫽" means "merge these two records and
|
||||||
|
when they have the same value, use the one on the right:"
|
||||||
|
-------------------------------
|
||||||
|
let overrides =
|
||||||
|
{ packageName =
|
||||||
|
upstream.packageName // { updateEntity1 = "new value", updateEntity2 = "new value" }
|
||||||
|
, packageName =
|
||||||
|
upstream.packageName // { version = "v4.0.0" }
|
||||||
|
, packageName =
|
||||||
|
upstream.packageName // { repo = "https://www.example.com/path/to/new/repo.git" }
|
||||||
|
}
|
||||||
|
-------------------------------
|
||||||
|
|
||||||
|
Example:
|
||||||
|
-------------------------------
|
||||||
|
let overrides =
|
||||||
|
{ halogen =
|
||||||
|
upstream.halogen // { version = "master" }
|
||||||
|
, halogen-vdom =
|
||||||
|
upstream.halogen-vdom // { version = "v4.0.0" }
|
||||||
|
}
|
||||||
|
-------------------------------
|
||||||
|
|
||||||
|
### Additions
|
||||||
|
|
||||||
|
Purpose:
|
||||||
|
- Add packages that aren't already included in the default package set
|
||||||
|
|
||||||
|
Syntax:
|
||||||
|
Replace the additions' "{=}" (an empty record) with the following idea:
|
||||||
|
-------------------------------
|
||||||
|
let additions =
|
||||||
|
{ package-name =
|
||||||
|
{ dependencies =
|
||||||
|
[ "dependency1"
|
||||||
|
, "dependency2"
|
||||||
|
]
|
||||||
|
, repo =
|
||||||
|
"https://example.com/path/to/git/repo.git"
|
||||||
|
, version =
|
||||||
|
"tag ('v4.0.0') or branch ('master')"
|
||||||
|
}
|
||||||
|
, package-name =
|
||||||
|
{ dependencies =
|
||||||
|
[ "dependency1"
|
||||||
|
, "dependency2"
|
||||||
|
]
|
||||||
|
, repo =
|
||||||
|
"https://example.com/path/to/git/repo.git"
|
||||||
|
, version =
|
||||||
|
"tag ('v4.0.0') or branch ('master')"
|
||||||
|
}
|
||||||
|
, etc.
|
||||||
|
}
|
||||||
|
-------------------------------
|
||||||
|
|
||||||
|
Example:
|
||||||
|
-------------------------------
|
||||||
|
let additions =
|
||||||
|
{ benchotron =
|
||||||
|
{ dependencies =
|
||||||
|
[ "arrays"
|
||||||
|
, "exists"
|
||||||
|
, "profunctor"
|
||||||
|
, "strings"
|
||||||
|
, "quickcheck"
|
||||||
|
, "lcg"
|
||||||
|
, "transformers"
|
||||||
|
, "foldable-traversable"
|
||||||
|
, "exceptions"
|
||||||
|
, "node-fs"
|
||||||
|
, "node-buffer"
|
||||||
|
, "node-readline"
|
||||||
|
, "datetime"
|
||||||
|
, "now"
|
||||||
|
]
|
||||||
|
, repo =
|
||||||
|
"https://github.com/hdgarrood/purescript-benchotron.git"
|
||||||
|
, version =
|
||||||
|
"v7.0.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
-------------------------------
|
||||||
|
-}
|
||||||
|
|
||||||
|
|
||||||
|
let upstream =
|
||||||
|
https://github.com/purescript/package-sets/releases/download/psc-0.13.6-20200404/packages.dhall sha256:f239f2e215d0cbd5c203307701748581938f74c4c78f4aeffa32c11c131ef7b6
|
||||||
|
|
||||||
|
let overrides = {=}
|
||||||
|
|
||||||
|
let additions = {=}
|
||||||
|
|
||||||
|
in upstream // overrides // additions
|
||||||
17
code_vs_zombies/spago.dhall
Normal file
17
code_vs_zombies/spago.dhall
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
{-
|
||||||
|
Welcome to a Spago project!
|
||||||
|
You can edit this file as you like.
|
||||||
|
-}
|
||||||
|
{ name = "shadown_of_the_knight"
|
||||||
|
, dependencies =
|
||||||
|
[ "arrays"
|
||||||
|
, "console"
|
||||||
|
, "effect"
|
||||||
|
, "integers"
|
||||||
|
, "math"
|
||||||
|
, "psci-support"
|
||||||
|
, "random"
|
||||||
|
]
|
||||||
|
, packages = ./packages.dhall
|
||||||
|
, sources = [ "src/**/*.purs", "test/**/*.purs" ]
|
||||||
|
}
|
||||||
35
code_vs_zombies/src/Lib.purs
Normal file
35
code_vs_zombies/src/Lib.purs
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
module Lib where
|
||||||
|
|
||||||
|
import Prelude
|
||||||
|
|
||||||
|
import Data.Int (fromNumber, pow, toNumber)
|
||||||
|
import Data.Maybe (fromMaybe)
|
||||||
|
import Math as M
|
||||||
|
import Range (Area(..), Pos(..), Range(..))
|
||||||
|
|
||||||
|
maxPos :: Pos -> Int
|
||||||
|
maxPos (Pos x y) = max x y
|
||||||
|
|
||||||
|
minPos :: Pos -> Int
|
||||||
|
minPos (Pos x y) = min x y
|
||||||
|
|
||||||
|
getMiddlePos :: Area -> Pos
|
||||||
|
getMiddlePos (Area (Range x1 x2) (Range y1 y2)) = Pos x y
|
||||||
|
where
|
||||||
|
x = abs (x1 + x2) / 2
|
||||||
|
y = abs (y1 + y2) / 2
|
||||||
|
|
||||||
|
abs :: Int -> Int
|
||||||
|
abs x = fromMaybe 0 $ fromNumber $ M.abs $ toNumber x
|
||||||
|
|
||||||
|
sqrt :: Int -> Int
|
||||||
|
sqrt x = fromMaybe 0 $ fromNumber $ M.sqrt $ toNumber x
|
||||||
|
|
||||||
|
dist :: Pos -> Pos -> Int
|
||||||
|
dist (Pos x1 y1) (Pos x2 y2) = sqrt $ a2 + b2
|
||||||
|
where
|
||||||
|
a2 = abs (x2 - x1) `pow` 2
|
||||||
|
b2 = abs (y2 - y1) `pow` 2
|
||||||
|
|
||||||
|
toPos :: forall e. { x :: Int, y :: Int | e } -> Pos
|
||||||
|
toPos p = Pos p.x p.y
|
||||||
47
code_vs_zombies/src/Main.purs
Normal file
47
code_vs_zombies/src/Main.purs
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
module Main where
|
||||||
|
|
||||||
|
import Prelude
|
||||||
|
|
||||||
|
import Data.Array (any, drop, head, length, sortBy)
|
||||||
|
import Data.Maybe (Maybe(..))
|
||||||
|
import Effect (Effect)
|
||||||
|
import Effect.Console (log)
|
||||||
|
import Lib (dist, toPos)
|
||||||
|
import Range (Pos(..))
|
||||||
|
import Reader (Player, Human, parseInput)
|
||||||
|
|
||||||
|
main :: Effect Unit
|
||||||
|
main = do
|
||||||
|
loop Nothing
|
||||||
|
|
||||||
|
loop :: Maybe Pos -> Effect Unit
|
||||||
|
loop target = do
|
||||||
|
input <- parseInput
|
||||||
|
loop' input.player input.humans target
|
||||||
|
|
||||||
|
loop' :: Player -> Array Human -> Maybe Pos -> Effect Unit
|
||||||
|
loop' player humans target = do
|
||||||
|
let nearestHuman = sortBy (\h1 h2 -> compare (dist (toPos h1) playerPos) (dist (toPos h2) playerPos)) humans
|
||||||
|
let sndHuman = if length nearestHuman > 1 then drop 1 nearestHuman else nearestHuman
|
||||||
|
|
||||||
|
let target' = case target of
|
||||||
|
Just t -> if targetAlive then [t] else map toPos sndHuman
|
||||||
|
Nothing -> if length nearestHuman == 2 then map toPos sndHuman else map toPos nearestHuman
|
||||||
|
|
||||||
|
let pos = case head target' of
|
||||||
|
Just p -> p
|
||||||
|
Nothing -> Pos 6000 6000
|
||||||
|
|
||||||
|
log $ show pos
|
||||||
|
|
||||||
|
loop $ Just pos
|
||||||
|
|
||||||
|
where
|
||||||
|
playerPos :: Pos
|
||||||
|
playerPos = toPos player
|
||||||
|
|
||||||
|
targetAlive :: Boolean
|
||||||
|
targetAlive = case target of
|
||||||
|
Just (Pos tx ty) -> any (\h -> h.x == tx && h.y == ty) humans
|
||||||
|
Nothing -> false
|
||||||
|
|
||||||
26
code_vs_zombies/src/Ruler.purs
Normal file
26
code_vs_zombies/src/Ruler.purs
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
module Range
|
||||||
|
( Area(..)
|
||||||
|
, Pos(..)
|
||||||
|
, Range(..)
|
||||||
|
, range
|
||||||
|
) where
|
||||||
|
|
||||||
|
import Prelude
|
||||||
|
|
||||||
|
-- data Building = Building Int Int
|
||||||
|
data Pos = Pos Int Int
|
||||||
|
data Area = Area Range Range
|
||||||
|
|
||||||
|
instance showPos :: Show Pos where
|
||||||
|
show (Pos x y) = show x <> " " <> show y
|
||||||
|
|
||||||
|
instance showRange :: Show Range where
|
||||||
|
show (Range x y) = show x <> "-" <> show y
|
||||||
|
|
||||||
|
instance showArea :: Show Area where
|
||||||
|
show (Area r1 r2) = show r1 <> " / " <> show r2
|
||||||
|
|
||||||
|
data Range = Range Int Int
|
||||||
|
|
||||||
|
range :: Int -> Int -> Range
|
||||||
|
range x y = Range (min x y) (max x y)
|
||||||
47
code_vs_zombies/src/ffi/Reader.js
Normal file
47
code_vs_zombies/src/ffi/Reader.js
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
exports.readline = readline
|
||||||
|
|
||||||
|
exports.parseInput = function() {
|
||||||
|
var inputs = readline().split(' ');
|
||||||
|
var x = parseInt(inputs[0]);
|
||||||
|
var y = parseInt(inputs[1]);
|
||||||
|
var humanCount = parseInt(readline());
|
||||||
|
var humans = []
|
||||||
|
for (let i = 0; i < humanCount; i++) {
|
||||||
|
var inputs = readline().split(' ');
|
||||||
|
var humanId = parseInt(inputs[0]);
|
||||||
|
var humanX = parseInt(inputs[1]);
|
||||||
|
var humanY = parseInt(inputs[2]);
|
||||||
|
humans.push({
|
||||||
|
id: humanId,
|
||||||
|
x: humanX,
|
||||||
|
y: humanY,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
var zombieCount = parseInt(readline());
|
||||||
|
var zombies = []
|
||||||
|
for (let i = 0; i < zombieCount; i++) {
|
||||||
|
var inputs = readline().split(' ');
|
||||||
|
var zombieId = parseInt(inputs[0]);
|
||||||
|
var zombieX = parseInt(inputs[1]);
|
||||||
|
var zombieY = parseInt(inputs[2]);
|
||||||
|
var zombieXNext = parseInt(inputs[3]);
|
||||||
|
var zombieYNext = parseInt(inputs[4]);
|
||||||
|
zombies.push({
|
||||||
|
id: zombieId,
|
||||||
|
x: zombieX,
|
||||||
|
y: zombieY,
|
||||||
|
nextX: zombieXNext,
|
||||||
|
nextY: zombieYNext,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
player: { x, y },
|
||||||
|
humanCount,
|
||||||
|
zombieCount,
|
||||||
|
humans,
|
||||||
|
zombies,
|
||||||
|
}
|
||||||
|
};
|
||||||
34
code_vs_zombies/src/ffi/Reader.purs
Normal file
34
code_vs_zombies/src/ffi/Reader.purs
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
module Reader where
|
||||||
|
|
||||||
|
import Effect (Effect)
|
||||||
|
|
||||||
|
type Player =
|
||||||
|
{ x :: Int
|
||||||
|
, y :: Int
|
||||||
|
}
|
||||||
|
|
||||||
|
type Human =
|
||||||
|
{ id :: Int
|
||||||
|
, x :: Int
|
||||||
|
, y :: Int
|
||||||
|
}
|
||||||
|
|
||||||
|
type Zombie =
|
||||||
|
{ id :: Int
|
||||||
|
, x :: Int
|
||||||
|
, y :: Int
|
||||||
|
, nextX :: Int
|
||||||
|
, nextY :: Int
|
||||||
|
}
|
||||||
|
|
||||||
|
type GameInput =
|
||||||
|
{ player :: Player
|
||||||
|
, humanCount :: Int
|
||||||
|
, zombieCount :: Int
|
||||||
|
, humans :: Array Human
|
||||||
|
, zombies :: Array Zombie
|
||||||
|
}
|
||||||
|
|
||||||
|
foreign import parseInput :: Effect GameInput
|
||||||
|
|
||||||
|
foreign import readline :: Effect String
|
||||||
19
code_vs_zombies/test/Main.purs
Normal file
19
code_vs_zombies/test/Main.purs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
module Test.Main where
|
||||||
|
|
||||||
|
import Prelude
|
||||||
|
|
||||||
|
import Effect (Effect)
|
||||||
|
import Effect.Console (log)
|
||||||
|
|
||||||
|
|
||||||
|
main :: Effect Unit
|
||||||
|
main = do
|
||||||
|
let input = {
|
||||||
|
x: 20,
|
||||||
|
y: 20,
|
||||||
|
width: 100,
|
||||||
|
height: 100,
|
||||||
|
turns: 50
|
||||||
|
}
|
||||||
|
-- loop input $ calcWindows input
|
||||||
|
log "hi"
|
||||||
7
code_vs_zombies/workspace.code-workspace
Normal file
7
code_vs_zombies/workspace.code-workspace
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"folders": [
|
||||||
|
{
|
||||||
|
"path": "."
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user