Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fun `King of Tokyo Duel`() {
- val iterations = 1000000
- val dice = 6
- val rolls = 3
- val map = mutableMapOf<Int, Int>()
- var i = iterations
- while (i != 0) {
- var attack = 0
- var exclam = 0
- var currentRoll = 0
- while (currentRoll != rolls) {
- val activeDice = dice - attack - exclam
- for (i in 1..activeDice) {
- val rand = Random.nextInt(1, 7)
- if (rand == 1) {
- attack++
- }
- if (rand == 2) {
- exclam++
- }
- }
- currentRoll++
- }
- val damage =
- if (exclam == 0) {
- attack
- } else {
- attack * exclam
- }
- map[damage] = map.getOrDefault(damage, 0) + 1
- i--
- }
- val sum = map.map { it.key * it.value }.sum()
- val percentagemap = map.mapValues { it.value.toDouble() / iterations }
- val average = sum.toDouble() / iterations
- }
Advertisement
Add Comment
Please, Sign In to add comment