Skip to content

Commit

Permalink
商玉AI
Browse files Browse the repository at this point in the history
  • Loading branch information
CuteReimu committed Dec 11, 2024
1 parent f3bc141 commit 124c5e4
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions src/main/kotlin/skill/JieDaoShaRen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.fengsheng.protos.skillJieDaoShaRenAToc
import com.fengsheng.protos.skillJieDaoShaRenATos
import com.fengsheng.protos.skillJieDaoShaRenBToc
import com.fengsheng.protos.skillJieDaoShaRenBTos
import com.fengsheng.skill.SkillId.SOU_JI
import com.google.protobuf.GeneratedMessage
import org.apache.logging.log4j.kotlin.logger
import java.util.concurrent.TimeUnit
Expand Down Expand Up @@ -191,27 +192,21 @@ class JieDaoShaRen : ActiveSkill {
fun ai(e: FightPhaseIdle, skill: ActiveSkill): Boolean {
val player = e.whoseFightTurn
!player.roleFaceUp || return false
player.game!!.players.anyoneWillWinOrDie(e) || return false
val availableTargets = player.game!!.players.filter {
it!!.alive && it.isEnemy(player) && it.cards.isNotEmpty()
}.ifEmpty { return false }
// val weights = availableTargets.map { it!! to it.cards.count(Black).toDouble() / it.cards.size }
// val totalWeight = weights.sumOf { it.second }
// var target = availableTargets.first()!!
// if (totalWeight > 0.0) { // 按权重随机
// var weight = Random.nextDouble(totalWeight)
// for ((p, w) in weights) {
// if (weight < w) {
// target = p
// break
// }
// weight -= w
// }
// } else {
val target = availableTargets.random()!!
// }
GameExecutor.post(player.game!!, {
skill.executeProtocol(player.game!!, player, skillJieDaoShaRenATos {
val g = player.game!!
var target = g.players.find { // 明的全黑
it!!.alive && it.cards.isNotEmpty() && it.cards.all { c -> c.isBlack() && c.id in g.canWeiBiCardIds }
}
if (target == null) {
val liXing = g.players.find { it!!.alive && it.cards.isNotEmpty() && it.getSkillUseCount(SOU_JI) > 0 }
if (liXing != null && (liXing.isEnemy(player) || liXing.cards.all { it.isBlack() }))
target = liXing // 发过技能的李醒,是敌人或者是全黑
}
if (target == null && g.players.anyoneWillWinOrDie(e)) { // 有人要赢了或者要死了,直接随机
target = g.players.filter { it!!.alive && it.isEnemy(player) && it.cards.isNotEmpty() }.randomOrNull()
}
if (target == null) return false
GameExecutor.post(g, {
skill.executeProtocol(g, player, skillJieDaoShaRenATos {
targetPlayerId = player.getAlternativeLocation(target.location)
})
}, 3, TimeUnit.SECONDS)
Expand Down

0 comments on commit 124c5e4

Please sign in to comment.