doc: reformatting documentation
diff --git a/src/battleship/core.clj b/src/battleship/core.clj
index 58b04ad..aa344c9 100644
--- a/src/battleship/core.clj
+++ b/src/battleship/core.clj
@@ -5,40 +5,50 @@
(def matrix-row 5)
-(defn compute-index "Computes a cell index based on a row and a column. "
+(defn compute-index
+ "Computes a cell index based on a row and a column. "
[row col]
(+ col (* matrix-row row)))
-(defn get-cell "Retrieves a cell from the battlefield: [:a :b :c]"
+(defn get-cell
+ "Retrieves a cell from the battlefield: [:a :b :c]"
[row col battlefield]
(battlefield (compute-index row col)))
-(defn random-bool "Generate a boolean based on the following frequency: 1/5 for a true and 4/5 for a false."
+(defn random-bool
+ "Generate a boolean based on the following frequency: 1/5 for a true and 4/5 for a false."
[]
(= (rand-int (+ matrix-row 1)) matrix-row))
-(defn init-cell "Initialize a cell"
+(defn init-cell
+ "Initialize a cell"
[]
{:has-enemy? (random-bool) :shot-by :none})
-(defn generate-game "Generates a 5x5 matrix game. Each cell of this matrix looks like this: {:has-enemy? true/false :shot-by playerX}"
+(defn generate-game
+ "Generates a 5x5 matrix game.
+ Each cell of this matrix looks like this: {:has-enemy? true/false :shot-by playerX}"
[]
(into [] (repeatedly (* matrix-row matrix-row) init-cell)))
-(defn found-active-enemy? "Predicate that tells if there is an active enemy at a given location."
+(defn found-active-enemy?
+ "Predicate that tells if there is an active enemy at a given location."
[row col battlefield]
(let [cell (get-cell row col battlefield)]
(and (:has-enemy? cell) (= :none (:shot-by cell)))))
-(defn score "Computes the score of all players. ex: {'player1' 5 'player2' 1}"
+(defn score
+ "Computes the score of all players. ex: {'player1' 5 'player2' 1}"
[battlefield]
(frequencies (for [cell battlefield :when (not= (:shot-by cell) :none)] (:shot-by cell))))
-(defn is-game-over? "Checks whether of not not there is an enemy left."
+(defn is-game-over?
+ "Checks whether of not not there is an enemy left."
[battlefield]
(not (true? (some #(= {:has-enemy? true :shot-by :none} %) battlefield))))
-(defn battlefield-string "Draws the battlefield with shot enemies."
+(defn battlefield-string
+ "Draws the battlefield with shot enemies."
[battlefield]
(->> battlefield
(map (comp (fn [shot-by] (if (= shot-by :none) "-" shot-by)) :shot-by))
diff --git a/src/battleship/handler.clj b/src/battleship/handler.clj
index 2f5068e..881a56b 100644
--- a/src/battleship/handler.clj
+++ b/src/battleship/handler.clj
@@ -10,7 +10,8 @@
(def games (atom {}))
-(defn lookup-game "Extracts a game context from the context of games."
+(defn lookup-game
+ "Extracts a game context from the context of games."
[game-id]
(@games game-id))
diff --git a/src/battleship/logic.clj b/src/battleship/logic.clj
index 7c76ad8..bc1bbe0 100644
--- a/src/battleship/logic.clj
+++ b/src/battleship/logic.clj
@@ -3,51 +3,63 @@
(:use battleship.core))
-(defn generate-game-id "Generates an random game identifier."
+(defn generate-game-id
+ "Generates an random game identifier."
[]
(str (java.util.UUID/randomUUID)))
-(defn register-new-game "Registers a new game into the global context."
+(defn register-new-game
+ "Registers a new game into the global context."
[games]
(let [game-id (generate-game-id)]
(swap! games assoc game-id (atom (generate-game)))
game-id))
-(defn shoot-enemy "Marks a cell as shot with the name of the player."
+(defn shoot-enemy
+ "Marks a cell as shot with the name of the player."
[row col player game]
(swap! game update-in [(compute-index row col) :shot-by] (fn [x] player )))
-(defn attempt-attack "A player attempt to shoot an enemy. If an enemy is shot the fun returns :success otherwise :failure"
+(defn attempt-attack
+ "A player attempt to shoot an enemy.
+ If an enemy is shot the fun returns :success otherwise :failure"
[row col player game]
(if (found-active-enemy? row col @game)
(do (shoot-enemy row col player game) :success)
:failure))
-(defn fire "Fires against an enemy supposed to be at a given location.
-Returns a result as following: {:fire-status :success|:failure :game-status :running|:over :score {...}}"
+(defn fire
+ "Fires against an enemy supposed to be at a given location.
+ Returns a result as following:
+ {:fire-status :success|:failure :game-status :running|:over :score {...}}"
[row col player game]
{:fire-status (attempt-attack row col player game)
:game-status ({true :over false :running} (is-game-over? @game))
:score (score @game)})
-(defn get-games-info "Retrieves the informations about all games. Ex: {game-id {player1 score1 player2 score2}}"
+(defn get-games-info
+ "Retrieves the informations about all games.
+ Ex: {game-id {player1 score1 player2 score2}}"
[games]
(for [ctx @games
:let [game-id (key ctx) bf @(val ctx) status {false :running true :over}]]
{game-id (assoc (score bf) :status (status (is-game-over? bf)))}))
-(defn get-game-stats "Retrieves a game context."
+(defn get-game-stats
+ "Retrieves a game context."
[game]
{:status ({true :over false :running} (is-game-over? game))
:score (score game)})
-(defn terminated-games "Returns all the games in a over state"
+(defn terminated-games
+ "Returns all the games in a over state"
[games]
(for [ctx @games
:let [game-id (key ctx) bf @(val ctx)]
:when (is-game-over? bf)]
game-id))
-(defn clean-up "Releases the terminated games memory."
+(defn clean-up
+ "Releases the terminated games memory."
[games]
(swap! games #(apply dissoc % (terminated-games games))))