Пример #1
0
        //public int MinHp()
        //{
        //    int[] input = new int[ArenaMaster.GetInstance().GetMonsterList().Count];
        //    for (int i = 0; i < ArenaMaster.GetInstance().GetMonsterList().Count; i++)
        //    {
        //        input[i] = ArenaMaster.GetInstance().GetMonsterList()[i].hp;
        //    }
        //    int minNum = input[0];
        //    foreach (int item in input)
        //    {
        //        if (minNum <= 0)
        //        {
        //            minNum = item;
        //        }
        //        else if (item < minNum && item > 0)
        //        {
        //            minNum = item;
        //        }
        //    }
        //    Console.WriteLine($"=={minNum}==");
        //    return minNum;
        //}

        public int AutoAim()
        {
            int selfNum = ArenaMaster.GetInstance().GetMonsterList().FindIndex(m => m.name == "Jack");

            int[] input = new int[ArenaMaster.GetInstance().GetMonsterList().Count];
            for (int i = 0; i < ArenaMaster.GetInstance().GetMonsterList().Count; i++)
            {
                input[i] = ArenaMaster.GetInstance().GetMonsterList()[i].hp;
            }

            int k        = 0;
            int minHpNum = input[0];

            for (int i = 0; i < ArenaMaster.GetInstance().GetMonsterList().Count; i++)
            {
                if (i != selfNum)
                {
                    if (minHpNum <= 0)
                    {
                        minHpNum = input[i];
                        k        = i;
                    }
                    if (input[i] < minHpNum && input[i] > 0)
                    {
                        minHpNum = input[i];
                        k        = i;
                    }
                }
            }
            //Console.WriteLine($"=={minHpNum}==");

            return(k);
        }
Пример #2
0
        public static ArenaMaster GetInstance()
        {
            if (instance == null)
            {
                instance = new ArenaMaster();
            }

            return(instance);
        }
Пример #3
0
        static void Main(string[] args)
        {
            List <Monster> monsters = new List <Monster>()
            {
                new Goblin("Alice"),
                new Orc("Bob"),
                new Goblin("Charlie"),
                new Orc("David"),
                new LuckyUnicorn("Lady"),
                new Dragon("Xiangfeng"),
                new FirstDragon("sixiang"),
                new Slime("Felix"),
                new Ironman("Chenyi"),
                new Slimoblin("Jack")
            };

            foreach (var monster in monsters)
            {
                monster.Spawn();
            }

            ArenaMaster.GetInstance().SetMonsterList(monsters);

            while (!IsBattleOver(monsters))
            {
                monsters.Sort();
                foreach (var activeMonster in monsters)
                {
                    if (activeMonster.IsDead())
                    {
                        continue;
                    }

                    int attackIndex = activeMonster.GetAttackIndex();
                    if (attackIndex < 0 || attackIndex >= monsters.Count)
                    {
                        continue;
                    }

                    activeMonster.Attack(monsters[attackIndex]);
                }
            }

            Monster winner = monsters.Find(m => !m.IsDead());

            if (winner != null)
            {
                Console.WriteLine($"The winner is {winner}!");
            }
            else
            {
                Console.WriteLine("All combatants have perished...");
            }
        }
Пример #4
0
        public override int GetAttackIndex()
        {
            int index = ArenaMaster.GetInstance().GetMonsterList().FindIndex(m => m.level > 1);

            if (index >= 0)
            {
                return(index);
            }
            else
            {
                return(base.GetAttackIndex());
            }
        }
Пример #5
0
        public override int GetAttackIndex()
        {
            // Fetches monster list
            var monsterList = ArenaMaster.GetInstance().GetMonsterList();
            // Initializes lowestHp with a high value
            var lowestHp = 999;

            // Strategy: avoid suicide and always target low health enemies. (Win rate: +-80%)
            // Attack lowest HP monster to farm some levels
            foreach (var t in monsterList.Where(t => lowestHp > t.hp && t.hp > 0 && t.type != "LuckyUnicorn"))
            {
                lowestHp = t.hp;
                // Console.WriteLine("Weakest enemy: " + lowestHp);
            }

            return(monsterList.FindIndex(data => data.hp == lowestHp));
        }
Пример #6
0
 public virtual int GetAttackIndex()
 {
     return(random.Next(0, ArenaMaster.GetInstance().GetMonsterList().Count));
 }