Skip to content

Commit

Permalink
Use BlockingGameListener to wait for game end in DslConsoleView
Browse files Browse the repository at this point in the history
  • Loading branch information
Zomis committed Jun 27, 2022
1 parent a8a0cc2 commit 57b2b50
Showing 1 changed file with 4 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import kotlinx.coroutines.*
import kotlinx.coroutines.flow.collect
import net.zomis.games.common.toSingleList
import net.zomis.games.dsl.flow.GameFlowImpl
import net.zomis.games.listeners.ConsoleControl
import net.zomis.games.listeners.ConsoleViewer
import net.zomis.games.listeners.PlayerController
import net.zomis.games.listeners.ReplayListener
import net.zomis.games.listeners.*
import net.zomis.games.server2.ServerGames
import net.zomis.games.server2.ais.AIRepository
import net.zomis.games.server2.ais.ServerAIs
Expand All @@ -28,23 +25,19 @@ class DslConsoleView<T : Any>(private val game: GameSpec<T>) {

val replayListener = ReplayListener(game.name)
runBlocking {
val blockingGameListener = BlockingGameListener()
val game = entryPoint.setup().startGame(this, playerCount) { g ->
listOf(
ConsoleViewer(g),
ConsoleControl(g, scanner),
replayListener,
blockingGameListener,
PlayerController(g, 0.toSingleList()) { controller ->
ServerAIs(AIRepository(), emptySet()).randomActionable(controller.game, controller.playerIndex)
}
)
}
if (game is GameFlowImpl<*>) {
while (game.isRunning()) {
game.feedbackReceiverFlow().collect {
println("Received feedback: $it")
}
}
}
blockingGameListener.awaitGameEnd()

val savedReplay = entryPoint.replay(this, replayListener.data()).goToEnd()
listOf<Int?>(null).plus(game.playerIndices).forEach {
Expand Down

0 comments on commit 57b2b50

Please sign in to comment.