Skip to content

Instantly share code, notes, and snippets.

@frankshearar
Created February 1, 2012 11:41
Show Gist options
  • Save frankshearar/1716687 to your computer and use it in GitHub Desktop.
Save frankshearar/1716687 to your computer and use it in GitHub Desktop.
4x4-1's pitiful strategy: place your ships in the lower half of the map
(ns battleships.demo)
;; This is an example of how to create a player to submit to the server.
;; The entire namespace is submitted to the server.
;; You submit the file using the submit function in the client namespace.
(defn- random-coord
"Generates a random valid coordinate."
[]
(let [rows ["A" "B" "C" "D" "E" "F" "G" "H" "I" "J"]
columns (vec (range 1 11))]
(str (rows (+ 5 (rand-int 5)))
(columns (rand-int 10)))))
(defn- random-orientation
"Generates a random valid orientation."
[]
([:h :v] (rand-int 2)))
(defn place-ship
"The ship is a map which represents the ship. You must return a map with the square you want to place it, and the orientation (:v is vertical, :h is horizontal)"
[ship]
{:square (random-coord) :orientation (random-orientation)})
(defn next-shot
"Where do you want to attack next?"
[context opponent-context]
(random-coord))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment