Last active
December 27, 2015 20:29
-
-
Save tnoda/7384650 to your computer and use it in GitHub Desktop.
Translating the `break` statement into Clojure.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(->> [(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