summaryrefslogtreecommitdiff
path: root/src/main/java/org/luxons
diff options
context:
space:
mode:
authorjbion <joffrey.bion@amadeus.com>2017-01-12 22:30:48 +0100
committerjbion <joffrey.bion@amadeus.com>2017-01-12 22:30:48 +0100
commit6bb2b1941da21b17d47e1b4b6f11c2166afa48b9 (patch)
treea38a1b7d0389f39ee398003723eda88cdc6dc668 /src/main/java/org/luxons
parentFix LobbyController to match the documentation (diff)
downloadseven-wonders-6bb2b1941da21b17d47e1b4b6f11c2166afa48b9.tar.gz
seven-wonders-6bb2b1941da21b17d47e1b4b6f11c2166afa48b9.tar.bz2
seven-wonders-6bb2b1941da21b17d47e1b4b6f11c2166afa48b9.zip
Add multiple ways to pick the side of the wonder
Diffstat (limited to 'src/main/java/org/luxons')
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/Settings.java24
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/data/definitions/WonderDefinition.java2
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/data/definitions/WonderSidePickMethod.java36
3 files changed, 55 insertions, 7 deletions
diff --git a/src/main/java/org/luxons/sevenwonders/game/Settings.java b/src/main/java/org/luxons/sevenwonders/game/Settings.java
index ae85fc46..cf7d1ea0 100644
--- a/src/main/java/org/luxons/sevenwonders/game/Settings.java
+++ b/src/main/java/org/luxons/sevenwonders/game/Settings.java
@@ -5,6 +5,7 @@ import java.util.Map;
import java.util.Random;
import org.luxons.sevenwonders.game.data.definitions.WonderSide;
+import org.luxons.sevenwonders.game.data.definitions.WonderSidePickMethod;
import com.fasterxml.jackson.annotation.JsonIgnore;
@@ -18,10 +19,14 @@ public class Settings {
private int defaultTradingCost = 2;
- private WonderSide wonderSide = WonderSide.A;
+ private WonderSidePickMethod wonderSidePickMethod = WonderSidePickMethod.EACH_RANDOM;
+
+ private transient WonderSide lastPickedSide = null;
private long randomSeedForTests = -1;
+ private transient Random random;
+
private int lostPointsPerDefeat = 1;
private Map<Integer, Integer> wonPointsPerVictoryPerAge = new HashMap<>();
@@ -68,12 +73,16 @@ public class Settings {
this.defaultTradingCost = defaultTradingCost;
}
- public WonderSide getWonderSide() {
- return wonderSide;
+ public WonderSidePickMethod getWonderSidePickMethod() {
+ return wonderSidePickMethod;
}
- public void setWonderSide(WonderSide wonderSide) {
- this.wonderSide = wonderSide;
+ public void setWonderSidePickMethod(WonderSidePickMethod wonderSidePickMethod) {
+ this.wonderSidePickMethod = wonderSidePickMethod;
+ }
+
+ public WonderSide pickWonderSide() {
+ return lastPickedSide = wonderSidePickMethod.pickSide(getRandom(), lastPickedSide);
}
public int getLostPointsPerDefeat() {
@@ -102,6 +111,9 @@ public class Settings {
@JsonIgnore
public Random getRandom() {
- return randomSeedForTests > 0 ? new Random(randomSeedForTests) : new Random();
+ if (random == null) {
+ random = randomSeedForTests > 0 ? new Random(randomSeedForTests) : new Random();
+ }
+ return random;
}
}
diff --git a/src/main/java/org/luxons/sevenwonders/game/data/definitions/WonderDefinition.java b/src/main/java/org/luxons/sevenwonders/game/data/definitions/WonderDefinition.java
index d44cccff..a972a517 100644
--- a/src/main/java/org/luxons/sevenwonders/game/data/definitions/WonderDefinition.java
+++ b/src/main/java/org/luxons/sevenwonders/game/data/definitions/WonderDefinition.java
@@ -17,7 +17,7 @@ public class WonderDefinition implements Definition<Wonder> {
Wonder wonder = new Wonder();
wonder.setName(name);
- WonderSideDefinition wonderSideDef = sides.get(settings.getWonderSide());
+ WonderSideDefinition wonderSideDef = sides.get(settings.pickWonderSide());
wonder.setInitialResource(wonderSideDef.getInitialResource());
wonder.setStages(wonderSideDef.createStages(settings));
wonder.setImage(wonderSideDef.getImage());
diff --git a/src/main/java/org/luxons/sevenwonders/game/data/definitions/WonderSidePickMethod.java b/src/main/java/org/luxons/sevenwonders/game/data/definitions/WonderSidePickMethod.java
new file mode 100644
index 00000000..08aaad14
--- /dev/null
+++ b/src/main/java/org/luxons/sevenwonders/game/data/definitions/WonderSidePickMethod.java
@@ -0,0 +1,36 @@
+package org.luxons.sevenwonders.game.data.definitions;
+
+import java.util.Random;
+
+public enum WonderSidePickMethod {
+ ALL_A {
+ @Override
+ public WonderSide pickSide(Random random, WonderSide lastPickedSide) {
+ return WonderSide.A;
+ }
+ },
+ ALL_B {
+ @Override
+ public WonderSide pickSide(Random random, WonderSide lastPickedSide) {
+ return WonderSide.B;
+ }
+ },
+ EACH_RANDOM {
+ @Override
+ public WonderSide pickSide(Random random, WonderSide lastPickedSide) {
+ return random.nextBoolean() ? WonderSide.A : WonderSide.B;
+ }
+ },
+ SAME_RANDOM_FOR_ALL {
+ @Override
+ public WonderSide pickSide(Random random, WonderSide lastPickedSide) {
+ if (lastPickedSide == null) {
+ return random.nextBoolean() ? WonderSide.A : WonderSide.B;
+ } else {
+ return lastPickedSide;
+ }
+ }
+ };
+
+ public abstract WonderSide pickSide(Random random, WonderSide lastPickedSide);
+}
bgstack15