From: JBM Date: Tue, 25 Aug 2020 16:16:44 +0000 (+0200) Subject: FIX: IT belongs in a MODEL! X-Git-Url: https://troll.desast.re/troll.git/commitdiff_plain/refs/heads/trolls-have-no-master?ds=inline FIX: IT belongs in a MODEL! (authored months ago, had remained WIP in my work directory for "some" reason) --- diff --git a/src/main/java/com/codingame/game/Model.java b/src/main/java/com/codingame/game/Model.java index 96140f5..beff100 100644 --- a/src/main/java/com/codingame/game/Model.java +++ b/src/main/java/com/codingame/game/Model.java @@ -192,6 +192,14 @@ class Model { p1.adjustScore(trollPosition); } + boolean FIX_IT() { + switch (league.fixLevel) { + case SOMETIMES: return random.nextInt(10) > 0; + case NEVER: return false; + default: throw new JavaLimitationError(); + } + } + private Integer winner; boolean haveWinner() { return winner != null; diff --git a/src/main/java/com/codingame/game/Referee.java b/src/main/java/com/codingame/game/Referee.java index 7a718e9..8f5fc97 100644 --- a/src/main/java/com/codingame/game/Referee.java +++ b/src/main/java/com/codingame/game/Referee.java @@ -81,17 +81,7 @@ public class Referee extends AbstractReferee { case Throw: try { player.model.consumeStones(player.stoneThrow); } catch (Model.Player.ThrewMoreStonesThanHad e) { - boolean FIX_IT; - switch (league.fixLevel) { - case SOMETIMES: - FIX_IT = model.random.nextInt(10) > 0; - break; - case NEVER: - FIX_IT = false; - break; - default: throw new JavaLimitationError(); - } - if (FIX_IT) { + if (model.FIX_IT()) { player.view.threwMoreStonesThanHad(); player.stoneThrow = player.model.consumeMaxStones(); } @@ -102,17 +92,7 @@ public class Referee extends AbstractReferee { } } catch (Model.Player.FailedToThrowStonesAndShouldHave e) { - boolean FIX_IT; - switch (league.fixLevel) { - case SOMETIMES: - FIX_IT = model.random.nextInt(10) > 0; - break; - case NEVER: - FIX_IT = false; - break; - default: throw new JavaLimitationError(); - } - if (FIX_IT) { + if (model.FIX_IT()) { player.view.failedToThrowStonesAndShouldHave(); player.stoneThrow = player.model.consumeMinStones(); }