seperate haskell und purescript directories

This commit is contained in:
weiss
2020-04-19 05:51:24 +02:00
parent 7dfe85a5fd
commit 49481147ff
67 changed files with 5 additions and 0 deletions

10
purescript/code_vs_zombies/.gitignore vendored Normal file
View File

@@ -0,0 +1,10 @@
/bower_components/
/node_modules/
/.pulp-cache/
/output/
/generated-docs/
/.psc-package/
/.psc*
/.purs*
/.psa*
/.spago

View 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"
}
]
}

View 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

View 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" ]
}

View 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

View 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

View 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)

View 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,
}
};

View 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

View 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"

View File

@@ -0,0 +1,7 @@
{
"folders": [
{
"path": "."
}
]
}