comparison src/sim.tp @ 9:66ea6fdd3fcb

Merge
author Mike Pavone <pavone@retrodev.com>
date Sat, 14 Jul 2012 01:46:25 -0700
parents 5941e6b3684c 1bd46f854dbb
children 370a1eeb8812
comparison
equal deleted inserted replaced
8:5941e6b3684c 9:66ea6fdd3fcb
9 if:else <- :self trueblock :elseblock { 9 if:else <- :self trueblock :elseblock {
10 elseblock: 10 elseblock:
11 } 11 }
12 } 12 }
13 13
14 cellType <- #{ 14 cellTypes <- #{
15 robot <- ("R" byte: 0) 15 allstr <- #[]
16 wall <- ("#" byte: 0) 16 allobj <- #[]
17 rock <- ("*" byte: 0) 17 make <- :idstr {
18 lambda <- ("\\" byte: 0) 18 ret <- #{
19 closedlift <- ("L" byte: 0) 19 id <- (idstr byte: 0)
20 openlift <- ("O" byte: 0) 20 }
21 earth <- ("." byte: 0) 21 allobj append: ret
22 empty <- (" " byte: 0) 22 allstr append: idstr
23 newline <- ("\n" byte: 0) 23 ret
24 }
25 find <- :idstr {
26 if: idstr = "R" { robot } else: {
27 index <- 0
28 while: {
29 if: index < (allstr length) {
30 (allstr get: index) != idstr
31 } else: {false}
32 } do: {
33 index <- index + 1
34 }
35 if: index <- (allstr length) {
36 allobj get: index
37 } else: {
38 empty
39 }
40 }
41 }
42 wall <- make: "#"
43 empty <- make: " "
44 earth <- make: "."
45 rock <- make: "*"
46 lambda <- make: "\\"
47 closedlift <- make: "L"
48 openlift <- make: "O"
49 newline <- make: "\n"
50 robot <- {
51 #{
52 id <- ("R" byte: 0)
53 heldBreath <- 0
54 }
24 } 55 }
25 56
26 state <- #{ 57 state <- #{
27 new <- :in_grid in_width in_height { 58 new <- :in_grid in_width in_height {
28 next_grid <- #[] 59 next_grid <- #[]
31 } 62 }
32 #{ 63 #{
33 grid <- in_grid 64 grid <- in_grid
34 width <- in_width 65 width <- in_width
35 height <- in_height 66 height <- in_height
67 robot <- cellTypes robot
36 address <- :x y { x + y * width } 68 address <- :x y { x + y * width }
37 setCell <- :x y cell { 69 setCell <- :x y cell {
38 grid set: (address: x y) cell 70 grid set: (address: x y) cell
39 } 71 }
40 getCell <- :x y { 72 getCell <- :x y {
41 grid get: (address: x y) 73 grid get: (address: x y)
42 } 74 }
75 water <- 0
76 flooding <- 0
77 waterproof <- 10
43 collected <- 0 78 collected <- 0
44 moves <- 0 79 moves <- 0
45 ended <- false 80 ended <- false
46 doMove <- :roboMove { 81 doMove <- :roboMove {
82
83 robo <- doMove r
84 nexty <- doMove y
47 ended <- roboMove = "A" 85 ended <- roboMove = "A"
48 } 86 }
49 advance <- :roboMove { 87 doUpdate <- {
50 doMove: roboMove 88 updateCell <- :x, y {
89 if
90 }
91 }
92 advance <- :roboCmd {
93 robot move: roboCmd
51 moves <- moves + 1 94 moves <- moves + 1
95 doUpdate:
52 self 96 self
53 } 97 }
54 98
55 } 99 }
56 } 100 }
59 index <- 0 103 index <- 0
60 maxRow <- 0 104 maxRow <- 0
61 curRow <- 0 105 curRow <- 0
62 while: {index < strLen} do: { 106 while: {index < strLen} do: {
63 curByte <- str byte: index 107 curByte <- str byte: index
64 if: curByte = (cellType newline) { 108 if: curByte = (cellType newline id) {
65 maxRow <- if: curRow > maxRow {curRow} else: {maxRow} 109 maxRow <- if: curRow > maxRow {curRow} else: {maxRow}
66 } else: { 110 } else: {
67 curRow = curRow + 1 111 curRow = curRow + 1
68 } 112 }
69 } 113 }