seperate haskell und purescript directories
This commit is contained in:
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
|
||||
Reference in New Issue
Block a user