From: JBM Date: Fri, 29 May 2020 12:54:25 +0000 (+0200) Subject: Make game parameters overridable through game settings X-Git-Url: https://troll.desast.re/troll.git/commitdiff_plain/055ce8e682c4b82d5b52362e88df2f9d6a7d53d6?ds=inline Make game parameters overridable through game settings --- diff --git a/PLAN.org b/PLAN.org index d8d1402..11f0892 100644 --- a/PLAN.org +++ b/PLAN.org @@ -46,6 +46,6 @@ That one's probably never going to be DONE ^^' - [ ] troll pants colors * TODO Troll quotes - pain au chocolat ou chocolatine -* TODO initial model parametrization +* DONE initial model parametrization * TODO view parameterization? * TODO troll races diff --git a/config/statement_en.html b/config/statement_en.html index 7ba83d1..428577f 100644 --- a/config/statement_en.html +++ b/config/statement_en.html @@ -100,7 +100,7 @@

  - Maps + Expert rules

@@ -120,6 +120,10 @@ is subject to change without notice. Why do you think they're provided in the game input?

+

+ You can also override them via game + settings roadLength and initialStones. +

@@ -137,7 +141,7 @@

This draft's last change is: - the troll can speak. + game parameters can be overridden.

diff --git a/src/main/java/com/codingame/game/Model.java b/src/main/java/com/codingame/game/Model.java index 405db66..46841db 100644 --- a/src/main/java/com/codingame/game/Model.java +++ b/src/main/java/com/codingame/game/Model.java @@ -1,7 +1,9 @@ package com.codingame.game; import java.util.Random; +import java.util.Properties; +import com.codingame.gameengine.core.GameManager; import com.codingame.gameengine.core.MultiplayerGameManager; import com.google.inject.Inject; @@ -93,6 +95,40 @@ class Model { break; } + Properties ps = gameManager.getGameParameters(); + String buf = ps.getProperty("roadLength"); + if (buf != null) { + try { + int i = Integer.parseInt(buf); + if (i < 0 || i > 20 || (i & 1) != 0) { + gameManager.addToGameSummary(GameManager.formatErrorMessage("Ignoring invalid road length: " + buf)); + } + else { + roadLength = i; + gameManager.addToGameSummary("Road length overridden to " + i); + } + } + catch(NumberFormatException e) { + gameManager.addToGameSummary(GameManager.formatErrorMessage("Ill-formed road length: " + buf)); + } + } + buf = ps.getProperty("initialStones"); + if (buf != null) { + try { + int i = Integer.parseInt(buf); + if (i > 50) { + gameManager.addToGameSummary(GameManager.formatErrorMessage("Ignoring invalid initial stone count: " + buf)); + } + else { + initialStones = i; + gameManager.addToGameSummary("Initial stone count overridden to " + buf); + } + } + catch (NumberFormatException e) { + gameManager.addToGameSummary(GameManager.formatErrorMessage("Ill-formed initial stone count: " + buf)); + } + } + trollPosition = roadLength / 2; p0 = new Player(0); diff --git a/src/test/java/Main.java b/src/test/java/Main.java index 79bfaed..8de5bd7 100644 --- a/src/test/java/Main.java +++ b/src/test/java/Main.java @@ -1,9 +1,15 @@ +import java.util.Properties; + import com.codingame.gameengine.runner.MultiplayerGameRunner; public class Main { public static void main(String[] args) { + Properties props = new Properties(); + props.setProperty("seed", "3"); MultiplayerGameRunner gameRunner = new MultiplayerGameRunner(); + gameRunner.setGameParameters(props); + gameRunner.addAgent(Player1.class); gameRunner.addAgent(PlayerRand.class);