summaryrefslogtreecommitdiff
path: root/game-engine/src/main/java
diff options
context:
space:
mode:
authorjbion <joffrey.bion@amadeus.com>2018-07-09 11:37:41 +0200
committerjbion <joffrey.bion@amadeus.com>2018-07-09 11:37:41 +0200
commita829a1769bb14c1557b98378bd7e985c8dc54013 (patch)
tree735300c1eaa9543aa6b002cfe1aa1b648272c579 /game-engine/src/main/java
parentKotlin mig: wonders package (diff)
downloadseven-wonders-a829a1769bb14c1557b98378bd7e985c8dc54013.tar.gz
seven-wonders-a829a1769bb14c1557b98378bd7e985c8dc54013.tar.bz2
seven-wonders-a829a1769bb14c1557b98378bd7e985c8dc54013.zip
Kotlin mig: Boards package
Diffstat (limited to 'game-engine/src/main/java')
-rw-r--r--game-engine/src/main/java/org/luxons/sevenwonders/game/boards/Board.java179
-rw-r--r--game-engine/src/main/java/org/luxons/sevenwonders/game/boards/BoardElementType.java28
-rw-r--r--game-engine/src/main/java/org/luxons/sevenwonders/game/boards/Military.java56
-rw-r--r--game-engine/src/main/java/org/luxons/sevenwonders/game/boards/RelativeBoardPosition.java28
-rw-r--r--game-engine/src/main/java/org/luxons/sevenwonders/game/boards/Science.java65
-rw-r--r--game-engine/src/main/java/org/luxons/sevenwonders/game/boards/ScienceType.java7
6 files changed, 0 insertions, 363 deletions
diff --git a/game-engine/src/main/java/org/luxons/sevenwonders/game/boards/Board.java b/game-engine/src/main/java/org/luxons/sevenwonders/game/boards/Board.java
deleted file mode 100644
index 23ce5da5..00000000
--- a/game-engine/src/main/java/org/luxons/sevenwonders/game/boards/Board.java
+++ /dev/null
@@ -1,179 +0,0 @@
-package org.luxons.sevenwonders.game.boards;
-
-import java.util.ArrayList;
-import java.util.EnumSet;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.luxons.sevenwonders.game.Settings;
-import org.luxons.sevenwonders.game.api.Table;
-import org.luxons.sevenwonders.game.cards.Card;
-import org.luxons.sevenwonders.game.cards.Color;
-import org.luxons.sevenwonders.game.effects.SpecialAbility;
-import org.luxons.sevenwonders.game.resources.Production;
-import org.luxons.sevenwonders.game.resources.TradingRules;
-import org.luxons.sevenwonders.game.scoring.PlayerScore;
-import org.luxons.sevenwonders.game.scoring.ScoreCategory;
-import org.luxons.sevenwonders.game.wonders.Wonder;
-
-public class Board {
-
- private final Wonder wonder;
-
- private final int playerIndex;
-
- private final List<Card> playedCards = new ArrayList<>();
-
- private final Production production = new Production();
-
- private final Production publicProduction = new Production();
-
- private final Science science = new Science();
-
- private final TradingRules tradingRules;
-
- private final Military military;
-
- private final Set<SpecialAbility> specialAbilities = EnumSet.noneOf(SpecialAbility.class);
-
- private Map<Integer, Boolean> consumedFreeCards = new HashMap<>();
-
- private Card copiedGuild;
-
- private int gold;
-
- private int pointsPer3Gold;
-
- public Board(Wonder wonder, int playerIndex, Settings settings) {
- this.wonder = wonder;
- this.playerIndex = playerIndex;
- this.gold = settings.getInitialGold();
- this.tradingRules = new TradingRules(settings.getDefaultTradingCost());
- this.military = new Military(settings.getLostPointsPerDefeat(), settings.getWonPointsPerVictoryPerAge());
- this.pointsPer3Gold = settings.getPointsPer3Gold();
- this.production.addFixedResource(wonder.getInitialResource(), 1);
- this.publicProduction.addFixedResource(wonder.getInitialResource(), 1);
- }
-
- public int getPlayerIndex() {
- return playerIndex;
- }
-
- public Wonder getWonder() {
- return wonder;
- }
-
- public List<Card> getPlayedCards() {
- return playedCards;
- }
-
- public void addCard(Card card) {
- playedCards.add(card);
- }
-
- int getNbCardsOfColor(List<Color> colorFilter) {
- return (int) playedCards.stream().filter(c -> colorFilter.contains(c.getColor())).count();
- }
-
- public boolean isPlayed(String cardName) {
- return getPlayedCards().stream().map(Card::getName).filter(name -> name.equals(cardName)).count() > 0;
- }
-
- public Production getProduction() {
- return production;
- }
-
- public Production getPublicProduction() {
- return publicProduction;
- }
-
- public TradingRules getTradingRules() {
- return tradingRules;
- }
-
- public Science getScience() {
- return science;
- }
-
- public int getGold() {
- return gold;
- }
-
- public void setGold(int amount) {
- this.gold = amount;
- }
-
- public void addGold(int amount) {
- this.gold += amount;
- }
-
- public void removeGold(int amount) {
- if (gold < amount) {
- throw new InsufficientFundsException(gold, amount);
- }
- this.gold -= amount;
- }
-
- public Military getMilitary() {
- return military;
- }
-
- public void addSpecial(SpecialAbility specialAbility) {
- specialAbilities.add(specialAbility);
- }
-
- public boolean hasSpecial(SpecialAbility specialAbility) {
- return specialAbilities.contains(specialAbility);
- }
-
- public boolean canPlayFreeCard(int age) {
- return hasSpecial(SpecialAbility.ONE_FREE_PER_AGE) && !consumedFreeCards.getOrDefault(age, false);
- }
-
- public void consumeFreeCard(int age) {
- consumedFreeCards.put(age, true);
- }
-
- public void setCopiedGuild(Card copiedGuild) {
- if (copiedGuild.getColor() != Color.PURPLE) {
- throw new IllegalArgumentException("The given card '" + copiedGuild + "' is not a Guild card");
- }
- this.copiedGuild = copiedGuild;
- }
-
- public Card getCopiedGuild() {
- return copiedGuild;
- }
-
- public PlayerScore computePoints(Table table) {
- PlayerScore score = new PlayerScore(gold);
- score.put(ScoreCategory.CIVIL, computePointsForCards(table, Color.BLUE));
- score.put(ScoreCategory.MILITARY, military.getTotalPoints());
- score.put(ScoreCategory.SCIENCE, science.computePoints());
- score.put(ScoreCategory.TRADE, computePointsForCards(table, Color.YELLOW));
- score.put(ScoreCategory.GUILD, computePointsForCards(table, Color.PURPLE));
- score.put(ScoreCategory.WONDER, wonder.computePoints(table, playerIndex));
- score.put(ScoreCategory.GOLD, computeGoldPoints());
- return score;
- }
-
- private int computePointsForCards(Table table, Color color) {
- return playedCards.stream()
- .filter(c -> c.getColor() == color)
- .flatMap(c -> c.getEffects().stream())
- .mapToInt(e -> e.computePoints(table, playerIndex))
- .sum();
- }
-
- private int computeGoldPoints() {
- return gold / 3 * pointsPer3Gold;
- }
-
- static class InsufficientFundsException extends RuntimeException {
- InsufficientFundsException(int current, int required) {
- super(String.format("Current balance is %d gold, but %d are required", current, required));
- }
- }
-}
diff --git a/game-engine/src/main/java/org/luxons/sevenwonders/game/boards/BoardElementType.java b/game-engine/src/main/java/org/luxons/sevenwonders/game/boards/BoardElementType.java
deleted file mode 100644
index e50f4ea0..00000000
--- a/game-engine/src/main/java/org/luxons/sevenwonders/game/boards/BoardElementType.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package org.luxons.sevenwonders.game.boards;
-
-import java.util.List;
-
-import org.luxons.sevenwonders.game.cards.Color;
-
-public enum BoardElementType {
- CARD {
- @Override
- public int getElementCount(Board board, List<Color> colors) {
- return board.getNbCardsOfColor(colors);
- }
- },
- BUILT_WONDER_STAGES {
- @Override
- public int getElementCount(Board board, List<Color> colors) {
- return board.getWonder().getNbBuiltStages();
- }
- },
- DEFEAT_TOKEN {
- @Override
- public int getElementCount(Board board, List<Color> colors) {
- return board.getMilitary().getNbDefeatTokens();
- }
- };
-
- public abstract int getElementCount(Board board, List<Color> colors);
-}
diff --git a/game-engine/src/main/java/org/luxons/sevenwonders/game/boards/Military.java b/game-engine/src/main/java/org/luxons/sevenwonders/game/boards/Military.java
deleted file mode 100644
index e5cc7033..00000000
--- a/game-engine/src/main/java/org/luxons/sevenwonders/game/boards/Military.java
+++ /dev/null
@@ -1,56 +0,0 @@
-package org.luxons.sevenwonders.game.boards;
-
-import java.util.Map;
-
-public class Military {
-
- private final int lostPointsPerDefeat;
-
- private final Map<Integer, Integer> wonPointsPerVictoryPerAge;
-
- private int nbShields = 0;
-
- private int totalPoints = 0;
-
- private int nbDefeatTokens = 0;
-
- Military(int lostPointsPerDefeat, Map<Integer, Integer> wonPointsPerVictoryPerAge) {
- this.lostPointsPerDefeat = lostPointsPerDefeat;
- this.wonPointsPerVictoryPerAge = wonPointsPerVictoryPerAge;
- }
-
- public int getNbShields() {
- return nbShields;
- }
-
- public void addShields(int nbShields) {
- this.nbShields += nbShields;
- }
-
- public int getTotalPoints() {
- return totalPoints;
- }
-
- public int getNbDefeatTokens() {
- return nbDefeatTokens;
- }
-
- public void victory(int age) {
- Integer wonPoints = wonPointsPerVictoryPerAge.get(age);
- if (wonPoints == null) {
- throw new UnknownAgeException(age);
- }
- totalPoints += wonPoints;
- }
-
- public void defeat() {
- totalPoints -= lostPointsPerDefeat;
- nbDefeatTokens++;
- }
-
- static final class UnknownAgeException extends IllegalArgumentException {
- UnknownAgeException(int unknownAge) {
- super(String.valueOf(unknownAge));
- }
- }
-}
diff --git a/game-engine/src/main/java/org/luxons/sevenwonders/game/boards/RelativeBoardPosition.java b/game-engine/src/main/java/org/luxons/sevenwonders/game/boards/RelativeBoardPosition.java
deleted file mode 100644
index 16b2f3a9..00000000
--- a/game-engine/src/main/java/org/luxons/sevenwonders/game/boards/RelativeBoardPosition.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package org.luxons.sevenwonders.game.boards;
-
-public enum RelativeBoardPosition {
- LEFT {
- @Override
- public int getIndexFrom(int playerIndex, int nbPlayers) {
- return wrapIndex(playerIndex - 1, nbPlayers);
- }
- },
- SELF {
- @Override
- public int getIndexFrom(int playerIndex, int nbPlayers) {
- return playerIndex;
- }
- },
- RIGHT {
- @Override
- public int getIndexFrom(int playerIndex, int nbPlayers) {
- return wrapIndex(playerIndex + 1, nbPlayers);
- }
- };
-
- public abstract int getIndexFrom(int playerIndex, int nbPlayers);
-
- int wrapIndex(int index, int nbPlayers) {
- return Math.floorMod(index, nbPlayers);
- }
-}
diff --git a/game-engine/src/main/java/org/luxons/sevenwonders/game/boards/Science.java b/game-engine/src/main/java/org/luxons/sevenwonders/game/boards/Science.java
deleted file mode 100644
index 34928bcc..00000000
--- a/game-engine/src/main/java/org/luxons/sevenwonders/game/boards/Science.java
+++ /dev/null
@@ -1,65 +0,0 @@
-package org.luxons.sevenwonders.game.boards;
-
-import java.util.Arrays;
-import java.util.EnumMap;
-import java.util.Map;
-
-public class Science {
-
- private Map<ScienceType, Integer> quantities = new EnumMap<>(ScienceType.class);
-
- private int jokers;
-
- public void add(ScienceType type, int quantity) {
- quantities.merge(type, quantity, (x, y) -> x + y);
- }
-
- public void addJoker(int quantity) {
- jokers += quantity;
- }
-
- public int getJokers() {
- return jokers;
- }
-
- public void addAll(Science science) {
- science.quantities.forEach(this::add);
- jokers += science.jokers;
- }
-
- public int getQuantity(ScienceType type) {
- return quantities.getOrDefault(type, 0);
- }
-
- public int size() {
- return quantities.values().stream().mapToInt(q -> q).sum() + jokers;
- }
-
- public int computePoints() {
- ScienceType[] types = ScienceType.values();
- Integer[] values = new Integer[types.length];
- for (int i = 0; i < types.length; i++) {
- values[i] = quantities.getOrDefault(types[i], 0);
- }
- return computePoints(values, jokers);
- }
-
- private static int computePoints(Integer[] values, int jokers) {
- if (jokers == 0) {
- return computePointsNoJoker(values);
- }
- int maxPoints = 0;
- for (int i = 0; i < values.length; i++) {
- values[i]++;
- maxPoints = Math.max(maxPoints, computePoints(values, jokers - 1));
- values[i]--;
- }
- return maxPoints;
- }
-
- private static int computePointsNoJoker(Integer[] values) {
- int independentSquaresSum = Arrays.stream(values).mapToInt(i -> i * i).sum();
- int nbGroupsOfAll = Arrays.stream(values).mapToInt(i -> i).min().orElse(0);
- return independentSquaresSum + nbGroupsOfAll * 7;
- }
-}
diff --git a/game-engine/src/main/java/org/luxons/sevenwonders/game/boards/ScienceType.java b/game-engine/src/main/java/org/luxons/sevenwonders/game/boards/ScienceType.java
deleted file mode 100644
index f1b14c6d..00000000
--- a/game-engine/src/main/java/org/luxons/sevenwonders/game/boards/ScienceType.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package org.luxons.sevenwonders.game.boards;
-
-public enum ScienceType {
- COMPASS,
- WHEEL,
- TABLET
-}
bgstack15