太阳神三国杀lua吧 关注:2,637贴子:73,375
  • 7回复贴,共1

求扫盲:如何让AI选择友军角色

只看楼主收藏回复

各位大佬,我是AI完全小白,AI文盲,想跟各位求一个最基础的【选择友军角色施放技能】的AI,技能如下(技能描述:出牌开始前,你可以选择一名角色,令其摸一张牌)
yautodraw = sgs.CreateTriggerSkill{
name = "yautodraw",
events = {sgs.EventPhaseStart},
frequency = sgs.Skill_Frequent,
on_trigger = function(self, event,player,data)
local room = player:getRoom()
if event == sgs.EventPhaseStart and player:getPhase() == sgs.Player_Play then
if room:askForSkillInvoke(player, self:objectName()) then
local alist=room:getOtherPlayers(player)
local to = room:askForPlayerChosen(player,alist , self:objectName(), "choose losehp", true, true)
to:drawCards(1)
end
end
end,
}
希望能为此技能制作一个选择施放目标的AI,实现的目标
1)选择手牌数量最少的【友军】角色来施放
2)施放之后,其他AI能识别我的身份。(比如我向主公施放,则其他AI会识别我是忠臣)
3)如果大神不嫌弃,也请指教一下最基础的【选择体力最低的敌军角色施放技能】,该怎么写?
谢谢各位大神!


IP属地:中国香港1楼2019-07-27 12:28回复
    AI文盲在此


    IP属地:湖北2楼2019-07-27 13:47
    收起回复
      1) 手牌最少的友军
      local minfriend = nil
      for _, afriend in ipairs(self.friends_noself) do
      if minfriend and (minfriend:getHandcardNum() > afriend:getHandcardNum()) then minfriend = afriend
      elseif not minfriend then minfriend = afriend end
      end
      2) 识别身份
      sgs.ai_playerchosen_intention.yautodraw = -10
      3) 体力最多的敌军
      local maxenemy = nil
      for _, anenemy in ipairs(self.enemies) do
      if maxenemy and (maxenemy:getHp() < anenemy:getHp()) then maxenemy = anenemy
      elseif not maxenemy then maxenemy = anenemy end
      end
      仅供参考


      IP属地:北京3楼2019-07-27 22:55
      回复
        谢谢大佬! 在你的程序里加了个头部和return,测试成功!! 非常非常的感谢!!
        --友善技能的AI,选择手牌最少的队友施放
        sgs.ai_skill_playerchosen["yautodraw"] = function(self, targets)
        local minfriend = nil
        for _, afriend in ipairs(self.friends_noself) do
        if minfriend and (minfriend:getHandcardNum() > afriend:getHandcardNum()) then
        minfriend = afriend
        elseif not minfriend then minfriend = afriend
        end
        end
        return minfriend
        end
        sgs.ai_playerchosen_intention["yautodraw"] = -10
        ------------------------以下是一个敌意技能的AI,选择最大体力的敌人施放
        sgs.ai_skill_playerchosen["yautohurt"] = function(self, targets)
        local maxenemy = nil
        for _, anenemy in ipairs(self.enemies) do
        if maxenemy and (maxenemy:getHp() < anenemy:getHp()) then
        maxenemy = anenemy
        elseif not maxenemy then maxenemy = anenemy
        end
        end
        return maxenemy
        end
        sgs.ai_playerchosen_intention["yautohurt"] = 10


        IP属地:中国香港4楼2019-07-28 00:42
        回复