Skip to content

Instantly share code, notes, and snippets.

@whostolebenfrog
Forked from cgrand/bots.clj
Last active December 19, 2015 00:19
Show Gist options
  • Save whostolebenfrog/5868115 to your computer and use it in GitHub Desktop.
Save whostolebenfrog/5868115 to your computer and use it in GitHub Desktop.
;; the backup bot where my real one failed
;; function name is ben
(ns tron.bots
(:require [tron.core :as tron]))
(defn up [[x y]]
[x (dec y)])
(defn down [[x y]]
[x (inc y)])
(defn left [[x y]]
[(dec x) y])
(defn right [[x y]]
[(inc x) y])
(defn neighbours [pos]
((juxt up down left right) pos))
(defn valid-neighbours [look pos]
{:post [(not-any? look %)]}
(remove look (neighbours pos)))
(defn ben
[look {pos :pos}]
(if (look (up pos))
{:pos (first (valid-neighbours look pos))}
{:pos (up pos)}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment