diff options
author | Joffrey Bion <joffrey.bion@booking.com> | 2020-05-26 10:12:57 +0200 |
---|---|---|
committer | Joffrey Bion <joffrey.bion@booking.com> | 2020-05-26 10:12:57 +0200 |
commit | 5126efc79f04c49240732c890278831df0db9c1a (patch) | |
tree | 727c8dd4dc665dd567919d9be9a6115fa332a2ac /sw-bot/src/main | |
parent | Simplify board summary's code (diff) | |
download | seven-wonders-5126efc79f04c49240732c890278831df0db9c1a.tar.gz seven-wonders-5126efc79f04c49240732c890278831df0db9c1a.tar.bz2 seven-wonders-5126efc79f04c49240732c890278831df0db9c1a.zip |
Make bots explore more by choosing random cards instead of first
Diffstat (limited to 'sw-bot/src/main')
-rw-r--r-- | sw-bot/src/main/kotlin/org/luxons/sevenwonders/bot/SevenWondersBot.kt | 14 |
1 files changed, 8 insertions, 6 deletions
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 68d96e55..c58eaea8 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 @@ -68,19 +68,21 @@ class SevenWondersBot( } } +@OptIn(ExperimentalStdlibApi::class) private fun createPlayCardMove(turnInfo: PlayerTurnInfo): PlayerMove { + val hand = turnInfo.hand ?: error("Cannot choose move, no hand in current turn info!") val wonderBuildability = turnInfo.wonderBuildability if (wonderBuildability.isBuildable) { - val transactions = wonderBuildability.cheapestTransactions.first() - return PlayerMove(MoveType.UPGRADE_WONDER, turnInfo.hand!!.first().name, transactions) + val transactions = wonderBuildability.cheapestTransactions.random() + return PlayerMove(MoveType.UPGRADE_WONDER, hand.random().name, transactions) } - val playableCard = turnInfo.hand!!.firstOrNull { it.playability.isPlayable } + val playableCard = hand.filter { it.playability.isPlayable }.randomOrNull() return if (playableCard != null) { - PlayerMove(MoveType.PLAY, playableCard.name, playableCard.playability.cheapestTransactions.first()) + PlayerMove(MoveType.PLAY, playableCard.name, playableCard.playability.cheapestTransactions.random()) } else { - PlayerMove(MoveType.DISCARD, turnInfo.hand!!.first().name, noTransactions()) + PlayerMove(MoveType.DISCARD, hand.random().name, noTransactions()) } } private fun createPickGuildMove(turnInfo: PlayerTurnInfo): PlayerMove = - PlayerMove(MoveType.COPY_GUILD, turnInfo.neighbourGuildCards.first().name) + PlayerMove(MoveType.COPY_GUILD, turnInfo.neighbourGuildCards.random().name) |