diff options
author | Joffrey BION <joffrey.bion@gmail.com> | 2018-07-05 09:35:27 +0200 |
---|---|---|
committer | Joffrey Bion <joffrey.bion@amadeus.com> | 2018-07-06 14:17:16 +0200 |
commit | ccfd6d1d3ba64eef7df1645c24d979c284fd99da (patch) | |
tree | 441bc4e931fc998d86f642390096af4d30e9b85f /game-engine | |
parent | Prevent PICK_NEIGHBOUR_GUILD action if no guild to pick (diff) | |
download | seven-wonders-ccfd6d1d3ba64eef7df1645c24d979c284fd99da.tar.gz seven-wonders-ccfd6d1d3ba64eef7df1645c24d979c284fd99da.tar.bz2 seven-wonders-ccfd6d1d3ba64eef7df1645c24d979c284fd99da.zip |
Kotlin mig: api package
Diffstat (limited to 'game-engine')
39 files changed, 604 insertions, 961 deletions
diff --git a/game-engine/build.gradle b/game-engine/build.gradle index 956e9f3a..5a3cc4ea 100644 --- a/game-engine/build.gradle +++ b/game-engine/build.gradle @@ -1,4 +1,7 @@ -apply plugin: 'java-library' +plugins { + id "org.jetbrains.kotlin.jvm" version "1.2.51" +} + apply plugin: 'checkstyle' group 'org.luxons' @@ -9,12 +12,15 @@ repositories { configurations { checkstyleConfig + ktlint } dependencies { + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" implementation 'com.google.code.gson:gson:2.8.0' testImplementation 'junit:junit:4.12' checkstyleConfig "org.hildan.checkstyle:checkstyle-config:2.1.0" + ktlint "com.github.shyiko:ktlint:0.24.0" } checkstyle { 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/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; - } -} diff --git a/game-engine/src/main/java/org/luxons/sevenwonders/game/api/Action.java b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/Action.kt index 88e392f9..37ab3e6f 100644 --- a/game-engine/src/main/java/org/luxons/sevenwonders/game/api/Action.java +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/Action.kt @@ -1,20 +1,10 @@ -package org.luxons.sevenwonders.game.api; +package org.luxons.sevenwonders.game.api -public enum Action { +enum class Action constructor(val message: String) { 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_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; - } + WAIT("Please wait for other players to perform extra actions.") } diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/CustomizableSettings.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/CustomizableSettings.kt new file mode 100644 index 00000000..354aecb6 --- /dev/null +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/CustomizableSettings.kt @@ -0,0 +1,15 @@ +package org.luxons.sevenwonders.game.api + +import org.luxons.sevenwonders.game.data.definitions.WonderSidePickMethod + +data class CustomizableSettings( + val randomSeedForTests: Long? = null, + val timeLimitInSeconds: Int = 45, + val wonderSidePickMethod: WonderSidePickMethod = WonderSidePickMethod.EACH_RANDOM, + val initialGold: Int = 3, + val discardedCardGold: Int = 3, + val defaultTradingCost: Int = 2, + val pointsPer3Gold: Int = 1, + val lostPointsPerDefeat: Int = 1, + val wonPointsPerVictoryPerAge: Map<Int, Int> = mapOf(1 to 1, 2 to 3, 3 to 5) +) diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/HandCard.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/HandCard.kt new file mode 100644 index 00000000..4c3a7a8d --- /dev/null +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/HandCard.kt @@ -0,0 +1,23 @@ +package org.luxons.sevenwonders.game.api + +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. + */ +class HandCard(val card: Card, table: Table, playerIndex: Int) { + + val isChainable: Boolean + + val isFree: Boolean + + val isPlayable: Boolean + + init { + val board = table.getBoard(playerIndex) + this.isChainable = card.isChainableOn(board) + this.isFree = card.isFreeFor(board) + this.isPlayable = card.isPlayable(table, playerIndex) + } +} diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/PlayerMove.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/PlayerMove.kt new file mode 100644 index 00000000..d0a1e1b3 --- /dev/null +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/PlayerMove.kt @@ -0,0 +1,10 @@ +package org.luxons.sevenwonders.game.api + +import org.luxons.sevenwonders.game.moves.MoveType +import org.luxons.sevenwonders.game.resources.ResourceTransaction + +data class PlayerMove( + val type: MoveType, + val cardName: String?, + val transactions: Collection<ResourceTransaction> = emptyList() +) diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/PlayerTurnInfo.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/PlayerTurnInfo.kt new file mode 100644 index 00000000..3439a9af --- /dev/null +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/PlayerTurnInfo.kt @@ -0,0 +1,14 @@ +package org.luxons.sevenwonders.game.api + +import org.luxons.sevenwonders.game.cards.Card + +data class PlayerTurnInfo( + val playerIndex: Int, + val table: Table, + val action: Action, + val hand: List<HandCard>, + val neighbourGuildCards: List<Card> +) { + val currentAge: Int = table.currentAge + val message: String = action.message +} diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/Table.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/Table.kt new file mode 100644 index 00000000..9ecfa6b0 --- /dev/null +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/Table.kt @@ -0,0 +1,66 @@ +package org.luxons.sevenwonders.game.api + +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. + */ +class Table(val boards: List<Board>) { + + val nbPlayers: Int = boards.size + + var currentAge = 0 + private set + + val handRotationDirection: HandRotationDirection + get() = HandRotationDirection.forAge(currentAge) + + var lastPlayedMoves: List<Move> = emptyList() + + fun getBoard(playerIndex: Int): Board { + return boards[playerIndex] + } + + fun getBoard(playerIndex: Int, position: RelativeBoardPosition): Board { + return boards[position.getIndexFrom(playerIndex, nbPlayers)] + } + + fun increaseCurrentAge() { + this.currentAge++ + } + + fun resolveMilitaryConflicts() { + for (i in 0 until nbPlayers) { + val board1 = getBoard(i) + val board2 = getBoard((i + 1) % nbPlayers) + resolveConflict(board1, board2, currentAge) + } + } + + private fun resolveConflict(board1: Board, board2: Board, age: Int) { + val shields1 = board1.military.nbShields + val shields2 = board2.military.nbShields + if (shields1 < shields2) { + board1.military.defeat() + board2.military.victory(age) + } else if (shields1 > shields2) { + board1.military.victory(age) + board2.military.defeat() + } + } + + fun getNeighbourGuildCards(playerIndex: Int): List<Card> { + return getNeighbourBoards(playerIndex).flatMap(Board::getPlayedCards).filter { c -> c.color == Color.PURPLE } + } + + private fun getNeighbourBoards(playerIndex: Int): List<Board> { + return Provider.values().map { getBoard(playerIndex, it.boardPosition) } + } +} diff --git a/game-engine/src/test/java/org/luxons/sevenwonders/game/GameTest.java b/game-engine/src/test/java/org/luxons/sevenwonders/game/GameTest.java index 02531cde..9beb44fd 100644 --- a/game-engine/src/test/java/org/luxons/sevenwonders/game/GameTest.java +++ b/game-engine/src/test/java/org/luxons/sevenwonders/game/GameTest.java @@ -21,7 +21,7 @@ import org.luxons.sevenwonders.game.resources.BestPriceCalculator; import org.luxons.sevenwonders.game.resources.ResourceTransaction; import org.luxons.sevenwonders.game.resources.ResourceTransactions; import org.luxons.sevenwonders.game.resources.Resources; -import org.luxons.sevenwonders.game.test.TestUtils; +import org.luxons.sevenwonders.game.test.TestUtilsKt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -48,7 +48,7 @@ public class GameTest { } private static Game createGame(int nbPlayers) { - CustomizableSettings settings = TestUtils.createCustomizableSettings(); + CustomizableSettings settings = TestUtilsKt.testCustomizableSettings(); return new GameDefinitionLoader().getGameDefinition().initGame(0, settings, nbPlayers); } @@ -99,11 +99,11 @@ public class GameTest { for (HandCard handCard : turnInfo.getHand()) { if (handCard.isPlayable()) { Set<ResourceTransaction> resourcesToBuy = findResourcesToBuyFor(handCard, turnInfo); - return TestUtils.createPlayerMove(handCard.getCard().getName(), MoveType.PLAY, resourcesToBuy); + return TestUtilsKt.createPlayerMove(MoveType.PLAY, handCard.getCard().getName(), resourcesToBuy); } } HandCard firstCardInHand = turnInfo.getHand().get(0); - return TestUtils.createPlayerMove(firstCardInHand.getCard().getName(), MoveType.DISCARD); + return TestUtilsKt.createPlayerMove(MoveType.DISCARD, firstCardInHand.getCard().getName()); } private static Set<ResourceTransaction> findResourcesToBuyFor(HandCard handCard, PlayerTurnInfo turnInfo) { @@ -122,6 +122,6 @@ public class GameTest { assertNotNull(neighbourGuilds); assertFalse(neighbourGuilds.isEmpty()); String cardName = neighbourGuilds.get(0).getName(); - return TestUtils.createPlayerMove(cardName, MoveType.COPY_GUILD); + return TestUtilsKt.createPlayerMove(MoveType.COPY_GUILD, cardName); } } diff --git a/game-engine/src/test/java/org/luxons/sevenwonders/game/api/TableTest.java b/game-engine/src/test/java/org/luxons/sevenwonders/game/api/TableTest.java index 93b6eb08..0dfa3a80 100644 --- a/game-engine/src/test/java/org/luxons/sevenwonders/game/api/TableTest.java +++ b/game-engine/src/test/java/org/luxons/sevenwonders/game/api/TableTest.java @@ -8,7 +8,7 @@ import org.junit.experimental.theories.Theory; import org.junit.runner.RunWith; import org.luxons.sevenwonders.game.boards.RelativeBoardPosition; import org.luxons.sevenwonders.game.cards.Card; -import org.luxons.sevenwonders.game.test.TestUtils; +import org.luxons.sevenwonders.game.test.TestUtilsKt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -26,7 +26,7 @@ public class TableTest { @Theory public void getBoard_wrapLeft(int nbPlayers) { assumeTrue(nbPlayers >= 2); - Table table = TestUtils.createTable(nbPlayers); + Table table = TestUtilsKt.testTable(nbPlayers); int last = nbPlayers - 1; assertEquals(table.getBoard(last), table.getBoard(0, RelativeBoardPosition.LEFT)); assertEquals(table.getBoard(0), table.getBoard(0, RelativeBoardPosition.SELF)); @@ -36,7 +36,7 @@ public class TableTest { @Theory public void getBoard_wrapRight(int nbPlayers) { assumeTrue(nbPlayers >= 2); - Table table = TestUtils.createTable(nbPlayers); + Table table = TestUtilsKt.testTable(nbPlayers); int last = nbPlayers - 1; assertEquals(table.getBoard(last - 1), table.getBoard(last, RelativeBoardPosition.LEFT)); assertEquals(table.getBoard(last), table.getBoard(last, RelativeBoardPosition.SELF)); @@ -46,7 +46,7 @@ public class TableTest { @Theory public void getBoard_noWrap(int nbPlayers) { assumeTrue(nbPlayers >= 3); - Table table = TestUtils.createTable(nbPlayers); + Table table = TestUtilsKt.testTable(nbPlayers); assertEquals(table.getBoard(0), table.getBoard(1, RelativeBoardPosition.LEFT)); assertEquals(table.getBoard(1), table.getBoard(1, RelativeBoardPosition.SELF)); assertEquals(table.getBoard(2), table.getBoard(1, RelativeBoardPosition.RIGHT)); @@ -55,8 +55,8 @@ public class TableTest { @Theory public void getNeighbourGuildCards(int nbPlayers) { assumeTrue(nbPlayers >= 4); - Table table = TestUtils.createTable(nbPlayers); - List<Card> guildCards = TestUtils.createGuildCards(4); + Table table = TestUtilsKt.testTable(nbPlayers); + List<Card> guildCards = TestUtilsKt.createGuildCards(4); table.getBoard(0).getPlayedCards().add(guildCards.get(0)); table.getBoard(0).getPlayedCards().add(guildCards.get(1)); table.getBoard(1).getPlayedCards().add(guildCards.get(2)); diff --git a/game-engine/src/test/java/org/luxons/sevenwonders/game/boards/BoardTest.java b/game-engine/src/test/java/org/luxons/sevenwonders/game/boards/BoardTest.java index c54ff0b2..4b373fa2 100644 --- a/game-engine/src/test/java/org/luxons/sevenwonders/game/boards/BoardTest.java +++ b/game-engine/src/test/java/org/luxons/sevenwonders/game/boards/BoardTest.java @@ -25,7 +25,7 @@ import org.luxons.sevenwonders.game.resources.ResourceType; import org.luxons.sevenwonders.game.resources.Resources; import org.luxons.sevenwonders.game.scoring.PlayerScore; import org.luxons.sevenwonders.game.scoring.ScoreCategory; -import org.luxons.sevenwonders.game.test.TestUtils; +import org.luxons.sevenwonders.game.test.TestUtilsKt; import static junit.framework.TestCase.assertEquals; import static org.junit.Assert.assertFalse; @@ -66,17 +66,16 @@ public class BoardTest { @Theory public void initialGold_respectsSettings(@FromDataPoints("gold") int goldAmountInSettings) { - CustomizableSettings customSettings = TestUtils.createCustomizableSettings(); - customSettings.setInitialGold(goldAmountInSettings); + CustomizableSettings customSettings = TestUtilsKt.testCustomizableSettings(goldAmountInSettings); Settings settings = new Settings(5, customSettings); - Board board = new Board(TestUtils.createWonder(), 0, settings); + Board board = new Board(TestUtilsKt.testWonder(), 0, settings); assertEquals(goldAmountInSettings, board.getGold()); } @Theory public void initialProduction_containsInitialResource(ResourceType type) { - Board board = new Board(TestUtils.createWonder(type), 0, new Settings(5)); - Resources resources = TestUtils.createResources(type); + Board board = new Board(TestUtilsKt.testWonder(type), 0, new Settings(5)); + Resources resources = TestUtilsKt.createResources(type); assertTrue(board.getProduction().contains(resources)); assertTrue(board.getPublicProduction().contains(resources)); } @@ -86,7 +85,7 @@ public class BoardTest { @FromDataPoints("gold") int goldRemoved) { assumeTrue(goldRemoved >= 0); assumeTrue(initialGold >= goldRemoved); - Board board = new Board(TestUtils.createWonder(), 0, new Settings(5)); + Board board = new Board(TestUtilsKt.testWonder(), 0, new Settings(5)); board.setGold(initialGold); board.removeGold(goldRemoved); assertEquals(initialGold - goldRemoved, board.getGold()); @@ -98,7 +97,7 @@ public class BoardTest { assumeTrue(goldRemoved >= 0); assumeTrue(initialGold < goldRemoved); thrown.expect(InsufficientFundsException.class); - Board board = new Board(TestUtils.createWonder(), 0, new Settings(5)); + Board board = new Board(TestUtilsKt.testWonder(), 0, new Settings(5)); board.setGold(initialGold); board.removeGold(goldRemoved); } @@ -106,8 +105,8 @@ public class BoardTest { @Theory public void getNbCardsOfColor_properCount_singleColor(ResourceType type, @FromDataPoints("nbCards") int nbCards, @FromDataPoints("nbCards") int nbOtherCards, Color color) { - Board board = TestUtils.createBoard(type); - TestUtils.addCards(board, nbCards, nbOtherCards, color); + Board board = TestUtilsKt.testBoard(type); + TestUtilsKt.addCards(board, nbCards, nbOtherCards, color); assertEquals(nbCards, board.getNbCardsOfColor(Collections.singletonList(color))); } @@ -116,17 +115,17 @@ public class BoardTest { @FromDataPoints("nbCards") int nbCards2, @FromDataPoints("nbCards") int nbOtherCards, Color color1, Color color2) { - Board board = TestUtils.createBoard(type); - TestUtils.addCards(board, nbCards1, color1); - TestUtils.addCards(board, nbCards2, color2); - TestUtils.addCards(board, nbOtherCards, TestUtils.getDifferentColorFrom(color1, color2)); + Board board = TestUtilsKt.testBoard(type); + TestUtilsKt.addCards(board, nbCards1, color1); + TestUtilsKt.addCards(board, nbCards2, color2); + TestUtilsKt.addCards(board, nbOtherCards, TestUtilsKt.getDifferentColorFrom(color1, color2)); assertEquals(nbCards1 + nbCards2, board.getNbCardsOfColor(Arrays.asList(color1, color2))); } @Test public void setCopiedGuild_succeedsOnPurpleCard() { - Board board = TestUtils.createBoard(ResourceType.CLAY); - Card card = TestUtils.createCard(Color.PURPLE); + Board board = TestUtilsKt.testBoard(ResourceType.CLAY); + Card card = TestUtilsKt.testCard(Color.PURPLE); board.setCopiedGuild(card); assertSame(card, board.getCopiedGuild()); @@ -135,8 +134,8 @@ public class BoardTest { @Theory public void setCopiedGuild_failsOnNonPurpleCard(Color color) { assumeTrue(color != Color.PURPLE); - Board board = TestUtils.createBoard(ResourceType.CLAY); - Card card = TestUtils.createCard(color); + Board board = TestUtilsKt.testBoard(ResourceType.CLAY); + Card card = TestUtilsKt.testCard(color); thrown.expect(IllegalArgumentException.class); board.setCopiedGuild(card); @@ -144,7 +143,7 @@ public class BoardTest { @Theory public void hasSpecial(SpecialAbility applied, SpecialAbility tested) { - Board board = TestUtils.createBoard(ResourceType.CLAY); + Board board = TestUtilsKt.testBoard(ResourceType.CLAY); Table table = new Table(Collections.singletonList(board)); SpecialAbilityActivation special = new SpecialAbilityActivation(applied); @@ -155,7 +154,7 @@ public class BoardTest { @Test public void canPlayFreeCard() { - Board board = TestUtils.createBoard(ResourceType.CLAY); + Board board = TestUtilsKt.testBoard(ResourceType.CLAY); Table table = new Table(Collections.singletonList(board)); SpecialAbilityActivation special = new SpecialAbilityActivation(SpecialAbility.ONE_FREE_PER_AGE); @@ -187,7 +186,7 @@ public class BoardTest { @Theory public void computePoints_gold(@FromDataPoints("gold") int gold) { assumeTrue(gold >= 0); - Board board = TestUtils.createBoard(ResourceType.WOOD); + Board board = TestUtilsKt.testBoard(ResourceType.WOOD); Table table = new Table(Collections.singletonList(board)); board.setGold(gold); @@ -199,12 +198,12 @@ public class BoardTest { @Theory public void computePoints_(@FromDataPoints("gold") int gold) { assumeTrue(gold >= 0); - Board board = TestUtils.createBoard(ResourceType.WOOD); + Board board = TestUtilsKt.testBoard(ResourceType.WOOD); Table table = new Table(Collections.singletonList(board)); board.setGold(gold); Effect effect = new RawPointsIncrease(5); - TestUtils.playCardWithEffect(table, 0, Color.BLUE, effect); + TestUtilsKt.playCardWithEffect(table, 0, Color.BLUE, effect); PlayerScore score = board.computePoints(table); assertEquals(gold / 3, (int) score.getPoints(ScoreCategory.GOLD)); diff --git a/game-engine/src/test/java/org/luxons/sevenwonders/game/boards/ScienceTest.java b/game-engine/src/test/java/org/luxons/sevenwonders/game/boards/ScienceTest.java index 24c63b31..b31da03b 100644 --- a/game-engine/src/test/java/org/luxons/sevenwonders/game/boards/ScienceTest.java +++ b/game-engine/src/test/java/org/luxons/sevenwonders/game/boards/ScienceTest.java @@ -5,7 +5,7 @@ import org.junit.experimental.theories.DataPoints; import org.junit.experimental.theories.Theories; import org.junit.experimental.theories.Theory; import org.junit.runner.RunWith; -import org.luxons.sevenwonders.game.test.TestUtils; +import org.luxons.sevenwonders.game.test.TestUtilsKt; import static org.junit.Assert.assertEquals; @@ -27,7 +27,7 @@ public class ScienceTest { @Test public void addAll_empty() { - Science initial = TestUtils.createScience(3, 4, 5, 1); + Science initial = TestUtilsKt.createScience(3, 4, 5, 1); Science empty = new Science(); initial.addAll(empty); assertEquals(3, initial.getQuantity(ScienceType.COMPASS)); @@ -38,8 +38,8 @@ public class ScienceTest { @Test public void addAll_noJoker() { - Science initial = TestUtils.createScience(3, 4, 5, 1); - Science other = TestUtils.createScience(1, 2, 3, 0); + Science initial = TestUtilsKt.createScience(3, 4, 5, 1); + Science other = TestUtilsKt.createScience(1, 2, 3, 0); initial.addAll(other); assertEquals(4, initial.getQuantity(ScienceType.COMPASS)); assertEquals(6, initial.getQuantity(ScienceType.WHEEL)); @@ -49,8 +49,8 @@ public class ScienceTest { @Test public void addAll_withJokers() { - Science initial = TestUtils.createScience(3, 4, 5, 1); - Science other = TestUtils.createScience(0, 0, 0, 3); + Science initial = TestUtilsKt.createScience(3, 4, 5, 1); + Science other = TestUtilsKt.createScience(0, 0, 0, 3); initial.addAll(other); assertEquals(3, initial.getQuantity(ScienceType.COMPASS)); assertEquals(4, initial.getQuantity(ScienceType.WHEEL)); @@ -60,8 +60,8 @@ public class ScienceTest { @Test public void addAll_mixed() { - Science initial = TestUtils.createScience(3, 4, 5, 1); - Science other = TestUtils.createScience(1, 2, 3, 4); + Science initial = TestUtilsKt.createScience(3, 4, 5, 1); + Science other = TestUtilsKt.createScience(1, 2, 3, 4); initial.addAll(other); assertEquals(4, initial.getQuantity(ScienceType.COMPASS)); assertEquals(6, initial.getQuantity(ScienceType.WHEEL)); @@ -71,31 +71,31 @@ public class ScienceTest { @Theory public void computePoints_compassesOnly_noJoker(int compasses) { - Science science = TestUtils.createScience(compasses, 0, 0, 0); + Science science = TestUtilsKt.createScience(compasses, 0, 0, 0); assertEquals(compasses * compasses, science.computePoints()); } @Theory public void computePoints_wheelsOnly_noJoker(int wheels) { - Science science = TestUtils.createScience(0, wheels, 0, 0); + Science science = TestUtilsKt.createScience(0, wheels, 0, 0); assertEquals(wheels * wheels, science.computePoints()); } @Theory public void computePoints_tabletsOnly_noJoker(int tablets) { - Science science = TestUtils.createScience(0, 0, tablets, 0); + Science science = TestUtilsKt.createScience(0, 0, tablets, 0); assertEquals(tablets * tablets, science.computePoints()); } @Theory public void computePoints_allSameNoJoker(int eachSymbol) { - Science science = TestUtils.createScience(eachSymbol, eachSymbol, eachSymbol, 0); + Science science = TestUtilsKt.createScience(eachSymbol, eachSymbol, eachSymbol, 0); assertEquals(3 * eachSymbol * eachSymbol + 7 * eachSymbol, science.computePoints()); } @Theory public void computePoints_expectation(int[] expectation) { - Science science = TestUtils.createScience(expectation[0], expectation[1], expectation[2], expectation[3]); + Science science = TestUtilsKt.createScience(expectation[0], expectation[1], expectation[2], expectation[3]); assertEquals(expectation[4], science.computePoints()); } } diff --git a/game-engine/src/test/java/org/luxons/sevenwonders/game/cards/CardTest.java b/game-engine/src/test/java/org/luxons/sevenwonders/game/cards/CardTest.java index 2a3b6806..b9681434 100644 --- a/game-engine/src/test/java/org/luxons/sevenwonders/game/cards/CardTest.java +++ b/game-engine/src/test/java/org/luxons/sevenwonders/game/cards/CardTest.java @@ -13,13 +13,13 @@ import org.luxons.sevenwonders.game.effects.Effect; import org.luxons.sevenwonders.game.effects.ProductionIncrease; import org.luxons.sevenwonders.game.resources.ResourceTransactions; import org.luxons.sevenwonders.game.resources.ResourceType; +import org.luxons.sevenwonders.game.test.TestUtilsKt; import org.luxons.sevenwonders.game.wonders.Wonder; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; -import static org.luxons.sevenwonders.game.test.TestUtils.createCard; public class CardTest { @@ -61,14 +61,14 @@ public class CardTest { @Test public void equals_falseWhenNull() { - Card card = createCard("TestCard"); + Card card = TestUtilsKt.testCard("TestCard"); //noinspection ObjectEqualsNull assertFalse(card.equals(null)); } @Test public void equals_falseWhenDifferentClass() { - Card card = createCard("TestCard"); + Card card = TestUtilsKt.testCard("TestCard"); Object object = new Object(); //noinspection EqualsBetweenInconvertibleTypes assertFalse(card.equals(object)); @@ -76,35 +76,35 @@ public class CardTest { @Test public void equals_trueWhenSame() { - Card card = createCard("TestCard"); + Card card = TestUtilsKt.testCard("TestCard"); assertEquals(card, card); } @Test public void equals_trueWhenSameContent() { - Card card1 = createCard("TestCard"); - Card card2 = createCard("TestCard"); + Card card1 = TestUtilsKt.testCard("TestCard"); + Card card2 = TestUtilsKt.testCard("TestCard"); assertTrue(card1.equals(card2)); } @Test public void equals_falseWhenDifferentName() { - Card card1 = createCard("TestCard1"); - Card card2 = createCard("TestCard2"); + Card card1 = TestUtilsKt.testCard("TestCard1"); + Card card2 = TestUtilsKt.testCard("TestCard2"); assertFalse(card1.equals(card2)); } @Test public void hashCode_sameWhenSameContent() { - Card card1 = createCard("TestCard"); - Card card2 = createCard("TestCard"); + Card card1 = TestUtilsKt.testCard("TestCard"); + Card card2 = TestUtilsKt.testCard("TestCard"); assertEquals(card1.hashCode(), card2.hashCode()); } @Test public void hashCode_differentWhenDifferentName() { - Card card1 = createCard("TestCard1"); - Card card2 = createCard("TestCard2"); + Card card1 = TestUtilsKt.testCard("TestCard1"); + Card card2 = TestUtilsKt.testCard("TestCard2"); assertNotEquals(card1.hashCode(), card2.hashCode()); } } diff --git a/game-engine/src/test/java/org/luxons/sevenwonders/game/cards/DecksTest.java b/game-engine/src/test/java/org/luxons/sevenwonders/game/cards/DecksTest.java index 8adeb44d..f572c5ac 100644 --- a/game-engine/src/test/java/org/luxons/sevenwonders/game/cards/DecksTest.java +++ b/game-engine/src/test/java/org/luxons/sevenwonders/game/cards/DecksTest.java @@ -12,7 +12,7 @@ import org.junit.experimental.theories.Theory; import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.luxons.sevenwonders.game.cards.Decks.CardNotFoundException; -import org.luxons.sevenwonders.game.test.TestUtils; +import org.luxons.sevenwonders.game.test.TestUtilsKt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -34,7 +34,7 @@ public class DecksTest { Map<Integer, List<Card>> cardsPerAge = new HashMap<>(); for (int age = 1; age <= nbAges; age++) { int firstCardNumber = (age - 1) * nbCardsPerAge; - cardsPerAge.put(age, TestUtils.createSampleCards(firstCardNumber, nbCardsPerAge)); + cardsPerAge.put(age, TestUtilsKt.createSampleCards(firstCardNumber, nbCardsPerAge)); } return new Decks(cardsPerAge); } diff --git a/game-engine/src/test/java/org/luxons/sevenwonders/game/cards/HandsTest.java b/game-engine/src/test/java/org/luxons/sevenwonders/game/cards/HandsTest.java index c20508e6..463dafcc 100644 --- a/game-engine/src/test/java/org/luxons/sevenwonders/game/cards/HandsTest.java +++ b/game-engine/src/test/java/org/luxons/sevenwonders/game/cards/HandsTest.java @@ -13,7 +13,7 @@ import org.junit.runner.RunWith; import org.luxons.sevenwonders.game.api.HandCard; import org.luxons.sevenwonders.game.api.Table; import org.luxons.sevenwonders.game.cards.Hands.PlayerIndexOutOfBoundsException; -import org.luxons.sevenwonders.game.test.TestUtils; +import org.luxons.sevenwonders.game.test.TestUtilsKt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -37,7 +37,7 @@ public class HandsTest { Map<Integer, List<Card>> hands = new HashMap<>(); for (int p = 0; p < nbPlayers; p++) { int firstCardNumber = (p - 1) * nbCardsPerPlayer; - hands.put(p, TestUtils.createSampleCards(firstCardNumber, nbCardsPerPlayer)); + hands.put(p, TestUtilsKt.createSampleCards(firstCardNumber, nbCardsPerPlayer)); } return new Hands(hands, nbPlayers); } @@ -50,8 +50,8 @@ public class HandsTest { @Test public void get_retrievesCorrectCards() { - List<Card> hand0 = TestUtils.createSampleCards(0, 5); - List<Card> hand1 = TestUtils.createSampleCards(5, 10); + List<Card> hand0 = TestUtilsKt.createSampleCards(0, 5); + List<Card> hand1 = TestUtilsKt.createSampleCards(5, 10); Map<Integer, List<Card>> handsMap = new HashMap<>(); handsMap.put(0, hand0); handsMap.put(1, hand1); @@ -126,14 +126,14 @@ public class HandsTest { @Test public void createHand_containsAllCards() { - List<Card> hand0 = TestUtils.createSampleCards(0, 5); - List<Card> hand1 = TestUtils.createSampleCards(5, 10); + List<Card> hand0 = TestUtilsKt.createSampleCards(0, 5); + List<Card> hand1 = TestUtilsKt.createSampleCards(5, 10); Map<Integer, List<Card>> handsMap = new HashMap<>(); handsMap.put(0, hand0); handsMap.put(1, hand1); Hands hands = new Hands(handsMap, 2); - Table table = TestUtils.createTable(2); + Table table = TestUtilsKt.testTable(2); List<HandCard> hand = hands.createHand(table, 0); for (HandCard handCard : hand) { diff --git a/game-engine/src/test/java/org/luxons/sevenwonders/game/cards/RequirementsTest.java b/game-engine/src/test/java/org/luxons/sevenwonders/game/cards/RequirementsTest.java index d2f505a4..6707dfab 100644 --- a/game-engine/src/test/java/org/luxons/sevenwonders/game/cards/RequirementsTest.java +++ b/game-engine/src/test/java/org/luxons/sevenwonders/game/cards/RequirementsTest.java @@ -14,7 +14,7 @@ import org.luxons.sevenwonders.game.resources.Provider; import org.luxons.sevenwonders.game.resources.ResourceTransactions; import org.luxons.sevenwonders.game.resources.ResourceType; import org.luxons.sevenwonders.game.resources.Resources; -import org.luxons.sevenwonders.game.test.TestUtils; +import org.luxons.sevenwonders.game.test.TestUtilsKt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -54,7 +54,7 @@ public class RequirementsTest { Requirements requirements = new Requirements(); requirements.setGold(requiredGold); - Board board = TestUtils.createBoard(ResourceType.CLAY, boardGold); + Board board = TestUtilsKt.testBoard(ResourceType.CLAY, boardGold); Table table = new Table(Collections.singletonList(board)); assertEquals(boardGold >= requiredGold, requirements.areMetWithoutNeighboursBy(board)); @@ -64,9 +64,9 @@ public class RequirementsTest { @Theory public void resourceRequirement_initialResource(ResourceType initialResource, ResourceType requiredResource) { - Requirements requirements = TestUtils.createRequirements(requiredResource); + Requirements requirements = TestUtilsKt.createRequirements(requiredResource); - Board board = TestUtils.createBoard(initialResource, 0); + Board board = TestUtilsKt.testBoard(initialResource, 0); Table table = new Table(Collections.singletonList(board)); assertEquals(initialResource == requiredResource, requirements.areMetWithoutNeighboursBy(board)); @@ -83,9 +83,9 @@ public class RequirementsTest { ResourceType requiredResource) { assumeTrue(initialResource != requiredResource); - Requirements requirements = TestUtils.createRequirements(requiredResource); + Requirements requirements = TestUtilsKt.createRequirements(requiredResource); - Board board = TestUtils.createBoard(initialResource, 0); + Board board = TestUtilsKt.testBoard(initialResource, 0); board.getProduction().addFixedResource(producedResource, 1); Table table = new Table(Collections.singletonList(board)); @@ -103,14 +103,14 @@ public class RequirementsTest { ResourceType requiredResource) { assumeTrue(initialResource != requiredResource); - Requirements requirements = TestUtils.createRequirements(requiredResource); + Requirements requirements = TestUtilsKt.createRequirements(requiredResource); - Board board = TestUtils.createBoard(initialResource, 2); - Board neighbourBoard = TestUtils.createBoard(initialResource, 0); + Board board = TestUtilsKt.testBoard(initialResource, 2); + Board neighbourBoard = TestUtilsKt.testBoard(initialResource, 0); neighbourBoard.getPublicProduction().addFixedResource(boughtResource, 1); Table table = new Table(Arrays.asList(board, neighbourBoard)); - ResourceTransactions resources = TestUtils.createTransactions(Provider.RIGHT_PLAYER, boughtResource); + ResourceTransactions resources = TestUtilsKt.createTransactions(Provider.RIGHT_PLAYER, boughtResource); assertFalse(requirements.areMetWithoutNeighboursBy(board)); assertEquals(boughtResource == requiredResource, requirements.areMetWithHelpBy(board, resources)); @@ -124,13 +124,13 @@ public class RequirementsTest { public void pay_boughtResource(ResourceType initialResource, ResourceType requiredResource) { assumeTrue(initialResource != requiredResource); - Requirements requirements = TestUtils.createRequirements(requiredResource); + Requirements requirements = TestUtilsKt.createRequirements(requiredResource); - Board board = TestUtils.createBoard(initialResource, 2); - Board neighbourBoard = TestUtils.createBoard(requiredResource, 0); + Board board = TestUtilsKt.testBoard(initialResource, 2); + Board neighbourBoard = TestUtilsKt.testBoard(requiredResource, 0); Table table = new Table(Arrays.asList(board, neighbourBoard)); - ResourceTransactions transactions = TestUtils.createTransactions(Provider.RIGHT_PLAYER, + ResourceTransactions transactions = TestUtilsKt.createTransactions(Provider.RIGHT_PLAYER, requiredResource); assertFalse(requirements.areMetWithoutNeighboursBy(board)); diff --git a/game-engine/src/test/java/org/luxons/sevenwonders/game/data/serializers/ScienceProgressSerializerTest.java b/game-engine/src/test/java/org/luxons/sevenwonders/game/data/serializers/ScienceProgressSerializerTest.java index 0387e198..517a4b1f 100644 --- a/game-engine/src/test/java/org/luxons/sevenwonders/game/data/serializers/ScienceProgressSerializerTest.java +++ b/game-engine/src/test/java/org/luxons/sevenwonders/game/data/serializers/ScienceProgressSerializerTest.java @@ -1,12 +1,13 @@ package org.luxons.sevenwonders.game.data.serializers; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; import org.junit.Before; import org.junit.Test; import org.luxons.sevenwonders.game.boards.ScienceType; import org.luxons.sevenwonders.game.effects.ScienceProgress; -import org.luxons.sevenwonders.game.test.TestUtils; +import org.luxons.sevenwonders.game.test.TestUtilsKt; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -30,66 +31,66 @@ public class ScienceProgressSerializerTest { @Test public void serialize_emptyToNull() { - ScienceProgress progress = TestUtils.createScienceProgress(0, 0, 0, 0); + ScienceProgress progress = TestUtilsKt.createScienceProgress(0, 0, 0, 0); String json = gson.toJson(progress); assertEquals("null", json); } @Test public void serialize_oneCompass() { - ScienceProgress progress = TestUtils.createScienceProgress(1, 0, 0, 0); + ScienceProgress progress = TestUtilsKt.createScienceProgress(1, 0, 0, 0); String json = gson.toJson(progress); assertEquals(COMPASS_STR, json); } @Test public void serialize_oneWheel() { - ScienceProgress progress = TestUtils.createScienceProgress(0, 1, 0, 0); + ScienceProgress progress = TestUtilsKt.createScienceProgress(0, 1, 0, 0); String json = gson.toJson(progress); assertEquals(WHEEL_STR, json); } @Test public void serialize_oneTablet() { - ScienceProgress progress = TestUtils.createScienceProgress(0, 0, 1, 0); + ScienceProgress progress = TestUtilsKt.createScienceProgress(0, 0, 1, 0); String json = gson.toJson(progress); assertEquals(TABLET_STR, json); } @Test public void serialize_oneJoker() { - ScienceProgress progress = TestUtils.createScienceProgress(0, 0, 0, 1); + ScienceProgress progress = TestUtilsKt.createScienceProgress(0, 0, 0, 1); String json = gson.toJson(progress); assertEquals(JOKER_STR, json); } @Test(expected = UnsupportedOperationException.class) public void serialize_failOnMultipleCompasses() { - ScienceProgress progress = TestUtils.createScienceProgress(2, 0, 0, 0); + ScienceProgress progress = TestUtilsKt.createScienceProgress(2, 0, 0, 0); gson.toJson(progress); } @Test(expected = UnsupportedOperationException.class) public void serialize_failOnMultipleWheels() { - ScienceProgress progress = TestUtils.createScienceProgress(0, 2, 0, 0); + ScienceProgress progress = TestUtilsKt.createScienceProgress(0, 2, 0, 0); gson.toJson(progress); } @Test(expected = UnsupportedOperationException.class) public void serialize_failOnMultipleTablets() { - ScienceProgress progress = TestUtils.createScienceProgress(0, 0, 2, 0); + ScienceProgress progress = TestUtilsKt.createScienceProgress(0, 0, 2, 0); gson.toJson(progress); } @Test(expected = UnsupportedOperationException.class) public void serialize_failOnMultipleJokers() { - ScienceProgress progress = TestUtils.createScienceProgress(0, 0, 0, 2); + ScienceProgress progress = TestUtilsKt.createScienceProgress(0, 0, 0, 2); gson.toJson(progress); } @Test(expected = UnsupportedOperationException.class) public void serialize_failOnMixedElements() { - ScienceProgress progress = TestUtils.createScienceProgress(1, 1, 0, 0); + ScienceProgress progress = TestUtilsKt.createScienceProgress(1, 1, 0, 0); gson.toJson(progress); } diff --git a/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/BonusPerBoardElementTest.java b/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/BonusPerBoardElementTest.java index bacea896..a32bc342 100644 --- a/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/BonusPerBoardElementTest.java +++ b/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/BonusPerBoardElementTest.java @@ -14,7 +14,7 @@ import org.luxons.sevenwonders.game.boards.BoardElementType; import org.luxons.sevenwonders.game.boards.RelativeBoardPosition; import org.luxons.sevenwonders.game.cards.CardBack; import org.luxons.sevenwonders.game.cards.Color; -import org.luxons.sevenwonders.game.test.TestUtils; +import org.luxons.sevenwonders.game.test.TestUtilsKt; import static org.junit.Assert.assertEquals; @@ -40,7 +40,7 @@ public class BonusPerBoardElementTest { @Before public void setUp() { - table = TestUtils.createTable(4); + table = TestUtilsKt.testTable(4); } private static BonusPerBoardElement createBonus(BoardElementType type, int gold, int points, Color... colors) { @@ -56,7 +56,7 @@ public class BonusPerBoardElementTest { public void computePoints_countsCards(RelativeBoardPosition boardPosition, int nbCards, int nbOtherCards, int points, int gold, Color color) { Board board = table.getBoard(0, boardPosition); - TestUtils.addCards(board, nbCards, nbOtherCards, color); + TestUtilsKt.addCards(board, nbCards, nbOtherCards, color); BonusPerBoardElement bonus = createBonus(BoardElementType.CARD, gold, points, color); bonus.setBoards(Collections.singletonList(boardPosition)); @@ -96,7 +96,7 @@ public class BonusPerBoardElementTest { public void apply_countsCards(RelativeBoardPosition boardPosition, int nbCards, int nbOtherCards, int points, int gold, Color color) { Board board = table.getBoard(0, boardPosition); - TestUtils.addCards(board, nbCards, nbOtherCards, color); + TestUtilsKt.addCards(board, nbCards, nbOtherCards, color); BonusPerBoardElement bonus = createBonus(BoardElementType.CARD, gold, points, color); bonus.setBoards(Collections.singletonList(boardPosition)); diff --git a/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/DiscountTest.java b/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/DiscountTest.java index 1de3a502..c13cec1b 100644 --- a/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/DiscountTest.java +++ b/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/DiscountTest.java @@ -9,7 +9,7 @@ import org.luxons.sevenwonders.game.boards.Board; import org.luxons.sevenwonders.game.resources.Provider; import org.luxons.sevenwonders.game.resources.ResourceTransactions; import org.luxons.sevenwonders.game.resources.ResourceType; -import org.luxons.sevenwonders.game.test.TestUtils; +import org.luxons.sevenwonders.game.test.TestUtilsKt; import static org.junit.Assert.assertEquals; @@ -33,14 +33,14 @@ public class DiscountTest { @Theory public void apply_givesDiscountedPrice(int discountedPrice, ResourceType discountedType, Provider provider) { - Board board = TestUtils.createBoard(ResourceType.CLAY, 3); + Board board = TestUtilsKt.testBoard(ResourceType.CLAY, 3); Discount discount = new Discount(); discount.setDiscountedPrice(discountedPrice); discount.getProviders().add(provider); discount.getResourceTypes().add(discountedType); discount.apply(board); - ResourceTransactions transactions = TestUtils.createTransactions(provider, discountedType); + ResourceTransactions transactions = TestUtilsKt.createTransactions(provider, discountedType); assertEquals(discountedPrice, board.getTradingRules().computeCost(transactions)); } @@ -50,23 +50,23 @@ public class DiscountTest { Assume.assumeTrue(otherProvider != provider); Assume.assumeTrue(otherType != discountedType); - Board board = TestUtils.createBoard(ResourceType.CLAY, 3); + Board board = TestUtilsKt.testBoard(ResourceType.CLAY, 3); Discount discount = new Discount(); discount.setDiscountedPrice(discountedPrice); discount.getProviders().add(provider); discount.getResourceTypes().add(discountedType); discount.apply(board); - // this is the default in the settings used by TestUtils.createBoard() + // this is the default in the settings used by TestUtilsKt.testBoard() int normalPrice = 2; - ResourceTransactions fromOtherType = TestUtils.createTransactions(provider, otherType); + ResourceTransactions fromOtherType = TestUtilsKt.createTransactions(provider, otherType); assertEquals(normalPrice, board.getTradingRules().computeCost(fromOtherType)); - ResourceTransactions fromOtherProvider = TestUtils.createTransactions(otherProvider, discountedType); + ResourceTransactions fromOtherProvider = TestUtilsKt.createTransactions(otherProvider, discountedType); assertEquals(normalPrice, board.getTradingRules().computeCost(fromOtherProvider)); - ResourceTransactions fromOtherProviderAndType = TestUtils.createTransactions(otherProvider, otherType); + ResourceTransactions fromOtherProviderAndType = TestUtilsKt.createTransactions(otherProvider, otherType); assertEquals(normalPrice, board.getTradingRules().computeCost(fromOtherProviderAndType)); } } diff --git a/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/GoldIncreaseTest.java b/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/GoldIncreaseTest.java index be124251..ffc506c0 100644 --- a/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/GoldIncreaseTest.java +++ b/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/GoldIncreaseTest.java @@ -7,7 +7,7 @@ import org.junit.runner.RunWith; import org.luxons.sevenwonders.game.api.Table; import org.luxons.sevenwonders.game.boards.Board; import org.luxons.sevenwonders.game.resources.ResourceType; -import org.luxons.sevenwonders.game.test.TestUtils; +import org.luxons.sevenwonders.game.test.TestUtilsKt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -28,7 +28,7 @@ public class GoldIncreaseTest { @Theory public void apply_increaseGoldWithRightAmount(int initialAmount, int goldIncreaseAmount, ResourceType type) { - Board board = TestUtils.createBoard(type, initialAmount); + Board board = TestUtilsKt.testBoard(type, initialAmount); GoldIncrease goldIncrease = new GoldIncrease(goldIncreaseAmount); goldIncrease.apply(board); @@ -39,7 +39,7 @@ public class GoldIncreaseTest { @Theory public void computePoints_isAlwaysZero(int gold) { GoldIncrease goldIncrease = new GoldIncrease(gold); - Table table = TestUtils.createTable(5); + Table table = TestUtilsKt.testTable(5); assertEquals(0, goldIncrease.computePoints(table, 0)); } diff --git a/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/MilitaryReinforcementsTest.java b/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/MilitaryReinforcementsTest.java index 478af746..f5a25d98 100644 --- a/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/MilitaryReinforcementsTest.java +++ b/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/MilitaryReinforcementsTest.java @@ -7,7 +7,7 @@ import org.junit.runner.RunWith; import org.luxons.sevenwonders.game.api.Table; import org.luxons.sevenwonders.game.boards.Board; import org.luxons.sevenwonders.game.resources.ResourceType; -import org.luxons.sevenwonders.game.test.TestUtils; +import org.luxons.sevenwonders.game.test.TestUtilsKt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -28,7 +28,7 @@ public class MilitaryReinforcementsTest { @Theory public void apply_increaseGoldWithRightAmount(int initialShields, int additionalShields, ResourceType type) { - Board board = TestUtils.createBoard(type); + Board board = TestUtilsKt.testBoard(type); board.getMilitary().addShields(initialShields); MilitaryReinforcements reinforcements = new MilitaryReinforcements(additionalShields); @@ -40,7 +40,7 @@ public class MilitaryReinforcementsTest { @Theory public void computePoints_isAlwaysZero(int shields) { MilitaryReinforcements reinforcements = new MilitaryReinforcements(shields); - Table table = TestUtils.createTable(5); + Table table = TestUtilsKt.testTable(5); assertEquals(0, reinforcements.computePoints(table, 0)); } diff --git a/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/ProductionIncreaseTest.java b/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/ProductionIncreaseTest.java index b6a47292..c39854e5 100644 --- a/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/ProductionIncreaseTest.java +++ b/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/ProductionIncreaseTest.java @@ -9,7 +9,7 @@ import org.luxons.sevenwonders.game.boards.Board; import org.luxons.sevenwonders.game.resources.Production; import org.luxons.sevenwonders.game.resources.ResourceType; import org.luxons.sevenwonders.game.resources.Resources; -import org.luxons.sevenwonders.game.test.TestUtils; +import org.luxons.sevenwonders.game.test.TestUtilsKt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -25,24 +25,24 @@ public class ProductionIncreaseTest { private static ProductionIncrease createProductionIncrease(ResourceType... types) { ProductionIncrease effect = new ProductionIncrease(); - effect.getProduction().addAll(TestUtils.createFixedProduction(types)); + effect.getProduction().addAll(TestUtilsKt.fixedProduction(types)); return effect; } @Theory public void apply_boardContainsAddedResourceType(ResourceType initialType, ResourceType addedType, ResourceType extraType) { - Board board = TestUtils.createBoard(initialType); + Board board = TestUtilsKt.testBoard(initialType); ProductionIncrease effect = createProductionIncrease(addedType); effect.setSellable(false); effect.apply(board); - Resources resources = TestUtils.createResources(initialType, addedType); + Resources resources = TestUtilsKt.createResources(initialType, addedType); assertTrue(board.getProduction().contains(resources)); assertFalse(board.getPublicProduction().contains(resources)); - Resources moreResources = TestUtils.createResources(initialType, addedType, extraType); + Resources moreResources = TestUtilsKt.createResources(initialType, addedType, extraType); assertFalse(board.getProduction().contains(moreResources)); assertFalse(board.getPublicProduction().contains(moreResources)); } @@ -50,17 +50,17 @@ public class ProductionIncreaseTest { @Theory public void apply_boardContainsAddedResourceType_sellable(ResourceType initialType, ResourceType addedType, ResourceType extraType) { - Board board = TestUtils.createBoard(initialType); + Board board = TestUtilsKt.testBoard(initialType); ProductionIncrease effect = createProductionIncrease(addedType); effect.setSellable(true); effect.apply(board); - Resources resources = TestUtils.createResources(initialType, addedType); + Resources resources = TestUtilsKt.createResources(initialType, addedType); assertTrue(board.getProduction().contains(resources)); assertTrue(board.getPublicProduction().contains(resources)); - Resources moreResources = TestUtils.createResources(initialType, addedType, extraType); + Resources moreResources = TestUtilsKt.createResources(initialType, addedType, extraType); assertFalse(board.getProduction().contains(moreResources)); assertFalse(board.getPublicProduction().contains(moreResources)); } @@ -68,7 +68,7 @@ public class ProductionIncreaseTest { @Theory public void computePoints_isAlwaysZero(ResourceType addedType) { ProductionIncrease effect = createProductionIncrease(addedType); - Table table = TestUtils.createTable(5); + Table table = TestUtilsKt.testTable(5); assertEquals(0, effect.computePoints(table, 0)); } @@ -82,7 +82,7 @@ public class ProductionIncreaseTest { @Theory public void equals_falseWhenDifferentClass(ResourceType addedType) { ProductionIncrease effect = createProductionIncrease(addedType); - Production production = TestUtils.createFixedProduction(addedType); + Production production = TestUtilsKt.fixedProduction(addedType); //noinspection EqualsBetweenInconvertibleTypes assertFalse(effect.equals(production)); } diff --git a/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/RawPointsIncreaseTest.java b/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/RawPointsIncreaseTest.java index 020eda73..dcf178f3 100644 --- a/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/RawPointsIncreaseTest.java +++ b/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/RawPointsIncreaseTest.java @@ -5,7 +5,7 @@ import org.junit.experimental.theories.Theories; import org.junit.experimental.theories.Theory; import org.junit.runner.RunWith; import org.luxons.sevenwonders.game.api.Table; -import org.luxons.sevenwonders.game.test.TestUtils; +import org.luxons.sevenwonders.game.test.TestUtilsKt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -22,7 +22,7 @@ public class RawPointsIncreaseTest { @Theory public void computePoints_equalsNbOfPoints(int points) { RawPointsIncrease rawPointsIncrease = new RawPointsIncrease(points); - Table table = TestUtils.createTable(5); + Table table = TestUtilsKt.testTable(5); assertEquals(points, rawPointsIncrease.computePoints(table, 0)); } diff --git a/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/ScienceProgressTest.java b/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/ScienceProgressTest.java index b5402a7e..cecafad9 100644 --- a/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/ScienceProgressTest.java +++ b/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/ScienceProgressTest.java @@ -8,7 +8,7 @@ import org.luxons.sevenwonders.game.boards.Board; import org.luxons.sevenwonders.game.boards.Science; import org.luxons.sevenwonders.game.boards.ScienceType; import org.luxons.sevenwonders.game.resources.ResourceType; -import org.luxons.sevenwonders.game.test.TestUtils; +import org.luxons.sevenwonders.game.test.TestUtilsKt; import static org.junit.Assert.assertEquals; @@ -23,11 +23,11 @@ public class ScienceProgressTest { @Theory public void apply_initContainsAddedScience(int initCompasses, int initWheels, int initTablets, int initJokers, int compasses, int wheels, int tablets, int jokers) { - Board board = TestUtils.createBoard(ResourceType.ORE); - Science initialScience = TestUtils.createScience(initCompasses, initWheels, initTablets, initJokers); + Board board = TestUtilsKt.testBoard(ResourceType.ORE); + Science initialScience = TestUtilsKt.createScience(initCompasses, initWheels, initTablets, initJokers); board.getScience().addAll(initialScience); - ScienceProgress effect = TestUtils.createScienceProgress(compasses, wheels, tablets, jokers); + ScienceProgress effect = TestUtilsKt.createScienceProgress(compasses, wheels, tablets, jokers); effect.apply(board); assertEquals(initCompasses + compasses, board.getScience().getQuantity(ScienceType.COMPASS)); diff --git a/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/SpecialAbilityActivationTest.java b/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/SpecialAbilityActivationTest.java index 0f30a3a5..021e8f7c 100644 --- a/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/SpecialAbilityActivationTest.java +++ b/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/SpecialAbilityActivationTest.java @@ -14,7 +14,7 @@ import org.luxons.sevenwonders.game.boards.BoardElementType; 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.test.TestUtils; +import org.luxons.sevenwonders.game.test.TestUtilsKt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -46,13 +46,13 @@ public class SpecialAbilityActivationTest { Arrays.asList(RelativeBoardPosition.LEFT, RelativeBoardPosition.SELF, RelativeBoardPosition.RIGHT)); bonus2.setPoints(1); - return new Card[] {TestUtils.createGuildCard(1, bonus), TestUtils.createGuildCard(2, bonus2)}; + return new Card[] {TestUtilsKt.createGuildCard(1, bonus), TestUtilsKt.createGuildCard(2, bonus2)}; } @Theory public void apply_addsAbility(SpecialAbility ability) { SpecialAbilityActivation effect = new SpecialAbilityActivation(ability); - Table table = TestUtils.createTable(5); + Table table = TestUtilsKt.testTable(5); effect.apply(table, 0); @@ -65,7 +65,7 @@ public class SpecialAbilityActivationTest { Assume.assumeTrue(ability != SpecialAbility.COPY_GUILD); SpecialAbilityActivation effect = new SpecialAbilityActivation(ability); - Table table = TestUtils.createTable(5); + Table table = TestUtilsKt.testTable(5); assertEquals(0, effect.computePoints(table, 0)); } @@ -73,7 +73,7 @@ public class SpecialAbilityActivationTest { @Theory public void computePoints_copiedGuild(Card guildCard, RelativeBoardPosition neighbour) { SpecialAbilityActivation effect = new SpecialAbilityActivation(SpecialAbility.COPY_GUILD); - Table table = TestUtils.createTable(5); + Table table = TestUtilsKt.testTable(5); Board neighbourBoard = table.getBoard(0, neighbour); neighbourBoard.addCard(guildCard); @@ -88,7 +88,7 @@ public class SpecialAbilityActivationTest { @Test(expected = IllegalStateException.class) public void computePoints_copyGuild_failWhenNoChosenGuild() { SpecialAbilityActivation effect = new SpecialAbilityActivation(SpecialAbility.COPY_GUILD); - Table table = TestUtils.createTable(5); + Table table = TestUtilsKt.testTable(5); effect.computePoints(table, 0); } } diff --git a/game-engine/src/test/java/org/luxons/sevenwonders/game/moves/BuildWonderMoveTest.java b/game-engine/src/test/java/org/luxons/sevenwonders/game/moves/BuildWonderMoveTest.java index 31e35edc..c58e1671 100644 --- a/game-engine/src/test/java/org/luxons/sevenwonders/game/moves/BuildWonderMoveTest.java +++ b/game-engine/src/test/java/org/luxons/sevenwonders/game/moves/BuildWonderMoveTest.java @@ -7,7 +7,7 @@ import org.junit.Test; 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.test.TestUtils; +import org.luxons.sevenwonders.game.test.TestUtilsKt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; @@ -16,19 +16,19 @@ public class BuildWonderMoveTest { @Test(expected = InvalidMoveException.class) public void validate_failsWhenCardNotInHand() { - Table table = TestUtils.createTable(3); - List<Card> hand = TestUtils.createSampleCards(0, 7); - Card anotherCard = TestUtils.createCard("Card that is not in the hand"); - Move move = TestUtils.createMove(0, anotherCard, MoveType.UPGRADE_WONDER); + Table table = TestUtilsKt.testTable(3); + List<Card> hand = TestUtilsKt.createSampleCards(0, 7); + Card anotherCard = TestUtilsKt.testCard("Card that is not in the hand"); + Move move = TestUtilsKt.createMove(0, anotherCard, MoveType.UPGRADE_WONDER); move.validate(table, hand); } @Test(expected = InvalidMoveException.class) public void validate_failsWhenWonderIsCompletelyBuilt() { - Settings settings = TestUtils.createSettings(3); - Table table = TestUtils.createTable(settings); - List<Card> hand = TestUtils.createSampleCards(0, 7); + Settings settings = TestUtilsKt.testSettings(3); + Table table = TestUtilsKt.testTable(settings); + List<Card> hand = TestUtilsKt.createSampleCards(0, 7); fillPlayerWonderLevels(settings, table, hand); @@ -49,7 +49,7 @@ public class BuildWonderMoveTest { private static void buildOneWonderLevel(Settings settings, Table table, List<Card> hand, int cardIndex) { Card card = hand.get(cardIndex); - Move move = TestUtils.createMove(0, card, MoveType.UPGRADE_WONDER); + Move move = TestUtilsKt.createMove(0, card, MoveType.UPGRADE_WONDER); move.validate(table, hand); move.place(table, Collections.emptyList(), settings); move.activate(table, Collections.emptyList(), settings); @@ -57,11 +57,11 @@ public class BuildWonderMoveTest { @Test public void place_increasesWonderLevel() { - Settings settings = TestUtils.createSettings(3); - Table table = TestUtils.createTable(settings); - List<Card> hand = TestUtils.createSampleCards(0, 7); + Settings settings = TestUtilsKt.testSettings(3); + Table table = TestUtilsKt.testTable(settings); + List<Card> hand = TestUtilsKt.createSampleCards(0, 7); Card cardToUse = hand.get(0); - Move move = TestUtils.createMove(0, cardToUse, MoveType.UPGRADE_WONDER); + Move move = TestUtilsKt.createMove(0, cardToUse, MoveType.UPGRADE_WONDER); move.validate(table, hand); // should not fail int initialStage = table.getBoard(0).getWonder().getNbBuiltStages(); diff --git a/game-engine/src/test/java/org/luxons/sevenwonders/game/resources/BestPriceCalculatorTest.java b/game-engine/src/test/java/org/luxons/sevenwonders/game/resources/BestPriceCalculatorTest.java index a5017097..bb0e757b 100644 --- a/game-engine/src/test/java/org/luxons/sevenwonders/game/resources/BestPriceCalculatorTest.java +++ b/game-engine/src/test/java/org/luxons/sevenwonders/game/resources/BestPriceCalculatorTest.java @@ -5,7 +5,7 @@ import java.util.Arrays; import org.junit.Test; import org.luxons.sevenwonders.game.api.Table; import org.luxons.sevenwonders.game.boards.Board; -import org.luxons.sevenwonders.game.test.TestUtils; +import org.luxons.sevenwonders.game.test.TestUtilsKt; import static org.junit.Assert.assertEquals; import static org.luxons.sevenwonders.game.resources.Provider.LEFT_PLAYER; @@ -20,7 +20,7 @@ public class BestPriceCalculatorTest { @Test public void bestPrice_0forEmptyResources() { - Table table = TestUtils.createTable(3); + Table table = TestUtilsKt.testTable(3); Resources resources = new Resources(); assertEquals(0, BestPriceCalculator.bestPrice(resources, table, 0)); assertEquals(new ResourceTransactions(), BestPriceCalculator.bestSolution(resources, table, 0)); @@ -28,22 +28,22 @@ public class BestPriceCalculatorTest { @Test public void bestPrice_fixedResources_defaultCost() { - Board left = TestUtils.createBoard(STONE); - Board main = TestUtils.createBoard(STONE); - Board right = TestUtils.createBoard(WOOD); + Board left = TestUtilsKt.testBoard(STONE); + Board main = TestUtilsKt.testBoard(STONE); + Board right = TestUtilsKt.testBoard(WOOD); Table table = new Table(Arrays.asList(main, right, left)); - Resources resources = TestUtils.createResources(STONE, STONE); + Resources resources = TestUtilsKt.createResources(STONE, STONE); assertEquals(2, BestPriceCalculator.bestPrice(resources, table, 0)); assertEquals(4, BestPriceCalculator.bestPrice(resources, table, 1)); assertEquals(2, BestPriceCalculator.bestPrice(resources, table, 2)); - ResourceTransaction stoneLeftSingle = TestUtils.createTransaction(LEFT_PLAYER, STONE); - ResourceTransaction stoneRightSingle = TestUtils.createTransaction(RIGHT_PLAYER, STONE); + ResourceTransaction stoneLeftSingle = TestUtilsKt.createTransaction(LEFT_PLAYER, STONE); + ResourceTransaction stoneRightSingle = TestUtilsKt.createTransaction(RIGHT_PLAYER, STONE); - ResourceTransactions stoneLeft = TestUtils.createTransactions(stoneLeftSingle); - ResourceTransactions stoneRight = TestUtils.createTransactions(stoneRightSingle); - ResourceTransactions stoneLeftAndRight = TestUtils.createTransactions(stoneLeftSingle, stoneRightSingle); + ResourceTransactions stoneLeft = TestUtilsKt.createTransactions(stoneLeftSingle); + ResourceTransactions stoneRight = TestUtilsKt.createTransactions(stoneRightSingle); + ResourceTransactions stoneLeftAndRight = TestUtilsKt.createTransactions(stoneLeftSingle, stoneRightSingle); assertEquals(stoneLeft, BestPriceCalculator.bestSolution(resources, table, 0)); assertEquals(stoneLeftAndRight, BestPriceCalculator.bestSolution(resources, table, 1)); @@ -52,22 +52,22 @@ public class BestPriceCalculatorTest { @Test public void bestPrice_fixedResources_overridenCost() { - Board main = TestUtils.createBoard(STONE); + Board main = TestUtilsKt.testBoard(STONE); main.getTradingRules().setCost(WOOD, RIGHT_PLAYER, 1); - Board left = TestUtils.createBoard(WOOD); - Board right = TestUtils.createBoard(WOOD); - Board opposite = TestUtils.createBoard(GLASS); + Board left = TestUtilsKt.testBoard(WOOD); + Board right = TestUtilsKt.testBoard(WOOD); + Board opposite = TestUtilsKt.testBoard(GLASS); Table table = new Table(Arrays.asList(main, right, opposite, left)); - Resources resources = TestUtils.createResources(WOOD); + Resources resources = TestUtilsKt.createResources(WOOD); assertEquals(1, BestPriceCalculator.bestPrice(resources, table, 0)); assertEquals(0, BestPriceCalculator.bestPrice(resources, table, 1)); assertEquals(2, BestPriceCalculator.bestPrice(resources, table, 2)); assertEquals(0, BestPriceCalculator.bestPrice(resources, table, 3)); - ResourceTransactions woodLeft = TestUtils.createTransactions(LEFT_PLAYER, WOOD); - ResourceTransactions woodRight = TestUtils.createTransactions(RIGHT_PLAYER, WOOD); + ResourceTransactions woodLeft = TestUtilsKt.createTransactions(LEFT_PLAYER, WOOD); + ResourceTransactions woodRight = TestUtilsKt.createTransactions(RIGHT_PLAYER, WOOD); assertEquals(woodRight, BestPriceCalculator.bestSolution(resources, table, 0)); assertEquals(new ResourceTransactions(), BestPriceCalculator.bestSolution(resources, table, 1)); assertEquals(woodLeft, BestPriceCalculator.bestSolution(resources, table, 2)); @@ -76,23 +76,23 @@ public class BestPriceCalculatorTest { @Test public void bestPrice_mixedResources_overridenCost() { - Board left = TestUtils.createBoard(WOOD); + Board left = TestUtilsKt.testBoard(WOOD); - Board main = TestUtils.createBoard(STONE); + Board main = TestUtilsKt.testBoard(STONE); main.getTradingRules().setCost(WOOD, RIGHT_PLAYER, 1); - Board right = TestUtils.createBoard(ORE); + Board right = TestUtilsKt.testBoard(ORE); right.getProduction().addChoice(WOOD, CLAY); right.getPublicProduction().addChoice(WOOD, CLAY); Table table = new Table(Arrays.asList(main, right, left)); - Resources resources = TestUtils.createResources(WOOD); + Resources resources = TestUtilsKt.createResources(WOOD); assertEquals(1, BestPriceCalculator.bestPrice(resources, table, 0)); assertEquals(0, BestPriceCalculator.bestPrice(resources, table, 1)); assertEquals(0, BestPriceCalculator.bestPrice(resources, table, 2)); - ResourceTransactions woodRight = TestUtils.createTransactions(RIGHT_PLAYER, WOOD); + ResourceTransactions woodRight = TestUtilsKt.createTransactions(RIGHT_PLAYER, WOOD); assertEquals(woodRight, BestPriceCalculator.bestSolution(resources, table, 0)); assertEquals(new ResourceTransactions(), BestPriceCalculator.bestSolution(resources, table, 1)); @@ -101,13 +101,13 @@ public class BestPriceCalculatorTest { @Test public void bestPrice_chooseCheapest() { - Board left = TestUtils.createBoard(WOOD); + Board left = TestUtilsKt.testBoard(WOOD); - Board main = TestUtils.createBoard(WOOD); + Board main = TestUtilsKt.testBoard(WOOD); main.getProduction().addChoice(CLAY, ORE); main.getTradingRules().setCost(CLAY, RIGHT_PLAYER, 1); - Board right = TestUtils.createBoard(WOOD); + Board right = TestUtilsKt.testBoard(WOOD); right.getProduction().addFixedResource(ORE, 1); right.getProduction().addFixedResource(CLAY, 1); right.getPublicProduction().addFixedResource(ORE, 1); @@ -115,13 +115,13 @@ public class BestPriceCalculatorTest { Table table = new Table(Arrays.asList(main, right, left)); - Resources resources = TestUtils.createResources(ORE, CLAY); + Resources resources = TestUtilsKt.createResources(ORE, CLAY); assertEquals(1, BestPriceCalculator.bestPrice(resources, table, 0)); assertEquals(0, BestPriceCalculator.bestPrice(resources, table, 1)); assertEquals(4, BestPriceCalculator.bestPrice(resources, table, 2)); - ResourceTransactions oreAndClayLeft = TestUtils.createTransactions(LEFT_PLAYER, ORE, CLAY); - ResourceTransactions clayRight = TestUtils.createTransactions(RIGHT_PLAYER, CLAY); + ResourceTransactions oreAndClayLeft = TestUtilsKt.createTransactions(LEFT_PLAYER, ORE, CLAY); + ResourceTransactions clayRight = TestUtilsKt.createTransactions(RIGHT_PLAYER, CLAY); assertEquals(clayRight, BestPriceCalculator.bestSolution(resources, table, 0)); assertEquals(new ResourceTransactions(), BestPriceCalculator.bestSolution(resources, table, 1)); assertEquals(oreAndClayLeft, BestPriceCalculator.bestSolution(resources, table, 2)); diff --git a/game-engine/src/test/java/org/luxons/sevenwonders/game/resources/ResourceTransactionsTest.java b/game-engine/src/test/java/org/luxons/sevenwonders/game/resources/ResourceTransactionsTest.java index 68795053..775973b5 100644 --- a/game-engine/src/test/java/org/luxons/sevenwonders/game/resources/ResourceTransactionsTest.java +++ b/game-engine/src/test/java/org/luxons/sevenwonders/game/resources/ResourceTransactionsTest.java @@ -6,7 +6,7 @@ import java.util.List; import java.util.Set; import org.junit.Test; -import org.luxons.sevenwonders.game.test.TestUtils; +import org.luxons.sevenwonders.game.test.TestUtilsKt; import static org.junit.Assert.assertEquals; @@ -15,15 +15,16 @@ public class ResourceTransactionsTest { @Test public void toTransactions() { List<ResourceTransaction> transactionList = new ArrayList<>(); - transactionList.add(TestUtils.createTransaction(Provider.LEFT_PLAYER, ResourceType.WOOD)); - transactionList.add(TestUtils.createTransaction(Provider.LEFT_PLAYER, ResourceType.CLAY)); - transactionList.add(TestUtils.createTransaction(Provider.RIGHT_PLAYER, ResourceType.WOOD)); + transactionList.add(TestUtilsKt.createTransaction(Provider.LEFT_PLAYER, ResourceType.WOOD)); + transactionList.add(TestUtilsKt.createTransaction(Provider.LEFT_PLAYER, ResourceType.CLAY)); + transactionList.add(TestUtilsKt.createTransaction(Provider.RIGHT_PLAYER, ResourceType.WOOD)); ResourceTransactions transactions = new ResourceTransactions(transactionList); Set<ResourceTransaction> expectedNormalized = new HashSet<>(); - expectedNormalized.add(TestUtils.createTransaction(Provider.LEFT_PLAYER, ResourceType.WOOD, ResourceType.CLAY)); - expectedNormalized.add(TestUtils.createTransaction(Provider.RIGHT_PLAYER, ResourceType.WOOD)); + expectedNormalized.add( + TestUtilsKt.createTransaction(Provider.LEFT_PLAYER, ResourceType.WOOD, ResourceType.CLAY)); + expectedNormalized.add(TestUtilsKt.createTransaction(Provider.RIGHT_PLAYER, ResourceType.WOOD)); assertEquals(expectedNormalized, new HashSet<>(transactions.toTransactions())); } diff --git a/game-engine/src/test/java/org/luxons/sevenwonders/game/resources/TradingRulesTest.java b/game-engine/src/test/java/org/luxons/sevenwonders/game/resources/TradingRulesTest.java index d9f32c78..3c447753 100644 --- a/game-engine/src/test/java/org/luxons/sevenwonders/game/resources/TradingRulesTest.java +++ b/game-engine/src/test/java/org/luxons/sevenwonders/game/resources/TradingRulesTest.java @@ -7,7 +7,7 @@ import org.junit.experimental.theories.DataPoints; import org.junit.experimental.theories.Theories; import org.junit.experimental.theories.Theory; import org.junit.runner.RunWith; -import org.luxons.sevenwonders.game.test.TestUtils; +import org.luxons.sevenwonders.game.test.TestUtilsKt; import static org.junit.Assert.assertEquals; import static org.junit.Assume.assumeTrue; @@ -52,14 +52,14 @@ public class TradingRulesTest { @Theory public void computeCost_defaultCostWhenNoOverride(int defaultCost, Provider provider, ResourceType type) { TradingRules rules = new TradingRules(defaultCost); - ResourceTransactions transactions = TestUtils.createTransactions(provider, type); + ResourceTransactions transactions = TestUtilsKt.createTransactions(provider, type); assertEquals(defaultCost, rules.computeCost(transactions)); } @Theory public void computeCost_twiceDefaultFor2Resources(int defaultCost, Provider provider, ResourceType type) { TradingRules rules = new TradingRules(defaultCost); - ResourceTransactions transactions = TestUtils.createTransactions(provider, type, type); + ResourceTransactions transactions = TestUtilsKt.createTransactions(provider, type, type); assertEquals(2 * defaultCost, rules.computeCost(transactions)); } @@ -67,7 +67,7 @@ public class TradingRulesTest { public void computeCost_overriddenCost(int defaultCost, int overriddenCost, Provider provider, ResourceType type) { TradingRules rules = new TradingRules(defaultCost); rules.setCost(type, provider, overriddenCost); - ResourceTransactions transactions = TestUtils.createTransactions(provider, type); + ResourceTransactions transactions = TestUtilsKt.createTransactions(provider, type); assertEquals(overriddenCost, rules.computeCost(transactions)); } @@ -79,7 +79,7 @@ public class TradingRulesTest { assumeTrue(overriddenProvider != provider || overriddenType != type); TradingRules rules = new TradingRules(defaultCost); rules.setCost(overriddenType, overriddenProvider, overriddenCost); - ResourceTransactions transactions = TestUtils.createTransactions(provider, type); + ResourceTransactions transactions = TestUtilsKt.createTransactions(provider, type); assertEquals(defaultCost, rules.computeCost(transactions)); } @@ -90,7 +90,7 @@ public class TradingRulesTest { assumeTrue(overriddenType != type); TradingRules rules = new TradingRules(defaultCost); rules.setCost(overriddenType, provider, overriddenCost); - ResourceTransactions transactions = TestUtils.createTransactions(provider, overriddenType, type); + ResourceTransactions transactions = TestUtilsKt.createTransactions(provider, overriddenType, type); assertEquals(defaultCost + overriddenCost, rules.computeCost(transactions)); } @@ -103,8 +103,8 @@ public class TradingRulesTest { rules.setCost(type, overriddenProvider, overriddenCost); List<ResourceTransaction> boughtResources = new ArrayList<>(2); - boughtResources.add(TestUtils.createTransaction(provider, type)); - boughtResources.add(TestUtils.createTransaction(overriddenProvider, type)); + boughtResources.add(TestUtilsKt.createTransaction(provider, type)); + boughtResources.add(TestUtilsKt.createTransaction(overriddenProvider, type)); assertEquals(defaultCost + overriddenCost, rules.computeCost(new ResourceTransactions(boughtResources))); } diff --git a/game-engine/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java b/game-engine/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java deleted file mode 100644 index 73a08a32..00000000 --- a/game-engine/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java +++ /dev/null @@ -1,247 +0,0 @@ -package org.luxons.sevenwonders.game.test; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.IntStream; - -import org.luxons.sevenwonders.game.Settings; -import org.luxons.sevenwonders.game.api.CustomizableSettings; -import org.luxons.sevenwonders.game.api.PlayerMove; -import org.luxons.sevenwonders.game.api.Table; -import org.luxons.sevenwonders.game.boards.Board; -import org.luxons.sevenwonders.game.boards.Science; -import org.luxons.sevenwonders.game.boards.ScienceType; -import org.luxons.sevenwonders.game.cards.Card; -import org.luxons.sevenwonders.game.cards.CardBack; -import org.luxons.sevenwonders.game.cards.Color; -import org.luxons.sevenwonders.game.cards.Requirements; -import org.luxons.sevenwonders.game.effects.Effect; -import org.luxons.sevenwonders.game.effects.ScienceProgress; -import org.luxons.sevenwonders.game.moves.Move; -import org.luxons.sevenwonders.game.moves.MoveType; -import org.luxons.sevenwonders.game.resources.Production; -import org.luxons.sevenwonders.game.resources.Provider; -import org.luxons.sevenwonders.game.resources.ResourceTransaction; -import org.luxons.sevenwonders.game.resources.ResourceTransactions; -import org.luxons.sevenwonders.game.resources.ResourceType; -import org.luxons.sevenwonders.game.resources.Resources; -import org.luxons.sevenwonders.game.wonders.Wonder; -import org.luxons.sevenwonders.game.wonders.WonderStage; - -public class TestUtils { - - private static final long SEED = 42; - - public static CustomizableSettings createCustomizableSettings() { - CustomizableSettings customizableSettings = new CustomizableSettings(); - customizableSettings.setRandomSeedForTests(SEED); - return customizableSettings; - } - - public static Settings createSettings(int nbPlayers) { - return new Settings(nbPlayers, createCustomizableSettings()); - } - - public static Table createTable(int nbPlayers) { - return createTable(createSettings(nbPlayers)); - } - - public static Table createTable(Settings settings) { - return new Table(createBoards(settings.getNbPlayers(), settings)); - } - - private static List<Board> createBoards(int count, Settings settings) { - List<Board> boards = new ArrayList<>(count); - for (int i = 0; i < count; i++) { - boards.add(createBoard(ResourceType.WOOD, settings)); - } - return boards; - } - - private static Board createBoard(ResourceType initialResource, Settings settings) { - Wonder wonder = createWonder(initialResource); - return new Board(wonder, 0, settings); - } - - public static Board createBoard(ResourceType initialResource) { - return createBoard(initialResource, createSettings(5)); - } - - private static Board createBoard(ResourceType initialResource, ResourceType... production) { - Board board = createBoard(initialResource); - board.getProduction().addAll(createFixedProduction(production)); - return board; - } - - public static Board createBoard(ResourceType initialResource, int gold, ResourceType... production) { - Board board = createBoard(initialResource, production); - board.setGold(gold); - return board; - } - - public static Wonder createWonder() { - return createWonder(ResourceType.WOOD); - } - - public static Wonder createWonder(ResourceType initialResource) { - WonderStage stage1 = createWonderStage(); - WonderStage stage2 = createWonderStage(); - WonderStage stage3 = createWonderStage(); - return new Wonder("Test Wonder " + initialResource.getSymbol(), initialResource, stage1, stage2, stage3); - } - - private static WonderStage createWonderStage(Effect... effects) { - return new WonderStage(new Requirements(), Arrays.asList(effects)); - } - - public static Production createFixedProduction(ResourceType... producedTypes) { - Production production = new Production(); - Resources fixedProducedResources = production.getFixedResources(); - fixedProducedResources.addAll(createResources(producedTypes)); - return production; - } - - public static Resources createResources(ResourceType... types) { - Resources resources = new Resources(); - for (ResourceType producedType : types) { - resources.add(producedType, 1); - } - return resources; - } - - public static ResourceTransactions createTransactions(Provider provider, ResourceType... resources) { - ResourceTransaction transaction = createTransaction(provider, resources); - return new ResourceTransactions(Collections.singletonList(transaction)); - } - - public static ResourceTransactions createTransactions(ResourceTransaction... transactions) { - return new ResourceTransactions(Arrays.asList(transactions)); - } - - public static ResourceTransaction createTransaction(Provider provider, ResourceType... resources) { - return new ResourceTransaction(provider, TestUtils.createResources(resources)); - } - - public static Requirements createRequirements(ResourceType... types) { - Resources resources = createResources(types); - Requirements requirements = new Requirements(); - requirements.setResources(resources); - return requirements; - } - - public static List<Card> createSampleCards(int fromIndex, int nbCards) { - List<Card> sampleCards = new ArrayList<>(); - for (int i = fromIndex; i < fromIndex + nbCards; i++) { - sampleCards.add(createCard(i, Color.BLUE)); - } - return sampleCards; - } - - public static Card createCard(String name) { - return createCard(name, Color.BLUE); - } - - public static Card createCard(Color color) { - return createCard("Test Card", color); - } - - public static Card createCard(Color color, Effect effect) { - return createCard("Test Card", color, effect); - } - - private static Card createCard(int num, Color color) { - return createCard("Test Card " + num, color); - } - - public static List<Card> createGuildCards(int count) { - return IntStream.range(0, count).mapToObj(i -> TestUtils.createGuildCard(i)).collect(Collectors.toList()); - } - - public static Card createGuildCard(int num, Effect... effects) { - return createCard("Test Guild " + num, Color.PURPLE, effects); - } - - private static Card createCard(String name, Color color, Effect... effects) { - Card card = new Card(name, color, new Requirements(), Arrays.asList(effects), null, null, "path/to/card/image"); - card.setBack(createCardBack()); - return card; - } - - private static CardBack createCardBack() { - return new CardBack("image-III"); - } - - public static void addCards(Board board, int nbCardsOfColor, int nbOtherCards, Color color) { - addCards(board, nbCardsOfColor, color); - Color otherColor = getDifferentColorFrom(color); - addCards(board, nbOtherCards, otherColor); - } - - public static void addCards(Board board, int nbCards, Color color) { - for (int i = 0; i < nbCards; i++) { - board.addCard(createCard(i, color)); - } - } - - public static Color getDifferentColorFrom(Color... colors) { - List<Color> forbiddenColors = Arrays.asList(colors); - for (Color color : Color.values()) { - if (!forbiddenColors.contains(color)) { - return color; - } - } - throw new IllegalArgumentException("All colors are forbidden!"); - } - - public static ScienceProgress createScienceProgress(int compasses, int wheels, int tablets, int jokers) { - ScienceProgress progress = new ScienceProgress(); - progress.setScience(TestUtils.createScience(compasses, wheels, tablets, jokers)); - return progress; - } - - public static Science createScience(int compasses, int wheels, int tablets, int jokers) { - Science science = new Science(); - if (compasses > 0) { - science.add(ScienceType.COMPASS, compasses); - } - if (wheels > 0) { - science.add(ScienceType.WHEEL, wheels); - } - if (tablets > 0) { - science.add(ScienceType.TABLET, tablets); - } - if (jokers > 0) { - science.addJoker(jokers); - } - return science; - } - - public static void playCardWithEffect(Table table, int playerIndex, Color color, Effect effect) { - Card card = createCard(color, effect); - Board board = table.getBoard(playerIndex); - board.addCard(card); - card.applyTo(table, playerIndex, new ResourceTransactions()); - } - - public static Move createMove(int playerIndex, Card card, MoveType type, ResourceTransaction... transactions) { - PlayerMove playerMove = createPlayerMove(card.getName(), type, Arrays.asList(transactions)); - return type.resolve(playerIndex, card, playerMove); - } - - public static PlayerMove createPlayerMove(String cardName, MoveType type) { - return createPlayerMove(cardName, type, Collections.emptySet()); - } - - public static PlayerMove createPlayerMove(String cardName, MoveType type, - Collection<ResourceTransaction> transactions) { - PlayerMove playerMove = new PlayerMove(); - playerMove.setCardName(cardName); - playerMove.setType(type); - playerMove.setTransactions(transactions); - return playerMove; - } -} diff --git a/game-engine/src/test/java/org/luxons/sevenwonders/game/wonders/WonderTest.java b/game-engine/src/test/java/org/luxons/sevenwonders/game/wonders/WonderTest.java index 5bf2affa..a7988f8a 100644 --- a/game-engine/src/test/java/org/luxons/sevenwonders/game/wonders/WonderTest.java +++ b/game-engine/src/test/java/org/luxons/sevenwonders/game/wonders/WonderTest.java @@ -2,7 +2,7 @@ package org.luxons.sevenwonders.game.wonders; import org.junit.Test; import org.luxons.sevenwonders.game.cards.CardBack; -import org.luxons.sevenwonders.game.test.TestUtils; +import org.luxons.sevenwonders.game.test.TestUtilsKt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; @@ -11,7 +11,7 @@ public class WonderTest { @Test public void buildLevel_increasesNbBuiltStages() { - Wonder wonder = TestUtils.createWonder(); + Wonder wonder = TestUtilsKt.testWonder(); assertEquals(0, wonder.getNbBuiltStages()); wonder.buildLevel(new CardBack("img")); assertEquals(1, wonder.getNbBuiltStages()); @@ -23,7 +23,7 @@ public class WonderTest { @Test public void buildLevel_failsIfFull() { - Wonder wonder = TestUtils.createWonder(); + Wonder wonder = TestUtilsKt.testWonder(); wonder.buildLevel(new CardBack("img")); wonder.buildLevel(new CardBack("img")); wonder.buildLevel(new CardBack("img")); diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/test/TestUtils.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/test/TestUtils.kt new file mode 100644 index 00000000..65cf8d5b --- /dev/null +++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/test/TestUtils.kt @@ -0,0 +1,229 @@ +package org.luxons.sevenwonders.game.test + +import org.luxons.sevenwonders.game.Settings +import org.luxons.sevenwonders.game.api.CustomizableSettings +import org.luxons.sevenwonders.game.api.PlayerMove +import org.luxons.sevenwonders.game.api.Table +import org.luxons.sevenwonders.game.boards.Board +import org.luxons.sevenwonders.game.boards.Science +import org.luxons.sevenwonders.game.boards.ScienceType +import org.luxons.sevenwonders.game.cards.Card +import org.luxons.sevenwonders.game.cards.CardBack +import org.luxons.sevenwonders.game.cards.Color +import org.luxons.sevenwonders.game.cards.Requirements +import org.luxons.sevenwonders.game.effects.Effect +import org.luxons.sevenwonders.game.effects.ScienceProgress +import org.luxons.sevenwonders.game.moves.Move +import org.luxons.sevenwonders.game.moves.MoveType +import org.luxons.sevenwonders.game.resources.Production +import org.luxons.sevenwonders.game.resources.Provider +import org.luxons.sevenwonders.game.resources.ResourceTransaction +import org.luxons.sevenwonders.game.resources.ResourceTransactions +import org.luxons.sevenwonders.game.resources.ResourceType +import org.luxons.sevenwonders.game.resources.Resources +import org.luxons.sevenwonders.game.wonders.Wonder +import org.luxons.sevenwonders.game.wonders.WonderStage +import java.util.Arrays + +private const val SEED: Long = 42 + +@JvmOverloads +fun testCustomizableSettings(initialGold: Int = 0): CustomizableSettings { + return CustomizableSettings(randomSeedForTests = SEED).copy(initialGold = initialGold) +} + +fun testSettings(nbPlayers: Int): Settings { + return Settings(nbPlayers, testCustomizableSettings()) +} + +fun testTable(nbPlayers: Int): Table { + return testTable(testSettings(nbPlayers)) +} + +fun testTable(settings: Settings): Table { + return Table(testBoards(settings.nbPlayers, settings)) +} + +private fun testBoards(count: Int, settings: Settings): List<Board> { + val boards = ArrayList<Board>(count) + for (i in 0 until count) { + boards.add(testBoard(ResourceType.WOOD, settings)) + } + return boards +} + +private fun testBoard(initialResource: ResourceType, settings: Settings): Board { + val wonder = testWonder(initialResource) + return Board(wonder, 0, settings) +} + +fun testBoard(initialResource: ResourceType): Board { + return testBoard(initialResource, testSettings(5)) +} + +private fun testBoard(initialResource: ResourceType, vararg production: ResourceType): Board { + val board = testBoard(initialResource) + board.production.addAll(fixedProduction(*production)) + return board +} + +fun testBoard(initialResource: ResourceType, gold: Int, vararg production: ResourceType): Board { + val board = testBoard(initialResource, *production) + board.gold = gold + return board +} + +@JvmOverloads +fun testWonder(initialResource: ResourceType = ResourceType.WOOD): Wonder { + val stage1 = createWonderStage() + val stage2 = createWonderStage() + val stage3 = createWonderStage() + return Wonder("Test Wonder " + initialResource.symbol!!, initialResource, stage1, stage2, stage3) +} + +private fun createWonderStage(vararg effects: Effect): WonderStage { + return WonderStage(Requirements(), Arrays.asList(*effects)) +} + +fun fixedProduction(vararg producedTypes: ResourceType): Production { + val production = Production() + val fixedProducedResources = production.fixedResources + fixedProducedResources.addAll(createResources(*producedTypes)) + return production +} + +fun createResources(vararg types: ResourceType): Resources { + val resources = Resources() + for (producedType in types) { + resources.add(producedType, 1) + } + return resources +} + +fun createTransactions(provider: Provider, vararg resources: ResourceType): ResourceTransactions { + val transaction = createTransaction(provider, *resources) + return ResourceTransactions(listOf(transaction)) +} + +fun createTransactions(vararg transactions: ResourceTransaction): ResourceTransactions { + return ResourceTransactions(Arrays.asList(*transactions)) +} + +fun createTransaction(provider: Provider, vararg resources: ResourceType): ResourceTransaction { + return ResourceTransaction(provider, createResources(*resources)) +} + +fun createRequirements(vararg types: ResourceType): Requirements { + val resources = createResources(*types) + val requirements = Requirements() + requirements.resources = resources + return requirements +} + +fun createSampleCards(fromIndex: Int, nbCards: Int): List<Card> { + val sampleCards = ArrayList<Card>() + for (i in fromIndex until fromIndex + nbCards) { + sampleCards.add(testCard(i, Color.BLUE)) + } + return sampleCards +} + +fun testCard(name: String): Card { + return testCard(name, Color.BLUE) +} + +fun testCard(color: Color): Card { + return testCard("Test Card", color) +} + +fun testCard(color: Color, effect: Effect): Card { + return testCard("Test Card", color, effect) +} + +private fun testCard(num: Int, color: Color): Card { + return testCard("Test Card $num", color) +} + +fun createGuildCards(count: Int): List<Card> { + return IntRange(0, count).map { createGuildCard(it) } +} + +fun createGuildCard(num: Int, vararg effects: Effect): Card { + return testCard("Test Guild $num", Color.PURPLE, *effects) +} + +private fun testCard(name: String, color: Color, vararg effects: Effect): Card { + val card = Card(name, color, Requirements(), Arrays.asList(*effects), null, null, "path/to/card/image") + card.back = createCardBack() + return card +} + +private fun createCardBack(): CardBack { + return CardBack("image-III") +} + +fun addCards(board: Board, nbCardsOfColor: Int, nbOtherCards: Int, color: Color) { + addCards(board, nbCardsOfColor, color) + val otherColor = getDifferentColorFrom(color) + addCards(board, nbOtherCards, otherColor) +} + +fun addCards(board: Board, nbCards: Int, color: Color) { + for (i in 0 until nbCards) { + board.addCard(testCard(i, color)) + } +} + +fun getDifferentColorFrom(vararg colors: Color): Color { + val forbiddenColors = Arrays.asList(*colors) + for (color in Color.values()) { + if (!forbiddenColors.contains(color)) { + return color + } + } + throw IllegalArgumentException("All colors are forbidden!") +} + +fun createScienceProgress(compasses: Int, wheels: Int, tablets: Int, jokers: Int): ScienceProgress { + val progress = ScienceProgress() + progress.science = createScience(compasses, wheels, tablets, jokers) + return progress +} + +fun createScience(compasses: Int, wheels: Int, tablets: Int, jokers: Int): Science { + val science = Science() + if (compasses > 0) { + science.add(ScienceType.COMPASS, compasses) + } + if (wheels > 0) { + science.add(ScienceType.WHEEL, wheels) + } + if (tablets > 0) { + science.add(ScienceType.TABLET, tablets) + } + if (jokers > 0) { + science.addJoker(jokers) + } + return science +} + +fun playCardWithEffect(table: Table, playerIndex: Int, color: Color, effect: Effect) { + val card = testCard(color, effect) + val board = table.getBoard(playerIndex) + board.addCard(card) + card.applyTo(table, playerIndex, ResourceTransactions()) +} + +fun createMove(playerIndex: Int, card: Card, type: MoveType, vararg transactions: ResourceTransaction): Move { + val playerMove = PlayerMove(type, card.name, Arrays.asList(*transactions)) + return type.resolve(playerIndex, card, playerMove) +} + +@JvmOverloads +fun createPlayerMove( + type: MoveType, + cardName: String?, + transactions: Collection<ResourceTransaction> = emptySet() +): PlayerMove { + return PlayerMove(type, cardName, transactions) +} |