Esempio n. 1
0
File: ACar.cs Progetto: znsoft/AiCup
 public bool TakeBonus(ABonus bonus)
 {
     if (GetDistanceTo2(bonus) > Geom.Sqr(Const.CarDiagonalHalfLength + Const.BonusDiagonalHalfLength))
     {
         return(false);
     }
     return(Geom.PolygonsIntersect(GetRect(0), bonus.GetRect()));
 }
Esempio n. 2
0
        public static void Draw()
        {
            if (_form.InvokeRequired)
            {
                _form.BeginInvoke(new DrawDelegate(Draw), new object[] { });
                return;
            }

            _renderTick++;
            if ((_renderTick - 1) % _myCarsCount != _myCarsCount - 1)
                return;

            var panel = _form.panel;

            _form.tickLabel.Text = MyStrategy.world.Tick + "";

            var drawArea = new Bitmap(panel.Size.Width, panel.Size.Height);
            panel.Image = drawArea;
            _graphics = Graphics.FromImage(drawArea);

            if (_myCarsCount == 1)
            {
                _form.jeepRadioButton.Enabled = false;
                _form.buggyRadioButton.Enabled = false;
                LookUp(new Point(MyStrategy.world.Cars.FirstOrDefault(x => x.IsTeammate)));
            }
            else
            {
                LookUp(
                    new Point(
                        MyStrategy.world.Cars.FirstOrDefault(
                            x =>
                                x.IsTeammate &&
                                (x.Type == CarType.Jeep && _form.jeepRadioButton.Checked ||
                                 x.Type == CarType.Buggy && _form.buggyRadioButton.Checked))));
            }

            //var myNextWp = MyStrategy.GetNextWayPoint(self);
            //FillRect(Brushes.Aqua, myNextWp.J * Const.TileSize, myNextWp.I * Const.TileSize, Const.TileSize, Const.TileSize);

            // tiles
            foreach (var tile in MyStrategy.MyTiles)
            {
                var margin = Const.TileMargin;
                var tsize = Const.TileSize;

                var dx = Const.TileSize*tile.J;
                var dy = Const.TileSize*tile.I;

                if (tile.Type == TileType.Unknown)
                    FillRect(Brushes.DarkGray, dx, dy, tsize, tsize);
                if (tile.Type == TileType.Empty)
                    FillRect(Brushes.Black, dx, dy, tsize, tsize);

                if (!tile.IsFreeLeft)
                    FillRect(Brushes.Black, dx, dy, margin, tsize);
                if (!tile.IsFreeTop)
                    FillRect(Brushes.Black, dx, dy, tsize, margin);
                if (!tile.IsFreeRight)
                    FillRect(Brushes.Black, dx + tsize - margin, dy, margin, tsize);
                if (!tile.IsFreeBottom)
                    FillRect(Brushes.Black, dx, dy + tsize - margin, tsize, margin);

                foreach (var part in tile.Parts)
                {
                    switch (part.Type)
                    {
                        case TilePartType.Circle:
                            FillCircle(Brushes.Black, part.Circle.X, part.Circle.Y, part.Circle.Radius);
                            break;
                        case TilePartType.Segment:
                            DrawLine(Brushes.DarkRed, part.Start.X, part.Start.Y, part.End.X, part.End.Y, 1);
                            break;
                        default:
                            throw new Exception("Unknown TilePartType");
                    }
                }
            }

            // Bonuses
            foreach (var bonus in MyStrategy.world.Bonuses)
            {
                var rect = new ABonus(bonus).GetRect();
                for (var i = 0; i < 4; i++)
                {
                    Brush brush;
                    if (bonus.Type == BonusType.PureScore)
                        brush = Brushes.OrangeRed;
                    else if (bonus.Type == BonusType.RepairKit)
                        brush = Brushes.LimeGreen;
                    else if (bonus.Type == BonusType.OilCanister)
                        brush = Brushes.DarkSlateGray;
                    else if (bonus.Type == BonusType.NitroBoost)
                        brush = Brushes.Blue;
                    else if (bonus.Type == BonusType.AmmoCrate)
                        brush = Brushes.DarkGoldenrod;
                    else
                        throw new Exception("Unknown BonusType");

                    DrawLine(brush, rect[i].X, rect[i].Y, rect[(i + 1) % 4].X, rect[(i + 1) % 4].Y, 2);
                }
            }

            // Cars
            foreach (var car in MyStrategy.world.Cars)
            {
                var isAvtive = DurabilityObserver.IsActive(car);
                var rect = new ACar(car).GetRectEx(isAvtive ? 0 : 1);
                for (var i = 0; i < 4; i++)
                {
                    DrawLine(car.IsTeammate ? Brushes.Green : Brushes.Red,
                        rect[i].X, rect[i].Y, rect[(i + 1)%4].X, rect[(i + 1)%4].Y,
                        isAvtive ? 2 : 1);
                }
                var to = Point.ByAngle(car.Angle)*100 + new Point(car);
                DrawLine(Brushes.Black, car.X, car.Y, to.X, to.Y, car.Type == CarType.Buggy ? 2 : 6);
                DrawText("~" + car.ProjectileCount, 50, Brushes.Black, car.X, car.Y);
            }

            // Oil
            foreach (var stick in MyStrategy.world.OilSlicks)
                FillCircle(Brushes.Black, stick.X, stick.Y, stick.Radius);

            // Nitro
            foreach (var car in MyStrategy.world.Cars)
            {
                if (car.RemainingNitroTicks > 0)
                    FillCircle(Brushes.Blue, car.X, car.Y, 40);
            }

            // Canisters
            foreach (var car in MyStrategy.world.Cars)
            {
                if (car.OilCanisterCount == 0)
                    continue;
                var canisterPen = car.RemainingOilCooldownTicks == 0 ? Pens.DarkSlateGray : Pens.Lavender;
                var slick = new AOilSlick(new ACar(car));
                DrawCircle(canisterPen, slick.X, slick.Y, slick.Radius);
                if (car.RemainingOiledTicks > 0)
                    FillCircle(Brushes.Black, car.X, car.Y, 30);
            }

            // Projectiles
            foreach (var pr in MyStrategy.world.Projectiles)
            {
                FillCircle(Brushes.OrangeRed, pr.X, pr.Y, pr.Radius);
            }

            // Segments
            try
            {
                foreach (var _el in SegmentsDrawQueue)
                {
                    var el = _el as object[];
                    var brush = el[0] as Brush;
                    var line = el[1] as Points;
                    var width = Convert.ToDouble(el[2]);
                    for (var i = 1; i < line.Count; i++)
                        DrawLine(brush, line[i - 1].X, line[i - 1].Y, line[i].X, line[i].Y, (float)width);
                }
            }
            catch (Exception)
            {
            }

            // Circles
            foreach (var el in CircleFillQueue)
            {
                var brush = el.Item1;
                var circle = el.Item2;
                FillCircle(brush, circle.X, circle.Y, circle.Radius);
            }

            CircleFillQueue.Clear();
            SegmentsDrawQueue.Clear();
        }
Esempio n. 3
0
        public static void Draw()
        {
            if (_form.InvokeRequired)
            {
                _form.BeginInvoke(new DrawDelegate(Draw), new object[] { });
                return;
            }

            _renderTick++;
            if ((_renderTick - 1) % _myCarsCount != _myCarsCount - 1)
            {
                return;
            }

            var panel = _form.panel;

            _form.tickLabel.Text = MyStrategy.world.Tick + "";

            var drawArea = new Bitmap(panel.Size.Width, panel.Size.Height);

            panel.Image = drawArea;
            _graphics   = Graphics.FromImage(drawArea);

            if (_myCarsCount == 1)
            {
                _form.jeepRadioButton.Enabled  = false;
                _form.buggyRadioButton.Enabled = false;
                LookUp(new Point(MyStrategy.world.Cars.FirstOrDefault(x => x.IsTeammate)));
            }
            else
            {
                LookUp(
                    new Point(
                        MyStrategy.world.Cars.FirstOrDefault(
                            x =>
                            x.IsTeammate &&
                            (x.Type == CarType.Jeep && _form.jeepRadioButton.Checked ||
                             x.Type == CarType.Buggy && _form.buggyRadioButton.Checked))));
            }

            //var myNextWp = MyStrategy.GetNextWayPoint(self);
            //FillRect(Brushes.Aqua, myNextWp.J * Const.TileSize, myNextWp.I * Const.TileSize, Const.TileSize, Const.TileSize);

            // tiles
            foreach (var tile in MyStrategy.MyTiles)
            {
                var margin = Const.TileMargin;
                var tsize  = Const.TileSize;

                var dx = Const.TileSize * tile.J;
                var dy = Const.TileSize * tile.I;

                if (tile.Type == TileType.Unknown)
                {
                    FillRect(Brushes.DarkGray, dx, dy, tsize, tsize);
                }
                if (tile.Type == TileType.Empty)
                {
                    FillRect(Brushes.Black, dx, dy, tsize, tsize);
                }

                if (!tile.IsFreeLeft)
                {
                    FillRect(Brushes.Black, dx, dy, margin, tsize);
                }
                if (!tile.IsFreeTop)
                {
                    FillRect(Brushes.Black, dx, dy, tsize, margin);
                }
                if (!tile.IsFreeRight)
                {
                    FillRect(Brushes.Black, dx + tsize - margin, dy, margin, tsize);
                }
                if (!tile.IsFreeBottom)
                {
                    FillRect(Brushes.Black, dx, dy + tsize - margin, tsize, margin);
                }

                foreach (var part in tile.Parts)
                {
                    switch (part.Type)
                    {
                    case TilePartType.Circle:
                        FillCircle(Brushes.Black, part.Circle.X, part.Circle.Y, part.Circle.Radius);
                        break;

                    case TilePartType.Segment:
                        DrawLine(Brushes.DarkRed, part.Start.X, part.Start.Y, part.End.X, part.End.Y, 1);
                        break;

                    default:
                        throw new Exception("Unknown TilePartType");
                    }
                }
            }

            // Bonuses
            foreach (var bonus in MyStrategy.world.Bonuses)
            {
                var rect = new ABonus(bonus).GetRect();
                for (var i = 0; i < 4; i++)
                {
                    Brush brush;
                    if (bonus.Type == BonusType.PureScore)
                    {
                        brush = Brushes.OrangeRed;
                    }
                    else if (bonus.Type == BonusType.RepairKit)
                    {
                        brush = Brushes.LimeGreen;
                    }
                    else if (bonus.Type == BonusType.OilCanister)
                    {
                        brush = Brushes.DarkSlateGray;
                    }
                    else if (bonus.Type == BonusType.NitroBoost)
                    {
                        brush = Brushes.Blue;
                    }
                    else if (bonus.Type == BonusType.AmmoCrate)
                    {
                        brush = Brushes.DarkGoldenrod;
                    }
                    else
                    {
                        throw new Exception("Unknown BonusType");
                    }

                    DrawLine(brush, rect[i].X, rect[i].Y, rect[(i + 1) % 4].X, rect[(i + 1) % 4].Y, 2);
                }
            }

            // Cars
            foreach (var car in MyStrategy.world.Cars)
            {
                var isAvtive = DurabilityObserver.IsActive(car);
                var rect     = new ACar(car).GetRectEx(isAvtive ? 0 : 1);
                for (var i = 0; i < 4; i++)
                {
                    DrawLine(car.IsTeammate ? Brushes.Green : Brushes.Red,
                             rect[i].X, rect[i].Y, rect[(i + 1) % 4].X, rect[(i + 1) % 4].Y,
                             isAvtive ? 2 : 1);
                }
                var to = Point.ByAngle(car.Angle) * 100 + new Point(car);
                DrawLine(Brushes.Black, car.X, car.Y, to.X, to.Y, car.Type == CarType.Buggy ? 2 : 6);
                DrawText("~" + car.ProjectileCount, 50, Brushes.Black, car.X, car.Y);
            }

            // Oil
            foreach (var stick in MyStrategy.world.OilSlicks)
            {
                FillCircle(Brushes.Black, stick.X, stick.Y, stick.Radius);
            }

            // Nitro
            foreach (var car in MyStrategy.world.Cars)
            {
                if (car.RemainingNitroTicks > 0)
                {
                    FillCircle(Brushes.Blue, car.X, car.Y, 40);
                }
            }



            // Canisters
            foreach (var car in MyStrategy.world.Cars)
            {
                if (car.OilCanisterCount == 0)
                {
                    continue;
                }
                var canisterPen = car.RemainingOilCooldownTicks == 0 ? Pens.DarkSlateGray : Pens.Lavender;
                var slick       = new AOilSlick(new ACar(car));
                DrawCircle(canisterPen, slick.X, slick.Y, slick.Radius);
                if (car.RemainingOiledTicks > 0)
                {
                    FillCircle(Brushes.Black, car.X, car.Y, 30);
                }
            }


            // Projectiles
            foreach (var pr in MyStrategy.world.Projectiles)
            {
                FillCircle(Brushes.OrangeRed, pr.X, pr.Y, pr.Radius);
            }

            // Segments
            try
            {
                foreach (var _el in SegmentsDrawQueue)
                {
                    var el    = _el as object[];
                    var brush = el[0] as Brush;
                    var line  = el[1] as Points;
                    var width = Convert.ToDouble(el[2]);
                    for (var i = 1; i < line.Count; i++)
                    {
                        DrawLine(brush, line[i - 1].X, line[i - 1].Y, line[i].X, line[i].Y, (float)width);
                    }
                }
            }
            catch (Exception)
            {
            }

            // Circles
            foreach (var el in CircleFillQueue)
            {
                var brush  = el.Item1;
                var circle = el.Item2;
                FillCircle(brush, circle.X, circle.Y, circle.Radius);
            }

            CircleFillQueue.Clear();
            SegmentsDrawQueue.Clear();
        }
Esempio n. 4
0
 public void AddBonus(ABonus bonus)
 {
     Weight -= bonus.Type == BonusType.PureScore ? 0.6 : 0.2;
 }
Esempio n. 5
0
File: ACar.cs Progetto: znsoft/AiCup
 public bool TakeBonus(ABonus bonus)
 {
     if (GetDistanceTo2(bonus) > Geom.Sqr(Const.CarDiagonalHalfLength + Const.BonusDiagonalHalfLength))
         return false;
     return Geom.PolygonsIntersect(GetRect(0), bonus.GetRect());
 }
Esempio n. 6
0
 public void AddBonus(ABonus bonus)
 {
     Weight -= bonus.Type == BonusType.PureScore ? 0.6 : 0.2;
 }