Example #1
0
        /// <summary>Preforms a random turn sequence for the AI</summary>
        /// <returns>A bool representing if the AI scored a hit on this turn</returns>
        public bool RandomTurn()
        {
            bool outp = false;

            int x = 0;
            int y = 0;

            CurCool--;
            do
            {
                int t = 0;
                if (CurCool <= 0 && AttackingList.Count > 0)
                {
                    t = RNG.Next(0, AttackingList.Count());
                    x = AttackingList[t];
                    AttackingList.RemoveAt(t);
                }
                else if (PossibleList.Count > 0)
                {
                    t = RNG.Next(0, PossibleList.Count());
                    x = PossibleList[t];
                    PossibleList.RemoveAt(t);
                }
                else
                {
                    x = 0;
                }
                y  = (int)(x / Player1.Width);
                x %= Player1.Width;
            }while (Player1.info[x, y] != Map.Tiles.Unknown);
            if (outp = Player1.AttemptFire(new int[] { x, y }))
            {
                if (SelectedShip.Destroyed && Player1.Ships.Count > 0)
                {
                    SelectedShip = Player1.Ships[RNG.Next(0, Player1.Ships.Count())];
                    foreach (int[] i in SelectedShip.BodyList())
                    {
                        AttackingList.Add(i[0] + i[1] * Player1.Width);
                    }
                }
            }
            if (CurCool <= 0)
            {
                CurCool = RNG.Next(HitCoolExRange[0], HitCoolExRange[1]);
            }
            return(outp);
        }