content
stringlengths
0
13M
path
stringlengths
4
263
contentHash
stringlengths
1
10
package ch.chrigu.wotr.location import java.util.* object LocationFinder { private val cache = Collections.synchronizedMap(HashMap<LocationName, List<GraphNode>>()) fun getDistance(from: LocationName, to: LocationName) = getShortestPath(from, to).first().getLength() fun getShortestPath(from: LocationName, to: LocationName): List<LocationPath> { val graph = cache[from] ?: initGraph(from) return visit(graph, from, graph.first { it.name == to }) } private fun visit(graph: List<GraphNode>, from: LocationName, to: GraphNode): List<LocationPath> = if (from == to.name) listOf(LocationPath(emptyList())) else to.previous.flatMap { visit(graph, from, it) }.map { it + LocationPath(listOf(to.name)) } private fun initGraph(from: LocationName): List<GraphNode> { val graph = LocationName.entries.map { if (it == from) GraphNode(it, distance = 0) else GraphNode(it) } val visit = LocationName.entries.toMutableSet() while (visit.isNotEmpty()) { val minDistance = graph.filter { visit.contains(it.name) && it.distance != null }.minBy { it.distance!! } visit.remove(minDistance.name) minDistance.name.adjacent() .map { neighbor -> graph.first { it.name == neighbor } } .forEach { neighbor -> val newDistance = minDistance.distance!! + 1 if (neighbor.distance == null || newDistance < neighbor.distance!!) { neighbor.distance = newDistance neighbor.previous = mutableListOf(minDistance) } else if (neighbor.distance == newDistance) { neighbor.previous.add(minDistance) } } } cache[from] = graph return graph } data class GraphNode(val name: LocationName, var previous: MutableList<GraphNode> = mutableListOf(), var distance: Int? = null) } data class LocationPath(val locations: List<LocationName>) { fun getLength() = locations.size operator fun plus(other: LocationPath) = LocationPath(locations + other.locations) }
wotr-cli/src/main/kotlin/ch/chrigu/wotr/location/LocationFinder.kt
1270596997
package ch.chrigu.wotr.location enum class LocationType { NONE, VILLAGE, CITY, STRONGHOLD, FORTIFICATION; }
wotr-cli/src/main/kotlin/ch/chrigu/wotr/location/LocationType.kt
1958857619
package ch.chrigu.wotr.figure import ch.chrigu.wotr.gamestate.GameState import ch.chrigu.wotr.location.LocationName import ch.chrigu.wotr.nation.NationName import ch.chrigu.wotr.player.Player import kotlinx.serialization.Serializable import kotlin.math.min @Serializable data class Figures(val all: List<Figure>, val type: FiguresType = FiguresType.LOCATION) { init { require(all.distinct().size == all.size) { "Figures $all are not unique" } if (type != FiguresType.REINFORCEMENTS) { require(getArmy().all { it.nation.player == armyPlayer }) { "All army members must be of the same player: ${getArmy()}" } require((all - getArmy().toSet()).all { !it.type.isUnit && (it.nation.player != armyPlayer || !it.type.canBePartOfArmy) && it.isCharacterOrNazgul() }) { "All figures not belonging to an army must be the other's player unique character: ${all - getArmy().toSet()}" } require(numUnits() <= 10) { "There must not be more than 10 units, but was ${numUnits()}" } if (numUnits() == 0) { require(all.none { it.isFreePeopleLeader }) { "Free people leaders must not exist without army units: $all" } } } } val armyPlayer: Player? get() = getArmy().firstOrNull()?.nation?.player fun subSet(numRegular: Int, numElite: Int, numLeader: Int, nation: NationName?): Figures { return copy(all = take(numRegular, FigureType.REGULAR, nation) + take(numElite, FigureType.ELITE, nation) + take(numLeader, FigureType.LEADER_OR_NAZGUL, nation)) } fun subSet(characters: List<FigureType>) = copy(all = characters.map { take(it) }) fun isEmpty() = all.isEmpty() operator fun plus(other: Figures) = copy(all = all + other.all) operator fun minus(other: Figures): Figures { require(all.containsAll(other.all)) return copy(all = all - other.all.toSet()) } /** * Excludes characters that do not belong to [armyPlayer]. * @return Empty if there are no units that could form an army. */ fun getArmy(): List<Figure> { check(type == FiguresType.LOCATION) val units = getUnits() return if (units.isEmpty()) emptyList() else units + all.filter { !it.type.isUnit && it.nation.player == units.first().nation.player && it.type.canBePartOfArmy } } /** * @see getArmy */ fun getArmyPerNation() = getArmy().groupBy { it.nation } fun intersect(other: Figures) = copy(all = all.intersect(other.all.toSet()).toList()) fun union(other: Figures) = copy(all = all.union(other.all).toList()) fun numElites() = numElites(all) fun numRegulars() = numRegulars(all) fun numLeadersOrNazgul() = numLeadersOrNazgul(all) fun characters() = all.filter { it.type.isUniqueCharacter } fun containsAll(figures: Figures) = all.containsAll(figures.all) fun combatRolls() = min(5, numUnits()) fun maxReRolls() = min(leadership(), combatRolls()) override fun toString() = (all.groupBy { it.nation }.map { (nation, figures) -> printArmy(figures) + " ($nation)" } + all.mapNotNull { it.type.shortcut }) .joinToString(", ") private fun getUnits() = all.filter { it.type.isUnit } private fun leadership() = all.sumOf { it.type.leadership } private fun printArmy(figures: List<Figure>) = numRegulars(figures).toString() + numElites(figures) + numLeadersOrNazgul(figures) private fun numLeadersOrNazgul(figures: List<Figure>) = figures.count { it.type == FigureType.LEADER_OR_NAZGUL } private fun numElites(figures: List<Figure>) = figures.count { it.type == FigureType.ELITE } private fun numRegulars(figures: List<Figure>) = figures.count { it.type == FigureType.REGULAR } fun numUnits() = all.count { it.type.isUnit } private fun take(type: FigureType) = all.first { it.type == type } private fun take(num: Int, type: FigureType, nation: NationName?): List<Figure> { val allOfType = all.filter { it.type == type } val list = allOfType.filter { nation == null || nation == it.nation }.take(num) check(list.size == num) if (num > 0 && nation == null) { check(allOfType.all { it.nation == allOfType[0].nation }) { "No clear nation in $allOfType" } } return list } companion object { fun parse(who: Array<String>, locationName: LocationName, gameState: GameState) = parse(who, gameState.location[locationName]!!.nonBesiegedFigures) fun parse(who: Array<String>, figures: Figures, defaultNationName: NationName? = null): Figures { return if (who.isEmpty()) figures else FigureParser(who.toList()).select(figures, defaultNationName) } } }
wotr-cli/src/main/kotlin/ch/chrigu/wotr/figure/Figures.kt
737212900
package ch.chrigu.wotr.figure import ch.chrigu.wotr.gamestate.GameStateHolder import org.springframework.shell.CompletionContext import org.springframework.shell.CompletionProposal import org.springframework.shell.completion.CompletionProvider abstract class AbstractFiguresCompletionProvider(protected val gameStateHolder: GameStateHolder) : CompletionProvider { override fun apply(context: CompletionContext): List<CompletionProposal> { return FigureParser(getWhoValue(context)).getCompletionProposals(getAllFigures(context)) .map { CompletionProposal(it) } } abstract fun getAllFigures(context: CompletionContext): Figures abstract fun getWhoValue(context: CompletionContext): List<String> }
wotr-cli/src/main/kotlin/ch/chrigu/wotr/figure/AbstractFiguresCompletionProvider.kt
2343024539
package ch.chrigu.wotr.figure import ch.chrigu.wotr.gamestate.GameStateHolder import org.springframework.shell.CompletionContext import org.springframework.stereotype.Component @Component class ReinforcementsCompletionProvider(gameStateHolder: GameStateHolder) : AbstractFiguresCompletionProvider(gameStateHolder) { override fun getAllFigures(context: CompletionContext) = gameStateHolder.current.reinforcements override fun getWhoValue(context: CompletionContext): List<String> = if (context.words.first().startsWith("-")) context.words.drop(1) else context.words }
wotr-cli/src/main/kotlin/ch/chrigu/wotr/figure/ReinforcementsCompletionProvider.kt
3433897811
package ch.chrigu.wotr.figure import ch.chrigu.wotr.gamestate.GameStateHolder import ch.chrigu.wotr.location.LocationName import org.springframework.shell.CompletionContext import org.springframework.stereotype.Component @Component class FiguresCompletionProvider(gameStateHolder: GameStateHolder) : AbstractFiguresCompletionProvider(gameStateHolder) { override fun getAllFigures(context: CompletionContext): Figures { val locationName = LocationName.get(getFromValue(context)) val location = gameStateHolder.current.location[locationName]!! return location.nonBesiegedFigures } override fun getWhoValue(context: CompletionContext) = context.words.dropWhile { it != "-w" && it != "--who" }.drop(1) private fun getFromValue(context: CompletionContext) = if (context.words.first().startsWith("-")) context.words[1] else context.words.first() }
wotr-cli/src/main/kotlin/ch/chrigu/wotr/figure/FiguresCompletionProvider.kt
916180956
package ch.chrigu.wotr.figure import ch.chrigu.wotr.nation.NationName class FigureParser(private val who: List<String>) { fun select(figures: Figures, defaultNationName: NationName? = null) = who.map { part -> check(part.isNotEmpty()) if (part[0].isDigit()) { val digits = part.takeWhile { it.isDigit() } require(digits.length in 1..3) val nation = if (part.contains("(") && part.contains(")")) NationName.find(part.substringAfter(")").substringBefore(")")) else null figures.subSet(digits[0].digitToInt(), digits.getOrNull(1)?.digitToInt() ?: 0, digits.getOrNull(2)?.digitToInt() ?: 0, nation ?: defaultNationName) } else { require(part.length == 2) val resolvedCharacters = part.chunked(2).map { FigureType.fromShortcut(it) } figures.subSet(resolvedCharacters) } } .fold(Figures(emptyList())) { a, b -> require(a.intersect(b).isEmpty()) a + b } fun getCompletionProposals(figures: Figures): List<String> { val prefix = who.take(who.size - 1) val before = FigureParser(prefix).select(figures) val remaining = figures - before val current = who.last() val armyOptions = (0..remaining.numRegulars()) .flatMap { regular -> (0..remaining.numElites()).map { regular.toString() + it } } .flatMap { units -> (0..remaining.numLeadersOrNazgul()).map { units + it } } val options = armyOptions + remaining.characters().map { it.type.shortcut!! } return options.filter { it.startsWith(current, true) } } }
wotr-cli/src/main/kotlin/ch/chrigu/wotr/figure/FigureParser.kt
2415038852
package ch.chrigu.wotr.figure enum class FiguresType { REINFORCEMENTS, LOCATION }
wotr-cli/src/main/kotlin/ch/chrigu/wotr/figure/FiguresType.kt
1189160878
package ch.chrigu.wotr.figure enum class FigureType( val shortcut: String? = null, val isUnit: Boolean = false, val canBePartOfArmy: Boolean = true, val minion: Boolean = false, val leadership: Int = 0, val level: FigureLevel? = null, val enablesDice: Int = 0 ) { WITCH_KING("wk", minion = true, leadership = 2, level = FlyingLevel, enablesDice = 1), SARUMAN("sa", minion = true, leadership = 1, level = NumberedLevel(0), enablesDice = 1), MOUTH_OF_SAURON("ms", minion = true, leadership = 2, level = NumberedLevel(3), enablesDice = 1), GANDALF_THE_WHITE("gw", leadership = 1, level = NumberedLevel(3), enablesDice = 1), GANDALF_THE_GREY("gg", leadership = 1, level = NumberedLevel(3)), STRIDER("st", leadership = 1, level = NumberedLevel(3)), ARAGORN("ar", leadership = 2, level = NumberedLevel(3), enablesDice = 1), BOROMIR("bo", leadership = 1, level = NumberedLevel(2)), GIMLI("gi", leadership = 1, level = NumberedLevel(2)), LEGOLAS("le", leadership = 1, level = NumberedLevel(2)), MERIADOC("me", leadership = 1, level = NumberedLevel(1)), PEREGRIN("pe", leadership = 1, level = NumberedLevel(1)), REGULAR(isUnit = true), ELITE(isUnit = true), LEADER_OR_NAZGUL(leadership = 1), FELLOWSHIP("fs", canBePartOfArmy = false); val isUniqueCharacter = shortcut != null override fun toString() = name.replace("_", " ").lowercase().replaceFirstChar { it.uppercaseChar() } companion object { fun fromShortcut(s: String) = entries.first { it.shortcut.equals(s, true) } } }
wotr-cli/src/main/kotlin/ch/chrigu/wotr/figure/FigureType.kt
4004012425
package ch.chrigu.wotr.figure import ch.chrigu.wotr.nation.NationName import ch.chrigu.wotr.player.Player import kotlinx.serialization.Serializable @Serializable class Figure(val type: FigureType, val nation: NationName) { init { if (type == FigureType.LEADER_OR_NAZGUL) { require(nation.player == Player.FREE_PEOPLE || nation == NationName.SAURON) } } val isFreePeopleLeader: Boolean get() = type == FigureType.LEADER_OR_NAZGUL && nation.player == Player.FREE_PEOPLE val isNazgul: Boolean get() = type == FigureType.LEADER_OR_NAZGUL && nation.player == Player.SHADOW fun isNazgulOrWitchKing() = isNazgul || type == FigureType.WITCH_KING fun isCharacterOrNazgul() = isNazgul || type.isUniqueCharacter override fun toString() = "${getTypeString()} ($nation)" private fun getTypeString() = if (type == FigureType.LEADER_OR_NAZGUL) { if (nation.player == Player.FREE_PEOPLE) "Leader" else "Nazgul" } else type.toString() }
wotr-cli/src/main/kotlin/ch/chrigu/wotr/figure/Figure.kt
1883294470
package ch.chrigu.wotr.figure sealed interface FigureLevel class NumberedLevel(val number: Int) : FigureLevel data object FlyingLevel : FigureLevel
wotr-cli/src/main/kotlin/ch/chrigu/wotr/figure/FigureLevel.kt
337913769
package ch.chrigu.wotr.dice import ch.chrigu.wotr.gamestate.GameState import ch.chrigu.wotr.player.Player import kotlinx.serialization.Serializable import kotlin.random.Random @Serializable data class Dice(val shadow: DiceAndRings = DiceAndRings(emptyList(), 0, Player.SHADOW), val freePeople: DiceAndRings = DiceAndRings(emptyList(), 3, Player.FREE_PEOPLE)) { fun useDie(dieUsage: DieUsage) = copy( shadow = if (dieUsage.player == Player.SHADOW) shadow.use(dieUsage) else shadow, freePeople = if (dieUsage.player == Player.FREE_PEOPLE) freePeople.use(dieUsage) else freePeople ) fun assignEyesAndRollDice(state: GameState, numEyes: Int) = copy( shadow = shadow.assignAndRoll(7 + state.numMinions(), numEyes), freePeople = freePeople.roll(4 + listOf(state.hasAragorn(), state.hasGandalfTheWhite()).sumOf { toInt(it) }) ) fun fakeShadowRoll(vararg die: DieType) = copy( shadow = shadow.fakeRoll(die.toList()) ) private fun toInt(it: Boolean) = if (it) 1 else 0 init { require(!shadow.rolled.contains(DieType.WILL_OF_THE_WEST)) require(!freePeople.rolled.contains(DieType.EYE)) } } @Serializable data class DiceAndRings(val rolled: List<DieType>, val rings: Int, val player: Player, val ringsUsed: Boolean = false, val huntBox: List<DieType> = emptyList()) { init { require(rings in 0..3) } fun isEmpty() = rolled.isEmpty() fun use(dieUsage: DieUsage): DiceAndRings { check(!dieUsage.useRing || !noRings()) return copy(rolled = removeOneDie(dieUsage.use), rings = if (dieUsage.useRing) rings - 1 else rings, ringsUsed = if (dieUsage.useRing) true else ringsUsed) } fun roll(num: Int) = copy(rolled = (0 until num).map { rollDie() }, ringsUsed = false, huntBox = emptyList()) fun fakeRoll(dice: List<DieType>) = copy(rolled = dice, ringsUsed = false, huntBox = emptyList()) fun assignAndRoll(num: Int, numEyes: Int): DiceAndRings { val roll = (0 until num - numEyes).map { rollDie() } val rolledEyes = roll.filter { it == DieType.EYE } return copy(rolled = roll - rolledEyes.toSet(), ringsUsed = false, huntBox = (0 until numEyes).map { DieType.EYE } + rolledEyes) } fun getDice(types: Set<DieType>): List<DieUsage> { val matchingDice = rolled.filter { types.contains(it) || it == DieType.WILL_OF_THE_WEST } val withRing = if (noRings()) emptyList() else (rolled - matchingDice.toSet()).map { DieUsage(it, true, player) } return matchingDice.map { DieUsage(it, false, player) } + withRing } override fun toString() = (rolled + (0 until rings).map { "X" }).joinToString(" ") + huntBoxToString() private fun removeOneDie(type: DieType): List<DieType> { val useIndex = rolled.indexOf(type) return rolled.subList(0, useIndex) + rolled.subList(useIndex + 1, rolled.size) } private fun huntBoxToString() = if (huntBox.isEmpty()) "" else " / " + huntBox.joinToString(" ") private fun rollDie() = player.dieFace[Random.nextInt(6)] private fun noRings() = rings == 0 || ringsUsed } enum class DieType(private val shortName: String? = null) { ARMY, MUSTER, ARMY_MUSTER("AM"), EYE, WILL_OF_THE_WEST, EVENT("P"), CHARACTER; override fun toString() = shortName ?: name.take(1) } data class DieUsage(val use: DieType, val useRing: Boolean, val player: Player) { override fun toString() = if (useRing) "ring" else use.toString() }
wotr-cli/src/main/kotlin/ch/chrigu/wotr/dice/Dice.kt
1366434532
package ch.chrigu.wotr.nation import kotlinx.serialization.Serializable @Serializable data class Nation(val box: Int, val active: Boolean, val name: NationName) { init { require(box >= 0) if (!active) require(box > 0) } fun isOnWar() = box == 0 fun moveDown() = copy(box = box - 1) }
wotr-cli/src/main/kotlin/ch/chrigu/wotr/nation/Nation.kt
277142012
package ch.chrigu.wotr.nation import ch.chrigu.wotr.player.Player import java.util.* enum class NationName(val player: Player, val shortcut: String) { GONDOR(Player.FREE_PEOPLE, "go"), ROHAN(Player.FREE_PEOPLE, "ro"), ELVES(Player.FREE_PEOPLE, "el"), DWARVES(Player.FREE_PEOPLE, "dw"), NORTHMEN(Player.FREE_PEOPLE, "no"), FREE_PEOPLE(Player.FREE_PEOPLE, "fp"), SAURON(Player.SHADOW, "sa"), ISENGARD(Player.SHADOW, "is"), SOUTHRONS_AND_EASTERLINGS(Player.SHADOW, "se"); val fullName = name.lowercase().split("_") .joinToString(" ") { part -> part.replaceFirstChar { it.titlecase(Locale.getDefault()) } } override fun toString() = fullName companion object { fun find(name: String) = entries.first { name.equals(it.fullName, true) || name.equals(it.shortcut, true) } } }
wotr-cli/src/main/kotlin/ch/chrigu/wotr/nation/NationName.kt
3016320726
package ch.chrigu.wotr.action import ch.chrigu.wotr.gamestate.GameState class AssignEyesAndThrowDiceAction(private val numEyes: Int) : GameAction { override fun apply(oldState: GameState): GameState { return oldState.copy(dice = oldState.dice.assignEyesAndRollDice(oldState, numEyes), cards = oldState.cards.phase1()) } override fun toString() = "Assign $numEyes and roll dice" }
wotr-cli/src/main/kotlin/ch/chrigu/wotr/action/AssignEyesAndThrowDiceAction.kt
2966072550
package ch.chrigu.wotr.action import ch.chrigu.wotr.dice.DieType import ch.chrigu.wotr.figure.Figures import ch.chrigu.wotr.gamestate.GameState import ch.chrigu.wotr.location.LocationName import kotlin.math.max data class MoveAction(private val fromLocation: LocationName, private val toLocation: LocationName, val figures: Figures) : GameAction { init { require(!figures.isEmpty()) { "Move action requires at least one figure" } require(fromLocation != toLocation) { "Move action must have two different locations" } } override fun apply(oldState: GameState) = oldState.removeFrom(fromLocation, figures).addTo(toLocation, figures) override fun tryToCombine(other: GameAction): GameAction? { if (other is MoveAction && fromLocation == other.fromLocation && toLocation == other.toLocation) { val union = figures.union(other.figures) if (union.all.size == max(figures.all.size, other.figures.all.size)) return null return MoveAction(fromLocation, toLocation, union) } return null } override fun toString() = "Move $figures from $fromLocation to $toLocation" fun isCharacterMovement() = figures.all.all { it.isCharacterOrNazgul() } fun isArmyMovement() = figures.all.any { it.type.isUnit } override fun requiredDice() = setOf(DieType.CHARACTER, DieType.ARMY, DieType.ARMY_MUSTER) }
wotr-cli/src/main/kotlin/ch/chrigu/wotr/action/MoveAction.kt
2424119226
package ch.chrigu.wotr.action import ch.chrigu.wotr.dice.DieType import ch.chrigu.wotr.gamestate.GameState interface GameAction { fun apply(oldState: GameState): GameState /** * Like [apply], but used for evaluating a bot action. */ fun simulate(oldState: GameState): GameState = apply(oldState) fun tryToCombine(other: GameAction): GameAction? = null fun requiredDice(): Set<DieType> = throw IllegalStateException("The action ${javaClass.simpleName} does not support to be played within a die action") }
wotr-cli/src/main/kotlin/ch/chrigu/wotr/action/GameAction.kt
1219560764
package ch.chrigu.wotr.action import ch.chrigu.wotr.dice.DieType import ch.chrigu.wotr.gamestate.GameState import ch.chrigu.wotr.nation.NationName data class PoliticsMarkerAction(private val name: NationName) : GameAction { override fun apply(oldState: GameState) = oldState.updateNation(name) { moveDown() } override fun requiredDice() = setOf(DieType.MUSTER, DieType.ARMY_MUSTER) override fun toString() = "Move politics marker of $name" }
wotr-cli/src/main/kotlin/ch/chrigu/wotr/action/PoliticsMarkerAction.kt
887056047
package ch.chrigu.wotr.action import ch.chrigu.wotr.figure.Figures import ch.chrigu.wotr.figure.FiguresType import ch.chrigu.wotr.gamestate.GameState import ch.chrigu.wotr.location.LocationName class MusterAction(private val figures: Figures, private val locationName: LocationName) : GameAction { override fun apply(oldState: GameState) = oldState.removeFromReinforcements(figures).addTo(locationName, figures.copy(type = FiguresType.LOCATION)) override fun toString() = "Muster $figures at $locationName" }
wotr-cli/src/main/kotlin/ch/chrigu/wotr/action/MusterAction.kt
1301979036
package ch.chrigu.wotr.action import ch.chrigu.wotr.card.EventType import ch.chrigu.wotr.dice.DieType import ch.chrigu.wotr.gamestate.GameState import org.jline.terminal.Terminal data class PlayEventAction(private val type: EventType, private val terminal: Terminal) : GameAction { override fun apply(oldState: GameState): GameState { val newState = oldState.copy(cards = oldState.cards.play(type)) terminal.writer().println("Search your $type deck for the first card whose requirement can be met and that will alter the game state. Play it.") return newState } override fun simulate(oldState: GameState): GameState { return oldState.copy(cards = oldState.cards.play(type)) } override fun requiredDice() = setOf(DieType.EVENT) + if (type == EventType.CHARACTER) setOf(DieType.CHARACTER) else setOf(DieType.ARMY, DieType.ARMY_MUSTER, DieType.MUSTER) override fun toString() = "Play $type event" }
wotr-cli/src/main/kotlin/ch/chrigu/wotr/action/PlayEventAction.kt
3452273411
package ch.chrigu.wotr.action import ch.chrigu.wotr.dice.DieType import ch.chrigu.wotr.figure.Figure import ch.chrigu.wotr.figure.Figures import ch.chrigu.wotr.gamestate.GameState import ch.chrigu.wotr.location.LocationName class MusterFiguresAction(private val musters: Map<Figures, LocationName>) : GameAction { private val actions = musters.map { (figures, location) -> MusterAction(figures, location) } constructor(figures: Figures, locationName: LocationName) : this(mapOf(figures to locationName)) constructor(vararg muster: Pair<Figure, LocationName>) : this(muster.associate { (f, l) -> Figures(listOf(f)) to l }) override fun apply(oldState: GameState): GameState = actions.fold(oldState) { state, action -> action.apply(state) } override fun requiredDice() = setOf(DieType.MUSTER, DieType.ARMY_MUSTER) operator fun plus(other: MusterFiguresAction?) = other?.let { MusterFiguresAction(musters + it.musters) } override fun toString() = actions.joinToString(", ") }
wotr-cli/src/main/kotlin/ch/chrigu/wotr/action/MusterFiguresAction.kt
2680230958
package ch.chrigu.wotr.action import ch.chrigu.wotr.card.EventType import ch.chrigu.wotr.combat.CombatSimulator import ch.chrigu.wotr.combat.CombatType import ch.chrigu.wotr.dice.DieType import ch.chrigu.wotr.figure.FigureType import ch.chrigu.wotr.figure.Figures import ch.chrigu.wotr.gamestate.GameState import ch.chrigu.wotr.location.LocationName import org.jline.terminal.Terminal /** * @param defenderLocation If null, it is a sortie or a siege battle. */ data class AttackAction( private val terminal: Terminal, private val attacker: Figures, private val defender: Figures, private val attackerLocation: LocationName, private val defenderLocation: LocationName? = null ) : GameAction { override fun apply(oldState: GameState): GameState { terminal.writer().println(toString()) terminal.writer().println("Search an appropriate combat card from ${getNumCombatCards()} ${getDeckType()}") return oldState } override fun simulate(oldState: GameState): GameState { val casualties = CombatSimulator( attacker, defender, getCombatType(oldState), oldState.location[defenderLocation ?: attackerLocation]!!.type, attackerLocation, defenderLocation ?: attackerLocation ) .repeat(20) return casualties.fold(oldState) { a, b -> b.apply(a) } } override fun toString() = "$attacker ($attackerLocation) attacks $defender (${defenderLocation ?: attackerLocation})" override fun requiredDice() = setOf(DieType.ARMY, DieType.ARMY_MUSTER) + if (attacker.all.any { !it.type.isUnit }) setOf(DieType.CHARACTER) else emptySet() private fun getNumCombatCards() = if (figures().any { it.type == FigureType.WITCH_KING }) 3 else 2 private fun figures() = attacker.all + defender.all private fun getCombatType(state: GameState) = if (defenderLocation == null) { if (state.location[attackerLocation]!!.nonBesiegedFigures.containsAll(attacker)) CombatType.SIEGE else CombatType.SORTIE } else CombatType.FIELD_BATTLE private fun getDeckType() = if (figures().count { it.isNazgulOrWitchKing() } > 3) EventType.CHARACTER else EventType.STRATEGY }
wotr-cli/src/main/kotlin/ch/chrigu/wotr/action/AttackAction.kt
2431959116
package ch.chrigu.wotr.action import ch.chrigu.wotr.gamestate.GameState class DieActionFactory(private val state: GameState) { fun everyCombination(action: GameAction) = state.dice.shadow.getDice(action.requiredDice()) .map { DieAction(it, listOf(action)) } }
wotr-cli/src/main/kotlin/ch/chrigu/wotr/action/DieActionFactory.kt
348607082
package ch.chrigu.wotr.action import ch.chrigu.wotr.card.EventType import ch.chrigu.wotr.dice.DieType import ch.chrigu.wotr.gamestate.GameState data class DrawEventAction(private val type: EventType) : GameAction { override fun apply(oldState: GameState): GameState { return oldState.copy(cards = oldState.cards.draw(type)) } override fun requiredDice() = setOf(DieType.EVENT) override fun toString() = "Draw $type event" }
wotr-cli/src/main/kotlin/ch/chrigu/wotr/action/DrawEventAction.kt
3135168014
package ch.chrigu.wotr.action import ch.chrigu.wotr.dice.DieType import ch.chrigu.wotr.figure.Figures import ch.chrigu.wotr.gamestate.GameState import ch.chrigu.wotr.location.LocationName class ReplaceFiguresAction(private val replace: Figures, private val by: Figures, private val location: LocationName) : GameAction { override fun apply(oldState: GameState) = oldState.removeFrom(location, replace) .addToReinforcements(replace) .removeFromReinforcements(by) .addTo(location, by) override fun requiredDice() = setOf(DieType.MUSTER, DieType.ARMY_MUSTER) override fun toString() = "Replace $replace by $by at $location" }
wotr-cli/src/main/kotlin/ch/chrigu/wotr/action/ReplaceFiguresAction.kt
1241788879
package ch.chrigu.wotr.action import ch.chrigu.wotr.figure.Figures import ch.chrigu.wotr.gamestate.GameState import ch.chrigu.wotr.location.LocationName import ch.chrigu.wotr.player.Player class KillAction(private val locationName: LocationName, private val figures: Figures) : GameAction { override fun apply(oldState: GameState) = oldState.removeFrom(locationName, figures) .addToReinforcements(Figures(figures.getArmy().filter { it.nation.player == Player.SHADOW && !it.type.isUniqueCharacter })) override fun toString() = "Kill $figures at $locationName" }
wotr-cli/src/main/kotlin/ch/chrigu/wotr/action/KillAction.kt
4081202606
package ch.chrigu.wotr.action import ch.chrigu.wotr.bot.BotActionFactory import ch.chrigu.wotr.gamestate.GameState import org.jline.terminal.Terminal class BotAction(private val terminal: Terminal, private val botActionFactory: BotActionFactory) : GameAction { override fun apply(oldState: GameState): GameState { val nextAction = botActionFactory.getNext(oldState) terminal.writer().println(nextAction.toString()) return nextAction.apply(oldState) } override fun toString() = "Bot action" }
wotr-cli/src/main/kotlin/ch/chrigu/wotr/action/BotAction.kt
3951088724
package ch.chrigu.wotr.action import ch.chrigu.wotr.dice.DieType import ch.chrigu.wotr.dice.DieUsage import ch.chrigu.wotr.gamestate.GameState data class DieAction(private val use: DieUsage, private val actions: List<GameAction>) : GameAction { override fun apply(oldState: GameState): GameState { return oldState.useDie(use).let { initial -> actions.fold(initial) { state, action -> action.apply(state) } } } override fun simulate(oldState: GameState): GameState { return oldState.useDie(use).let { initial -> actions.fold(initial) { state, action -> action.simulate(state) } } } override fun tryToCombine(other: GameAction): GameAction? { if (other !is DieAction || use != other.use) return null val combined = if (actions.size == 1 && other.actions.size == 1) actions[0].tryToCombine(other.actions[0]) else null if (combined != null) return DieAction(use, listOf(combined)) val allActions = actions + other.actions if (!allActions.all { it is MoveAction }) return null if (allActions.sumOf { (it as MoveAction).figures.numUnits() } > 10) return null val figures1 = actions.map { (it as MoveAction).figures }.reduce { a, b -> a + b } val figures2 = other.actions.map { (it as MoveAction).figures }.reduce { a, b -> a + b } if (!figures1.intersect(figures2).isEmpty()) return null if (allActions.all { isCharacterMovement(it) }) { return DieAction(use, allActions) } else if (allActions.size == 2 && allActions.all { isArmyMovement(it) } && (use.use != DieType.CHARACTER || use.useRing)) { return DieAction(use, allActions) } return null } private fun isCharacterMovement(action: GameAction) = action is MoveAction && action.isCharacterMovement() private fun isArmyMovement(action: GameAction) = action is MoveAction && action.isArmyMovement() override fun toString() = "Use $use to $actions" }
wotr-cli/src/main/kotlin/ch/chrigu/wotr/action/DieAction.kt
506418036
package ch.chrigu.wotr import ch.chrigu.wotr.commands.BoardCommands import ch.chrigu.wotr.commands.BotCommands import ch.chrigu.wotr.commands.SaveLoadCommands import ch.chrigu.wotr.commands.UndoRedoCommands import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.boot.runApplication import org.springframework.shell.command.annotation.EnableCommand @SpringBootApplication @EnableCommand(BoardCommands::class, UndoRedoCommands::class, BotCommands::class, SaveLoadCommands::class) class WotrCliApplication fun main(args: Array<String>) { runApplication<WotrCliApplication>(*args) }
wotr-cli/src/main/kotlin/ch/chrigu/wotr/WotrCliApplication.kt
3630006125
package ch.chrigu.wotr.bot import ch.chrigu.wotr.action.AssignEyesAndThrowDiceAction import ch.chrigu.wotr.gamestate.GameState import org.springframework.core.annotation.Order import org.springframework.stereotype.Component import kotlin.math.max @Order(0) @Component class ThrowDiceStrategy : BotStrategy { override fun getActions(state: GameState) = if (state.dice.shadow.isEmpty()) listOf(AssignEyesAndThrowDiceAction(numEyes(state))) else emptyList() private fun numEyes(state: GameState) = if (state.fellowship.mordor == null) max(1, state.fellowship.numRerolls(state)) else if (state.fellowship.remainingCorruption() < 5) state.fellowship.remainingCorruption() else 2 }
wotr-cli/src/main/kotlin/ch/chrigu/wotr/bot/ThrowDiceStrategy.kt
3102393102
package ch.chrigu.wotr.bot import ch.chrigu.wotr.action.AttackAction import ch.chrigu.wotr.gamestate.GameState import ch.chrigu.wotr.location.Location import ch.chrigu.wotr.player.Player import org.jline.terminal.Terminal import org.springframework.core.annotation.Order import org.springframework.stereotype.Component @Order(4) @Component class AttackStrategy(private val terminal: Terminal) : BotStrategy { override fun getActions(state: GameState) = state.location.values.flatMap { location -> val nonBesiegedFigures = location.nonBesiegedFigures if (location.besiegedFigures.armyPlayer == Player.SHADOW) { listOf(AttackAction(terminal, location.besiegedFigures, nonBesiegedFigures, location.name)) } else if (nonBesiegedFigures.armyPlayer == Player.SHADOW) { getSiegeAttack(location) + location.adjacentLocations.mapNotNull { adjacent -> getFieldBattle(location, state.location[adjacent]!!) } } else { emptyList() } } private fun getFieldBattle(location: Location, adjacent: Location): AttackAction? { val defender = adjacent.nonBesiegedFigures return if (defender.armyPlayer == Player.FREE_PEOPLE) AttackAction(terminal, location.nonBesiegedFigures, defender, location.name, adjacent.name) else null } private fun getSiegeAttack(location: Location) = if (location.besiegedFigures.armyPlayer == Player.FREE_PEOPLE) listOf(AttackAction(terminal, location.nonBesiegedFigures, location.besiegedFigures, location.name)) else emptyList() }
wotr-cli/src/main/kotlin/ch/chrigu/wotr/bot/AttackStrategy.kt
3848674210
package ch.chrigu.wotr.bot object Combinations { fun <T> allSizes(all: List<T>): List<List<T>> { if (all.isEmpty()) return listOf(emptyList()) else { val first = listOf(all.first()) val other = allSizes(all.drop(1)) return other.map { first + it } + other } } fun <T> ofSize(all: List<T>, size: Int): List<List<T>> { if (all.size < size) return emptyList() if (size == 1) return all.map { listOf(it) } return all.flatMapIndexed { index, pick -> ofSize(all.drop(index + 1), size - 1).map { listOf(pick) + it } } } }
wotr-cli/src/main/kotlin/ch/chrigu/wotr/bot/Combinations.kt
2460407788
package ch.chrigu.wotr.bot import ch.chrigu.wotr.action.* import ch.chrigu.wotr.card.EventType import ch.chrigu.wotr.figure.FigureType import ch.chrigu.wotr.figure.Figures import ch.chrigu.wotr.gamestate.GameState import ch.chrigu.wotr.location.Location import ch.chrigu.wotr.location.LocationName import ch.chrigu.wotr.location.LocationType import ch.chrigu.wotr.nation.NationName import ch.chrigu.wotr.player.Player import org.jline.terminal.Terminal import org.springframework.core.annotation.Order import org.springframework.stereotype.Component /** * Includes playing event card. */ @Order(2) @Component class MusterStrategy(private val terminal: Terminal) : BotStrategy { override fun getActions(state: GameState): List<GameAction> { val nations = state.nation.values.filter { it.name.player == Player.SHADOW } val onWar = nations.filter { it.isOnWar() }.map { it.name } val settlements = state.location.values.filter { it.nation in onWar && !it.captured } val combinations = Combinations.ofSize(settlements, 2) return (nations.map { it.name } - onWar.toSet()).map { PoliticsMarkerAction(it) } + combinations.flatMap { (a, b) -> val regularA = regular(a, state) val regularB = regular(b, state) val nazgulA = nazgul(a, state) val nazgulB = nazgul(b, state) listOfNotNull( regularA?.plus(regularB), nazgulA?.plus(nazgulB), regularA?.plus(nazgulB), nazgulA?.plus(regularB) ) } + settlements.mapNotNull { elite(it, state) } + sarumansVoice(state) + listOf(PlayEventAction(EventType.STRATEGY, terminal)) } private fun elite(location: Location, state: GameState) = unit(state, location, FigureType.ELITE) private fun regular(location: Location, state: GameState) = unit(state, location, FigureType.REGULAR) private fun nazgul(location: Location, state: GameState) = if (location.type == LocationType.STRONGHOLD && location.nation == NationName.SAURON) unit(state, location, FigureType.LEADER_OR_NAZGUL) else null private fun sarumansVoice(state: GameState): List<GameAction> { if (!state.hasSaruman()) return emptyList() val orthancRegulars = state.location[LocationName.ORTHANC]!!.nonBesiegedFigures.all.filter { it.nation == NationName.ISENGARD && it.type == FigureType.REGULAR }.take(2) val elites = state.reinforcements.all.filter { it.nation == NationName.ISENGARD && it.type == FigureType.ELITE }.take(2) val orthanc = if (orthancRegulars.size == 2 && elites.size == 2) ReplaceFiguresAction(Figures(orthancRegulars), Figures(elites), LocationName.ORTHANC) else null val threeRegulars = state.reinforcements.all.filter { it.nation == NationName.ISENGARD && it.type == FigureType.REGULAR }.take(3) .let { if (it.size == 3) MusterFiguresAction(it[0] to LocationName.ORTHANC, it[1] to LocationName.SOUTH_DUNLAND, it[2] to LocationName.NORTH_DUNLAND) else null } return listOfNotNull(orthanc, threeRegulars) } private fun unit(state: GameState, location: Location, type: FigureType): MusterFiguresAction? { val unit = state.reinforcements.all.firstOrNull { it.type == type && it.nation == location.nation } return unit?.let { MusterFiguresAction(Figures(listOf(unit)), location.name) } } }
wotr-cli/src/main/kotlin/ch/chrigu/wotr/bot/MusterStrategy.kt
1896012176
package ch.chrigu.wotr.bot import ch.chrigu.wotr.card.Cards import ch.chrigu.wotr.dice.Dice import ch.chrigu.wotr.dice.DiceAndRings import ch.chrigu.wotr.dice.DieType import ch.chrigu.wotr.fellowship.Fellowship import ch.chrigu.wotr.figure.Figure import ch.chrigu.wotr.figure.FigureType import ch.chrigu.wotr.figure.Figures import ch.chrigu.wotr.figure.NumberedLevel import ch.chrigu.wotr.gamestate.GameState import ch.chrigu.wotr.location.Location import ch.chrigu.wotr.location.LocationType import ch.chrigu.wotr.nation.Nation import ch.chrigu.wotr.player.Player import kotlin.math.max import kotlin.math.min object BotEvaluationService { fun count(state: GameState) = countDice(state.dice) + countVp(state) + countFellowship(state.fellowship, state) + state.location.values.sumOf { countLocation(it, state) } + countCards(state.cards) + countNations(state.nation.values) private fun countNations(nations: Collection<Nation>) = nations.sumOf { if (it.name.player == Player.SHADOW) countNation(it) else -countNation(it) } private fun countNation(nation: Nation) = if (nation.isOnWar()) 10 else if (nation.active) 8 - nation.box else 4 - nation.box private fun countVp(state: GameState) = if (state.vpShadow() >= 10) 100 else if (state.vpFreePeople() >= 4) 90 else 5 * state.vpShadow() - 10 * state.vpFreePeople() private fun countDice(dice: Dice) = count(dice.shadow, Player.SHADOW) - count(dice.freePeople, Player.FREE_PEOPLE) private fun count(diceAndRings: DiceAndRings, player: Player) = 10 * diceAndRings.rings + diceAndRings.rolled .groupBy { it }.entries.sumOf { (type, list) -> when (type) { DieType.WILL_OF_THE_WEST -> 3 DieType.ARMY_MUSTER -> max(3, list.size) DieType.ARMY -> if (player == Player.SHADOW) 2 else 1 DieType.CHARACTER -> if (player == Player.FREE_PEOPLE) 2 else 1 else -> 1 } } private fun countFellowship(fellowship: Fellowship, state: GameState) = if (fellowship.corruption >= Fellowship.MAX_CORRUPTION) 100 else if (fellowship.mordor != null && fellowship.mordor >= Fellowship.MORDOR_STEPS) -100 else fellowship.corruption * 2 - fellowship.progress - (fellowship.mordor ?: 0) * 2 + (if (fellowship.discovered) 5 else 0) + fellowship.numRerolls(state) * 5 - state.companions.sumOf { (it.type.level as? NumberedLevel)?.number ?: 0 } * 2 private fun countLocation(location: Location, state: GameState): Int { val figurePoints = location.allFigures().sumOf { countFigure(it) } val figures = location.nonBesiegedFigures val armyPlayer = figures.armyPlayer val playerModifier = if (armyPlayer == Player.SHADOW) 1 else -1 val siegeModifier = if (location.besiegedFigures.isEmpty()) 1 else 3 val nearestLocationsToOccupy = location.distanceTo(state) { it.currentlyOccupiedBy()?.opponent == armyPlayer } val nearestArmies = if (location.besiegedFigures.isEmpty()) location.distanceTo(state) { it.nonBesiegedFigures.armyPlayer?.opponent == armyPlayer } .map { (l, distance) -> Triple(l, l.nonBesiegedFigures, distance) } else listOf(Triple(location, location.besiegedFigures, 0)) val nearArmyThreat = nearestArmies.sumOf { (location, defender, distance) -> pointsAgainstArmy(figures, defender, distance, location) } val nearSettlementThreat = nearestLocationsToOccupy.entries.sumOf { (l, distance) -> pointsForOccupation(figures, l, distance) } return figurePoints + nearArmyThreat * playerModifier * siegeModifier + nearSettlementThreat * playerModifier } private fun pointsForOccupation(attacker: Figures, location: Location, distance: Int): Int { val defender = if (distance == 0) location.besiegedFigures else location.nonBesiegedFigures return if (defender.armyPlayer == null) max(50 - distance * 2, 0) * (location.victoryPoints * 10 + 1) else pointsAgainstArmy(attacker, defender, distance, location) * (location.victoryPoints * 2 + 1) } private fun pointsAgainstArmy(attacker: Figures, defender: Figures, distance: Int, location: Location): Int { val stronghold = distance == 0 || location.type == LocationType.STRONGHOLD val defenderBonus = if (stronghold) 2.5f else if (location.type == LocationType.CITY || location.type == LocationType.FORTIFICATION) 1.5f else 1.0f return max(0, armyValue(attacker) - Math.round(armyValue(defender) * defenderBonus)) } private fun armyValue(army: Figures) = army.combatRolls() + army.maxReRolls() + army.numElites() * 2 + army.numRegulars() private fun countFigure(figure: Figure): Int { val modifier = if (figure.nation.player == Player.SHADOW) 1 else -1 val type = figure.type val points = if (type.isUniqueCharacter) ((type.level as? NumberedLevel)?.number ?: 0) * 2 + type.enablesDice * 10 else if (type == FigureType.ELITE) 3 else 1 return modifier * points } private fun countCards(cards: Cards) = min(4, cards.numCards()) }
wotr-cli/src/main/kotlin/ch/chrigu/wotr/bot/BotEvaluationService.kt
3448876176
package ch.chrigu.wotr.bot import ch.chrigu.wotr.action.AssignEyesAndThrowDiceAction import ch.chrigu.wotr.action.DieActionFactory import ch.chrigu.wotr.action.GameAction import ch.chrigu.wotr.gamestate.GameState import org.springframework.stereotype.Component import java.util.* import kotlin.math.min @Component class BotActionFactory(private val strategies: List<BotStrategy>) { fun getNext(state: GameState): GameAction { val dieActionFactory = DieActionFactory(state) val singleActions = strategies.asSequence().flatMap { it.getActions(state) } .flatMap { withDice(it, dieActionFactory) } .toSet() .mapNotNull { EvaluatedAction.create(it, state) } .toSortedSet() check(singleActions.isNotEmpty()) { "There is no possible bot action" } val combinedActions = combineFirst(min(10, singleActions.size), singleActions) return combinedActions.first().action } private fun combineFirst(num: Int, actions: SortedSet<EvaluatedAction>): SortedSet<EvaluatedAction> { val combinations = (0 until num).flatMap { index -> val action = actions.drop(index).first() actions.drop(index + 1).mapNotNull { a -> a.tryToCombine(action) } } actions.addAll(combinations) return if (num == 1) actions else combineFirst(num - 1, actions) } private fun withDice(action: GameAction, dieActionFactory: DieActionFactory) = if (action is AssignEyesAndThrowDiceAction) listOf(action) else dieActionFactory.everyCombination(action) companion object { private fun evaluate(action: GameAction, state: GameState): Int? { val newState: GameState try { newState = action.simulate(state) } catch (e: IllegalArgumentException) { return null } return BotEvaluationService.count(newState) } } data class EvaluatedAction(val action: GameAction, val score: Int, val state: GameState) : Comparable<EvaluatedAction> { override fun compareTo(other: EvaluatedAction): Int { return score.compareTo(other.score) } override fun toString() = "Score $score: $action" fun tryToCombine(other: EvaluatedAction): EvaluatedAction? { val combined = action.tryToCombine(other.action) return if (combined == null) null else create(combined, state) } companion object { fun create(action: GameAction, state: GameState) = evaluate(action, state)?.let { EvaluatedAction(action, it, state) } } } }
wotr-cli/src/main/kotlin/ch/chrigu/wotr/bot/BotActionFactory.kt
287059214
package ch.chrigu.wotr.bot import ch.chrigu.wotr.action.DrawEventAction import ch.chrigu.wotr.card.EventType import ch.chrigu.wotr.gamestate.GameState import org.springframework.core.annotation.Order import org.springframework.stereotype.Component @Component @Order(10) class DrawEventStrategy : BotStrategy { override fun getActions(state: GameState) = EventType.entries.map { DrawEventAction(it) } }
wotr-cli/src/main/kotlin/ch/chrigu/wotr/bot/DrawEventStrategy.kt
2574604361
package ch.chrigu.wotr.bot import ch.chrigu.wotr.card.EventType import ch.chrigu.wotr.action.GameAction import ch.chrigu.wotr.action.MoveAction import ch.chrigu.wotr.action.PlayEventAction import ch.chrigu.wotr.figure.Figure import ch.chrigu.wotr.figure.FigureType import ch.chrigu.wotr.figure.Figures import ch.chrigu.wotr.gamestate.GameState import ch.chrigu.wotr.player.Player import org.jline.terminal.Terminal import org.springframework.core.annotation.Order import org.springframework.stereotype.Component @Order(1) @Component class HarmFellowshipStrategy(private val terminal: Terminal) : BotStrategy { override fun getActions(state: GameState) = getEventAction() + getNazgulAction(state) + getArmyAction(state) private fun getNazgulAction(state: GameState) = state.findAll { it.isNazgulOrWitchKing() } .filter { (location, _) -> location != state.fellowshipLocation } .map { (location, figure) -> MoveAction(location.name, state.fellowshipLocation.name, Figures(listOf(figure))) } private fun getArmyAction(state: GameState): List<GameAction> { val fellowshipLocation = state.fellowshipLocation val armies = fellowshipLocation.adjacentArmies(Player.SHADOW, state) return armies.map { val from = state.getLocationWith(it)!! MoveAction(from.name, fellowshipLocation.name, Figures(listOf(regularIfPossible(it)))) } } private fun getEventAction() = listOf(PlayEventAction(EventType.CHARACTER, terminal)) private fun regularIfPossible(figures: List<Figure>) = figures.firstOrNull { it.type == FigureType.REGULAR } ?: figures.first { it.type.isUnit } }
wotr-cli/src/main/kotlin/ch/chrigu/wotr/bot/HarmFellowshipStrategy.kt
722775874
package ch.chrigu.wotr.bot import ch.chrigu.wotr.action.GameAction import ch.chrigu.wotr.action.MoveAction import ch.chrigu.wotr.action.PlayEventAction import ch.chrigu.wotr.card.EventType import ch.chrigu.wotr.figure.Figure import ch.chrigu.wotr.figure.FigureType import ch.chrigu.wotr.figure.Figures import ch.chrigu.wotr.gamestate.GameState import ch.chrigu.wotr.location.Location import ch.chrigu.wotr.player.Player import org.jline.terminal.Terminal import org.springframework.core.annotation.Order import org.springframework.stereotype.Component @Order(3) @Component class MoveArmyStrategy(private val terminal: Terminal) : BotStrategy { override fun getActions(state: GameState): List<GameAction> { return (state.location.values .filter { it.nonBesiegedFigures.armyPlayer == Player.SHADOW } .flatMap { toMoveActions(it, state) }) + listOf(PlayEventAction(EventType.STRATEGY, terminal)) } private fun toMoveActions(location: Location, state: GameState) = combinations(location.nonBesiegedFigures, state) .flatMap { figures -> location.adjacentLocations.map { MoveAction(location.name, it, figures) } } private fun combinations(of: Figures, gameState: GameState): List<Figures> { val characterCombinations = Combinations.allSizes(of.characters().map { it.type }) .map { of.subSet(it) } val figuresSortedByPriority = of.getArmyPerNation().entries.sortedByDescending { (nation, army) -> val onWar = if (gameState.nation[nation]!!.isOnWar()) 100 else 0 onWar + army.size } .flatMap { (_, army) -> army } return (0..of.numRegulars()).flatMap { numRegular -> (0..of.numElites()).flatMap { numElite -> (0..of.numLeadersOrNazgul()).map { numLeader -> take(figuresSortedByPriority, numRegular, numElite, numLeader) } } } .filter { !it.isEmpty() } .flatMap { combineWithCharacters(it, characterCombinations) } } private fun take(figuresSortedByPriority: List<Figure>, numRegular: Int, numElite: Int, numLeader: Int) = Figures( figuresSortedByPriority.filter { it.type == FigureType.REGULAR }.take(numRegular) + figuresSortedByPriority.filter { it.type == FigureType.ELITE }.take(numElite) + figuresSortedByPriority.filter { it.type == FigureType.LEADER_OR_NAZGUL }.take(numLeader) ) private fun combineWithCharacters(figuresWithoutCharacters: Figures, characterCombinations: List<Figures>) = characterCombinations.map { figuresWithoutCharacters + it } }
wotr-cli/src/main/kotlin/ch/chrigu/wotr/bot/MoveArmyStrategy.kt
3043173096
package ch.chrigu.wotr.bot import ch.chrigu.wotr.action.GameAction import ch.chrigu.wotr.gamestate.GameState interface BotStrategy { /** * All actions that make sense for this strategy. */ fun getActions(state: GameState): List<GameAction> }
wotr-cli/src/main/kotlin/ch/chrigu/wotr/bot/BotStrategy.kt
2990647503
package ch.chrigu.wotr.commands import org.springframework.shell.command.CommandExceptionResolver import org.springframework.shell.command.CommandHandlingResult import org.springframework.stereotype.Component import java.lang.Exception @Component class CustomExceptionResolver : CommandExceptionResolver { override fun resolve(e: Exception): CommandHandlingResult = CommandHandlingResult.of(e.message + "\n", 1) }
wotr-cli/src/main/kotlin/ch/chrigu/wotr/commands/CustomExceptionResolver.kt
3810777422
package ch.chrigu.wotr.commands import ch.chrigu.wotr.gamestate.GameStateHolder import ch.chrigu.wotr.gamestate.GameStateLoader import org.springframework.shell.command.annotation.Command import org.springframework.shell.command.annotation.Option import java.io.File @Command(group = "Save/Load") class SaveLoadCommands(private val gameStateHolder: GameStateHolder) { @Command(command = ["save"], description = "Save current game") fun save(@Option file: File = File("wotr.json")) = GameStateLoader.saveFile(file, gameStateHolder.current) @Command(command = ["load"], description = "Load game") fun load(@Option file: File = File("wotr.json")) = gameStateHolder.reset( GameStateLoader.loadFile(file) ) }
wotr-cli/src/main/kotlin/ch/chrigu/wotr/commands/SaveLoadCommands.kt
3844548556
package ch.chrigu.wotr.commands import ch.chrigu.wotr.action.BotAction import ch.chrigu.wotr.bot.BotActionFactory import ch.chrigu.wotr.gamestate.GameStateHolder import org.jline.terminal.Terminal import org.springframework.shell.command.annotation.Command @Command(group = "Bot") class BotCommands(private val gameStateHolder: GameStateHolder, private val terminal: Terminal, private val botActionFactory: BotActionFactory) { @Command(command = ["bot"], alias = ["b"], description = "Shadow bot takes its next move") fun botCommand() = gameStateHolder.apply(BotAction(terminal, botActionFactory)) }
wotr-cli/src/main/kotlin/ch/chrigu/wotr/commands/BotCommands.kt
1786998460
package ch.chrigu.wotr.commands import ch.chrigu.wotr.gamestate.GameStateHolder import org.springframework.context.annotation.Bean import org.springframework.shell.Availability import org.springframework.shell.AvailabilityProvider import org.springframework.shell.command.annotation.Command import org.springframework.shell.command.annotation.CommandAvailability @Command(group = "Undo/Redo") class UndoRedoCommands(private val gameStateHolder: GameStateHolder) { @Command(command = ["undo"], description = "Undo last command") @CommandAvailability(provider = ["undoAvailability"]) fun undo() = gameStateHolder.undo() @Bean fun undoAvailability() = AvailabilityProvider { if (gameStateHolder.allowUndo()) Availability.available() else Availability.unavailable("Nothing to undo") } @Command(command = ["redo"], description = "Redo undone command") @CommandAvailability(provider = ["redoAvailability"]) fun redo() = gameStateHolder.redo() @Bean fun redoAvailability() = AvailabilityProvider { if (gameStateHolder.allowRedo()) Availability.available() else Availability.unavailable("Nothing to redo") } }
wotr-cli/src/main/kotlin/ch/chrigu/wotr/commands/UndoRedoCommands.kt
2703974838
package ch.chrigu.wotr.commands import ch.chrigu.wotr.gamestate.GameStateHolder import org.jline.utils.AttributedString import org.jline.utils.AttributedStyle import org.springframework.shell.jline.PromptProvider import org.springframework.stereotype.Component @Component class WotrPromptProvider(private val gameStateHolder: GameStateHolder) : PromptProvider { override fun getPrompt() = AttributedString("${gameStateHolder.current}>", AttributedStyle.DEFAULT.foreground(AttributedStyle.RED)) }
wotr-cli/src/main/kotlin/ch/chrigu/wotr/commands/WotrPromptProvider.kt
105362269
package ch.chrigu.wotr.commands import ch.chrigu.wotr.action.KillAction import ch.chrigu.wotr.action.MoveAction import ch.chrigu.wotr.action.MusterAction import ch.chrigu.wotr.figure.Figures import ch.chrigu.wotr.gamestate.GameStateHolder import ch.chrigu.wotr.location.Location import ch.chrigu.wotr.location.LocationName import org.springframework.shell.command.CommandRegistration import org.springframework.shell.command.annotation.Command import org.springframework.shell.command.annotation.Option import org.springframework.shell.command.annotation.OptionValues @Command(group = "Board", description = "Commands that modify the board state") class BoardCommands(private val gameStateHolder: GameStateHolder) { @Command(command = ["move"], alias = ["mo"], description = "Move figures from one location to another") fun moveCommand( @Option(shortNames = ['f']) @OptionValues(provider = ["locationCompletionProvider"]) from: String, @Option(shortNames = ['t']) @OptionValues(provider = ["locationCompletionProvider"]) to: String, @Option(shortNames = ['w'], arity = CommandRegistration.OptionArity.ZERO_OR_MORE) @OptionValues(provider = ["figuresCompletionProvider"]) who: Array<String>? ): Location { val fromLocation = LocationName.get(from) val toLocation = LocationName.get(to) val figures = Figures.parse(who ?: emptyArray(), fromLocation, gameStateHolder.current) val newState = gameStateHolder.apply(MoveAction(fromLocation, toLocation, figures)) return newState.location[toLocation]!! } @Command(command = ["kill"], alias = ["k"], description = "Remove figures from location") fun killCommand( @Option(shortNames = ['l']) @OptionValues(provider = ["locationCompletionProvider"]) location: String, @Option(shortNames = ['w'], arity = CommandRegistration.OptionArity.ZERO_OR_MORE) @OptionValues(provider = ["figuresCompletionProvider"]) who: Array<String>? ): Location { val locationName = LocationName.get(location) val figures = Figures.parse(who ?: emptyArray(), locationName, gameStateHolder.current) val newState = gameStateHolder.apply(KillAction(locationName, figures)) return newState.location[locationName]!! } @Command(command = ["muster"], alias = ["mu"], description = "Move figures from reinforcements to location") fun musterCommand( @Option(shortNames = ['l']) @OptionValues(provider = ["locationCompletionProvider"]) location: String, @Option(shortNames = ['w'], arityMin = 1) @OptionValues(provider = ["reinforcementsCompletionProvider"]) who: Array<String> ): Location { val locationName = LocationName.get(location) val figures = Figures.parse(who, gameStateHolder.current.reinforcements, gameStateHolder.current.location[locationName]!!.nation) val newState = gameStateHolder.apply(MusterAction(figures, locationName)) return newState.location[locationName]!! } }
wotr-cli/src/main/kotlin/ch/chrigu/wotr/commands/BoardCommands.kt
720133782
package ch.chrigu.wotr.gamestate import ch.chrigu.wotr.figure.Figure import ch.chrigu.wotr.figure.FigureType import ch.chrigu.wotr.figure.Figures import ch.chrigu.wotr.figure.FiguresType import ch.chrigu.wotr.location.Location import ch.chrigu.wotr.location.LocationName import ch.chrigu.wotr.location.LocationName.* import ch.chrigu.wotr.nation.Nation import ch.chrigu.wotr.nation.NationName import ch.chrigu.wotr.nation.NationName.* import ch.chrigu.wotr.player.Player object GameStateFactory { private val initFigures = mapOf( f(ERED_LUIN, 1, 0, 0), f(EREBOR, 1, 2, 1), f(IRON_HILLS, 1, 0, 0), f(THE_SHIRE, 1, 0, 0), f(NORTH_DOWNS, 0, 1, 0), f(DALE, 1, 0, 1), f(CARROCK, 1, 0, 0), f(BREE, 1, 0, 0), f(GREY_HAVENS, 1, 1, 1), f(RIVENDELL, 0, 2, 1), f(WOODLAND_REALM, 1, 1, 1), f(LORIEN, 1, 2, 1), f(EDORAS, 1, 1, 0), f(FORDS_OF_ISEN, 2, 0, 1), f(HELMS_DEEP, 1, 0, 0), f(MINAS_TIRITH, 3, 1, 1), f(DOL_AMROTH, 3, 0, 0), f(OSGILIATH, 2, 0, 0, GONDOR), f(PELARGIR, 1, 0, 0), f(ORTHANC, 4, 1, 0), f(NORTH_DUNLAND, 1, 0, 0), f(SOUTH_DUNLAND, 1, 0, 0), f(FAR_HARAD, 3, 1, 0), f(NEAR_HARAD, 3, 1, 0), f(NORTH_RHUN, 2, 0, 0), f(SOUTH_RHUN, 3, 1, 0), f(UMBAR, 3, 0, 0), f(BARAD_DUR, 4, 1, 1), f(DOL_GULDUR, 5, 1, 1), f(GORGOROTH, 3, 0, 0), f(MINAS_MORGUL, 5, 0, 1), f(MORIA, 2, 0, 0), f(MOUNT_GUNDABAD, 2, 0, 0), f(NURN, 2, 0, 0), f(MORANNON, 5, 0, 1) ) fun newGame() = GameState(LocationName.entries.associateWith { getLocation(it) }, createNations(), createReinforcements(), createCompanions()) private fun createNations() = NationName.entries.filter { it != FREE_PEOPLE } .associateWith { Nation(getBoxNumber(it), getNationActive(it), it) } private fun getBoxNumber(nationName: NationName) = when (nationName) { SAURON, ISENGARD -> 1 GONDOR, SOUTHRONS_AND_EASTERLINGS -> 2 else -> 3 } private fun getNationActive(nationName: NationName) = nationName.player == Player.SHADOW || nationName == ELVES private fun getLocation(location: LocationName) = Location(location, getFigures(location)) private fun getFigures(name: LocationName): Figures { if (initFigures.containsKey(name)) { val notNullNation: NationName = initFigures[name]!!.second ?: name.nation!! val all = initFigures[name]!!.first .map { Figure(it, notNullNation) } val fs = if (name == RIVENDELL) listOf(Figure(FigureType.FELLOWSHIP, FREE_PEOPLE)) else emptyList() return Figures(all + fs) } else { return Figures(emptyList()) } } private fun createReinforcements() = Figures( createFiguresFromNationName(DWARVES, 2, 3, 3) + createFiguresFromNationName(ELVES, 2, 4) + createFiguresFromNationName(GONDOR, 6, 4, 3) + createFiguresFromNationName(NORTHMEN, 6, 4, 3) + createFiguresFromNationName(ROHAN, 6, 4, 3) + createFiguresFromNationName(ISENGARD, 6, 5) + createFiguresFromNationName(SAURON, 8, 4, 4) + createFiguresFromNationName(SOUTHRONS_AND_EASTERLINGS, 10, 3) + listOf(Figure(FigureType.WITCH_KING, SAURON), Figure(FigureType.MOUTH_OF_SAURON, SAURON), Figure(FigureType.SARUMAN, ISENGARD)) + listOf(Figure(FigureType.ARAGORN, FREE_PEOPLE), Figure(FigureType.GANDALF_THE_WHITE, FREE_PEOPLE)), FiguresType.REINFORCEMENTS ) private fun createCompanions() = listOf( Figure(FigureType.GANDALF_THE_GREY, FREE_PEOPLE), Figure(FigureType.STRIDER, NORTHMEN), Figure(FigureType.GIMLI, DWARVES), Figure(FigureType.LEGOLAS, ELVES), Figure(FigureType.BOROMIR, GONDOR), Figure(FigureType.PEREGRIN, FREE_PEOPLE), Figure(FigureType.MERIADOC, FREE_PEOPLE) ) private fun f(name: LocationName, numRegular: Int, numElite: Int, numLeaderOrNazgul: Int, nation: NationName? = null) = name to Pair(createFigures(numRegular, numElite, numLeaderOrNazgul), nation) private fun createFiguresFromNationName(nation: NationName, numRegular: Int, numElite: Int, numLeaderOrNazgul: Int = 0) = createFigures(numRegular, numElite, numLeaderOrNazgul) .map { Figure(it, nation) } private fun createFigures(numRegular: Int, numElite: Int, numLeaderOrNazgul: Int) = (0 until numRegular).map { FigureType.REGULAR } + (0 until numElite).map { FigureType.ELITE } + (0 until numLeaderOrNazgul).map { FigureType.LEADER_OR_NAZGUL } }
wotr-cli/src/main/kotlin/ch/chrigu/wotr/gamestate/GameStateFactory.kt
1502682967
package ch.chrigu.wotr.gamestate import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json import java.io.File object GameStateLoader { fun saveFile(file: File, gameState: GameState) = file.run { createNewFile() writeText(Json.encodeToString(gameState)) } fun loadFile(file: File) = Json.decodeFromString<GameState>(file.readText()) }
wotr-cli/src/main/kotlin/ch/chrigu/wotr/gamestate/GameStateLoader.kt
3186729073
package ch.chrigu.wotr.gamestate import ch.chrigu.wotr.action.GameAction import org.springframework.stereotype.Component @Component class GameStateHolder { private val history = mutableListOf(GameStateFactory.newGame()) private var currentIndex = 0 val current get() = history[currentIndex] fun apply(action: GameAction): GameState { val newState = action.apply(current) removeFutureActions() history.add(newState) currentIndex++ return newState } fun undo(): GameState { check(allowUndo()) currentIndex-- return current } fun redo(): GameState { check(allowRedo()) currentIndex++ return current } fun allowUndo() = currentIndex > 0 fun allowRedo() = currentIndex < history.size - 1 fun reset(newState: GameState) { history.clear() history.add(newState) currentIndex = 0 } private fun removeFutureActions() { repeat(history.size - currentIndex - 1) { history.removeLast() } } }
wotr-cli/src/main/kotlin/ch/chrigu/wotr/gamestate/GameStateHolder.kt
1011103815
package ch.chrigu.wotr.gamestate import ch.chrigu.wotr.card.Cards import ch.chrigu.wotr.dice.Dice import ch.chrigu.wotr.dice.DieUsage import ch.chrigu.wotr.fellowship.Fellowship import ch.chrigu.wotr.figure.Figure import ch.chrigu.wotr.figure.FigureType import ch.chrigu.wotr.figure.Figures import ch.chrigu.wotr.figure.FiguresType import ch.chrigu.wotr.location.Location import ch.chrigu.wotr.location.LocationName import ch.chrigu.wotr.nation.Nation import ch.chrigu.wotr.nation.NationName import ch.chrigu.wotr.player.Player import kotlinx.serialization.Serializable @Serializable data class GameState( val location: Map<LocationName, Location>, val nation: Map<NationName, Nation>, val reinforcements: Figures, val companions: List<Figure>, val fellowship: Fellowship = Fellowship(), val dice: Dice = Dice(), val cards: Cards = Cards() ) { init { require(reinforcements.type == FiguresType.REINFORCEMENTS) } val fellowshipLocation get() = fellowship.getFellowshipLocation(this) fun getLocationWith(figures: List<Figure>) = location.values.firstOrNull { it.allFigures().containsAll(figures) } fun findAll(filter: (Figure) -> Boolean) = location.values.flatMap { location -> location.allFigures().filter(filter).map { location to it } } fun vpFreePeople() = location.values.filter { it.captured && it.currentlyOccupiedBy() == Player.FREE_PEOPLE }.sumOf { it.victoryPoints } fun vpShadow() = location.values.filter { it.captured && it.currentlyOccupiedBy() == Player.SHADOW }.sumOf { it.victoryPoints } fun removeFrom(locationName: LocationName, figures: Figures) = location(locationName) { remove(figures) } fun addTo(locationName: LocationName, figures: Figures) = location(locationName) { add(figures) } fun addToReinforcements(figures: Figures) = copy(reinforcements = reinforcements + figures) fun removeFromReinforcements(figures: Figures) = copy(reinforcements = reinforcements - figures) fun useDie(use: DieUsage) = copy(dice = dice.useDie(use)) fun numMinions() = location.values.sumOf { it.allFigures().count { figure -> figure.type.minion } } fun hasAragorn() = has(FigureType.ARAGORN) fun hasGandalfTheWhite() = has(FigureType.GANDALF_THE_WHITE) fun hasSaruman() = has(FigureType.SARUMAN) fun updateNation(name: NationName, modifier: Nation.() -> Nation) = copy(nation = nation + (name to nation[name]!!.run(modifier))) override fun toString() = "FP: ${dice.freePeople} [VP: ${getVictoryPoints(Player.FREE_PEOPLE)}, Pr: ${fellowship.progress}]\n" + "SH: ${dice.shadow} [VP: ${getVictoryPoints(Player.SHADOW)}, Co: ${fellowship.corruption}, $cards]" private fun has(figureType: FigureType) = location.values.any { l -> l.allFigures().any { f -> f.type == figureType } } private fun location(locationName: LocationName, modifier: Location.() -> Location) = copy(location = location + (locationName to location[locationName]!!.run(modifier))) private fun getVictoryPoints(player: Player) = location.values.filter { it.nation?.player != player && it.captured } .fold(0) { a, b -> a + b.victoryPoints } }
wotr-cli/src/main/kotlin/ch/chrigu/wotr/gamestate/GameState.kt
2496564801
package ch.chrigu.wotr.fellowship import ch.chrigu.wotr.figure.FigureType import ch.chrigu.wotr.gamestate.GameState import ch.chrigu.wotr.location.LocationName import ch.chrigu.wotr.player.Player import kotlinx.serialization.Serializable @Serializable data class Fellowship(val progress: Int = 0, val corruption: Int = 0, val mordor: Int? = null, val discovered: Boolean = false) { init { require(progress in 0..MAX_CORRUPTION) { "Progress should be between 0 and 12, but was $progress" } require(corruption in 0..MAX_CORRUPTION) { "Corruption should be between 0 and 12, but was $corruption" } if (mordor != null) { require(progress == 0) require(mordor in 0..MORDOR_STEPS) } } fun numStepsLeft(state: GameState) = if (mordor == null) getFellowshipLocation(state).getShortestPath(LocationName.MORANNON, LocationName.MINAS_MORGUL) .first().getLength() + MORDOR_STEPS else MORDOR_STEPS - mordor fun remainingCorruption() = MAX_CORRUPTION - corruption fun numRerolls(state: GameState): Int { val fellowshipLocation = getFellowshipLocation(state) return listOf( fellowshipLocation.allFigures().any { it.isNazgul }, fellowshipLocation.nonBesiegedFigures.armyPlayer == Player.SHADOW || fellowshipLocation.besiegedFigures.armyPlayer == Player.SHADOW, fellowshipLocation.currentlyOccupiedBy() == Player.SHADOW ) .count { it } } fun getFellowshipLocation(state: GameState) = state.location.values.first { it.contains(FigureType.FELLOWSHIP) } companion object { const val MORDOR_STEPS = 5 const val MAX_CORRUPTION = 12 } }
wotr-cli/src/main/kotlin/ch/chrigu/wotr/fellowship/Fellowship.kt
701249924
package ch.chrigu.wotr.player import ch.chrigu.wotr.dice.DieType enum class Player(val dieFace: List<DieType>) { SHADOW(listOf(DieType.ARMY, DieType.ARMY_MUSTER, DieType.MUSTER, DieType.EYE, DieType.EVENT, DieType.CHARACTER)), FREE_PEOPLE(listOf(DieType.ARMY, DieType.ARMY_MUSTER, DieType.MUSTER, DieType.WILL_OF_THE_WEST, DieType.EVENT, DieType.CHARACTER)); val opponent: Player get() = entries.first { it != this } }
wotr-cli/src/main/kotlin/ch/chrigu/wotr/player/Player.kt
2237794717
package com.example.coingecko import androidx.test.platform.app.InstrumentationRegistry import androidx.test.ext.junit.runners.AndroidJUnit4 import org.junit.Test import org.junit.runner.RunWith import org.junit.Assert.* /** * Instrumented test, which will execute on an Android device. * * See [testing documentation](http://d.android.com/tools/testing). */ @RunWith(AndroidJUnit4::class) class ExampleInstrumentedTest { @Test fun useAppContext() { // Context of the app under test. val appContext = InstrumentationRegistry.getInstrumentation().targetContext assertEquals("com.example.coingecko", appContext.packageName) } }
coin-gecko/app/src/androidTest/java/com/example/coingecko/ExampleInstrumentedTest.kt
2783401706
package com.example.coingecko import org.junit.Test import org.junit.Assert.* /** * Example local unit test, which will execute on the development machine (host). * * See [testing documentation](http://d.android.com/tools/testing). */ class ExampleUnitTest { @Test fun addition_isCorrect() { assertEquals(4, 2 + 2) } }
coin-gecko/app/src/test/java/com/example/coingecko/ExampleUnitTest.kt
2036695190
package com.example.coingecko.di import com.example.coingecko.data.repository.CoinRepositoryImpl import com.example.coingecko.data.source.CoinGeckoApi import com.example.coingecko.domain.repository.CoinRepository import com.example.coingecko.util.Constants import dagger.Module import dagger.Provides import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent import retrofit2.Retrofit import retrofit2.converter.gson.GsonConverterFactory import javax.inject.Singleton @Module @InstallIn(SingletonComponent::class) object CoinGeckoModule { @Provides @Singleton fun provideJokesApi(): CoinGeckoApi { return Retrofit.Builder() .baseUrl(Constants.BASE_URL) .addConverterFactory(GsonConverterFactory.create()) .build() .create(CoinGeckoApi::class.java) } @Provides @Singleton fun provideCoinGeckoRepository(api:CoinGeckoApi): CoinRepository { return CoinRepositoryImpl(api=api) } }
coin-gecko/app/src/main/java/com/example/coingecko/di/CoinGeckoModule.kt
2576891611
package com.example.coingecko.util sealed class ResponseState<T>(val data :T?=null,val message:String?=null){ class Loading<T>(data:T?=null):ResponseState<T>(data) class Success<T>(data:T):ResponseState<T>(data) class Error<T>(message:String,data:T?=null):ResponseState<T>(data,message) }
coin-gecko/app/src/main/java/com/example/coingecko/util/ResponseState.kt
2076729680
package com.example.coingecko.util object Constants { const val BASE_URL = "https://api.coingecko.com/" }
coin-gecko/app/src/main/java/com/example/coingecko/util/Constants.kt
4072296858
package com.example.coingecko import android.app.Application import dagger.hilt.android.HiltAndroidApp @HiltAndroidApp class CoinGeckoApplication: Application()
coin-gecko/app/src/main/java/com/example/coingecko/CoinGeckoApplication.kt
1964683844
package com.example.coingecko.data.repository import com.example.coingecko.data.source.CoinGeckoApi import com.example.coingecko.data.source.dto.CoinDetailDTO.CoinDetailDTO import com.example.coingecko.data.source.dto.CoinListDTO.CoinListDTOItem import com.example.coingecko.domain.repository.CoinRepository import javax.inject.Inject class CoinRepositoryImpl @Inject constructor( private val api : CoinGeckoApi ) : CoinRepository { override suspend fun getAllCoins(page:String): List<CoinListDTOItem> { return api.getAllCoins(page=page) } override suspend fun getCoinById(id: String): CoinDetailDTO { return api.getCoinById(id=id) } }
coin-gecko/app/src/main/java/com/example/coingecko/data/repository/CoinRepositoryImpl.kt
508856632
package com.example.coingecko.data.source.dto.CoinDetailDTO data class ConvertedLast( val btc: Double, val eth: Double, val usd: Int )
coin-gecko/app/src/main/java/com/example/coingecko/data/source/dto/CoinDetailDTO/ConvertedLast.kt
2505485536
package com.example.coingecko.data.source.dto.CoinDetailDTO data class PriceChangePercentage1yInCurrency( val aed: Double, val ars: Double, val aud: Double, val bch: Double, val bdt: Double, val bhd: Double, val bits: Double, val bmd: Double, val bnb: Double, val brl: Double, val btc: Int, val cad: Double, val chf: Double, val clp: Double, val cny: Double, val czk: Double, val dkk: Double, val dot: Double, val eos: Double, val eth: Double, val eur: Double, val gbp: Double, val hkd: Double, val huf: Double, val idr: Double, val ils: Double, val inr: Double, val jpy: Double, val krw: Double, val kwd: Double, val link: Double, val lkr: Double, val ltc: Double, val mmk: Double, val mxn: Double, val myr: Double, val ngn: Double, val nok: Double, val nzd: Double, val php: Double, val pkr: Double, val pln: Double, val rub: Double, val sar: Double, val sats: Double, val sek: Double, val sgd: Double, val thb: Double, val `try`: Double, val twd: Double, val uah: Double, val usd: Double, val vef: Double, val vnd: Double, val xag: Double, val xau: Double, val xdr: Double, val xlm: Double, val xrp: Double, val yfi: Double, val zar: Double )
coin-gecko/app/src/main/java/com/example/coingecko/data/source/dto/CoinDetailDTO/PriceChangePercentage1yInCurrency.kt
2034478546
package com.example.coingecko.data.source.dto.CoinDetailDTO data class AthDate( val aed: String, val ars: String, val aud: String, val bch: String, val bdt: String, val bhd: String, val bits: String, val bmd: String, val bnb: String, val brl: String, val btc: String, val cad: String, val chf: String, val clp: String, val cny: String, val czk: String, val dkk: String, val dot: String, val eos: String, val eth: String, val eur: String, val gbp: String, val gel: String, val hkd: String, val huf: String, val idr: String, val ils: String, val inr: String, val jpy: String, val krw: String, val kwd: String, val link: String, val lkr: String, val ltc: String, val mmk: String, val mxn: String, val myr: String, val ngn: String, val nok: String, val nzd: String, val php: String, val pkr: String, val pln: String, val rub: String, val sar: String, val sats: String, val sek: String, val sgd: String, val thb: String, val `try`: String, val twd: String, val uah: String, val usd: String, val vef: String, val vnd: String, val xag: String, val xau: String, val xdr: String, val xlm: String, val xrp: String, val yfi: String, val zar: String )
coin-gecko/app/src/main/java/com/example/coingecko/data/source/dto/CoinDetailDTO/AthDate.kt
4107164044
package com.example.coingecko.data.source.dto.CoinDetailDTO data class Localization( val ar: String, val bg: String, val cs: String, val da: String, val de: String, val el: String, val en: String, val es: String, val fi: String, val fr: String, val he: String, val hi: String, val hr: String, val hu: String, val id: String, val `it`: String, val ja: String, val ko: String, val lt: String, val nl: String, val no: String, val pl: String, val pt: String, val ro: String, val ru: String, val sk: String, val sl: String, val sv: String, val th: String, val tr: String, val uk: String, val vi: String, val zh: String, val zhtw: String )
coin-gecko/app/src/main/java/com/example/coingecko/data/source/dto/CoinDetailDTO/Localization.kt
3700381235
package com.example.coingecko.data.source.dto.CoinDetailDTO data class Ath( val aed: Int, val ars: Int, val aud: Int, val bch: Double, val bdt: Int, val bhd: Int, val bits: Int, val bmd: Int, val bnb: Int, val brl: Int, val btc: Double, val cad: Int, val chf: Int, val clp: Int, val cny: Int, val czk: Int, val dkk: Int, val dot: Int, val eos: Int, val eth: Double, val eur: Int, val gbp: Int, val gel: Int, val hkd: Int, val huf: Int, val idr: Int, val ils: Int, val inr: Int, val jpy: Int, val krw: Int, val kwd: Int, val link: Int, val lkr: Int, val ltc: Double, val mmk: Int, val mxn: Int, val myr: Int, val ngn: Int, val nok: Int, val nzd: Int, val php: Int, val pkr: Int, val pln: Int, val rub: Int, val sar: Int, val sats: Int, val sek: Int, val sgd: Int, val thb: Int, val `try`: Int, val twd: Int, val uah: Int, val usd: Int, val vef: Long, val vnd: Int, val xag: Double, val xau: Double, val xdr: Int, val xlm: Int, val xrp: Int, val yfi: Double, val zar: Int )
coin-gecko/app/src/main/java/com/example/coingecko/data/source/dto/CoinDetailDTO/Ath.kt
983265126
package com.example.coingecko.data.source.dto.CoinDetailDTO data class MarketCapChangePercentage24hInCurrency( val aed: Double, val ars: Double, val aud: Double, val bch: Double, val bdt: Double, val bhd: Double, val bits: Double, val bmd: Double, val bnb: Double, val brl: Double, val btc: Double, val cad: Double, val chf: Double, val clp: Double, val cny: Double, val czk: Double, val dkk: Double, val dot: Double, val eos: Double, val eth: Double, val eur: Double, val gbp: Double, val gel: Double, val hkd: Double, val huf: Double, val idr: Double, val ils: Double, val inr: Double, val jpy: Double, val krw: Double, val kwd: Double, val link: Double, val lkr: Double, val ltc: Double, val mmk: Double, val mxn: Double, val myr: Double, val ngn: Double, val nok: Double, val nzd: Double, val php: Double, val pkr: Double, val pln: Double, val rub: Double, val sar: Double, val sats: Double, val sek: Double, val sgd: Double, val thb: Double, val `try`: Double, val twd: Double, val uah: Double, val usd: Double, val vef: Double, val vnd: Double, val xag: Double, val xau: Double, val xdr: Double, val xlm: Double, val xrp: Double, val yfi: Double, val zar: Double )
coin-gecko/app/src/main/java/com/example/coingecko/data/source/dto/CoinDetailDTO/MarketCapChangePercentage24hInCurrency.kt
3997589689
package com.example.coingecko.data.source.dto.CoinDetailDTO data class Atl( val aed: Double, val ars: Double, val aud: Double, val bch: Double, val bdt: Double, val bhd: Double, val bits: Int, val bmd: Double, val bnb: Double, val brl: Double, val btc: Double, val cad: Double, val chf: Double, val clp: Int, val cny: Double, val czk: Double, val dkk: Double, val dot: Double, val eos: Double, val eth: Double, val eur: Double, val gbp: Double, val gel: Int, val hkd: Double, val huf: Int, val idr: Int, val ils: Double, val inr: Double, val jpy: Double, val krw: Int, val kwd: Double, val link: Double, val lkr: Int, val ltc: Double, val mmk: Int, val mxn: Double, val myr: Double, val ngn: Double, val nok: Double, val nzd: Double, val php: Double, val pkr: Double, val pln: Double, val rub: Double, val sar: Double, val sats: Int, val sek: Double, val sgd: Double, val thb: Double, val `try`: Double, val twd: Double, val uah: Double, val usd: Double, val vef: Double, val vnd: Int, val xag: Double, val xau: Double, val xdr: Double, val xlm: Int, val xrp: Int, val yfi: Double, val zar: Double )
coin-gecko/app/src/main/java/com/example/coingecko/data/source/dto/CoinDetailDTO/Atl.kt
2861728849
package com.example.coingecko.data.source.dto.CoinDetailDTO data class Image( val large: String, val small: String, val thumb: String )
coin-gecko/app/src/main/java/com/example/coingecko/data/source/dto/CoinDetailDTO/Image.kt
1891681313
package com.example.coingecko.data.source.dto.CoinDetailDTO data class ConvertedVolume( val btc: Double, val eth: Double, val usd: Int )
coin-gecko/app/src/main/java/com/example/coingecko/data/source/dto/CoinDetailDTO/ConvertedVolume.kt
1601996990
package com.example.coingecko.data.source.dto.CoinDetailDTO data class CodeAdditionsDeletions4Weeks( val additions: Int, val deletions: Int )
coin-gecko/app/src/main/java/com/example/coingecko/data/source/dto/CoinDetailDTO/CodeAdditionsDeletions4Weeks.kt
1501724694
package com.example.coingecko.data.source.dto.CoinDetailDTO data class MarketCap( val aed: Long, val ars: Long, val aud: Long, val bch: Long, val bdt: Long, val bhd: Long, val bits: Long, val bmd: Long, val bnb: Long, val brl: Long, val btc: Int, val cad: Long, val chf: Long, val clp: Long, val cny: Long, val czk: Long, val dkk: Long, val dot: Long, val eos: Long, val eth: Int, val eur: Long, val gbp: Long, val gel: Long, val hkd: Long, val huf: Long, val idr: Long, val ils: Long, val inr: Long, val jpy: Long, val krw: Long, val kwd: Long, val link: Long, val lkr: Long, val ltc: Long, val mmk: Long, val mxn: Long, val myr: Long, val ngn: Long, val nok: Long, val nzd: Long, val php: Long, val pkr: Long, val pln: Long, val rub: Long, val sar: Long, val sats: Long, val sek: Long, val sgd: Long, val thb: Long, val `try`: Long, val twd: Long, val uah: Long, val usd: Long, val vef: Long, val vnd: Long, val xag: Long, val xau: Int, val xdr: Long, val xlm: Long, val xrp: Long, val yfi: Int, val zar: Long )
coin-gecko/app/src/main/java/com/example/coingecko/data/source/dto/CoinDetailDTO/MarketCap.kt
2699141689
package com.example.coingecko.data.source.dto.CoinDetailDTO data class AthChangePercentage( val aed: Double, val ars: Double, val aud: Double, val bch: Double, val bdt: Double, val bhd: Double, val bits: Double, val bmd: Double, val bnb: Double, val brl: Double, val btc: Double, val cad: Double, val chf: Double, val clp: Double, val cny: Double, val czk: Double, val dkk: Double, val dot: Double, val eos: Double, val eth: Double, val eur: Double, val gbp: Double, val gel: Double, val hkd: Double, val huf: Double, val idr: Double, val ils: Double, val inr: Double, val jpy: Double, val krw: Double, val kwd: Double, val link: Double, val lkr: Double, val ltc: Double, val mmk: Double, val mxn: Double, val myr: Double, val ngn: Double, val nok: Double, val nzd: Double, val php: Double, val pkr: Double, val pln: Double, val rub: Double, val sar: Double, val sats: Double, val sek: Double, val sgd: Double, val thb: Double, val `try`: Double, val twd: Double, val uah: Double, val usd: Double, val vef: Double, val vnd: Double, val xag: Double, val xau: Double, val xdr: Double, val xlm: Double, val xrp: Double, val yfi: Double, val zar: Double )
coin-gecko/app/src/main/java/com/example/coingecko/data/source/dto/CoinDetailDTO/AthChangePercentage.kt
1450446108
package com.example.coingecko.data.source.dto.CoinDetailDTO data class ReposUrl( val bitbucket: List<Any>, val github: List<String> )
coin-gecko/app/src/main/java/com/example/coingecko/data/source/dto/CoinDetailDTO/ReposUrl.kt
1080203586
package com.example.coingecko.data.source.dto.CoinDetailDTO data class MarketData( val ath: Ath, val ath_change_percentage: AthChangePercentage, val ath_date: AthDate, val atl: Atl, val atl_change_percentage: AtlChangePercentage, val atl_date: AtlDate, val circulating_supply: Int, val current_price: CurrentPrice, val fdv_to_tvl_ratio: Any, val fully_diluted_valuation: FullyDilutedValuation, val high_24h: High24h, val last_updated: String, val low_24h: Low24h, val market_cap: MarketCap, val market_cap_change_24h: Double, val market_cap_change_24h_in_currency: MarketCapChange24hInCurrency, val market_cap_change_percentage_24h: Double, val market_cap_change_percentage_24h_in_currency: MarketCapChangePercentage24hInCurrency, val market_cap_fdv_ratio: Double, val market_cap_rank: Int, val max_supply: Int, val mcap_to_tvl_ratio: Any, val price_change_24h: Double, val price_change_24h_in_currency: PriceChange24hInCurrency, val price_change_percentage_14d: Double, val price_change_percentage_14d_in_currency: PriceChangePercentage14dInCurrency, val price_change_percentage_1h_in_currency: PriceChangePercentage1hInCurrency, val price_change_percentage_1y: Double, val price_change_percentage_1y_in_currency: PriceChangePercentage1yInCurrency, val price_change_percentage_200d: Double, val price_change_percentage_200d_in_currency: PriceChangePercentage200dInCurrency, val price_change_percentage_24h: Double, val price_change_percentage_24h_in_currency: PriceChangePercentage24hInCurrency, val price_change_percentage_30d: Double, val price_change_percentage_30d_in_currency: PriceChangePercentage200dInCurrency, val price_change_percentage_60d: Double, val price_change_percentage_60d_in_currency: PriceChangePercentage200dInCurrency, val price_change_percentage_7d: Double, val price_change_percentage_7d_in_currency: PriceChangePercentage7dInCurrency, val roi: Any, val total_supply: Int, val total_value_locked: Any, val total_volume: TotalVolume )
coin-gecko/app/src/main/java/com/example/coingecko/data/source/dto/CoinDetailDTO/MarketData.kt
297115083
package com.example.coingecko.data.source.dto.CoinDetailDTO data class AtlDate( val aed: String, val ars: String, val aud: String, val bch: String, val bdt: String, val bhd: String, val bits: String, val bmd: String, val bnb: String, val brl: String, val btc: String, val cad: String, val chf: String, val clp: String, val cny: String, val czk: String, val dkk: String, val dot: String, val eos: String, val eth: String, val eur: String, val gbp: String, val gel: String, val hkd: String, val huf: String, val idr: String, val ils: String, val inr: String, val jpy: String, val krw: String, val kwd: String, val link: String, val lkr: String, val ltc: String, val mmk: String, val mxn: String, val myr: String, val ngn: String, val nok: String, val nzd: String, val php: String, val pkr: String, val pln: String, val rub: String, val sar: String, val sats: String, val sek: String, val sgd: String, val thb: String, val `try`: String, val twd: String, val uah: String, val usd: String, val vef: String, val vnd: String, val xag: String, val xau: String, val xdr: String, val xlm: String, val xrp: String, val yfi: String, val zar: String )
coin-gecko/app/src/main/java/com/example/coingecko/data/source/dto/CoinDetailDTO/AtlDate.kt
3161251519
package com.example.coingecko.data.source.dto.CoinDetailDTO data class Ticker( val base: String, val bid_ask_spread_percentage: Double, val coin_id: String, val converted_last: ConvertedLast, val converted_volume: ConvertedVolume, val is_anomaly: Boolean, val is_stale: Boolean, val last: Double, val last_fetch_at: String, val last_traded_at: String, val market: Market, val target: String, val target_coin_id: String, val timestamp: String, val token_info_url: Any, val trade_url: String, val trust_score: String, val volume: Double )
coin-gecko/app/src/main/java/com/example/coingecko/data/source/dto/CoinDetailDTO/Ticker.kt
15861619
package com.example.coingecko.data.source.dto.CoinDetailDTO data class Low24h( val aed: Int, val ars: Int, val aud: Int, val bch: Double, val bdt: Int, val bhd: Double, val bits: Int, val bmd: Int, val bnb: Double, val brl: Int, val btc: Int, val cad: Int, val chf: Int, val clp: Int, val cny: Int, val czk: Int, val dkk: Int, val dot: Int, val eos: Int, val eth: Double, val eur: Int, val gbp: Int, val gel: Int, val hkd: Int, val huf: Int, val idr: Int, val ils: Int, val inr: Int, val jpy: Int, val krw: Int, val kwd: Double, val link: Int, val lkr: Int, val ltc: Double, val mmk: Int, val mxn: Int, val myr: Int, val ngn: Int, val nok: Int, val nzd: Int, val php: Int, val pkr: Int, val pln: Int, val rub: Int, val sar: Int, val sats: Int, val sek: Int, val sgd: Int, val thb: Int, val `try`: Int, val twd: Int, val uah: Int, val usd: Int, val vef: Double, val vnd: Int, val xag: Double, val xau: Double, val xdr: Int, val xlm: Int, val xrp: Int, val yfi: Double, val zar: Int )
coin-gecko/app/src/main/java/com/example/coingecko/data/source/dto/CoinDetailDTO/Low24h.kt
1464292628
package com.example.coingecko.data.source.dto.CoinDetailDTO data class DeveloperData( val closed_issues: Int, val code_additions_deletions_4_weeks: CodeAdditionsDeletions4Weeks, val commit_count_4_weeks: Int, val forks: Int, val last_4_weeks_commit_activity_series: List<Int>, val pull_request_contributors: Int, val pull_requests_merged: Int, val stars: Int, val subscribers: Int, val total_issues: Int )
coin-gecko/app/src/main/java/com/example/coingecko/data/source/dto/CoinDetailDTO/DeveloperData.kt
3139978158
package com.example.coingecko.data.source.dto.CoinDetailDTO data class Description( val ar: String, val bg: String, val cs: String, val da: String, val de: String, val el: String, val en: String, val es: String, val fi: String, val fr: String, val he: String, val hi: String, val hr: String, val hu: String, val id: String, val `it`: String, val ja: String, val ko: String, val lt: String, val nl: String, val no: String, val pl: String, val pt: String, val ro: String, val ru: String, val sk: String, val sl: String, val sv: String, val th: String, val tr: String, val uk: String, val vi: String, val zh: String, val zhtw: String )
coin-gecko/app/src/main/java/com/example/coingecko/data/source/dto/CoinDetailDTO/Description.kt
812993166
package com.example.coingecko.data.source.dto.CoinDetailDTO data class PriceChange24hInCurrency( val aed: Double, val ars: Double, val aud: Double, val bch: Double, val bdt: Double, val bhd: Double, val bits: Double, val bmd: Double, val bnb: Double, val brl: Double, val btc: Int, val cad: Double, val chf: Double, val clp: Double, val cny: Double, val czk: Double, val dkk: Double, val dot: Double, val eos: Double, val eth: Double, val eur: Double, val gbp: Double, val gel: Double, val hkd: Double, val huf: Double, val idr: Double, val ils: Double, val inr: Double, val jpy: Double, val krw: Double, val kwd: Double, val link: Double, val lkr: Double, val ltc: Double, val mmk: Double, val mxn: Double, val myr: Double, val ngn: Int, val nok: Double, val nzd: Double, val php: Double, val pkr: Double, val pln: Double, val rub: Double, val sar: Double, val sats: Double, val sek: Double, val sgd: Double, val thb: Double, val `try`: Double, val twd: Double, val uah: Double, val usd: Double, val vef: Double, val vnd: Double, val xag: Double, val xau: Double, val xdr: Double, val xlm: Double, val xrp: Double, val yfi: Double, val zar: Double )
coin-gecko/app/src/main/java/com/example/coingecko/data/source/dto/CoinDetailDTO/PriceChange24hInCurrency.kt
3211284024
package com.example.coingecko.data.source.dto.CoinDetailDTO data class FullyDilutedValuation( val aed: Long, val ars: Long, val aud: Long, val bch: Long, val bdt: Long, val bhd: Long, val bits: Long, val bmd: Long, val bnb: Long, val brl: Long, val btc: Int, val cad: Long, val chf: Long, val clp: Long, val cny: Long, val czk: Long, val dkk: Long, val dot: Long, val eos: Long, val eth: Int, val eur: Long, val gbp: Long, val gel: Long, val hkd: Long, val huf: Long, val idr: Long, val ils: Long, val inr: Long, val jpy: Long, val krw: Long, val kwd: Long, val link: Long, val lkr: Long, val ltc: Long, val mmk: Long, val mxn: Long, val myr: Long, val ngn: Long, val nok: Long, val nzd: Long, val php: Long, val pkr: Long, val pln: Long, val rub: Long, val sar: Long, val sats: Long, val sek: Long, val sgd: Long, val thb: Long, val `try`: Long, val twd: Long, val uah: Long, val usd: Long, val vef: Long, val vnd: Long, val xag: Long, val xau: Int, val xdr: Long, val xlm: Long, val xrp: Long, val yfi: Int, val zar: Long )
coin-gecko/app/src/main/java/com/example/coingecko/data/source/dto/CoinDetailDTO/FullyDilutedValuation.kt
1813293253
package com.example.coingecko.data.source.dto.CoinDetailDTO data class Platforms( val x: String )
coin-gecko/app/src/main/java/com/example/coingecko/data/source/dto/CoinDetailDTO/Platforms.kt
2195771315
package com.example.coingecko.data.source.dto.CoinDetailDTO data class MarketCapChange24hInCurrency( val aed: Double, val ars: Double, val aud: Double, val bch: Int, val bdt: Double, val bhd: Double, val bits: Long, val bmd: Double, val bnb: Double, val brl: Double, val btc: Int, val cad: Double, val chf: Double, val clp: Double, val cny: Double, val czk: Double, val dkk: Double, val dot: Double, val eos: Long, val eth: Double, val eur: Double, val gbp: Double, val gel: Double, val hkd: Double, val huf: Double, val idr: Int, val ils: Double, val inr: Double, val jpy: Double, val krw: Double, val kwd: Double, val link: Int, val lkr: Double, val ltc: Double, val mmk: Double, val mxn: Double, val myr: Double, val ngn: Long, val nok: Int, val nzd: Double, val php: Double, val pkr: Double, val pln: Double, val rub: Double, val sar: Double, val sats: Long, val sek: Double, val sgd: Double, val thb: Double, val `try`: Double, val twd: Double, val uah: Long, val usd: Double, val vef: Double, val vnd: Int, val xag: Int, val xau: Double, val xdr: Double, val xlm: Double, val xrp: Double, val yfi: Double, val zar: Double )
coin-gecko/app/src/main/java/com/example/coingecko/data/source/dto/CoinDetailDTO/MarketCapChange24hInCurrency.kt
1397602214
package com.example.coingecko.data.source.dto.CoinDetailDTO data class DetailPlatforms( val x: X )
coin-gecko/app/src/main/java/com/example/coingecko/data/source/dto/CoinDetailDTO/DetailPlatforms.kt
3876740893
package com.example.coingecko.data.source.dto.CoinDetailDTO data class CurrentPrice( val aed: Int, val ars: Int, val aud: Int, val bch: Double, val bdt: Int, val bhd: Double, val bits: Int, val bmd: Int, val bnb: Double, val brl: Int, val btc: Int, val cad: Int, val chf: Int, val clp: Int, val cny: Int, val czk: Int, val dkk: Int, val dot: Int, val eos: Int, val eth: Double, val eur: Int, val gbp: Int, val gel: Int, val hkd: Int, val huf: Int, val idr: Int, val ils: Int, val inr: Int, val jpy: Int, val krw: Int, val kwd: Double, val link: Int, val lkr: Int, val ltc: Double, val mmk: Int, val mxn: Int, val myr: Int, val ngn: Int, val nok: Int, val nzd: Int, val php: Int, val pkr: Int, val pln: Int, val rub: Int, val sar: Int, val sats: Int, val sek: Int, val sgd: Int, val thb: Int, val `try`: Int, val twd: Int, val uah: Int, val usd: Int, val vef: Double, val vnd: Int, val xag: Double, val xau: Double, val xdr: Int, val xlm: Int, val xrp: Int, val yfi: Double, val zar: Int )
coin-gecko/app/src/main/java/com/example/coingecko/data/source/dto/CoinDetailDTO/CurrentPrice.kt
1915908253
package com.example.coingecko.data.source.dto.CoinDetailDTO data class TotalVolume( val aed: Long, val ars: Long, val aud: Long, val bch: Int, val bdt: Long, val bhd: Long, val bits: Long, val bmd: Long, val bnb: Int, val brl: Long, val btc: Int, val cad: Long, val chf: Long, val clp: Long, val cny: Long, val czk: Long, val dkk: Long, val dot: Int, val eos: Long, val eth: Int, val eur: Long, val gbp: Long, val gel: Long, val hkd: Long, val huf: Long, val idr: Long, val ils: Long, val inr: Long, val jpy: Long, val krw: Long, val kwd: Long, val link: Int, val lkr: Long, val ltc: Int, val mmk: Long, val mxn: Long, val myr: Long, val ngn: Long, val nok: Long, val nzd: Long, val php: Long, val pkr: Long, val pln: Long, val rub: Long, val sar: Long, val sats: Long, val sek: Long, val sgd: Long, val thb: Long, val `try`: Long, val twd: Long, val uah: Long, val usd: Long, val vef: Int, val vnd: Long, val xag: Int, val xau: Int, val xdr: Long, val xlm: Long, val xrp: Long, val yfi: Int, val zar: Long )
coin-gecko/app/src/main/java/com/example/coingecko/data/source/dto/CoinDetailDTO/TotalVolume.kt
621517609
package com.example.coingecko.data.source.dto.CoinDetailDTO data class PriceChangePercentage1hInCurrency( val aed: Double, val ars: Double, val aud: Double, val bch: Double, val bdt: Double, val bhd: Double, val bits: Double, val bmd: Double, val bnb: Double, val brl: Double, val btc: Int, val cad: Double, val chf: Double, val clp: Double, val cny: Double, val czk: Double, val dkk: Double, val dot: Double, val eos: Double, val eth: Double, val eur: Double, val gbp: Double, val gel: Double, val hkd: Double, val huf: Double, val idr: Double, val ils: Double, val inr: Double, val jpy: Double, val krw: Double, val kwd: Double, val link: Double, val lkr: Double, val ltc: Double, val mmk: Double, val mxn: Double, val myr: Double, val ngn: Double, val nok: Double, val nzd: Double, val php: Double, val pkr: Double, val pln: Double, val rub: Double, val sar: Double, val sats: Double, val sek: Double, val sgd: Double, val thb: Double, val `try`: Double, val twd: Double, val uah: Double, val usd: Double, val vef: Double, val vnd: Double, val xag: Double, val xau: Double, val xdr: Double, val xlm: Double, val xrp: Double, val yfi: Double, val zar: Double )
coin-gecko/app/src/main/java/com/example/coingecko/data/source/dto/CoinDetailDTO/PriceChangePercentage1hInCurrency.kt
1486147469
package com.example.coingecko.data.source.dto.CoinDetailDTO data class Links( val announcement_url: List<String>, val bitcointalk_thread_identifier: Any, val blockchain_site: List<String>, val chat_url: List<String>, val facebook_username: String, val homepage: List<String>, val official_forum_url: List<String>, val repos_url: ReposUrl, val subreddit_url: String, val telegram_channel_identifier: String, val twitter_screen_name: String )
coin-gecko/app/src/main/java/com/example/coingecko/data/source/dto/CoinDetailDTO/Links.kt
1687114532
package com.example.coingecko.data.source.dto.CoinDetailDTO data class PriceChangePercentage14dInCurrency( val aed: Double, val ars: Double, val aud: Double, val bch: Double, val bdt: Double, val bhd: Double, val bits: Double, val bmd: Double, val bnb: Double, val brl: Double, val btc: Int, val cad: Double, val chf: Double, val clp: Double, val cny: Double, val czk: Double, val dkk: Double, val dot: Double, val eos: Double, val eth: Double, val eur: Double, val gbp: Double, val gel: Double, val hkd: Double, val huf: Double, val idr: Double, val ils: Double, val inr: Double, val jpy: Double, val krw: Double, val kwd: Double, val link: Double, val lkr: Double, val ltc: Double, val mmk: Double, val mxn: Double, val myr: Double, val ngn: Double, val nok: Double, val nzd: Double, val php: Double, val pkr: Double, val pln: Double, val rub: Double, val sar: Double, val sats: Double, val sek: Double, val sgd: Double, val thb: Double, val `try`: Double, val twd: Double, val uah: Double, val usd: Double, val vef: Double, val vnd: Double, val xag: Double, val xau: Double, val xdr: Double, val xlm: Double, val xrp: Double, val yfi: Double, val zar: Double )
coin-gecko/app/src/main/java/com/example/coingecko/data/source/dto/CoinDetailDTO/PriceChangePercentage14dInCurrency.kt
286060441
package com.example.coingecko.data.source.dto.CoinDetailDTO data class PriceChangePercentage200dInCurrency( val aed: Double, val ars: Double, val aud: Double, val bch: Double, val bdt: Double, val bhd: Double, val bits: Double, val bmd: Double, val bnb: Double, val brl: Double, val btc: Int, val cad: Double, val chf: Double, val clp: Double, val cny: Double, val czk: Double, val dkk: Double, val dot: Double, val eos: Double, val eth: Double, val eur: Double, val gbp: Double, val hkd: Double, val huf: Double, val idr: Double, val ils: Double, val inr: Double, val jpy: Double, val krw: Double, val kwd: Double, val link: Double, val lkr: Double, val ltc: Double, val mmk: Double, val mxn: Double, val myr: Double, val ngn: Double, val nok: Double, val nzd: Double, val php: Double, val pkr: Double, val pln: Double, val rub: Double, val sar: Double, val sats: Double, val sek: Double, val sgd: Double, val thb: Double, val `try`: Double, val twd: Double, val uah: Double, val usd: Double, val vef: Double, val vnd: Double, val xag: Double, val xau: Double, val xdr: Double, val xlm: Double, val xrp: Double, val yfi: Double, val zar: Double )
coin-gecko/app/src/main/java/com/example/coingecko/data/source/dto/CoinDetailDTO/PriceChangePercentage200dInCurrency.kt
2005394620
package com.example.coingecko.data.source.dto.CoinDetailDTO data class X( val contract_address: String, val decimal_place: Any )
coin-gecko/app/src/main/java/com/example/coingecko/data/source/dto/CoinDetailDTO/X.kt
395844567
package com.example.coingecko.data.source.dto.CoinDetailDTO data class Market( val has_trading_incentive: Boolean, val identifier: String, val name: String )
coin-gecko/app/src/main/java/com/example/coingecko/data/source/dto/CoinDetailDTO/Market.kt
1907894050
package com.example.coingecko.data.source.dto.CoinDetailDTO import com.example.coingecko.domain.model.CoinDetail data class CoinDetailDTO( val additional_notices: List<Any>, val asset_platform_id: Any, val block_time_in_minutes: Int, val categories: List<String>, val community_data: CommunityData, val country_origin: String, val description: Description, val detail_platforms: DetailPlatforms, val developer_data: DeveloperData, val genesis_date: String, val hashing_algorithm: String, val id: String, val image: Image, val last_updated: String, val links: Links, val localization: Localization, val market_cap_rank: Int, val market_data: MarketData, val name: String, val platforms: Platforms, val preview_listing: Boolean, val public_notice: Any, val sentiment_votes_down_percentage: Double, val sentiment_votes_up_percentage: Double, val status_updates: List<Any>, val symbol: String, val tickers: List<Ticker>, val watchlist_portfolio_users: Int, val web_slug: String ){ fun toCoinDetail(): CoinDetail { return CoinDetail( image=image.large, name = name, price = market_data.current_price.usd.toDouble(), price_percent_change = market_data.price_change_percentage_24h_in_currency.usd, lowPrice = market_data.low_24h.usd.toDouble(), highPrice = market_data.high_24h.usd.toDouble(), description = description.en, market_cap = market_data.market_cap.usd.toDouble() ) } }
coin-gecko/app/src/main/java/com/example/coingecko/data/source/dto/CoinDetailDTO/CoinDetailDTO.kt
2488222405
package com.example.coingecko.data.source.dto.CoinDetailDTO data class AtlChangePercentage( val aed: Double, val ars: Double, val aud: Double, val bch: Double, val bdt: Double, val bhd: Double, val bits: Double, val bmd: Double, val bnb: Double, val brl: Double, val btc: Double, val cad: Double, val chf: Double, val clp: Double, val cny: Double, val czk: Double, val dkk: Double, val dot: Double, val eos: Double, val eth: Double, val eur: Double, val gbp: Double, val gel: Double, val hkd: Double, val huf: Double, val idr: Double, val ils: Double, val inr: Double, val jpy: Double, val krw: Double, val kwd: Double, val link: Double, val lkr: Double, val ltc: Double, val mmk: Double, val mxn: Double, val myr: Double, val ngn: Double, val nok: Double, val nzd: Double, val php: Double, val pkr: Double, val pln: Double, val rub: Double, val sar: Double, val sats: Double, val sek: Double, val sgd: Double, val thb: Double, val `try`: Double, val twd: Double, val uah: Double, val usd: Double, val vef: Double, val vnd: Double, val xag: Double, val xau: Double, val xdr: Double, val xlm: Double, val xrp: Double, val yfi: Double, val zar: Double )
coin-gecko/app/src/main/java/com/example/coingecko/data/source/dto/CoinDetailDTO/AtlChangePercentage.kt
2751377927
package com.example.coingecko.data.source.dto.CoinDetailDTO data class CommunityData( val facebook_likes: Any, val reddit_accounts_active_48h: Int, val reddit_average_comments_48h: Int, val reddit_average_posts_48h: Int, val reddit_subscribers: Int, val telegram_channel_user_count: Any, val twitter_followers: Int )
coin-gecko/app/src/main/java/com/example/coingecko/data/source/dto/CoinDetailDTO/CommunityData.kt
64177768
package com.example.coingecko.data.source.dto.CoinDetailDTO data class High24h( val aed: Int, val ars: Int, val aud: Int, val bch: Double, val bdt: Int, val bhd: Double, val bits: Int, val bmd: Int, val bnb: Double, val brl: Int, val btc: Int, val cad: Int, val chf: Int, val clp: Int, val cny: Int, val czk: Int, val dkk: Int, val dot: Int, val eos: Int, val eth: Double, val eur: Int, val gbp: Int, val gel: Int, val hkd: Int, val huf: Int, val idr: Int, val ils: Int, val inr: Int, val jpy: Int, val krw: Int, val kwd: Double, val link: Int, val lkr: Int, val ltc: Double, val mmk: Int, val mxn: Int, val myr: Int, val ngn: Int, val nok: Int, val nzd: Int, val php: Int, val pkr: Int, val pln: Int, val rub: Int, val sar: Int, val sats: Int, val sek: Int, val sgd: Int, val thb: Int, val `try`: Int, val twd: Int, val uah: Int, val usd: Int, val vef: Double, val vnd: Int, val xag: Double, val xau: Double, val xdr: Int, val xlm: Int, val xrp: Int, val yfi: Double, val zar: Int )
coin-gecko/app/src/main/java/com/example/coingecko/data/source/dto/CoinDetailDTO/High24h.kt
629747408
package com.example.coingecko.data.source.dto.CoinListDTO class CoinListDTO : ArrayList<CoinListDTOItem>()
coin-gecko/app/src/main/java/com/example/coingecko/data/source/dto/CoinListDTO/CoinListDTO.kt
2718148194
package com.example.coingecko.data.source.dto.CoinListDTO import com.example.coingecko.domain.model.Coin data class CoinListDTOItem( val ath: Double, val ath_change_percentage: Double, val ath_date: String, val atl: Double, val atl_change_percentage: Double, val atl_date: String, val circulating_supply: Double, val current_price: Double, val fully_diluted_valuation: Long, val high_24h: Double, val id: String, val image: String, val last_updated: String, val low_24h: Double, val market_cap: Long, val market_cap_change_24h: Double, val market_cap_change_percentage_24h: Double, val market_cap_rank: Int, val max_supply: Double, val name: String, val price_change_24h: Double, val price_change_percentage_24h: Double, val roi: Roi, val symbol: String, val total_supply: Double, val total_volume: Long ){ //to fetch these details from above fun toCoin(): Coin { return Coin( name = name, market_cap = market_cap, price = current_price, price_percent_change = price_change_percentage_24h, image = image, id = id, lowPrice = low_24h, highPrice = high_24h ) } }
coin-gecko/app/src/main/java/com/example/coingecko/data/source/dto/CoinListDTO/CoinListDTOItem.kt
4174850383
package com.example.coingecko.data.source.dto.CoinListDTO data class Roi( val currency: String, val percentage: Double, val times: Double )
coin-gecko/app/src/main/java/com/example/coingecko/data/source/dto/CoinListDTO/Roi.kt
944705385
package com.example.coingecko.data.source import com.example.coingecko.data.source.dto.CoinDetailDTO.CoinDetailDTO import com.example.coingecko.data.source.dto.CoinListDTO.CoinListDTOItem import retrofit2.http.GET import retrofit2.http.Path import retrofit2.http.Query interface CoinGeckoApi { //https://www.coingecko.com/api/documentation @GET("/api/v3/coins/markets?vs_currency=usd&order=market_cap_desc&per_page=100&sparkline=false") suspend fun getAllCoins(@Query("page")page:String): List<CoinListDTOItem> @GET("/api/v3/coins/{id}") suspend fun getCoinById(@Path("id")id:String): CoinDetailDTO }
coin-gecko/app/src/main/java/com/example/coingecko/data/source/CoinGeckoApi.kt
670623134
package com.example.coingecko.domain.repository import com.example.coingecko.data.source.dto.CoinDetailDTO.CoinDetailDTO import com.example.coingecko.data.source.dto.CoinListDTO.CoinListDTOItem interface CoinRepository { suspend fun getAllCoins(page:String): List<CoinListDTOItem> suspend fun getCoinById(id:String): CoinDetailDTO }
coin-gecko/app/src/main/java/com/example/coingecko/domain/repository/CoinRepository.kt
2766285321
package com.example.coingecko.domain.use_case import com.example.coingecko.domain.model.Coin import com.example.coingecko.domain.repository.CoinRepository import com.example.coingecko.util.ResponseState import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow import retrofit2.HttpException import java.io.IOException import javax.inject.Inject class CoinListUseCase @Inject constructor( private val repository: CoinRepository ) { operator fun invoke(page:String): Flow<ResponseState<List<Coin>>> = flow { try { emit(ResponseState.Loading<List<Coin>>()) val coins = repository.getAllCoins(page).map { it.toCoin() } emit(ResponseState.Success<List<Coin>>(coins)) } catch (e: HttpException) { emit(ResponseState.Error<List<Coin>>(e.localizedMessage ?: "An Unexpected Error")) } catch (e: IOException) { emit(ResponseState.Error<List<Coin>>("Internet Error")) } } }
coin-gecko/app/src/main/java/com/example/coingecko/domain/use_case/CoinListUseCase.kt
1256543058