示例#1
0
        /// <summary>
        /// Choose a cell around the one that has been hit to completely destroy a ship
        /// </summary>
        /// <returns>Adjacent coordinates</returns>
        private Coordinates SearchingShot()
        {
            Random rand         = new Random(Guid.NewGuid().GetHashCode());
            var    hitNeighbors = FiringBoard.GetHitNeighbors();
            var    neighborID   = rand.Next(hitNeighbors.Count);

            return(hitNeighbors[neighborID]);
        }
示例#2
0
        public Coordinates FireShot()
        {
            //If there are hits on the board with neighbors which don't have shots, we should fire at those first.
            var hitNeighbors = FiringBoard.GetHitNeighbors();
            var coords       = hitNeighbors.Any() ? SearchingShot() : RandomShot();

            Console.WriteLine(Name + " says: \"Firing shot at " + coords.Row.ToString() + ", " + coords.Column.ToString() + "\"");
            return(coords);
        }
示例#3
0
        /// <summary>
        /// Choose a cell for firing a shot and return its coordinates
        /// </summary>
        public Coordinates FireShot()
        {
            //If there are hits on the board with neighbors which don't have shots, we should fire at those first.
            Random      r            = new Random();
            var         hitNeighbors = FiringBoard.GetHitNeighbors();
            Coordinates coords;

            if (hitNeighbors.Any())
            {
                coords = SearchingShot();
            }
            else
            {
                coords = RandomShot();
            }
            return(coords);
        }