Skip to content

Commit 78a8206

Browse files
committed
Fixed next and back
1 parent bd7a047 commit 78a8206

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

strats/stdgame.clj

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
(def LEFT 1)
33
(def DOWN 2)
44
(def RIGHT 3)
5-
(def DIRECTIONS [UP RIGTH DOWN LEFT UP RIGHT])
5+
(def DIRECTIONS [UP RIGTH DOWN LEFT])
66

77

88
(def WALL 0)
@@ -41,9 +41,13 @@
4141
'((succ x), y))))))
4242

4343
(defn next [direction]
44-
(nth DIRECTIONS (succ direction)))
44+
(if (== direction LEFT)
45+
UP
46+
(let [pos (lookup DIRECTIONS direction)]
47+
(nth DIRECTIONS (succ pos)))))
4548

4649
(defn back [direction]
4750
(if (== direction UP)
4851
RIGHT
49-
(nth DIRECTIONS (pred direction))))
52+
(let [pos (lookup DIRECTIONS direction)]
53+
(nth DIRECTIONS (pred pos)))))

strats/stdlib.clj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,10 @@
66

77
(defn pred [x]
88
(sub x 1))
9+
10+
(defn lookup [list elem]
11+
(let [lookup-in (fn [l p]
12+
(if (== (head l) elem)
13+
p
14+
(lookup-in (tail l) (succ p))))]
15+
(lookup-in list 0)))

0 commit comments

Comments
 (0)