Skip to content

Commit

Permalink
New consolidated game state introduced for ML training
Browse files Browse the repository at this point in the history
  • Loading branch information
anoniim committed Jun 8, 2024
1 parent 11582a2 commit 7e8a19a
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions ml-training/src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
@@ -1,22 +1,42 @@
package net.solvetheriddle.cardgame

import GameEndState
import GameEngine
import SpeedMode
import engine.Card
import engine.CardDeck
import engine.GameDifficulty
import engine.GameSettings
import engine.player.Player
import engine.player.PlayerFactory
import engine.rating.EloRatingSystem
import engine.rating.Leaderboard
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import mocks.NoOpSoundPlayer

fun main() {
println("Let's do some ML training!")
val game = createNewGameEngine("CP1")
GlobalScope.launch {
runBlocking {
val cardFlow = game.card
val playersFlow = game.players
val gameEndStateFlow = game.gameEndState
val gameStateFlow = combine(cardFlow, playersFlow, gameEndStateFlow) { card, players, gameEndState ->
GameState(players, card, gameEndState)
}
println("Setting collection")
launch {
gameStateFlow.collect { gameState ->
println("Game state: $gameState")
}
}
println("Starting game")
game.startGame()

}
println("done")
}

private fun createNewGameEngine(modelName: String): GameEngine {
Expand All @@ -25,5 +45,12 @@ private fun createNewGameEngine(modelName: String): GameEngine {
val ratingSystem = EloRatingSystem(Leaderboard(emptyMap()))
val sounds = Sounds(NoOpSoundPlayer())
val players = PlayerFactory(settings).createPlayers(modelName)
return GameEngine(players, cardDeck, settings, ratingSystem, sounds)
}
return GameEngine(players, cardDeck, settings, ratingSystem, sounds,
speedMode = SpeedMode.FAST)
}

private data class GameState(
val players: List<Player>,
val card: Card?,
val gameEndState: GameEndState?
)

0 comments on commit 7e8a19a

Please sign in to comment.