Exemplo n.º 1
0
 /// <summary>
 /// Notifies the MapContext that a zeebot will change its facing, by a certain value.
 /// </summary>
 /// <param name="zeebot">The zeebot that is chaning facing.</param>
 /// <param name="value">The increment value with which the facing is changing (positive means
 /// counter-clockwise rotation). </param>
 /// </param>
 public void ChangeFacing(IZeebot zeebot, double value)
 {
     zeebots[zeebot].Facing += value;
 }
Exemplo n.º 2
0
 public void AddZeebotAt(IZeebot zeebot, MovingPoint position)
 {
     zeebot.Id = zeebots.Count;
     zeebot.MapContext = this;
     zeebots[zeebot] = position;
 }
Exemplo n.º 3
0
 public void AddZeebot(IZeebot zeebot)
 {
     zeebot.Id = zeebots.Count;
     zeebot.MapContext = this;
     zeebots[zeebot] = GetRandomPoint();
 }
Exemplo n.º 4
0
        /// <summary>
        /// Notifies the MapContext that a zeebot will try to move forward a certain value.
        /// </summary>
        /// <param name="zeebot">The zeebot that is attempting to move.</param>
        /// <param name="value">The value with which the zeebots tries to move forward. </param>
        /// <param name="success">How much of the value did the zeebot succeed to move forward.
        /// </param>
        /// <returns>Whether the move succeeded or not.</returns>
        public bool TryMove(IZeebot zeebot, double value, out double success)
        {
            MovingPoint mp = zeebots[zeebot];
            Point end = new Point();
            end.X = mp.Location.X + value * Math.Cos(mp.Facing);
            end.Y = mp.Location.Y + value * Math.Sin(mp.Facing);

            bool result = map.TryMove(mp.Location, end, out success);
            end.X = mp.Location.X + success * Math.Cos(mp.Facing);
            end.Y = mp.Location.Y + success * Math.Sin(mp.Facing);
            mp.Location = end;
            if (!map.InMinMaxBox(mp.Location))
                throw new Exception(string.Format("Not in min-max at: {0}", mp.Location));
            return result;
        }
Exemplo n.º 5
0
 public double QueryZeebotDistance(IZeebot zeebot, IZeebot otherZeebot)
 {
     Point other = zeebots[otherZeebot].Location;
     return zeebots[zeebot].Location.DistanceTo(other);
 }
Exemplo n.º 6
0
        /// <summary>
        /// A zeebot shoots its laser beam in front of him, and asks the MapContext at 
        /// what distance is an obstacle in front of him, if any. Returns the distance to 
        /// the first obstacle in front of the zeebot, or NaN if no such object exist in the 
        /// range of the laser's distance (the laser expired).
        /// </summary>
        /// <param name="zeebot"> The zeebot that is performing the query.</param>
        /// <returns> The distance to the obstacle in front of the zeebot, or NaN if the laser 
        /// expired. </returns>
        public double QueryLaser(IZeebot zeebot)
        {
            MovingPoint mp = zeebots[zeebot];
            Point end = new Point();
            end.X = mp.Location.X + LaserDistance * Math.Cos(mp.Facing);
            end.Y = mp.Location.Y + LaserDistance * Math.Sin(mp.Facing);

            double result;
            if (map.CanMove(mp.Location, end, out result))
                return double.NaN;
            else
                return result;
        }