Skip to content

Instantly share code, notes, and snippets.

@cgrand
Created May 21, 2013 09:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save cgrand/5618560 to your computer and use it in GitHub Desktop.
Save cgrand/5618560 to your computer and use it in GitHub Desktop.
Fork it and paste your TRON bot
@kotarak
Copy link

kotarak 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