Skip to content

Instantly share code, notes, and snippets.

@erikhuizinga
Last active November 13, 2020 20:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erikhuizinga/f9e286dcf1d1a30b8d8301eed4f8085a to your computer and use it in GitHub Desktop.
Save erikhuizinga/f9e286dcf1d1a30b8d8301eed4f8085a to your computer and use it in GitHub Desktop.
7 Wonders Duel: Solo helper in Kotlin Script
val setup = """
ℹ️ SETUP
Set up the Age I cards like in a normal game, but sit so you're facing the first row of cards in the structure.
The zone to the left of the card structure is your City. The zone to the right of the structure is the Leader's City. Begin the game by giving 7 coins to yourself and none to the Leader.
Shuffle all the Wonder cards and draw 3. Choose 2 of these cards for yourself and give the third to the Leader.
Do this a second time. You will therefore start with 4 Wonder cards in your city and 2 in the Leader's City.
The Leader's 2 Wonder cards are treated as if already constructed. Immediately apply the following effects if they are on the Leader's Wonders:
- Shield and swords: move the military pawn accordingly.
- Coins: give the Leader as many Coins as shown (from the bank).
- Broken Coins: you lose as many Coins as shown.
- Progress tokens: take a random Progress token from those discarded at the beginning of the game and give it to the Leader.
Other effects are ignored. Victory points on each of the Leader's Wonder cards are counted with their final score (if there is no military or scientific supremacy before the end of the game).
""".trimIndent()
val gameplay = """
ℹ️ GAMEPLAY
Follow the instructions by this helper program for 7 Wonders Duel: Solo.
""".trimIndent()
interface Leader {
val replays: Set<Replays> get() = emptySet()
val cardColor: CardColors
val gameStartText: String
val gameEndText: String get() = ""
}
enum class Replays { CIRCLE, TRIANGLE }
enum class CardColors { PURPLE, YELLOW, BLUE, GREY, BROWN, RED, GREEN }
enum class Leaders : Leader {
CAESAR {
override val cardColor = CardColors.PURPLE
override val gameStartText = "starts with the Strategy Progress token."
},
HAMMURABI {
override val replays = setOf(Replays.CIRCLE)
override val cardColor = CardColors.YELLOW
override val gameStartText = "starts with the Economy Progress token."
override val gameEndText = "❕ Add 5 victory points to his score if the game ends after Age III."
},
CLEOPATRA {
override val replays = setOf(Replays.TRIANGLE)
override val cardColor = CardColors.BLUE
override val gameStartText = "starts with the Philosophy and Agriculture Progress tokens."
},
ARISTOTLE {
override val replays = setOf(Replays.CIRCLE)
override val cardColor = CardColors.GREY
override val gameStartText = "starts with the Law and Mathematics Progress tokens."
},
BILKIS {
override val replays = setOf(Replays.CIRCLE, Replays.TRIANGLE)
override val cardColor = CardColors.BROWN
override val gameStartText = "starts with the Economy Progress token."
};
}
enum class Directions { LEFT, RIGHT }
class DecisionCard(
val direction: Directions = Directions.RIGHT,
val primaryCardColor: CardColors? = CardColors.GREEN,
val secondaryCardColor: CardColors? = CardColors.RED,
val tertiaryCardColor: CardColors? = null,
val replay: Replays? = null
)
val decisionCards = listOf(
DecisionCard(),
DecisionCard(),
DecisionCard(),
DecisionCard(primaryCardColor = CardColors.RED, secondaryCardColor = CardColors.GREEN),
DecisionCard(primaryCardColor = CardColors.RED, secondaryCardColor = CardColors.GREEN),
DecisionCard(
primaryCardColor = null,
tertiaryCardColor = CardColors.GREEN,
replay = Replays.TRIANGLE
),
DecisionCard(direction = Directions.LEFT),
DecisionCard(
direction = Directions.LEFT,
primaryCardColor = CardColors.RED,
secondaryCardColor = CardColors.GREEN
),
DecisionCard(
direction = Directions.LEFT,
primaryCardColor = CardColors.RED,
secondaryCardColor = CardColors.GREEN
),
DecisionCard(
direction = Directions.LEFT,
primaryCardColor = CardColors.RED,
secondaryCardColor = CardColors.GREEN
),
DecisionCard(direction = Directions.LEFT),
DecisionCard(
direction = Directions.LEFT,
primaryCardColor = null,
secondaryCardColor = CardColors.GREEN,
tertiaryCardColor = CardColors.RED,
replay = Replays.CIRCLE
),
)
val cardIterator = sequence {
while (true) {
println("ℹ️ Shuffling Decision card deck.")
yieldAll(decisionCards.shuffled())
}
}.iterator()
fun unknownInputError() {
println("❌ Input not recognized, please input y, n or e.")
}
fun produceAction() = readLine()!!.toLowerCase().take(1)
println(setup)
println()
println(gameplay)
println()
println("👑 OPPONENT")
val leader = Leaders.values().random()
val leaderName = leader.name.toLowerCase().capitalize()
println("You play against $leaderName.")
if (leader.gameStartText.isNotEmpty()) {
println("$leaderName ${leader.gameStartText}")
println("👉 Place that in $leaderName's City.")
}
println("❕ $leaderName prefers cards of color ${leader.cardColor.name}.")
if (leader.replays.isNotEmpty()) {
println("❕ $leaderName has a chance of extra turns.")
}
if (leader.gameEndText.isNotEmpty()) {
println(leader.gameEndText)
}
println()
var leaderTurnIndex = 0
var age = 1
fun leaderTurn(): Unit {
println("ℹ️ Leader turn ${++leaderTurnIndex}")
with(cardIterator.next()) {
val direction = direction.name
val primaryCardColor = (primaryCardColor ?: leader.cardColor)
val secondaryCardColor = (secondaryCardColor ?: leader.cardColor)
val tertiaryCardColor = (tertiaryCardColor ?: leader.cardColor)
val colors = listOf(primaryCardColor, secondaryCardColor, tertiaryCardColor)
.filter { age == 3 || it != CardColors.PURPLE }
.map { it.name }
println("Starting from the $direction...")
colors.forEach { println("take the first available $it card, otherwise...") }
println("take the first available card.")
println("👉 Place the card in the $leaderName's City and apply its effect as in the base game. They pay nothing for the card. If $leaderName has a pair of scientific symbols, they take the first available Progress token from the $direction.")
if (replay in leader.replays) {
println("❕ The Decision card lets $leaderName take another turn!")
leaderTurn()
}
}
}
fun playerTurn() = println("👉 Take your turn(s).")
fun firstAgeTurn() {
println("❔ Is it $leaderName's turn or yours? L/y (LEADER/you)")
when (produceAction()) {
"", "l" -> {
println()
leaderTurn()
println()
playerTurn()
}
"y" -> {
println()
playerTurn()
}
else -> {
unknownInputError()
firstAgeTurn()
}
}
}
var isPlaying = true
println("ℹ️ $leaderName goes first in Age I.")
leaderTurn()
println()
playerTurn()
println()
do {
println("❔ Draw another decision card for $leaderName? Y/n/e (YES/no/end)")
println("No proceeds to next age, end finishes the game, e.g. after a victory.")
when (produceAction()) {
"n" -> {
println()
age++
if (age in 2..3) {
print("ℹ️ You are now in Age ")
repeat(age) { print('I') }
println('.')
println("❕ If $leaderName has the choice, they choose to play first in this Age.")
firstAgeTurn()
println()
}
}
"", "y" -> {
println()
leaderTurn()
println()
playerTurn()
println()
}
"e" -> {
println()
isPlaying = false
}
else -> {
unknownInputError()
println()
}
}
} while (age in 1..3 && isPlaying)
if (age >= 3 && leader.gameEndText.isNotEmpty()) {
println(leader.gameEndText)
println()
}
println("GAME OVER")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment