Example #1
0
        public void Update(Mower mower, Random rand)
        {
            foreach (var grassArea in GrassInTotal)
            {
                if (!mower.Boundary.Intersects(grassArea))
                {
                    if (CurrentlyUnderMower.Contains(grassArea))
                    {
                        CurrentlyUnderMower.Remove(grassArea);
                    }

                    continue;
                }

                if (CurrentlyUnderMower.Contains(grassArea))
                {
                    continue;
                }
                grassArea.DrivingOver();
                LeftToMowe.Remove(grassArea);
                CurrentlyUnderMower.Add(grassArea);
            }

            mower.Update();
            if (MyField.Contains(mower.Boundary))
            {
                return;
            }

            mower.SetRandomOtherDirection(rand, mower.Boundary.ClipInside(MyField));
        }
Example #2
0
        /// <summary>
        /// Initializes the current simulation.
        /// </summary>
        /// <param name="field">Field (defined in count of grass areas).</param>
        /// <param name="mower"></param>
        /// <param name="rand"></param>
        public void Initilize(Field field, Mower mower, Random rand)
        {
            lock (Locker)
            {
                if (Rand != null)
                {
                    return;
                }

                Rand = rand;
            }

            if (_initialized)
            {
                return;
            }

            myGarden = new Garden(field);
            myMower  = mower;

            _initialized = true;
        }