Skip to content

Instantly share code, notes, and snippets.

@tnoda
Last active December 27, 2015 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tnoda/7384650 to your computer and use it in GitHub Desktop.
Save tnoda/7384650 to your computer and use it in GitHub Desktop.
Translating the `break` statement into Clojure.
(let [m (BattleMap. "Ironbottom Sound")
f (Fleet. "Center Fleet")]
(loop []
(doto f .repair .supply)
(when (and (.isFullyRepaired f)
(.isFullySupplied f)
(>= (.morale f) 40))
(.attack f m)
(if (-> m .gauges pos?)
(recur))))
m)
BattleMap battleMap = new BattleMap("Ironbottom Sound");
Fleet fleet = new Fleet("Center Force");
while (battleMap.gauges > 0) {
fleet.repair();
fleet.supply();
if (!fleet.isFullyRepaired() || !fleet.isFullySupplied() || fleet.morale < 40) {
break;
}
fleet.attack(battleMap); // updates and returns the battleMap.
}
return battleMap;
(->> [(BattleMap. "Ironbottom Sound") (Fleet. "Center Fleet")]
(iterate (fn [[m f]]
(doto f .repair .supply (.attack m))
[m f]))
(drop-while #(-> % first .gauges pos?))
ffirst)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment