summaryrefslogtreecommitdiff
path: root/sw-bot
diff options
context:
space:
mode:
authorjoffrey-bion <joffrey.bion@gmail.com>2020-12-13 01:08:31 +0100
committerjoffrey-bion <joffrey.bion@gmail.com>2020-12-13 01:09:31 +0100
commitc5ab4aff9f70d7bd12e00d9b54faf14e9e4658da (patch)
treef97bf9d16b4c385fb994db1bd730f05a7780b387 /sw-bot
parentImprove synchronization in GameController (diff)
downloadseven-wonders-c5ab4aff9f70d7bd12e00d9b54faf14e9e4658da.tar.gz
seven-wonders-c5ab4aff9f70d7bd12e00d9b54faf14e9e4658da.tar.bz2
seven-wonders-c5ab4aff9f70d7bd12e00d9b54faf14e9e4658da.zip
Add logging of BOT status
Related: https://github.com/joffrey-bion/seven-wonders/issues/71
Diffstat (limited to 'sw-bot')
-rw-r--r--sw-bot/build.gradle.kts2
-rw-r--r--sw-bot/src/main/kotlin/org/luxons/sevenwonders/bot/SevenWondersBot.kt7
2 files changed, 8 insertions, 1 deletions
diff --git a/sw-bot/build.gradle.kts b/sw-bot/build.gradle.kts
index c4cd1eaa..64a03734 100644
--- a/sw-bot/build.gradle.kts
+++ b/sw-bot/build.gradle.kts
@@ -7,6 +7,8 @@ dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.1")
+ implementation("org.slf4j:slf4j-api:1.7.30")
+
testImplementation(kotlin("test"))
testImplementation(kotlin("test-junit"))
}
diff --git a/sw-bot/src/main/kotlin/org/luxons/sevenwonders/bot/SevenWondersBot.kt b/sw-bot/src/main/kotlin/org/luxons/sevenwonders/bot/SevenWondersBot.kt
index 6170acb8..d0331c15 100644
--- a/sw-bot/src/main/kotlin/org/luxons/sevenwonders/bot/SevenWondersBot.kt
+++ b/sw-bot/src/main/kotlin/org/luxons/sevenwonders/bot/SevenWondersBot.kt
@@ -13,6 +13,7 @@ import org.luxons.sevenwonders.model.PlayerMove
import org.luxons.sevenwonders.model.PlayerTurnInfo
import org.luxons.sevenwonders.model.api.actions.Icon
import org.luxons.sevenwonders.model.resources.noTransactions
+import org.slf4j.LoggerFactory
import kotlin.random.Random
import kotlin.time.Duration
import kotlin.time.ExperimentalTime
@@ -25,6 +26,8 @@ data class BotConfig(
val globalTimeout: Duration = 10.hours,
)
+private val logger = LoggerFactory.getLogger(SevenWondersBot::class.simpleName)
+
@OptIn(ExperimentalTime::class, ExperimentalCoroutinesApi::class)
class SevenWondersBot(
private val displayName: String,
@@ -34,7 +37,7 @@ class SevenWondersBot(
suspend fun play(serverUrl: String, gameId: Long) = withTimeout(botConfig.globalTimeout) {
val session = client.connect(serverUrl)
- session.chooseName(displayName, Icon("desktop"))
+ val player = session.chooseName(displayName, Icon("desktop"))
val gameStartedEvents = session.watchGameStarted()
session.joinGameAndWaitLobby(gameId)
val firstTurn = gameStartedEvents.first()
@@ -48,6 +51,8 @@ class SevenWondersBot(
}
.collect { turn ->
botDelay()
+ val shortTurnDescription = "action ${turn.action}, ${turn.hand?.size ?: 0} cards in hand"
+ logger.info("BOT $player: playing turn ($shortTurnDescription)")
session.playTurn(turn)
}
}
bgstack15