Created
May 21, 2013 09:23
-
-
Save cgrand/5618560 to your computer and use it in GitHub Desktop.
Fork it and paste your TRON bot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; |
paddycakes
commented
May 21, 2013
; Yolina
(ns tron.bots.squiggly
(:require [tron.core :as tron]))
(def mock-bots
{[2 0] true
[5 3] true})
(defn mock-look
[pos]
(if (tron/valid-pos? pos)
(get mock-bots pos) :wall))
(def directions #{[1 0] [0 1] [-1 0] [0 -1]})
(def poss [0 0])
; (defn move [[x y] [dx dy]] [(+ x dx) (+ y dy)])
(defn right [[x y]] [(inc x) y])
(defn down [[x y]] [x (inc y)])
(defn left [[x y]] [(- x 1) y])
(defn up [[x y]] [x (- y 1)])
(defn all-valid [f pos] (rest (iterate f pos)))
(defn valids [look f pos] (count (take-while (complement look) (all-valid f pos))))
; Call this function
(defn move
[look {pos :pos}]
(let [dirs [up down left right]
best (apply max-key #(valids look % pos) dirs)]
{:pos (best pos)})
)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment