summaryrefslogtreecommitdiff
path: root/sw-engine/src
diff options
context:
space:
mode:
authorjoffrey-bion <joffrey.bion@gmail.com>2021-02-16 01:57:13 +0100
committerjoffrey-bion <joffrey.bion@gmail.com>2021-02-16 02:24:33 +0100
commit6a91cb4afa645ca0c1712433e212fb654a68da06 (patch)
tree219f71111c733f35e6c17329bb871a87fea13c99 /sw-engine/src
parentFix PLAY_LAST effect at end of age (Babylon B) (diff)
downloadseven-wonders-6a91cb4afa645ca0c1712433e212fb654a68da06.tar.gz
seven-wonders-6a91cb4afa645ca0c1712433e212fb654a68da06.tar.bz2
seven-wonders-6a91cb4afa645ca0c1712433e212fb654a68da06.zip
Fix copy-guild move (points are now counted properly)
Resolves: https://github.com/joffrey-bion/seven-wonders/issues/126
Diffstat (limited to 'sw-engine/src')
-rw-r--r--sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/boards/Board.kt6
-rw-r--r--sw-engine/src/test/kotlin/org/luxons/sevenwonders/engine/boards/BoardTest.kt39
-rw-r--r--sw-engine/src/test/kotlin/org/luxons/sevenwonders/engine/test/TestUtils.kt10
3 files changed, 39 insertions, 16 deletions
diff --git a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/boards/Board.kt b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/boards/Board.kt
index 3a3521ee..2fb5e36c 100644
--- a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/boards/Board.kt
+++ b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/boards/Board.kt
@@ -87,7 +87,7 @@ internal class Board(
ScoreCategory.MILITARY to military.totalPoints,
ScoreCategory.SCIENCE to science.computePoints(),
ScoreCategory.TRADE to computePointsForCards(player, Color.YELLOW),
- ScoreCategory.GUILD to computePointsForCards(player, Color.PURPLE),
+ ScoreCategory.GUILD to computePointsForCards(player, Color.PURPLE) + copiedGuildPoints(player),
ScoreCategory.WONDER to wonder.computePoints(player),
ScoreCategory.GOLD to computeGoldPoints(),
),
@@ -96,6 +96,10 @@ internal class Board(
private fun computePointsForCards(player: Player, color: Color): Int =
playedCards.filter { it.color === color }.flatMap { it.effects }.sumBy { it.computePoints(player) }
+ private fun copiedGuildPoints(player: Player): Int = copiedGuild?.computePoints(player) ?: 0
+
+ private fun Card.computePoints(player: Player): Int = effects.sumBy { it.computePoints(player) }
+
private fun computeGoldPoints(): Int = gold / 3 * pointsPer3Gold
internal class InsufficientFundsException(current: Int, required: Int) :
diff --git a/sw-engine/src/test/kotlin/org/luxons/sevenwonders/engine/boards/BoardTest.kt b/sw-engine/src/test/kotlin/org/luxons/sevenwonders/engine/boards/BoardTest.kt
index 909d5e99..821855ba 100644
--- a/sw-engine/src/test/kotlin/org/luxons/sevenwonders/engine/boards/BoardTest.kt
+++ b/sw-engine/src/test/kotlin/org/luxons/sevenwonders/engine/boards/BoardTest.kt
@@ -9,18 +9,10 @@ import org.junit.experimental.theories.Theories
import org.junit.experimental.theories.Theory
import org.junit.runner.RunWith
import org.luxons.sevenwonders.engine.boards.Board.InsufficientFundsException
-import org.luxons.sevenwonders.engine.effects.RawPointsIncrease
-import org.luxons.sevenwonders.engine.effects.SpecialAbility
-import org.luxons.sevenwonders.engine.effects.SpecialAbilityActivation
+import org.luxons.sevenwonders.engine.effects.*
import org.luxons.sevenwonders.engine.resources.resourcesOf
-import org.luxons.sevenwonders.engine.test.addCards
-import org.luxons.sevenwonders.engine.test.getDifferentColorFrom
-import org.luxons.sevenwonders.engine.test.playCardWithEffect
-import org.luxons.sevenwonders.engine.test.singleBoardPlayer
-import org.luxons.sevenwonders.engine.test.testBoard
-import org.luxons.sevenwonders.engine.test.testCard
-import org.luxons.sevenwonders.engine.test.testSettings
-import org.luxons.sevenwonders.engine.test.testWonder
+import org.luxons.sevenwonders.engine.test.*
+import org.luxons.sevenwonders.model.boards.RelativeBoardPosition
import org.luxons.sevenwonders.model.cards.Color
import org.luxons.sevenwonders.model.resources.ResourceType
import org.luxons.sevenwonders.model.score.ScoreCategory
@@ -186,6 +178,31 @@ class BoardTest {
assertEquals(5 + gold / 3, score.totalPoints)
}
+ @Theory
+ fun computePoints_countsCopiedGuild(@FromDataPoints("gold") gold: Int) {
+ assumeTrue(gold >= 0)
+ val left = testBoard(initialGold = gold)
+ val self = testBoard(initialGold = gold)
+ val right = testBoard(initialGold = gold)
+
+ left.addCard(testCard(color = Color.YELLOW))
+ right.addCard(testCard(color = Color.YELLOW))
+ right.addCard(testCard(color = Color.YELLOW))
+ self.copiedGuild = testCard(
+ name = "Custom guild for yellows",
+ color = Color.PURPLE,
+ effect = BonusPerBoardElement(
+ boards = listOf(RelativeBoardPosition.LEFT, RelativeBoardPosition.RIGHT),
+ type = BoardElementType.CARD,
+ colors = listOf(Color.YELLOW),
+ points = 1,
+ )
+ )
+
+ val score = self.computeScore(testPlayer(left, self, right))
+ assertEquals(3, score.pointsByCategory[ScoreCategory.GUILD])
+ }
+
companion object {
@JvmStatic
diff --git a/sw-engine/src/test/kotlin/org/luxons/sevenwonders/engine/test/TestUtils.kt b/sw-engine/src/test/kotlin/org/luxons/sevenwonders/engine/test/TestUtils.kt
index 0e8800f3..7a13eccd 100644
--- a/sw-engine/src/test/kotlin/org/luxons/sevenwonders/engine/test/TestUtils.kt
+++ b/sw-engine/src/test/kotlin/org/luxons/sevenwonders/engine/test/TestUtils.kt
@@ -132,12 +132,14 @@ internal fun playCardWithEffect(player: Player, color: Color, effect: Effect) {
internal fun createMove(context: PlayerContext, card: Card, type: MoveType): Move =
type.resolve(PlayerMove(type, card.name), card, context, emptyList())
-internal fun singleBoardPlayer(board: Board): Player = object : Player {
+internal fun singleBoardPlayer(board: Board): Player = testPlayer(leftBoard = null, selfBoard = board, rightBoard = null)
+
+internal fun testPlayer(leftBoard: Board?, selfBoard: Board, rightBoard: Board?): Player = object : Player {
override val index = 0
- override val board = board
+ override val board = selfBoard
override fun getBoard(relativePosition: RelativeBoardPosition): Board = when (relativePosition) {
- RelativeBoardPosition.LEFT -> throw RuntimeException("No LEFT board")
+ RelativeBoardPosition.LEFT -> leftBoard ?: error("No LEFT board")
RelativeBoardPosition.SELF -> this.board
- RelativeBoardPosition.RIGHT -> throw RuntimeException("No RIGHT board")
+ RelativeBoardPosition.RIGHT -> rightBoard ?: error("No RIGHT board")
}
}
bgstack15