summaryrefslogtreecommitdiff
path: root/sw-bot
diff options
context:
space:
mode:
authorJoffrey Bion <joffrey.bion@booking.com>2020-05-26 10:12:57 +0200
committerJoffrey Bion <joffrey.bion@booking.com>2020-05-26 10:12:57 +0200
commit5126efc79f04c49240732c890278831df0db9c1a (patch)
tree727c8dd4dc665dd567919d9be9a6115fa332a2ac /sw-bot
parentSimplify board summary's code (diff)
downloadseven-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')
-rw-r--r--sw-bot/src/main/kotlin/org/luxons/sevenwonders/bot/SevenWondersBot.kt14
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)
bgstack15