Exemplo n.º 1
0
        public override bool OnSkillInvoke(TrustedAI ai, Player player, object data)
        {
            if (data is Player p)
            {
                if (ai.IsFriend(p, player))
                {
                    foreach (int id in p.GetEquips())
                    {
                        if (ai.GetKeepValue(id, p, Player.Place.PlaceEquip) < 0)
                        {
                            return(true);
                        }
                    }

                    return(false);
                }
                else
                {
                    foreach (int id in p.GetEquips())
                    {
                        if (ai.GetKeepValue(id, p, Player.Place.PlaceEquip) < 0)
                        {
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
Exemplo n.º 2
0
        public override void OnEvent(TrustedAI ai, TriggerEvent triggerEvent, Player player, object data)
        {
            if (triggerEvent == TriggerEvent.ChoiceMade && data is string choice)
            {
                string[] choices = choice.Split(':');
                if (choices[1] == Name)
                {
                    Room   room   = ai.Room;
                    int    id     = int.Parse(choices[2]);
                    Player target = room.FindPlayer(choices[4]);

                    if (player != target && ai.GetPlayerTendency(target) != "unknown")
                    {
                        if (room.GetCardPlace(id) == Player.Place.PlaceDelayedTrick)
                        {
                            ai.UpdatePlayerRelation(player, target, true);
                        }
                        else
                        {
                            bool friend = ai.GetKeepValue(id, target, Player.Place.PlaceEquip) < 0;
                            ai.UpdatePlayerRelation(player, target, friend);
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        public override bool OnSkillInvoke(TrustedAI ai, Player player, object data)
        {
            double value = 0;
            Room   room  = ai.Room;

            foreach (Player p in room.GetAlivePlayers())
            {
                if (p.Chained && RoomLogic.CanDiscard(room, player, p, "he"))
                {
                    if (p == player)
                    {
                        List <int> ids = new List <int>();
                        foreach (int id in player.GetCards("he"))
                        {
                            if (RoomLogic.CanDiscard(room, player, player, id))
                            {
                                ids.Add(id);
                            }
                        }

                        ai.SortByKeepValue(ref ids, false);
                        value += ai.GetKeepValue(ids[0], player);
                    }
                    else
                    {
                        value += ai.FindCards2Discard(player, p, string.Empty, "he", HandlingMethod.MethodDiscard).Score;
                    }
                }
            }

            return(value > 3);
        }
Exemplo n.º 4
0
        public override int OnPickAG(TrustedAI ai, Player player, List <int> card_ids, bool refusable)
        {
            if (player.ContainsTag(Name))
            {
                Room   room   = ai.Room;
                Player target = room.FindPlayer((string)player.GetTag(Name));
                if (target != null && !ai.IsFriend(target))
                {
                    double best   = -1000;
                    int    result = -1;
                    foreach (int id in card_ids)
                    {
                        double value = ai.GetKeepValue(id, target, Player.Place.PlaceHand);
                        if (value > best)
                        {
                            best   = value;
                            result = id;
                        }
                    }
                    if (best > 0 && result != -1)
                    {
                        return(result);
                    }
                }
            }

            return(-1);
        }
Exemplo n.º 5
0
        public override CardUseStruct OnResponding(TrustedAI ai, Player player, string pattern, string prompt, object data)
        {
            CardUseStruct use         = new CardUseStruct(null, player, new List <Player>());
            string        target_name = prompt.Split(':')[1];
            Room          room        = ai.Room;
            Player        target      = room.FindPlayer(target_name);

            if (target != null)
            {
                if (ai.IsFriend(target))
                {
                    foreach (int id in player.GetEquips())
                    {
                        if (ai.GetKeepValue(id, player) < 0 && RoomLogic.CanDiscard(room, target, player, id))
                        {
                            return(use);
                        }
                    }

                    //System.Diagnostics.Debug.Assert(room.GetAI(target) == null, "ai挑衅目标错误");
                }

                List <ScoreStruct> scores = ai.CaculateSlashIncome(player, null, new List <Player> {
                    target
                });

                if (scores.Count > 0 && scores[0].Score > -2 && scores[0].Card != null)
                {
                    use.Card = scores[0].Card;
                    use.To.Add(target);
                }
            }

            return(use);
        }
Exemplo n.º 6
0
        public override CardUseStruct OnResponding(TrustedAI ai, Player player, string pattern, string prompt, object data)
        {
            CardUseStruct use = new CardUseStruct(null, player, new List <Player>());

            if (player.ContainsTag("ziliang_aidata") && player.GetTag("ziliang_aidata") is string player_name)
            {
                Room   room   = ai.Room;
                Player target = room.FindPlayer(player_name);
                if (target != null)
                {
                    double best_v = 0;
                    int    result = -1;
                    foreach (int id in player.GetPile("field"))
                    {
                        double value = Math.Max(ai.GetKeepValue(id, target, Player.Place.PlaceHand), ai.GetUseValue(id, target, Player.Place.PlaceHand));
                        if (value > best_v)
                        {
                            best_v = value;
                            result = id;
                        }

                        if (best_v > 2.5 && result >= 0)
                        {
                            use.Card = new WrappedCard("ZiliangCard")
                            {
                                Skill = Name, ShowSkill = Name
                            };
                            use.Card.AddSubCard(result);
                        }
                    }
                }
            }

            return(use);
        }
Exemplo n.º 7
0
 public override void OnEvent(TrustedAI ai, TriggerEvent triggerEvent, Player player, object data)
 {
     if (triggerEvent == TriggerEvent.ChoiceMade && data is string str)
     {
         Room     room = ai.Room;
         string[] strs = str.Split(':');
         if (str.StartsWith("playerChosen:shenfu") && strs[1] == Name && player.HandcardNum % 2 == 1)
         {
             Player target = room.FindPlayer(strs[2]);
             if (ai.GetPlayerTendency(target) != "unknown" && ai is StupidAI _ai && !_ai.NeedDamage(new DamageStruct(Name, player, target, 1, DamageStruct.DamageNature.Thunder)))
             {
                 ai.UpdatePlayerRelation(player, target, false);
             }
         }
         else if (str.StartsWith("skillChoice:shenfu") && strs[1] == Name)
         {
             Player target = null;
             foreach (Player p in room.GetAlivePlayers())
             {
                 if (p.HasFlag("shenfu_target"))
                 {
                     target = p;
                     break;
                 }
             }
             if (ai.GetPlayerTendency(target) != "unknown" && strs[2] == "draw")
             {
                 ai.UpdatePlayerRelation(player, target, true);
             }
         }
         else if (str.StartsWith("cardChosen:shenfu") && strs[1] == Name)
         {
             int    id     = int.Parse(strs[2]);
             Player target = room.FindPlayer(strs[4]);
             if (ai.GetPlayerTendency(target) != "unknown")
             {
                 if (room.GetCardPlace(id) == Player.Place.PlaceHand)
                 {
                     ai.UpdatePlayerRelation(player, target, false);
                 }
                 else if (room.GetCardPlace(id) == Player.Place.PlaceEquip)
                 {
                     bool friendly = ai.GetKeepValue(id, target, Player.Place.PlaceEquip) > 0;
                     ai.UpdatePlayerRelation(player, target, friendly);
                 }
             }
         }
     }
 }
Exemplo n.º 8
0
        public override string OnChoice(TrustedAI ai, Player player, string choice, object data)
        {
            List <int> ids = player.GetCards("e");

            if (ids.Count <= 2)
            {
                ai.SortByKeepValue(ref ids, false);
                if (!ai.IsWeak() || ai.GetKeepValue(ids[0], player) < 0)
                {
                    return("discard");
                }
            }

            return("remove");
        }
Exemplo n.º 9
0
 public override void OnEvent(TrustedAI ai, TriggerEvent triggerEvent, Player player, object data)
 {
     if (triggerEvent == TriggerEvent.ChoiceMade && data is string str)
     {
         Room     room = ai.Room;
         string[] strs = str.Split(':');
         if (str.StartsWith("playerChosen:cuike") && strs[1] == Name)
         {
             Player target = room.FindPlayer(strs[2]);
             if (ai.GetPlayerTendency(target) != "unknown" && ai is StupidAI _ai)
             {
                 if (!player.HasFlag(Name) && !_ai.NeedDamage(new DamageStruct(Name, player, target)))
                 {
                     ai.UpdatePlayerRelation(player, target, false);
                 }
                 else if (player.HasFlag(Name) && player.IsAllNude())
                 {
                     ai.UpdatePlayerRelation(player, target, false);
                 }
             }
         }
         else if (str.StartsWith("cardChosen:cuike"))
         {
             int    id     = int.Parse(strs[2]);
             Player target = room.FindPlayer(strs[3]);
             if (ai.GetPlayerTendency(target) != "unknown")
             {
                 if (room.GetCardPlace(id) == Player.Place.PlaceEquip)
                 {
                     ai.UpdatePlayerRelation(player, target, ai.GetKeepValue(id, target) > 0);
                 }
                 else if (room.GetCardPlace(id) == Player.Place.PlaceDelayedTrick)
                 {
                     ai.UpdatePlayerRelation(player, target, true);
                 }
                 else
                 {
                     ai.UpdatePlayerRelation(player, target, false);
                 }
             }
         }
     }
 }
Exemplo n.º 10
0
        public override int OnPickAG(TrustedAI ai, Player player, List <int> card_ids, bool refusable)
        {
            if (player.ContainsTag(Name))
            {
                Room   room   = ai.Room;
                Player target = null;
                foreach (Player p in room.GetOtherPlayers(player))
                {
                    if (p.HasFlag("shangyi_target"))
                    {
                        target = p;
                        break;
                    }
                }

                if (target != null && !ai.IsFriend(target))
                {
                    double best   = -1000;
                    int    result = -1;
                    foreach (int id in card_ids)
                    {
                        double value = ai.GetKeepValue(id, target, Player.Place.PlaceHand);
                        if (value > best)
                        {
                            best   = value;
                            result = id;
                        }
                    }
                    if (best > 0 && result != -1)
                    {
                        return(result);
                    }
                }
            }

            return(-1);
        }
Exemplo n.º 11
0
        public override List <WrappedCard> GetTurnUse(TrustedAI ai, Player player)
        {
            if (!player.HasUsed(WendaoCard.ClassName) && !player.IsNude())
            {
                Room room = ai.Room;
                int  pp   = -1;
                foreach (int id in room.DiscardPile)
                {
                    WrappedCard card = room.GetCard(id);
                    if (card.Name == PeaceSpell.ClassName)
                    {
                        pp = id;
                        break;
                    }
                }
                if (pp == -1)
                {
                    foreach (Player p in room.GetAlivePlayers())
                    {
                        foreach (int id in p.GetEquips())
                        {
                            WrappedCard card = room.GetCard(id);
                            if (card.Name == PeaceSpell.ClassName)
                            {
                                pp = id;
                                break;
                            }
                        }
                        if (pp != -1)
                        {
                            break;
                        }
                    }
                }

                if (pp > -1)
                {
                    WrappedCard wd = new WrappedCard(WendaoCard.ClassName)
                    {
                        ShowSkill = Name,
                        Skill     = Name
                    };
                    List <int> ids = player.GetCards("he");
                    ai.SortByKeepValue(ref ids, false);
                    foreach (int id in ids)
                    {
                        WrappedCard card = room.GetCard(id);
                        if (WrappedCard.IsRed(card.Suit) && card.Name != PeaceSpell.ClassName && ai.GetKeepValue(id, player) < 0)
                        {
                            wd.AddSubCard(id);
                            return(new List <WrappedCard> {
                                wd
                            });
                        }
                    }

                    ai.SortByUseValue(ref ids, false);
                    foreach (int id in ids)
                    {
                        WrappedCard card = room.GetCard(id);
                        if (WrappedCard.IsRed(card.Suit) && card.Name != PeaceSpell.ClassName)
                        {
                            wd.AddSubCard(id);
                            return(new List <WrappedCard> {
                                wd
                            });
                        }
                    }
                }
            }

            return(new List <WrappedCard>());
        }
Exemplo n.º 12
0
        public override ScoreStruct GetDamageScore(TrustedAI ai, DamageStruct damage)
        {
            ScoreStruct score = new ScoreStruct
            {
                Score = 0
            };

            if (damage.To != null && ai.HasSkill(Name, damage.To) && damage.Card != null)
            {
                score.Score = 1.2;
                FunctionCard fcard = Engine.GetFunctionCard(damage.Card.Name);
                if (!(fcard is SkillCard))
                {
                    foreach (int id in damage.Card.SubCards)
                    {
                        double value = Math.Max(ai.GetUseValue(id, damage.To, Player.Place.PlaceHand), ai.GetKeepValue(id, damage.To, Player.Place.PlaceHand));
                        score.Score += value * 0.45;
                    }

                    if (ai.WillSkipPlayPhase(damage.To))
                    {
                        score.Score /= 3;
                    }

                    if (damage.Damage >= damage.To.Hp)
                    {
                        score.Score /= 2;
                    }

                    if (damage.From != null && damage.From == damage.To && score.Score > 0)
                    {
                        score.Score /= 4;
                    }
                }

                if (damage.Damage > 1)
                {
                    score.Score /= 1.5;
                }
                if (ai.WillSkipPlayPhase(damage.To))
                {
                    score.Score /= 1.5;
                }

                if (ai.IsEnemy(damage.To))
                {
                    score.Score = -score.Score;
                }
                else
                {
                    score.Score -= 1.5;
                }
            }

            return(score);
        }
Exemplo n.º 13
0
        public override List <int> OnDiscard(TrustedAI ai, Player player, List <int> cards, int min, int max, bool option)
        {
            if (!ai.WillShowForAttack())
            {
                return(new List <int>());
            }

            Room       room   = ai.Room;
            Player     target = room.Current;
            List <int> ids    = new List <int>();

            foreach (int id in player.HandCards)
            {
                if (RoomLogic.CanDiscard(room, player, player, id))
                {
                    ids.Add(id);
                }
            }
            ai.SortByKeepValue(ref ids, false);
            double value = ai.GetKeepValue(ids[0], player);

            if (ai.GetOverflow(player) > 1)
            {
                value /= 3;
            }
            DamageStruct damage = new DamageStruct(Name, player, target);

            if (ai.IsFriend(target))
            {
                bool range = false;
                foreach (Player p in room.GetOtherPlayers(target))
                {
                    if (ai.GetPrioEnemies().Contains(p) && RoomLogic.InMyAttackRange(room, target, p))
                    {
                        range = true;
                        break;
                    }
                }

                if (range && target.HandcardNum + target.GetPile("wooden_ox").Count > 3)
                {
                    if (ai.GetDamageScore(damage).Score < -3 && ai.HasSkill("wushuang|jianchu", target) && value < 3)
                    {
                        return new List <int> {
                                   ids[0]
                        }
                    }
                    ;
                }
            }
            else
            {
                if (ai.GetDamageScore(damage).Score > 7 && value < 7)
                {
                    return new List <int> {
                               ids[0]
                    }
                }
                ;
                else if (ai.GetDamageScore(damage).Score > 4 && value < 3)
                {
                    if (ai.IsLackCard(target, Slash.ClassName) || target.HandcardNum + target.GetPile("wooden_ox").Count < 3)
                    {
                        return(new List <int> {
                            ids[0]
                        });
                    }
                    else
                    {
                        bool range = false;
                        foreach (Player p in room.GetOtherPlayers(target))
                        {
                            if (ai.IsFriend(p) && RoomLogic.InMyAttackRange(room, target, p))
                            {
                                range = true;
                                break;
                            }
                        }

                        if (!range)
                        {
                            return new List <int> {
                                       ids[0]
                            }
                        }
                        ;
                    }
                }
            }

            return(new List <int>());
        }
    }
Exemplo n.º 14
0
        public override List <int> OnExchange(TrustedAI ai, Player player, string pattern, int min, int max, string pile)
        {
            if (ai.WillShowForDefence())
            {
                Room room = ai.Room;
                //有君角在,不要用太平发动
                Player lord = RoomLogic.FindPlayerBySkillName(room, "wendao");

                List <int> ids = new List <int>();
                foreach (int id in player.HandCards)
                {
                    WrappedCard card = room.GetCard(id);
                    if (card.Name == PeaceSpell.ClassName && lord != null)
                    {
                        continue;
                    }
                    bool add = true;
                    foreach (int _id in player.GetPile("sorcery"))
                    {
                        if (room.GetCard(_id).Suit == card.Suit)
                        {
                            add = false;
                            break;
                        }
                    }
                    if (add)
                    {
                        ids.Add(id);
                    }
                }

                foreach (int id in player.GetEquips())
                {
                    WrappedCard card = room.GetCard(id);
                    if (card.Name == PeaceSpell.ClassName && lord != null)
                    {
                        continue;
                    }
                    bool add = true;
                    foreach (int _id in player.GetPile("sorcery"))
                    {
                        if (room.GetCard(_id).Suit == card.Suit)
                        {
                            add = false;
                            break;
                        }
                    }
                    if (add)
                    {
                        ids.Add(id);
                    }
                }

                if (ids.Count > 0)
                {
                    ai.SortByKeepValue(ref ids, false);
                    foreach (int id in ids)
                    {
                        double keep = ai.GetKeepValue(id, player);
                        double use  = ai.GetUseValue(id, player);
                        if (keep < 0 || (keep <= 5 && use <= 5))
                        {
                            return new List <int> {
                                       id
                            }
                        }
                        ;
                    }
                }
            }

            return(new List <int>());
        }