Skip to content

Commit

Permalink
Merge pull request #99 from JoshMeredith/dev
Browse files Browse the repository at this point in the history
Two new worlds
  • Loading branch information
JoshMeredith authored Oct 17, 2017
2 parents afa9385 + fc6728b commit f2443d2
Show file tree
Hide file tree
Showing 92 changed files with 55,258 additions and 12,539 deletions.
12,336 changes: 6,563 additions & 5,773 deletions assets-gen/assets.ai

Large diffs are not rendered by default.

12,482 changes: 12,482 additions & 0 deletions assets-gen/grass.ai

Large diffs are not rendered by default.

6,453 changes: 0 additions & 6,453 deletions assets-gen/playerSprite/assets.ai

This file was deleted.

12,293 changes: 12,293 additions & 0 deletions assets-gen/sand.ai

Large diffs are not rendered by default.

12,352 changes: 12,352 additions & 0 deletions assets-gen/snow.ai

Large diffs are not rendered by default.

10,506 changes: 10,506 additions & 0 deletions assets-gen/stone.ai

Large diffs are not rendered by default.

File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
7 changes: 7 additions & 0 deletions level-gen/sol/level-11.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
walkForward;
walkForward;
turnRight;
walkForward;
walkForward;
turnLeft;
walkForward;
7 changes: 7 additions & 0 deletions level-gen/sol/level-12.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
times (100) {
if (clearInFront?) {
walkForward;
} else {
turnLeft;
}
}
7 changes: 7 additions & 0 deletions level-gen/sol/level-13.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
times (10) {
if (clearInFront?) {
walkForward;
} else {
turnLeft;
}
}
14 changes: 14 additions & 0 deletions level-gen/sol/level-14.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
times (100) {
times (15) {
if (clearInFront?) {
walkForward;
}
}
turnLeft;
times (15) {
if (clearInFront?) {
walkForward;
}
}
turnRight;
}
24 changes: 24 additions & 0 deletions level-gen/sol/level-15.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
times(10000) {
turnRight;
if (clearInFront?) {
walkForward;
} else {
turnLeft;
if (clearInFront?) {
walkForward;
} else {
turnLeft;
if (clearInFront?) {
walkForward;
} else {
turnLeft;
if (clearInFront?) {
walkForward;
} else {
turnLeft;
walkForward;
}
}
}
}
}
File renamed without changes.
50 changes: 50 additions & 0 deletions level-gen/staircase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env python3

import random

N = 15

left = [
0,
0,
3,
3,
3,
5,
5,
6,
6,
8,
8,
8,
8,
8,
10,
]

right = [
4,
6,
6,
7,
7,
7,
7,
7,
9,
9,
9,
10,
12,
15,
15,
]

grid = [ ['L' for i in range(N)] for j in range(N) ]
for i in range(N):
for j in range(left[i], right[i]):
grid[i][j] = '_'
grid = grid[::-1]

for g in grid:
print(str(g) + ',')
45 changes: 45 additions & 0 deletions level-gen/tree.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env python3

import random

random.seed(4920)

N = 15

grid = [ ['L' for i in range(N)] for j in range(N) ]
done = [ [False for i in range(N)] for j in range(N) ]
ddr = [1, 0, -1, 0]
ddc = [0, 1, 0, -1]

def degree(r, c):
tot = 0
for (dr, dc) in zip(ddr, ddc):
nr = r + dr
nc = c + dc
if min(nr, nc) >= 0 and max(nr, nc) < N and grid[nr][nc] == '_':
tot += 1
return tot

sr = random.randint(0, N-1)
sc = random.randint(0, N-1)
todo = set([(sr, sc)])

while len(todo) > 0:
(r, c) = todo.pop()
done[r][c] = True

if degree(r, c) <= 1:
grid[r][c] = '_'
for dr, dc in zip(ddr, ddc):
nr = r + dr
nc = c + dc
if min(nr, nc) >= 0 and max(nr, nc) < N:
if not done[nr][nc] and degree(nr, nc) <= 1:
todo.add((nr, nc))

leaves = [ (r, c) for r in range(N) for c in range(N) if grid[r][c] == '_' and
degree(r, c) <= 1 ]
leaves = list(map(lambda x: {'row': x[0]+1, 'col': x[1]+1}, leaves))
random.shuffle(leaves)
print(grid)
print(leaves)
33 changes: 23 additions & 10 deletions purescript/src/Interpreter.purs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Data.Traversable (traverse_)
import Data.Tuple (Tuple(..))
import Data.Tuple.Nested ((/\), over2, get1, get2)
import Data.Unfoldable (replicateA)
import Prelude ( Unit, bind, const, discard, pure, unit, when
import Prelude ( Unit, bind, const, discard, pure, unit
, (#), ($), (&&), (<<<), (==), (>>=), (||), (*>))
import Run (run)
import Run.Streaming (Resume(..), runYield, yield)
Expand All @@ -23,8 +23,8 @@ import Unsafe.Coerce (unsafeCoerce)


import Types ( AST(..), Statement(..), World, Definition(..), Interpreter
, Expression(..), Direction, Move)
import World (step, moves, directions, facing)
, Expression(..), Direction, Move, Questions(..))
import World (step, moves, directions, facing, predicates, inspect)


testNum :: Int
Expand All @@ -42,7 +42,7 @@ runInterpreter initial (AST ss) baseDefs =
evalState (fromFoldable baseDefs /\ initial /\ unit) $
go (BlockStatement ss)
where
go :: Statement -> Interpreter
go :: Statement -> Interpreter Unit
go (CommandStatement command) = do
defs <- get <#> get1
case defs # lookup command of
Expand All @@ -54,8 +54,13 @@ runInterpreter initial (AST ss) baseDefs =
_ :: Array Unit <- replicateA n $ go child
pure unit

go (IfStatement (BoolExp p) child) =
when p $ go child
go (IfStatement p ifs elses) = do
b <- evalPredicate p
case (b /\ elses) of
(true /\ _ ) -> go ifs
(false /\ (Just es)) -> go es
(false /\ Nothing ) -> pure unit


go (BlockStatement childStatements) =
childStatements # traverse_ go
Expand All @@ -64,17 +69,25 @@ runInterpreter initial (AST ss) baseDefs =
pure unit


send :: World -> Interpreter
send :: World -> Interpreter Unit
send w = do
yield w
modify (over2 (const w))


sendMove :: Move -> Interpreter
sendMove :: Move -> Interpreter Unit
sendMove m = do
get <#> get2 <#> step m >>= send


evalPredicate :: Expression -> Interpreter Boolean
evalPredicate (BoolExp b) = pure b
evalPredicate (Question q) = get <#> get2 <#> inspect (p q)
where
p ClearInFront = predicates.clearInFront



nextResume
:: forall a o. Resume () a Unit o
-> {value :: o , resume :: Resume () a Unit o}
Expand Down Expand Up @@ -117,12 +130,12 @@ environment = {
}


walk :: Direction -> Interpreter
walk :: Direction -> Interpreter Unit
walk dir = do
adjustFacing
sendMove moves.walkForward
where
adjustFacing :: Interpreter
adjustFacing :: Interpreter Unit
adjustFacing = do
f <- get <#> get2 <#> facing
case unit of
Expand Down
43 changes: 43 additions & 0 deletions purescript/src/Levenshtein.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
Copyright (c) 2011 Andrei Mackenzie
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

// Compute the edit distance between the two given strings
exports.editDistance = function(a){
return function (b) {
if(a.length == 0) return b.length;
if(b.length == 0) return a.length;

var matrix = [];

// increment along the first column of each row
var i;
for(i = 0; i <= b.length; i++){
matrix[i] = [i];
}

// increment each column in the first row
var j;
for(j = 0; j <= a.length; j++){
matrix[0][j] = j;
}

// Fill in the rest of the matrix
for(i = 1; i <= b.length; i++){
for(j = 1; j <= a.length; j++){
if(b.charAt(i-1) == a.charAt(j-1)){
matrix[i][j] = matrix[i-1][j-1];
} else {
matrix[i][j] = Math.min(matrix[i-1][j-1] + 1, // substitution
Math.min(matrix[i][j-1] + 1, // insertion
matrix[i-1][j] + 1)); // deletion
}
}
}

return matrix[b.length][a.length];
};
};
5 changes: 5 additions & 0 deletions purescript/src/Levenshtein.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Levenshtein (
editDistance
) where

foreign import editDistance :: String -> String -> Int
Loading

0 comments on commit f2443d2

Please sign in to comment.