From 3e8a95a6b1afaa4dba0173879e0f6e185c0384c0 Mon Sep 17 00:00:00 2001 From: weiss Date: Fri, 10 Apr 2020 05:24:09 +0200 Subject: [PATCH] - wood 1 - avoid - build archers and knights --- code_royal/.vscode/tasks.json | 5 +- code_royal/spago.dhall | 8 +- code_royal/src/Lib.purs | 7 +- code_royal/src/Main.purs | 131 ++++- code_royal/src/ffi/GameInput.purs | 15 +- code_vs_zombies/index.js | 797 ------------------------------ 6 files changed, 129 insertions(+), 834 deletions(-) delete mode 100644 code_vs_zombies/index.js diff --git a/code_royal/.vscode/tasks.json b/code_royal/.vscode/tasks.json index 1204ff6..800ccc9 100644 --- a/code_royal/.vscode/tasks.json +++ b/code_royal/.vscode/tasks.json @@ -15,12 +15,13 @@ "group": { "kind": "build", "isDefault": true - } + }, + "problemMatcher": [] }, { "label": "build_purescript_old", "type": "shell", - "command": "spago bundle-app && sed -i \"$ d\" index.js && uglifyjs index.js --compress --mangle --output index.js", + "command": "spago bundle-app && uglifyjs index.js --compress --mangle --output index.js", "group": "build" } ] diff --git a/code_royal/spago.dhall b/code_royal/spago.dhall index 2fea272..ab63ad2 100644 --- a/code_royal/spago.dhall +++ b/code_royal/spago.dhall @@ -3,13 +3,7 @@ Welcome to a Spago project! You can edit this file as you like. -} { name = "code_royal" -, dependencies = - [ "arrays" - , "console" - , "effect" - , "integers" - , "math" - ] +, dependencies = [ "arrays", "console", "effect", "integers", "math", "random" ] , packages = ./packages.dhall , sources = [ "src/**/*.purs", "test/**/*.purs" ] } diff --git a/code_royal/src/Lib.purs b/code_royal/src/Lib.purs index bb97ffe..4d6c37d 100644 --- a/code_royal/src/Lib.purs +++ b/code_royal/src/Lib.purs @@ -3,8 +3,9 @@ module Lib where import Prelude import Data.Int (fromNumber, pow, toNumber) -import Data.Maybe (fromMaybe) +import Data.Maybe (fromJust) import Math as M +import Partial.Unsafe (unsafePartial) import Range (Area(..), Pos(..), Range(..)) maxPos :: Pos -> Int @@ -20,10 +21,10 @@ getMiddlePos (Area (Range x1 x2) (Range y1 y2)) = Pos x y y = abs (y1 + y2) / 2 abs :: Int -> Int -abs x = fromMaybe 0 $ fromNumber $ M.abs $ toNumber x +abs x = unsafePartial $ fromJust $ fromNumber $ M.abs $ toNumber x sqrt :: Int -> Int -sqrt x = fromMaybe 0 $ fromNumber $ M.sqrt $ toNumber x +sqrt x = unsafePartial $ fromJust $ fromNumber $ M.floor $ M.sqrt $ toNumber x dist :: forall a b. { x :: Int, y :: Int | a } -> { x :: Int, y :: Int | b } -> Int dist p1 p2 = sqrt $ a2 + b2 diff --git a/code_royal/src/Main.purs b/code_royal/src/Main.purs index a4faee7..ab45cd4 100644 --- a/code_royal/src/Main.purs +++ b/code_royal/src/Main.purs @@ -2,14 +2,15 @@ module Main where import Prelude -import Data.Array (any, drop, filter, head, length, sortBy) +import Control.MonadZero (guard) +import Data.Array (any, filter, foldl, head, length, reverse, sortBy, (!!)) import Data.Maybe (Maybe(..), fromJust) import Effect (Effect) import Effect.Console (log, error) -import GameInput (Site, Minion, SiteInfo, parseInitInput, parseInput) -import Lib (dist, toPos) +import Effect.Random (randomInt) +import GameInput (Minion, Site, SiteInfo, ProtoSite, parseInitInput, parseInput) +import Lib (dist) import Partial.Unsafe (unsafePartial) -import Range (Pos(..)) main :: Effect Unit main = do @@ -20,36 +21,120 @@ main = do loop :: Int -> Array SiteInfo -> Effect Unit loop numSites siteInfo = do input <- parseInput numSites - + let touchedSite = if input.touchedSite == -1 then Nothing else Just input.touchedSite - loop' numSites input.gold touchedSite siteInfo input.sites input.units + loop' numSites input.gold touchedSite (combinedSites input.sites) input.units + where + -- combine sites with siteInfo + combinedSites :: Array ProtoSite -> Array Site + combinedSites sites = do + protoS <- sites + infoS <- siteInfo + guard $ protoS.id == infoS.id + pure { id: protoS.id + , structureType: protoS.structureType + , owner: protoS.owner + , param1: protoS.param1 + , param2: protoS.param2 + , x: infoS.x + , y: infoS.y + , radius: infoS.radius + } -loop' :: Int -> Int -> Maybe Int -> Array SiteInfo -> Array Site -> Array Minion -> Effect Unit -loop' numSites gold touchedSite siteInfo sites units = do - error $ "Sites: " <> show sites - error $ "SiteI: " <> show siteInfo +loop' :: Int -> Int -> Maybe Int -> Array Site -> Array Minion -> Effect Unit +loop' numSites gold touchedSite sites units = do + -- error $ "Free sites: " <> (show $ map (\s -> s.id) freeSites) + -- error $ "Near sites: " <> (show $ map (\s -> s.id) nearSites) - let queen = unsafePartial $ fromJust $ head $ filter (\u -> u.unitType == -1 && u.owner == 0) units - let siteInfo' = sortBy (compareSiteInfoDist queen) siteInfo + if (length $ friendlySites sites) > 3 + then log avoid + else case head $ nearSites queen sites of + Just sInfo -> do + let typ = if hasKnightsBarrack sites then 1 else 0 + log $ build sInfo typ + Nothing -> do + log avoid - case head siteInfo' of - Just sInfo -> do - log $ build sInfo - log $ "TRAIN " <> show sInfo.id - Nothing -> do - log $ "WAIT" - log $ "TRAIN" + t <- trainAll gold sites + log $ t - loop numSites siteInfo + loop numSites (toSiteInfo <$> sites) + where + avoid :: String + avoid = case nearestEnemy of + Just enemy -> "MOVE " <> show (site enemy).x <> " " <> show (site enemy).y + Nothing -> "MOVE 0 0" + where site enemy = unsafePartial $ fromJust $ head $ + sortBy (\s1 s2 -> compare (dist enemy s2) (dist enemy s1)) (friendlySites sites) -compareSiteInfoDist :: Minion -> SiteInfo -> SiteInfo -> Ordering + queen :: Minion + queen = unsafePartial $ fromJust $ head $ filter (\u -> u.unitType == -1 && u.owner == 0) units + + enemyQueen :: Minion + enemyQueen = unsafePartial $ fromJust $ head $ filter (\u -> u.unitType == -1 && u.owner == 1) units + + -- nearest non-queen enemy + nearestEnemy :: Maybe Minion + nearestEnemy = head $ filter (\u -> u.unitType /= -1 && isEnemy u) units + +-- TODO: make pure +trainAll :: Int -> Array Site -> Effect String +trainAll gold sites = do + randBarrack <- randomBarrack + choose <- randomInt 1 100 + let barrack = if gold > 100 && choose < 23 then knightBarrack else randBarrack + pure $ foldl siteToIds "TRAIN" barrack + where + siteToIds acc site = acc <> " " <> show site.id + knightBarrack = case head $ knightBarracks sites of + Just barrack -> [barrack] + Nothing -> [] + randomBarrack = do + let ownBarracks = filter isOwn $ barracks sites + rand <- randomInt 0 $ length ownBarracks + case ownBarracks !! rand of + Just barrack -> pure [barrack] + Nothing -> pure [] + +freeSites :: Array Site -> Array Site +freeSites = filter (\s -> s.owner == -1) + +friendlySites :: Array Site -> Array Site +friendlySites = filter (\s -> s.owner == 0) + +nearSites :: Minion -> Array Site -> Array Site +nearSites unit sites = sortBy (compareSiteInfoDist unit) (freeSites sites) + +hasKnightsBarrack :: Array Site -> Boolean +hasKnightsBarrack sites = any (\s -> s.param2 == 0) (friendlySites sites) + +knightBarracks :: Array Site -> Array Site +knightBarracks sites = filter (\s -> s.param2 == 0) (friendlySites sites) + +toSiteInfo :: Site -> SiteInfo +toSiteInfo s = { id: s.id, x: s.x, y: s.y, radius: s.radius } + +compareSiteInfoDist :: Minion -> Site -> Site -> Ordering compareSiteInfoDist u s1 s2 = compare (dist s1 u) (dist s2 u) -build :: forall e. { id :: Int | e } -> String -build s = "BUILD " <> show s.id <> " BARRACKS-ARCHER" +build :: forall e. { id :: Int | e } -> Int -> String +build s typ = "BUILD " <> show s.id <> " BARRACKS-" <> t + where t = if typ == 0 then "KNIGHT" else "ARCHER" + +isOwn :: forall a. { owner :: Int | a } -> Boolean +isOwn = owner 0 + +isEnemy :: forall a. { owner :: Int | a } -> Boolean +isEnemy = owner 1 + +owner :: Int -> forall a. { owner :: Int | a } -> Boolean +owner oId r = r.owner == oId + +barracks :: Array Site -> Array Site +barracks sites = filter (\b -> b.structureType == 2) sites moveToPos :: forall e. { x :: Int, y :: Int | e } -> String moveToPos p = "MOVE " <> show p.x <> " " <> show p.y diff --git a/code_royal/src/ffi/GameInput.purs b/code_royal/src/ffi/GameInput.purs index 53e3480..f581141 100644 --- a/code_royal/src/ffi/GameInput.purs +++ b/code_royal/src/ffi/GameInput.purs @@ -10,7 +10,7 @@ type GameInitInput = type GameInput = { gold :: Int , touchedSite :: Int -- -1 if none - , sites :: Array Site + , sites :: Array ProtoSite , units :: Array Minion } @@ -21,7 +21,7 @@ type SiteInfo = , radius :: Int } -type Site = +type ProtoSite = { id :: Int , structureType :: Int -- -1 No structure, 2 Barracks , owner :: Int -- -1 No structure, 0 friendly, 1 enemy @@ -29,6 +29,17 @@ type Site = , param2 :: Int -- -1 No structure, barracks: 0 knight 1 archer } +type Site = + { id :: Int + , x :: Int + , y :: Int + , radius :: Int + , structureType :: Int + , owner :: Int + , param1 :: Int + , param2 :: Int + } + type Minion = { x :: Int , y :: Int diff --git a/code_vs_zombies/index.js b/code_vs_zombies/index.js deleted file mode 100644 index 1db219a..0000000 --- a/code_vs_zombies/index.js +++ /dev/null @@ -1,797 +0,0 @@ -// 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(); \ No newline at end of file