예제 #1
0
 public FieldInfo()
 {
     Ships        = new ShipList();
     Shots        = new ShotList();
     ShipsLeft    = new ShipList();
     ShotsAgainst = new ShotList();
 }
예제 #2
0
        /// <summary>
        /// Determines whether or not the <paramref name="ships"/> have an equal amount of <see cref="Ship"/>s and identical <see cref="Ship.Length"/>s
        /// as in this <see cref="ShipList"/>.
        /// </summary>
        /// <param name="ships">A <see cref="ShipList"/> to compare.</param>
        /// <returns>A value indicating the same <see cref="Ship"/> configuration of the two <see cref="ShipList"/>s.</returns>
        public bool EqualLengthsAs(ShipList ships)
        {
            if (ships.Count != Count)
            {
                return(false);
            }
            var lengthsThis = new List <int>();

            for (var i = 0; i < Count; i++)
            {
                lengthsThis.Add(shipList[i].Length);
            }
            foreach (var ship in ships)
            {
                if (lengthsThis.Contains(ship.Length))
                {
                    lengthsThis.Remove(ship.Length);
                }
                else
                {
                    return(false);
                }
            }
            return(true);
        }
예제 #3
0
 /// <summary>
 /// Adds the <see cref="Ship"/>s contained in the <paramref name="list"/>.
 /// </summary>
 /// <param name="list">A <see cref="ShipList"/> to add <see cref="Ship"/>s from.</param>
 public void Add(ShipList list)
 {
     foreach (var ship in list)
     {
         shipList.Add(ship);
     }
 }
 public MatchConfig(MatchConfig copy)
 {
     StartingShips  = new ShipList(copy.StartingShips);
     NumberOfRounds = copy.NumberOfRounds;
     FieldSize      = copy.FieldSize;
     TimeLimit      = copy.TimeLimit;
     GameMode       = copy.GameMode;
     Random         = copy.Random;
 }
예제 #5
0
 public FieldInfo(FieldInfo copy)
 {
     if (copy != null)
     {
         Ships        = new ShipList(copy.Ships);
         Shots        = new ShotList(copy.Shots);
         ShipsLeft    = new ShipList(copy.ShipsLeft);
         ShotsAgainst = new ShotList(copy.ShotsAgainst);
     }
 }
 public MatchConfig(Match matchCopy)
 {
     if (matchCopy.StartingShips != null)
     {
         StartingShips = new ShipList(matchCopy.StartingShips.ToList());
     }
     NumberOfRounds = matchCopy.NumberOfRounds;
     FieldSize      = matchCopy.FieldSize;
     TimeLimit      = matchCopy.TimeLimit;
     GameMode       = GameMode.Classic;
     Random         = matchCopy.Random;
 }
예제 #7
0
 /// <summary>
 /// Does nothing, but makes it so only deriving classes may create a <see cref="MatchInfo"/>.
 /// </summary>
 public MatchInfo(MatchConfig conf, List <Register> registers)
 {
     fieldSize       = conf.FieldSize;
     gameMode        = conf.GameMode;
     initShips       = conf.StartingShips;
     methodTimeLimit = conf.TimeLimit;
     controllerNames = new List <string>();
     foreach (var reg in registers)
     {
         controllerNames.Add(reg.Name);
     }
 }
예제 #8
0
 public ShipList(ShipList copyList)
 {
     shipList = new List <Ship>();
     if (copyList != null)
     {
         minLength = int.MaxValue;
         maxLength = int.MinValue;
         foreach (var ship in copyList.shipList)
         {
             Add(new Ship(ship));
         }
     }
 }
예제 #9
0
        /// <summary>
        /// Generates a <see cref="ShipList"/> of <see cref="Ship"/>s that conflict with one another.
        /// </summary>
        /// <returns>A <see cref="ShipList"/> of conflicting <see cref="Ship"/>s.</returns>
        public ShipList GetConflictingShips()
        {
            ShipList conflictingShips = new ShipList();

            foreach (var ship in shipList)
            {
                foreach (var shipCompare in shipList)
                {
                    if (ship != shipCompare && ship.ConflictsWith(shipCompare))
                    {
                        conflictingShips.Add(ship);
                    }
                }
            }
            return(conflictingShips);
        }
예제 #10
0
        /// <summary>
        /// Generates a <see cref="ShipList"/> containing <see cref="Ship"/>s that have been sunk according
        /// to the <paramref name="shots"/>.
        /// </summary>
        /// <param name="shots">The <see cref="ShotList"/> containing <see cref="Shot"/>s made against
        /// the containing <see cref="Ship"/>s.</param>
        /// <returns>A <see cref="ShipList"/> of <see cref="Ship"/>s that completely occupy the spaces
        /// given by the <paramref name="shots"/>.</returns>
        public ShipList GetSunkShips(ShotList shots)
        {
            var newList = new ShipList();
            int shotCount;

            foreach (var ship in shipList)
            {
                shotCount = 0;
                foreach (var coord in ship.GetAllLocations())
                {
                    if (shots.Contains(coord))
                    {
                        shotCount++;
                    }
                }
                if (shotCount == ship.Length)
                {
                    newList.Add(ship);
                }
            }
            return(newList);
        }
예제 #11
0
 public ShipListEnumerator(ShipList ships)
 {
     collection = ships;
     currentIdx = -1;
 }
예제 #12
0
 public virtual ShipList PlaceShips(ShipList initialShips)
 {
     return(null);
 }