Skip to content

Instantly share code, notes, and snippets.

@cgrand
Created June 26, 2013 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 12 You must be signed in to fork a gist
  • Save cgrand/5868058 to your computer and use it in GitHub Desktop.
Save cgrand/5868058 to your computer and use it in GitHub Desktop.
Fork & paste your bot code here!
;; INCLUDE THE NAME OF THE BOTT FN AT THE TOP
@hasanzaidi
Copy link

;; Function is hasan-bot

(ns tron.bots
(:require [tron.core :as tron]))

(defn empty-look
"A mock look function which just checks for the arena
boundaries."
[pos](when-not %28tron/valid-pos? pos%29 :wall))

(defn mock-look
"Returns a mock look function which checks for the arena
boundaries and the specified occupied positions."
[& occupied-poses](let [occupied-poses %28set occupied-poses%29]
%28fn [pos]
%28or %28occupied-poses pos%29
%28when-not %28tron/valid-pos? pos%29 :wall%29%29%29))

(defn neighbours [[x y]]

[[x (dec y)]
 [x (inc y)]
 [(dec x) y]
 [(inc x) y]
 ]

)

(defn any-neighbours[look pos dir](take-while #%28not %28look %%29%29 %28iterate dir pos%29)
)

(defn valid-neighbours [look pos](remove look %28neighbours pos%29)
)

(defn go-right-bot
"To infinity and beyond!"
[look {[x y] :pos}]
{:pos [(inc x) y]})

(defn hasan-bot
[look {[x y] :pos}]
{:pos [(inc x) y]})

(defn right [[x y]]
[(inc x) y])

(defn left [[x y]]
[(dec x) y])

(defn up [[x y]]up
[x (dec y)])

(defn down [[x y]]
[x (inc y)])

(defn go-right [pos]
{:pos (right pos)}
)

(defn go-left [pos]
{:pos (left pos)}
)

(defn go-down [pos]
{:pos (down pos)}
)

(defn go-up [pos]
{:pos (up pos)}
)

(defn dont-go-left [look pos](if %28look %28down pos%29%29
%28dont-go-up look pos%29
%28go-down pos%29)
)

(defn dont-go-right [look pos](if %28look %28left pos%29%29
%28dont-go-left look pos%29
%28go-left pos%29)
)

(defn dont-go-up [look pos](if %28look %28right pos%29%29
%28dont-go-right look pos%29
%28go-right pos%29)
)

(defn hasan-bot
[look {pos :pos}]

(if (look (up pos))
(dont-go-up look pos)
(go-up pos)

))

;; launch bots
(tron/run hasan-bot)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment