summaryrefslogtreecommitdiff
path: root/game-engine/src/main/java/org
diff options
context:
space:
mode:
authorJoffrey BION <joffrey.bion@gmail.com>2018-07-05 09:35:27 +0200
committerJoffrey Bion <joffrey.bion@amadeus.com>2018-07-06 14:17:16 +0200
commitccfd6d1d3ba64eef7df1645c24d979c284fd99da (patch)
tree441bc4e931fc998d86f642390096af4d30e9b85f /game-engine/src/main/java/org
parentPrevent PICK_NEIGHBOUR_GUILD action if no guild to pick (diff)
downloadseven-wonders-ccfd6d1d3ba64eef7df1645c24d979c284fd99da.tar.gz
seven-wonders-ccfd6d1d3ba64eef7df1645c24d979c284fd99da.tar.bz2
seven-wonders-ccfd6d1d3ba64eef7df1645c24d979c284fd99da.zip
Kotlin mig: api package
Diffstat (limited to 'game-engine/src/main/java/org')
-rw-r--r--game-engine/src/main/java/org/luxons/sevenwonders/game/Game.java12
-rw-r--r--game-engine/src/main/java/org/luxons/sevenwonders/game/Settings.java93
-rw-r--r--game-engine/src/main/java/org/luxons/sevenwonders/game/Settings.kt34
-rw-r--r--game-engine/src/main/java/org/luxons/sevenwonders/game/api/Action.java20
-rw-r--r--game-engine/src/main/java/org/luxons/sevenwonders/game/api/CustomizableSettings.java128
-rw-r--r--game-engine/src/main/java/org/luxons/sevenwonders/game/api/HandCard.java49
-rw-r--r--game-engine/src/main/java/org/luxons/sevenwonders/game/api/PlayerMove.java45
-rw-r--r--game-engine/src/main/java/org/luxons/sevenwonders/game/api/PlayerTurnInfo.java77
-rw-r--r--game-engine/src/main/java/org/luxons/sevenwonders/game/api/Table.java106
9 files changed, 40 insertions, 524 deletions
diff --git a/game-engine/src/main/java/org/luxons/sevenwonders/game/Game.java b/game-engine/src/main/java/org/luxons/sevenwonders/game/Game.java
index 853d7490..2696adbf 100644
--- a/game-engine/src/main/java/org/luxons/sevenwonders/game/Game.java
+++ b/game-engine/src/main/java/org/luxons/sevenwonders/game/Game.java
@@ -2,6 +2,7 @@ package org.luxons.sevenwonders.game;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -77,16 +78,15 @@ public class Game {
}
private PlayerTurnInfo createPlayerTurnInfo(int playerIndex) {
- PlayerTurnInfo pti = new PlayerTurnInfo(playerIndex, table);
List<HandCard> hand = hands.createHand(table, playerIndex);
- pti.setHand(hand);
Action action = determineAction(hand, table.getBoard(playerIndex));
- pti.setAction(action);
- pti.setMessage(action.getMessage());
+
+ List<Card> neighbourGuildCards = Collections.emptyList();
if (action == Action.PICK_NEIGHBOR_GUILD) {
- pti.setNeighbourGuildCards(table.getNeighbourGuildCards(playerIndex));
+ neighbourGuildCards = table.getNeighbourGuildCards(playerIndex);
}
- return pti;
+
+ return new PlayerTurnInfo(playerIndex, table, action, hand, neighbourGuildCards);
}
public Collection<PlayerTurnInfo> getCurrentTurnInfo() {
diff --git a/game-engine/src/main/java/org/luxons/sevenwonders/game/Settings.java b/game-engine/src/main/java/org/luxons/sevenwonders/game/Settings.java
deleted file mode 100644
index f05b0b01..00000000
--- a/game-engine/src/main/java/org/luxons/sevenwonders/game/Settings.java
+++ /dev/null
@@ -1,93 +0,0 @@
-package org.luxons.sevenwonders.game;
-
-import java.util.Map;
-import java.util.Random;
-
-import org.luxons.sevenwonders.game.api.CustomizableSettings;
-import org.luxons.sevenwonders.game.data.definitions.WonderSide;
-import org.luxons.sevenwonders.game.data.definitions.WonderSidePickMethod;
-
-public class Settings {
-
- private final Random random;
-
- private final int timeLimitInSeconds;
-
- private final int nbPlayers;
-
- private final int initialGold;
-
- private final int discardedCardGold;
-
- private final int defaultTradingCost;
-
- private final int pointsPer3Gold;
-
- private final WonderSidePickMethod wonderSidePickMethod;
-
- private WonderSide lastPickedSide = null;
-
- private final int lostPointsPerDefeat;
-
- private final Map<Integer, Integer> wonPointsPerVictoryPerAge;
-
- public Settings(int nbPlayers) {
- this(nbPlayers, new CustomizableSettings());
- }
-
- public Settings(int nbPlayers, CustomizableSettings customSettings) {
- long seed = customSettings.getRandomSeedForTests();
- this.random = seed > 0 ? new Random(seed) : new Random();
- this.timeLimitInSeconds = customSettings.getTimeLimitInSeconds();
- this.nbPlayers = nbPlayers;
- this.initialGold = customSettings.getInitialGold();
- this.discardedCardGold = customSettings.getDiscardedCardGold();
- this.defaultTradingCost = customSettings.getDefaultTradingCost();
- this.pointsPer3Gold = customSettings.getPointsPer3Gold();
- this.wonderSidePickMethod = customSettings.getWonderSidePickMethod();
- this.lostPointsPerDefeat = customSettings.getLostPointsPerDefeat();
- this.wonPointsPerVictoryPerAge = customSettings.getWonPointsPerVictoryPerAge();
- }
-
- public Random getRandom() {
- return random;
- }
-
- public int getTimeLimitInSeconds() {
- return timeLimitInSeconds;
- }
-
- public int getNbPlayers() {
- return nbPlayers;
- }
-
- public int getInitialGold() {
- return initialGold;
- }
-
- public int getDiscardedCardGold() {
- return discardedCardGold;
- }
-
- public int getDefaultTradingCost() {
- return defaultTradingCost;
- }
-
- public int getPointsPer3Gold() {
- return pointsPer3Gold;
- }
-
- public WonderSide pickWonderSide() {
- WonderSide newSide = wonderSidePickMethod.pickSide(getRandom(), lastPickedSide);
- lastPickedSide = newSide;
- return newSide;
- }
-
- public int getLostPointsPerDefeat() {
- return lostPointsPerDefeat;
- }
-
- public Map<Integer, Integer> getWonPointsPerVictoryPerAge() {
- return wonPointsPerVictoryPerAge;
- }
-}
diff --git a/game-engine/src/main/java/org/luxons/sevenwonders/game/Settings.kt b/game-engine/src/main/java/org/luxons/sevenwonders/game/Settings.kt
new file mode 100644
index 00000000..70dddccf
--- /dev/null
+++ b/game-engine/src/main/java/org/luxons/sevenwonders/game/Settings.kt
@@ -0,0 +1,34 @@
+package org.luxons.sevenwonders.game
+
+import org.luxons.sevenwonders.game.api.CustomizableSettings
+import org.luxons.sevenwonders.game.data.definitions.WonderSide
+import org.luxons.sevenwonders.game.data.definitions.WonderSidePickMethod
+import java.util.Random
+
+class Settings @JvmOverloads constructor(
+ val nbPlayers: Int,
+ customSettings: CustomizableSettings = CustomizableSettings()
+) {
+ val random: Random
+ val timeLimitInSeconds: Int = customSettings.timeLimitInSeconds
+ val initialGold: Int = customSettings.initialGold
+ val discardedCardGold: Int = customSettings.discardedCardGold
+ val defaultTradingCost: Int = customSettings.defaultTradingCost
+ val pointsPer3Gold: Int = customSettings.pointsPer3Gold
+ val lostPointsPerDefeat: Int = customSettings.lostPointsPerDefeat
+ val wonPointsPerVictoryPerAge: Map<Int, Int> = customSettings.wonPointsPerVictoryPerAge
+
+ private val wonderSidePickMethod: WonderSidePickMethod = customSettings.wonderSidePickMethod
+ private var lastPickedSide: WonderSide? = null
+
+ init {
+ val seed = customSettings.randomSeedForTests
+ this.random = if (seed != null) Random(seed) else Random()
+ }
+
+ fun pickWonderSide(): WonderSide {
+ val newSide = wonderSidePickMethod.pickSide(random, lastPickedSide)
+ lastPickedSide = newSide
+ return newSide
+ }
+}
diff --git a/game-engine/src/main/java/org/luxons/sevenwonders/game/api/Action.java b/game-engine/src/main/java/org/luxons/sevenwonders/game/api/Action.java
deleted file mode 100644
index 88e392f9..00000000
--- a/game-engine/src/main/java/org/luxons/sevenwonders/game/api/Action.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package org.luxons.sevenwonders.game.api;
-
-public enum Action {
- PLAY("Pick the card you want to play or discard."),
- PLAY_2("Pick the first card you want to play or discard. Note that you have the ability to play these 2 last cards."
- + " You will choose how to play the last one during your next turn."),
- PLAY_LAST("You have the special ability to play your last card. Choose how you want to play it."),
- PICK_NEIGHBOR_GUILD("Choose a Guild card (purple) that you want to copy from one of your neighbours."),
- WAIT("Please wait for other players to perform extra actions.");
-
- private final String message;
-
- Action(String message) {
- this.message = message;
- }
-
- public String getMessage() {
- return message;
- }
-}
diff --git a/game-engine/src/main/java/org/luxons/sevenwonders/game/api/CustomizableSettings.java b/game-engine/src/main/java/org/luxons/sevenwonders/game/api/CustomizableSettings.java
deleted file mode 100644
index 2cbf8727..00000000
--- a/game-engine/src/main/java/org/luxons/sevenwonders/game/api/CustomizableSettings.java
+++ /dev/null
@@ -1,128 +0,0 @@
-package org.luxons.sevenwonders.game.api;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
-
-import org.luxons.sevenwonders.game.data.definitions.WonderSidePickMethod;
-
-public class CustomizableSettings {
-
- private long randomSeedForTests = -1;
-
- private int timeLimitInSeconds = 45;
-
- private WonderSidePickMethod wonderSidePickMethod = WonderSidePickMethod.EACH_RANDOM;
-
- private int initialGold = 3;
-
- private int discardedCardGold = 3;
-
- private int defaultTradingCost = 2;
-
- private int pointsPer3Gold = 1;
-
- private int lostPointsPerDefeat = 1;
-
- private Map<Integer, Integer> wonPointsPerVictoryPerAge = new HashMap<>();
-
- public CustomizableSettings() {
- wonPointsPerVictoryPerAge.put(1, 1);
- wonPointsPerVictoryPerAge.put(2, 3);
- wonPointsPerVictoryPerAge.put(3, 5);
- }
-
- public long getRandomSeedForTests() {
- return randomSeedForTests;
- }
-
- public void setRandomSeedForTests(long randomSeedForTests) {
- this.randomSeedForTests = randomSeedForTests;
- }
-
- public int getTimeLimitInSeconds() {
- return timeLimitInSeconds;
- }
-
- public void setTimeLimitInSeconds(int timeLimitInSeconds) {
- this.timeLimitInSeconds = timeLimitInSeconds;
- }
-
- public int getInitialGold() {
- return initialGold;
- }
-
- public void setInitialGold(int initialGold) {
- this.initialGold = initialGold;
- }
-
- public int getDiscardedCardGold() {
- return discardedCardGold;
- }
-
- public void setDiscardedCardGold(int discardedCardGold) {
- this.discardedCardGold = discardedCardGold;
- }
-
- public int getDefaultTradingCost() {
- return defaultTradingCost;
- }
-
- public void setDefaultTradingCost(int defaultTradingCost) {
- this.defaultTradingCost = defaultTradingCost;
- }
-
- public int getPointsPer3Gold() {
- return pointsPer3Gold;
- }
-
- public void setPointsPer3Gold(int pointsPer3Gold) {
- this.pointsPer3Gold = pointsPer3Gold;
- }
-
- public WonderSidePickMethod getWonderSidePickMethod() {
- return wonderSidePickMethod;
- }
-
- public void setWonderSidePickMethod(WonderSidePickMethod wonderSidePickMethod) {
- this.wonderSidePickMethod = wonderSidePickMethod;
- }
-
- public int getLostPointsPerDefeat() {
- return lostPointsPerDefeat;
- }
-
- public void setLostPointsPerDefeat(int lostPointsPerDefeat) {
- this.lostPointsPerDefeat = lostPointsPerDefeat;
- }
-
- public Map<Integer, Integer> getWonPointsPerVictoryPerAge() {
- return wonPointsPerVictoryPerAge;
- }
-
- public void setWonPointsPerVictoryPerAge(Map<Integer, Integer> wonPointsPerVictoryPerAge) {
- this.wonPointsPerVictoryPerAge = wonPointsPerVictoryPerAge;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
- CustomizableSettings that = (CustomizableSettings) o;
- return randomSeedForTests == that.randomSeedForTests && timeLimitInSeconds == that.timeLimitInSeconds
- && initialGold == that.initialGold && discardedCardGold == that.discardedCardGold
- && defaultTradingCost == that.defaultTradingCost && pointsPer3Gold == that.pointsPer3Gold
- && lostPointsPerDefeat == that.lostPointsPerDefeat && wonderSidePickMethod == that.wonderSidePickMethod
- && Objects.equals(wonPointsPerVictoryPerAge, that.wonPointsPerVictoryPerAge);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(randomSeedForTests, timeLimitInSeconds, wonderSidePickMethod, initialGold,
- discardedCardGold, defaultTradingCost, pointsPer3Gold, lostPointsPerDefeat, wonPointsPerVictoryPerAge);
- }
-}
diff --git a/game-engine/src/main/java/org/luxons/sevenwonders/game/api/HandCard.java b/game-engine/src/main/java/org/luxons/sevenwonders/game/api/HandCard.java
deleted file mode 100644
index a97679c2..00000000
--- a/game-engine/src/main/java/org/luxons/sevenwonders/game/api/HandCard.java
+++ /dev/null
@@ -1,49 +0,0 @@
-package org.luxons.sevenwonders.game.api;
-
-import org.luxons.sevenwonders.game.boards.Board;
-import org.luxons.sevenwonders.game.cards.Card;
-
-/**
- * A card with contextual information relative to the hand it is sitting in. The extra information is especially useful
- * because it frees the client from a painful business logic implementation.
- */
-public class HandCard {
-
- private final Card card;
-
- private final boolean chainable;
-
- private final boolean free;
-
- private final boolean playable;
-
- public HandCard(Card card, Table table, int playerIndex) {
- Board board = table.getBoard(playerIndex);
- this.card = card;
- this.chainable = card.isChainableOn(board);
- this.free = card.isFreeFor(board);
- this.playable = card.isPlayable(table, playerIndex);
- }
-
- public Card getCard() {
- return card;
- }
-
- public boolean isChainable() {
- return chainable;
- }
-
- public boolean isFree() {
- return free;
- }
-
- public boolean isPlayable() {
- return playable;
- }
-
- @Override
- public String toString() {
- return "HandCard{" + "card=" + card + ", chainable=" + chainable + ", free=" + free + ", playable=" + playable
- + '}';
- }
-}
diff --git a/game-engine/src/main/java/org/luxons/sevenwonders/game/api/PlayerMove.java b/game-engine/src/main/java/org/luxons/sevenwonders/game/api/PlayerMove.java
deleted file mode 100644
index 807e51a9..00000000
--- a/game-engine/src/main/java/org/luxons/sevenwonders/game/api/PlayerMove.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package org.luxons.sevenwonders.game.api;
-
-import java.util.ArrayList;
-import java.util.Collection;
-
-import org.luxons.sevenwonders.game.moves.MoveType;
-import org.luxons.sevenwonders.game.resources.ResourceTransaction;
-
-public class PlayerMove {
-
- private MoveType type;
-
- private String cardName;
-
- private Collection<ResourceTransaction> transactions = new ArrayList<>();
-
- public MoveType getType() {
- return type;
- }
-
- public void setType(MoveType type) {
- this.type = type;
- }
-
- public String getCardName() {
- return cardName;
- }
-
- public void setCardName(String cardName) {
- this.cardName = cardName;
- }
-
- public Collection<ResourceTransaction> getTransactions() {
- return transactions;
- }
-
- public void setTransactions(Collection<ResourceTransaction> transactions) {
- this.transactions = transactions;
- }
-
- @Override
- public String toString() {
- return type + " '" + cardName + '\'';
- }
-}
diff --git a/game-engine/src/main/java/org/luxons/sevenwonders/game/api/PlayerTurnInfo.java b/game-engine/src/main/java/org/luxons/sevenwonders/game/api/PlayerTurnInfo.java
deleted file mode 100644
index 3d92d40b..00000000
--- a/game-engine/src/main/java/org/luxons/sevenwonders/game/api/PlayerTurnInfo.java
+++ /dev/null
@@ -1,77 +0,0 @@
-package org.luxons.sevenwonders.game.api;
-
-import java.util.List;
-
-import org.luxons.sevenwonders.game.cards.Card;
-
-public class PlayerTurnInfo {
-
- private final int playerIndex;
-
- private final Table table;
-
- private final int currentAge;
-
- private Action action;
-
- private List<HandCard> hand;
-
- private List<Card> neighbourGuildCards;
-
- private String message;
-
- public PlayerTurnInfo(int playerIndex, Table table) {
- this.playerIndex = playerIndex;
- this.table = table;
- this.currentAge = table.getCurrentAge();
- }
-
- public int getPlayerIndex() {
- return playerIndex;
- }
-
- public Table getTable() {
- return table;
- }
-
- public int getCurrentAge() {
- return currentAge;
- }
-
- public List<HandCard> getHand() {
- return hand;
- }
-
- public void setHand(List<HandCard> hand) {
- this.hand = hand;
- }
-
- public List<Card> getNeighbourGuildCards() {
- return neighbourGuildCards;
- }
-
- public void setNeighbourGuildCards(List<Card> neighbourGuildCards) {
- this.neighbourGuildCards = neighbourGuildCards;
- }
-
- public Action getAction() {
- return action;
- }
-
- public void setAction(Action action) {
- this.action = action;
- }
-
- public String getMessage() {
- return message;
- }
-
- public void setMessage(String message) {
- this.message = message;
- }
-
- @Override
- public String toString() {
- return "PlayerTurnInfo{" + "playerIndex=" + playerIndex + ", action=" + action + ", hand=" + hand + '}';
- }
-}
diff --git a/game-engine/src/main/java/org/luxons/sevenwonders/game/api/Table.java b/game-engine/src/main/java/org/luxons/sevenwonders/game/api/Table.java
deleted file mode 100644
index 82f9055a..00000000
--- a/game-engine/src/main/java/org/luxons/sevenwonders/game/api/Table.java
+++ /dev/null
@@ -1,106 +0,0 @@
-package org.luxons.sevenwonders.game.api;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.stream.Collectors;
-
-import org.luxons.sevenwonders.game.boards.Board;
-import org.luxons.sevenwonders.game.boards.RelativeBoardPosition;
-import org.luxons.sevenwonders.game.cards.Card;
-import org.luxons.sevenwonders.game.cards.Color;
-import org.luxons.sevenwonders.game.cards.HandRotationDirection;
-import org.luxons.sevenwonders.game.moves.Move;
-import org.luxons.sevenwonders.game.resources.Provider;
-
-/**
- * The table contains what is visible by all the players in the game: the boards and their played cards, and the
- * players' information.
- */
-public class Table {
-
- private final int nbPlayers;
-
- private final List<Board> boards;
-
- private int currentAge = 0;
-
- private List<Move> lastPlayedMoves;
-
- public Table(List<Board> boards) {
- this.nbPlayers = boards.size();
- this.boards = boards;
- }
-
- public int getNbPlayers() {
- return nbPlayers;
- }
-
- public List<Board> getBoards() {
- return boards;
- }
-
- public Board getBoard(int playerIndex) {
- return boards.get(playerIndex);
- }
-
- public Board getBoard(int playerIndex, RelativeBoardPosition position) {
- return boards.get(position.getIndexFrom(playerIndex, nbPlayers));
- }
-
- public List<Move> getLastPlayedMoves() {
- return lastPlayedMoves;
- }
-
- public void setLastPlayedMoves(List<Move> lastPlayedMoves) {
- this.lastPlayedMoves = lastPlayedMoves;
- }
-
- public int getCurrentAge() {
- return currentAge;
- }
-
- public void increaseCurrentAge() {
- this.currentAge++;
- }
-
- public HandRotationDirection getHandRotationDirection() {
- return HandRotationDirection.forAge(currentAge);
- }
-
- public void resolveMilitaryConflicts() {
- for (int i = 0; i < nbPlayers; i++) {
- Board board1 = getBoard(i);
- Board board2 = getBoard((i + 1) % nbPlayers);
- resolveConflict(board1, board2, currentAge);
- }
- }
-
- private static void resolveConflict(Board board1, Board board2, int age) {
- int shields1 = board1.getMilitary().getNbShields();
- int shields2 = board2.getMilitary().getNbShields();
- if (shields1 < shields2) {
- board2.getMilitary().victory(age);
- board1.getMilitary().defeat();
- } else if (shields1 > shields2) {
- board1.getMilitary().victory(age);
- board2.getMilitary().defeat();
- }
- }
-
- public List<Card> getNeighbourGuildCards(int playerIndex) {
- return getNeighbourBoards(playerIndex).stream()
- .map(Board::getPlayedCards)
- .flatMap(List::stream)
- .filter(c -> c.getColor() == Color.PURPLE)
- .collect(Collectors.toList());
- }
-
- private List<Board> getNeighbourBoards(int playerIndex) {
- Provider[] providers = Provider.values();
- List<Board> boards = new ArrayList<>(providers.length);
- for (Provider provider : providers) {
- boards.add(getBoard(playerIndex, provider.getBoardPosition()));
- }
- return boards;
- }
-}
bgstack15