comparison code/grid.lm @ 46:d631e68a45d5

separated out grid functions for reuse inside gameState.lm
author William Morgan <billjunk@mrgn.org>
date Sun, 27 Jul 2014 01:36:39 -0700
parents
children 57a4bddadd46
comparison
equal deleted inserted replaced
45:75f808e60aa8 46:d631e68a45d5
1 #{
2 import: [
3 length
4 reverse
5 split:at
6 map
7 fold:with
8 filter
9 flatten
10 ] from: (module: "ll.lm")
11
12 import: [
13 makeTree:size
14 makeTree
15 get:fromTree:size
16 get:fromTree
17 treeMap:size
18 treeMap
19 tree:size:update:with
20 tree:update:with
21 tree:set:to
22 ] from: (module: "tree.lm")
23
24 grid:get <- :grid :pos {
25 x <- pos value
26 y <- pos tail
27 get: x fromTree: (get: y fromTree: grid)
28 }
29
30 grid:update:with <- :grid :pos :fun {
31 x <- pos value
32 y <- pos tail
33 tree: grid update: y with: :row {
34 tree: row update: x with: fun
35 }
36 }
37
38 grid:set:to <- :grid :pos :val {
39 grid: grid update: pos with: :el { val }
40 }
41
42 grid:inBounds? <- :grid :pos {
43 x <- pos value
44 y <- pos tail
45 maxY <- grid value
46 maxX <- (get: 0 fromTree: grid) value
47 ((x >= 0) + (y >= 0) + (x < maxX) + (y < maxY)) > 0
48 }
49
50 calcPos <- :move from {
51 x <- from value
52 y <- from tail
53 if: move {
54 if: move = 1 {
55 x <- x + 1
56 } else: {
57 if: move = 2 {
58 y <- y + 1
59 } else: {
60 x <- x - 1
61 }
62 }
63 } else: {
64 y <- y - 1
65 }
66 #[x y]
67 }
68 }