Пример #1
0
        // Find all reachable tiles.

        public static void DrawPath(MyPosition p1, MyPosition p2)
        {
            var k = 0;

            LogService.WriteLine("DIST: " + DistService.GetDist(p1, p2));
            while ((int)p1.X != (int)p2.X || (int)p1.Y != (int)p2.Y)
            {
                k++;
                if (k > 30)
                {
                    return;
                }
                var best     = p1;
                var bestDist = 100000000.0;
                for (var i = 0; i < 4; i++)
                {
                    var xx = (int)p1.X + dxes[i];
                    var yy = (int)p1.Y + dyes[i];
                    if (!Game.OnBoard(xx, yy) || Game.GetTile(xx, yy) == AiCup2019.Model.Tile.Wall)
                    {
                        continue;
                    }
                    //LogService.DrawLineBetweenCenter(p1, new MyPosition(xx, yy), 0, 0, 1);
                    var newPos = new MyPosition(xx, yy);
                    var dist   = GetDist(p2, newPos);
                    if (dist < bestDist)
                    {
                        best     = newPos;
                        bestDist = dist;
                    }
                }
                LogService.DrawLineBetweenCenter(p1, best, 0, 0, 1);
                p1 = best;
            }
        }
Пример #2
0
 private static MyPosition GetWeapon(MyGame game, SimUnit unit)
 {
     //if (unit.Allied != null)
     //{
     //    return new MyPosition(game.Weapons.Where(w => new MyPosition(w.Position).Dist(unit.Allied) >  .OrderBy(p => DistService.GetDist(new MyPosition(p.Position), unit.Position)).First().Position);
     //}
     return(new MyPosition(game.Weapons.OrderBy(p => DistService.GetDist(new MyPosition(p.Position), unit.Position)).First().Position));
 }
Пример #3
0
        private static MyPosition GetHealing(MyGame game, SimUnit unit)
        {
            var target = game.HealthPacks.OrderBy(p => DistService.GetDist(p, unit.Position)).FirstOrDefault(h => DistService.GetDist(h, unit.Position) < DistService.GetDist(h, unit.TargetEnemy.Position));

            if (target == null)
            {
                target = game.HealthPacks.OrderBy(p => DistService.GetDist(p, unit.Position)).First();
            }
            return(target);
        }
Пример #4
0
        public static MyPosition FindWalkTarget(SimGame game, SimUnit unit)
        {
            var target = GetRealTarget(game, unit);

            for (var y = (int)target.Y; y < game.game.Height; y++)
            {
                var p = new MyPosition(target.X, y);
                var d = DistService.GetDist(p, unit.Position);
                if (d < game.game.Width * game.game.Height * 4)
                {
                    target = p;
                    break;
                }
            }

            LogService.DrawLine(target, unit.Position, 1, 0, 0);
            return(target);
        }
Пример #5
0
        private static MyPosition Hide(SimGame game, SimUnit unit)
        {
            var heights = game.game.GetHideouts();

            return(heights.OrderByDescending(p => DistService.GetDist(p, unit.TargetEnemy.Position) - DistService.GetDist(unit.Position, p) * 0.5).FirstOrDefault() ?? unit.TargetEnemy.Position);
        }
Пример #6
0
        public static void Simulate(SimGame game, int depth, bool draw = false)
        {
            foreach (var unit in game.Units)
            {
                unit.GetNextMove(depth);
            }

            var steps = Const.Steps * Const.DepthPerMove;

            Const.Sims += Const.DepthPerMove;
            var timer = 0;

            for (var s = 0; s < steps; s++)
            {
                foreach (var u in game.Units)
                {
                    u.ApplyAction(u.CurrentAction, game, Const.Time, timer == 0);
                }

                if (timer == 3)
                {
                    foreach (var b in game.Bullets)
                    {
                        b.Move(game, Const.Time * Const.Steps);
                    }
                }

                if (timer-- <= 0)
                {
                    timer = Const.Steps;
                }
            }

            foreach (var u in game.Units)
            {
                if (draw)
                {
                    u.Draw(u.Health < u._health);
                }
                if (u.DidTouch)
                {
                    u.Score += DistService.GetDist(u.Position, u.WalkTarget);
                }
                else
                {
                    var d = DistService.GetDist(u.Position, u.WalkTarget) + Math.Abs(u.Position.X - u.WalkTarget.X) * 0.5;
                    u.Score -= d;
                    if (d < 0.6)
                    {
                        u.DidTouch = true;
                    }
                }
                if (!u.HasWeapon)
                {
                    continue;
                }

                foreach (var u2 in game.Units)
                {
                    if (u == u2)
                    {
                        continue;
                    }
                    if (u.TeamId == u2.TeamId)
                    {
                        if (Math.Abs(u.Position.X - u2.Position.X) < 3 && Math.Abs(u.Position.Y - u2.Position.Y) < 4)
                        {
                            u.Score -= 1000;
                        }
                    }
                    else if (Math.Abs(u.Position.X - u2.Position.X) < 3 && Math.Abs(u.Position.Y - u2.Position.Y) < 4)
                    {
                        u.Score -= 100;
                    }
                }
            }
        }