Ejemplo n.º 1
0
        /*
         * Проверка что кто-то стоит впереди
         * p2   p5  p3  p4   p1
         * |    |   |   |    |
         * o-----------------o
         * |                 |
         * |                 |
         */
        public bool IsSomeoneAhead(ACar car, int direction)
        {
            var   carRect = car.GetRect(0);
            Point p1, p2;

            if (direction > 0)
            {
                p1 = carRect[0] + Point.ByAngle(car.Angle) * 20;
                p2 = carRect[3] + Point.ByAngle(car.Angle) * 20;
            }
            else
            {
                p1 = carRect[1] - Point.ByAngle(car.Angle) * 20;
                p2 = carRect[2] - Point.ByAngle(car.Angle) * 20;
            }
            var p3 = (p1 + p2) / 2;
            var p4 = (p1 + p3) / 2;
            var p5 = (p2 + p3) / 2;

            return(world.Cars.Select(x => new ACar(x).GetRect(0)).Any(
                       rect => Geom.ContainPoint(rect, p1) ||
                       Geom.ContainPoint(rect, p2) ||
                       Geom.ContainPoint(rect, p3) ||
                       Geom.ContainPoint(rect, p4) ||
                       Geom.ContainPoint(rect, p5)
                       ));
        }
Ejemplo n.º 2
0
Archivo: ACar.cs Proyecto: znsoft/AiCup
 public bool IntersectWith(ACar car, double safeMargin)
 {
     if (GetDistanceTo2(car) > Geom.Sqr(Const.CarDiagonalHalfLength + Const.CarDiagonalHalfLength))
     {
         return(false);
     }
     return(Geom.PolygonsIntersect(GetRect(0), car.GetRect(safeMargin)));
 }
Ejemplo n.º 3
0
        public bool Intersect(ACar car, double extendRadius)
        {
            if (Type == ProjectileType.Washer)
                return Geom.ContainPoint(car.GetRect(-extendRadius), this);

            var r = Radius + extendRadius;
            if (GetDistanceTo2(car) > Geom.Sqr(r + Const.CarDiagonalHalfLength))
                return false;

            return car.GetRectEx().Any(p => GetDistanceTo(p) < r);
        }
Ejemplo n.º 4
0
        public bool Intersect(ACar car, double extendRadius)
        {
            if (Type == ProjectileType.Washer)
            {
                return(Geom.ContainPoint(car.GetRect(-extendRadius), this));
            }

            var r = Radius + extendRadius;

            if (GetDistanceTo2(car) > Geom.Sqr(r + Const.CarDiagonalHalfLength))
            {
                return(false);
            }

            return(car.GetRectEx().Any(p => GetDistanceTo(p) < r));
        }
Ejemplo n.º 5
0
        public static bool ModelMove(ACar car, AMove m, bool simpleMode = false, bool exactlyBorders = false)
        {
            var prevStateX     = car.X;
            var prevStateY     = car.Y;
            var prevStateAngle = car.Angle;

            var turn = m.WheelTurn is Point?TurnRound(car.GetAngleTo(m.WheelTurn as Point)) : Convert.ToDouble(m.WheelTurn);

            car.Move(m.EnginePower, turn, m.IsBrake, m.IsUseNitro, simpleMode);
            var ok = car.GetRect(0).All(p => !IntersectTail(p, exactlyBorders ? 0 : MagicConst.SafeMargin));

            if (!ok)
            {
                // HACK
                car.X            = prevStateX;
                car.Y            = prevStateY;
                car.Angle        = prevStateAngle;
                car.Speed        = Point.Zero;
                car.AngularSpeed = 0;
            }
            return(ok);
        }
Ejemplo n.º 6
0
        public static bool ModelMove(ACar car, AMove m, bool simpleMode = false, bool exactlyBorders = false)
        {
            var prevStateX = car.X;
            var prevStateY = car.Y;
            var prevStateAngle = car.Angle;

            var turn = m.WheelTurn is Point ? TurnRound(car.GetAngleTo(m.WheelTurn as Point)) : Convert.ToDouble(m.WheelTurn);
            car.Move(m.EnginePower, turn, m.IsBrake, m.IsUseNitro, simpleMode);
            var ok = car.GetRect(0).All(p => !IntersectTail(p, exactlyBorders ? 0 : MagicConst.SafeMargin));
            if (!ok)
            {
                // HACK
                car.X = prevStateX;
                car.Y = prevStateY;
                car.Angle = prevStateAngle;
                car.Speed = Point.Zero;
                car.AngularSpeed = 0;
            }
            return ok;
        }
Ejemplo n.º 7
0
 /*
  * Проверка что кто-то стоит впереди
  * p2   p5  p3  p4   p1
  * |    |   |   |    |
  * o-----------------o
  * |                 |
  * |                 |
  */
 public bool IsSomeoneAhead(ACar car, int direction)
 {
     var carRect = car.GetRect(0);
     Point p1, p2;
     if (direction > 0)
     {
         p1 = carRect[0] + Point.ByAngle(car.Angle)*20;
         p2 = carRect[3] + Point.ByAngle(car.Angle)*20;
     }
     else
     {
         p1 = carRect[1] - Point.ByAngle(car.Angle) * 20;
         p2 = carRect[2] - Point.ByAngle(car.Angle) * 20;
     }
     var p3 = (p1 + p2)/2;
     var p4 = (p1 + p3)/2;
     var p5 = (p2 + p3)/2;
     return world.Cars.Select(x => new ACar(x).GetRect(0)).Any(
         rect => Geom.ContainPoint(rect, p1) ||
                 Geom.ContainPoint(rect, p2) ||
                 Geom.ContainPoint(rect, p3) ||
                 Geom.ContainPoint(rect, p4) ||
                 Geom.ContainPoint(rect, p5)
         );
 }
Ejemplo n.º 8
0
Archivo: ACar.cs Proyecto: znsoft/AiCup
 public bool IntersectWith(ACar car, double safeMargin)
 {
     if (GetDistanceTo2(car) > Geom.Sqr(Const.CarDiagonalHalfLength + Const.CarDiagonalHalfLength))
         return false;
     return Geom.PolygonsIntersect(GetRect(0), car.GetRect(safeMargin));
 }