seperate haskell und purescript directories
This commit is contained in:
11
purescript/vindinium/.gitignore
vendored
Normal file
11
purescript/vindinium/.gitignore
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
/bower_components/
|
||||
/node_modules/
|
||||
/.pulp-cache/
|
||||
/output/
|
||||
/generated-docs/
|
||||
/.psc-package/
|
||||
/.psc*
|
||||
/.purs*
|
||||
/.psa*
|
||||
/.spago
|
||||
/index.js
|
||||
28
purescript/vindinium/.vscode/tasks.json
vendored
Normal file
28
purescript/vindinium/.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
// 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 && uglifyjs index.js --mangle --output index.min.js",
|
||||
"presentation": {
|
||||
"echo": true,
|
||||
"focus": true,
|
||||
"reveal": "silent"
|
||||
},
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
},
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"label": "build_purescript_old",
|
||||
"type": "shell",
|
||||
"command": "spago bundle-app && uglifyjs index.js --compress --mangle --output index.js",
|
||||
"group": "build"
|
||||
}
|
||||
]
|
||||
}
|
||||
1
purescript/vindinium/index.min.js
vendored
Normal file
1
purescript/vindinium/index.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
128
purescript/vindinium/packages.dhall
Normal file
128
purescript/vindinium/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
|
||||
18
purescript/vindinium/spago.dhall
Normal file
18
purescript/vindinium/spago.dhall
Normal file
@@ -0,0 +1,18 @@
|
||||
{-
|
||||
Welcome to a Spago project!
|
||||
You can edit this file as you like.
|
||||
-}
|
||||
{ name = "vinidium"
|
||||
, dependencies =
|
||||
[ "arrays"
|
||||
, "console"
|
||||
, "effect"
|
||||
, "integers"
|
||||
, "js-date"
|
||||
, "math"
|
||||
, "ordered-collections"
|
||||
, "random"
|
||||
]
|
||||
, packages = ./packages.dhall
|
||||
, sources = [ "src/**/*.purs", "test/**/*.purs", "../lib/**/*.purs" ]
|
||||
}
|
||||
55
purescript/vindinium/src/Main.purs
Normal file
55
purescript/vindinium/src/Main.purs
Normal file
@@ -0,0 +1,55 @@
|
||||
module Main where
|
||||
|
||||
import Prelude
|
||||
|
||||
import Control.Monad.State (State, gets, modify_, runState)
|
||||
import Data.Maybe (Maybe(..))
|
||||
import Data.Tuple (fst, snd)
|
||||
import Effect (Effect)
|
||||
import Effect.Console (log, error)
|
||||
import Effect.Random (randomInt)
|
||||
import GameInput (parseInitInput, parseInput, GameInitInput, Board, Entity)
|
||||
import Graph
|
||||
|
||||
type GameState =
|
||||
{ boardSize :: Int
|
||||
, heroId :: Int
|
||||
, board :: Board
|
||||
, entityCount :: Int
|
||||
, entities :: Array Entity
|
||||
}
|
||||
|
||||
main :: Effect Unit
|
||||
main = do
|
||||
initInput <- parseInitInput
|
||||
error $ show $ initInput.board
|
||||
nextRound initInput Nothing
|
||||
|
||||
nextRound :: GameInitInput -> Maybe GameState -> Effect Unit
|
||||
nextRound initInput gameState = do
|
||||
input <- parseInput
|
||||
-- error $ show $ G.shortestPath "[4,4]" "[1,1]" graph
|
||||
|
||||
-- do we start on the left side of the map?
|
||||
|
||||
let gameState' =
|
||||
{ boardSize: initInput.boardSize
|
||||
, heroId: initInput.heroId
|
||||
, board: initInput.board
|
||||
, entityCount: input.entityCount
|
||||
, entities: input.entities
|
||||
}
|
||||
rand <- randomInt 0 3
|
||||
|
||||
let res = runState (loop rand) gameState'
|
||||
let state = snd res
|
||||
let val = fst res
|
||||
log $ val
|
||||
nextRound initInput (Just state)
|
||||
|
||||
loop :: Int -> State GameState String
|
||||
loop rand
|
||||
| rand == 0 = pure "NORTH"
|
||||
| rand == 1 = pure "EAST"
|
||||
| rand == 2 = pure "SOUTH"
|
||||
| otherwise = pure "WEST"
|
||||
26
purescript/vindinium/src/Ruler.purs
Normal file
26
purescript/vindinium/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)
|
||||
52
purescript/vindinium/src/ffi/GameInput.js
Normal file
52
purescript/vindinium/src/ffi/GameInput.js
Normal file
@@ -0,0 +1,52 @@
|
||||
"use strict";
|
||||
|
||||
exports.readline = readline
|
||||
|
||||
exports.parseInitInput = function() {
|
||||
var size = parseInt(readline());
|
||||
var board = []
|
||||
for (var i = 0; i < size; i++) {
|
||||
var inner = []
|
||||
var line = readline();
|
||||
for (var l=0; l < line.length; l++) {
|
||||
inner.push(line[l])
|
||||
}
|
||||
board.push(inner)
|
||||
}
|
||||
var myId = parseInt(readline()); // ID of your hero
|
||||
|
||||
return {
|
||||
boardSize: size,
|
||||
heroId: myId,
|
||||
board: board
|
||||
}
|
||||
};
|
||||
|
||||
exports.parseInput = function(numSites) {
|
||||
return function() {
|
||||
var entityCount = parseInt(readline()); // the number of entities
|
||||
var entities = []
|
||||
for (var i = 0; i < entityCount; i++) {
|
||||
var inputs = readline().split(' ');
|
||||
var entityType = inputs[0]; // HERO or MINE
|
||||
var id = parseInt(inputs[1]); // the ID of a hero or the owner of a mine
|
||||
var x = parseInt(inputs[2]); // the x position of the entity
|
||||
var y = parseInt(inputs[3]); // the y position of the entity
|
||||
var life = parseInt(inputs[4]); // the life of a hero (-1 for mines)
|
||||
var gold = parseInt(inputs[5]); // the gold of a hero (-1 for mines)
|
||||
entities.push({
|
||||
entityType: entityType,
|
||||
id: id,
|
||||
x: x,
|
||||
y: y,
|
||||
life: life,
|
||||
gold: gold,
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
entityCount: entityCount,
|
||||
entities: entities
|
||||
}
|
||||
}
|
||||
};
|
||||
34
purescript/vindinium/src/ffi/GameInput.purs
Normal file
34
purescript/vindinium/src/ffi/GameInput.purs
Normal file
@@ -0,0 +1,34 @@
|
||||
module GameInput where
|
||||
|
||||
import Effect (Effect)
|
||||
|
||||
-- TODO: Convert to proper types
|
||||
|
||||
data BoardElement = Spawn Int | Wall | Tavern | Mine | Empty
|
||||
type Board = Array (Array String)
|
||||
|
||||
type GameInitInput =
|
||||
{ boardSize :: Int
|
||||
, heroId :: Int
|
||||
, board :: Board
|
||||
}
|
||||
|
||||
type Entity =
|
||||
{ type :: String
|
||||
, id :: Int
|
||||
, x :: Int
|
||||
, y :: Int
|
||||
, life :: Int
|
||||
, gold :: Int
|
||||
}
|
||||
|
||||
type GameInput =
|
||||
{ entityCount :: Int
|
||||
, entities :: Array Entity
|
||||
}
|
||||
|
||||
foreign import parseInitInput :: Effect GameInitInput
|
||||
|
||||
foreign import parseInput :: Effect GameInput
|
||||
|
||||
foreign import readline :: Effect String
|
||||
57
purescript/vindinium/test/Main.purs
Normal file
57
purescript/vindinium/test/Main.purs
Normal file
@@ -0,0 +1,57 @@
|
||||
module Test.Main where
|
||||
|
||||
import Prelude
|
||||
|
||||
import Data.Array (concatMap, (..))
|
||||
import Data.Foldable (foldl)
|
||||
import Data.Int (fromNumber)
|
||||
import Data.JSDate (JSDate, getTime, now)
|
||||
import Data.Map (Map, showTree)
|
||||
import Data.Maybe (fromJust)
|
||||
import Effect (Effect)
|
||||
import Effect.Console (log)
|
||||
import Graph (Graph(..), addEdge, addNode, empty, pathExists, shortestPath)
|
||||
import Partial.Unsafe (unsafePartial)
|
||||
|
||||
|
||||
main :: Effect Unit
|
||||
main = do
|
||||
let graph = foldl addEdge' graph' $ concatMap nodeConnections nodes
|
||||
|
||||
d0 <- now
|
||||
log $ show $ shortestPath graph "[2,2]" "[9,9]"
|
||||
log $ show $ shortestPath graph "[2,2]" "[9,9]"
|
||||
log $ show $ shortestPath graph "[2,2]" "[9,9]"
|
||||
d1 <- now
|
||||
test "exists test" d0 d1
|
||||
|
||||
log ""
|
||||
|
||||
-- log $ "execution time of ALL: " <> (show $ (getTime d7 - getTime d0) / 3000.0) <> "s"
|
||||
|
||||
test :: String -> JSDate -> JSDate -> Effect Unit
|
||||
test tName d0 d1 = do
|
||||
let t0 = getTime d0
|
||||
let t1 = getTime d1
|
||||
log $ "execution time of " <> tName <> ": " <> (show $ (t1 - t0) / 3.0) <> "ms"
|
||||
|
||||
addEdge' :: forall v. Ord v => Graph v -> Array v -> Graph v
|
||||
addEdge' g v = unsafePartial $ addEdge'' v
|
||||
where
|
||||
addEdge'' :: Partial => Array v -> Graph v
|
||||
addEdge'' [a,b] = addEdge g a b
|
||||
|
||||
graph' = foldl addNode empty sNodes
|
||||
|
||||
sNodes :: Array String
|
||||
sNodes = map (\n -> show n) nodes
|
||||
|
||||
nodes = do
|
||||
x <- (1..10)
|
||||
y <- (1..10)
|
||||
pure $ [x, y]
|
||||
|
||||
nodeConnections :: Array Int -> Array (Array String)
|
||||
nodeConnections [x, y] = [ [o, show [x-1,y]], [o, show [x+1,y]], [o, show [x,y-1]], [o, show [x,y+1]] ]
|
||||
where o = show [x, y]
|
||||
nodeConnections _ = []
|
||||
10
purescript/vindinium/workspace.code-workspace
Normal file
10
purescript/vindinium/workspace.code-workspace
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"folders": [
|
||||
{
|
||||
"path": "."
|
||||
},
|
||||
{
|
||||
"path": "..\\lib"
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user