Skip to content

Commit

Permalink
白小年技能AI优化 (#279)
Browse files Browse the repository at this point in the history
* 白小年技能AI优化

* gradlew ktlintFormat

* 逻辑优化

* 白小年AI

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: 奇葩の灵梦 <[email protected]>
  • Loading branch information
3 people authored Sep 2, 2024
1 parent ef95339 commit 53a80d3
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions src/main/kotlin/skill/ZhuanJiao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package com.fengsheng.skill
import com.fengsheng.*
import com.fengsheng.card.countTrueCard
import com.fengsheng.protos.Common.color.Black
import com.fengsheng.protos.Common.secret_task.*
import com.fengsheng.protos.Common.secret_task.Disturber
import com.fengsheng.protos.Common.secret_task.Pioneer
import com.fengsheng.protos.Role.skill_zhuan_jiao_tos
import com.fengsheng.protos.skillWaitForZhuanJiaoToc
import com.fengsheng.protos.skillZhuanJiaoToc
import com.fengsheng.protos.skillZhuanJiaoTos
import com.google.protobuf.GeneratedMessage
import org.apache.logging.log4j.kotlin.logger
import java.util.concurrent.TimeUnit
import kotlin.random.Random

/**
* 白小年技能【转交】:你使用一张手牌后,可以从你的情报区选择一张非黑色情报,将其置入另一名角色的情报区,然后你摸两张牌。你不能通过此技能让任何角色收集三张或更多同色情报。
Expand Down Expand Up @@ -52,41 +52,45 @@ class ZhuanJiao : TriggeredSkill {
if (r is RobotPlayer) {
// 先行者会至少有2张情报才会发动技能
r.identity != Black || r.secretTask != Pioneer || r.messageCards.countTrueCard() > 1 || return null
for (messageCard in r.messageCards) {
var target: Player? = null
var value = -1
var mCard = r.messageCards.first()
for (messageCard in r.messageCards.toList()) {
!messageCard.isBlack() || continue
val players = r.game!!.players.filterNotNull().filter { p ->
if (p === r || !p.alive) return@filter false
if (r.identity == Black) {
if (r.secretTask != Disturber) {
if (p.identity in messageCard.colors) return@filter false
}
} else {
if (p.isEnemy(r)) return@filter false
}
!p.checkThreeSameMessageCard(messageCard)
}
if (players.isNotEmpty()) {
val target = run {
if (r.identity == Black) {
// 搅局者会从所有角色中选择情报最少的人
if (r.secretTask == Disturber) return@run players.minBy { it.messageCards.size }
if (r.secretTask == Mutator) return@run players.maxBy { it.messageCards.size }
val v1 = r.calculateRemoveCardValue(whoseTurn, r, messageCard)
for (player in players) {
val v = r.calculateMessageCardValue(whoseTurn, player, messageCard)
if (v1 + v + 20 > value) {
value = v1 + v + 20
target = player
mCard = messageCard
}
players[Random.nextInt(players.size)]
}
GameExecutor.post(r.game!!, {
r.game!!.tryContinueResolveProtocol(r, skillZhuanJiaoTos {
targetPlayerId = r.getAlternativeLocation(target.location)
enable = true
cardId = messageCard.id
})
}, 3, TimeUnit.SECONDS)
return null
}
}
GameExecutor.post(r.game!!, {
r.game!!.tryContinueResolveProtocol(r, skillZhuanJiaoTos {})
}, 1, TimeUnit.SECONDS)
if (target != null) {
GameExecutor.post(r.game!!, {
r.game!!.tryContinueResolveProtocol(r, skillZhuanJiaoTos {
targetPlayerId = r.getAlternativeLocation(target.location)
enable = true
cardId = mCard.id
})
}, 3, TimeUnit.SECONDS)
} else {
GameExecutor.post(r.game!!, {
r.game!!.tryContinueResolveProtocol(r, skillZhuanJiaoTos {})
}, 1, TimeUnit.SECONDS)
}
}
return null
}
Expand Down

0 comments on commit 53a80d3

Please sign in to comment.