# HG changeset patch # User Robert McIntyre # Date 1395198288 14400 # Node ID a331d5ff73e0c101bf96977687d9b613c24a3bc0 # Parent e6a7e80f885a5bd94d297b6f7a963368e7721fa4 saving progress for the night. completed self-organizing touch, still working on stream predicates. diff -r e6a7e80f885a -r a331d5ff73e0 org/self_organizing_touch.clj --- a/org/self_organizing_touch.clj Tue Mar 18 22:29:03 2014 -0400 +++ b/org/self_organizing_touch.clj Tue Mar 18 23:04:48 2014 -0400 @@ -80,8 +80,7 @@ [coll] (loop [result () coll (sort-by (comp - count) coll)] (if (empty? coll) result - (let [x (first coll) - xs (rest coll) + (let [[x & xs] coll c (count x)] (if (some (fn [other-set] @@ -91,12 +90,6 @@ (recur result xs) (recur (cons x result) xs)))))) -(defn rect-region [[x0 y0] [x1 y1]] - (vec - (for [x (range x0 (inc x1)) - y (range y0 (inc y1))] - [x y]))) - (def all-touch-coordinates (concat (rect-region [0 15] [7 22]) @@ -112,8 +105,7 @@ data [[(vec (keys touched-region)) (vec (vals touched-region))]] touch-display (view-touch)] - (touch-display data) - (touch-display data))) + (repeatedly 5 #(touch-display data)) data)) (defn learn-touch-regions [] (let [experiences (atom []) diff -r e6a7e80f885a -r a331d5ff73e0 org/worm_learn.clj --- a/org/worm_learn.clj Tue Mar 18 22:29:03 2014 -0400 +++ b/org/worm_learn.clj Tue Mar 18 23:04:48 2014 -0400 @@ -144,28 +144,27 @@ (defn touch-average [[coords touch]] (/ (average (map first touch)) (average (map second touch)))) -(def worm-segment-touch-bottom - [[8 15] [8 16] [8 17] [8 18] [8 19] [8 20] [8 21] [8 22] [9 15] - [9 16] [9 17] [9 18] [9 19] [9 20] [9 21] [9 22] [10 15] [10 16] - [10 17] [10 18] [10 19] [10 20] [10 21] [10 22] [11 15] [11 16] - [11 17] [11 18] [11 19] [11 20] [11 21] [11 22] [12 15] [12 16] - [12 17] [12 18] [12 19] [12 20] [12 21] [12 22] [13 15] [13 16] - [13 17] [13 18] [13 19] [13 20] [13 21] [13 22] [14 15] [14 16] - [14 17] [14 18] [14 19] [14 20] [14 21] [14 22]]) +(defn rect-region [[x0 y0] [x1 y1]] + (vec + (for [x (range x0 (inc x1)) + y (range y0 (inc y1))] + [x y]))) +(def worm-segment-touch-bottom (rect-region [8 15] [14 22])) - -(defn floor-contact [[coords contact :as touch]] - (let [raw-average - (average - (map - first - (vals - (select-keys - (zipmap coords contact) - ))))] - (Math/abs (- 1. (* 10 raw-average))))) - +(defn contact + "Determine how much contact a particular worm segment has with + other objects. Returns a value between 0 and 1, where 1 is full + contact and 0 is no contact." + [[coords contact :as touch]] + (-> (zipmap coords contact) + (select-keys worm-segment-touch-bottom) + (vals) + (#(map first %)) + (average) + (* 10) + (- 1) + (Math/abs))) (defn wiggling? "Is the worm wiggling?" @@ -251,7 +250,7 @@ ;;(if (straight? @experiences) (println "Straight")) ;; (println-repl ;; (apply format "%.2f %.2f %.2f %.2f %.2f\n" - ;; (map floor-contact touch-data))) + ;; (map contact touch-data))) ) (muscle-display