Skip to content

Commit 2c72f2a

Browse files
committed
simple algo
1 parent 1dc6abb commit 2c72f2a

File tree

1 file changed

+62
-2
lines changed

1 file changed

+62
-2
lines changed

strats/simple.clj

+62-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,68 @@
11
(defn main [world undocumented]
22
'(initial_state step_fn))
33

4+
(defn world-map [world]
5+
(head world))
6+
7+
(defn lambda-man [world]
8+
(nth world 2))
9+
10+
(defn direction [actor]
11+
(nth actor 3))
12+
13+
(defn location [actor]
14+
(nth actor 2))
15+
16+
(def UP 0)
17+
(def LEFT 1)
18+
(def DOWN 2)
19+
(def RIGHT 3)
20+
(def DIRECTIONS [UP RIGTH DOWN LEFT UP RIGHT])
21+
22+
23+
(def WALL 0)
24+
(def EMPTY 1)
25+
(def PILL 2)
26+
(def POWER-PILL 3)
27+
(def FRUIT 4)
28+
(def LM 5)
29+
(def GHOST 6)
30+
31+
(def at [world-map x y]
32+
(nth (nth (world-map) y) x))
33+
34+
(def neighbour [pos direction]
35+
(let [x (head pos)
36+
y (tail pos)]
37+
(if (== direction UP)
38+
'(x, (prev y))
39+
(if (== direction LEFT)
40+
'((prev x), y)
41+
(if (== direction DOWN)
42+
'(x, (succ y))
43+
'((succ x), y))))))
44+
45+
(defn next [direction]
46+
(nth DIRECTIONS (succ direction)))
47+
48+
(defn back [direction]
49+
(if (== direction UP)
50+
RIGHT
51+
(nth DIRECTIONS (pred direction))))
52+
453
(def initial_state
5-
'())
54+
0)
655

756
(defn step_fn [state world]
8-
'())
57+
(let [lm (lambda-man world)
58+
dir (direction lm)
59+
loc (location lm)
60+
t1 (next dir)
61+
t2 (back t1)
62+
t3 (back t2)
63+
is-free (fn [t] (not (== WALL (neighbour loc t))))]
64+
'(state, (if (is-free t1)
65+
t1
66+
(if (is-free t2)
67+
t2
68+
t3)))))

0 commit comments

Comments
 (0)