예제 #1
0
 public Trooper(long id, int x, int y, long playerId,
     int teammateIndex, bool isTeammate, TrooperType type, TrooperStance stance,
     int hitpoints, int maximalHitpoints, int actionPoints, int initialActionPoints,
     double visionRange, double shootingRange, int shootCost,
     int standingDamage, int kneelingDamage, int proneDamage, int damage,
     bool isHoldingGrenade, bool isHoldingMedikit, bool isHoldingFieldRation)
     : base(id, x, y)
 {
     this.playerId = playerId;
     this.teammateIndex = teammateIndex;
     this.isTeammate = isTeammate;
     this.type = type;
     this.stance = stance;
     this.hitpoints = hitpoints;
     this.maximalHitpoints = maximalHitpoints;
     this.actionPoints = actionPoints;
     this.initialActionPoints = initialActionPoints;
     this.visionRange = visionRange;
     this.shootingRange = shootingRange;
     this.shootCost = shootCost;
     this.standingDamage = standingDamage;
     this.kneelingDamage = kneelingDamage;
     this.proneDamage = proneDamage;
     this.damage = damage;
     this.isHoldingGrenade = isHoldingGrenade;
     this.isHoldingMedikit = isHoldingMedikit;
     this.isHoldingFieldRation = isHoldingFieldRation;
 }
예제 #2
0
파일: IfBonus.cs 프로젝트: znsoft/AiCup
 bool IsBetween(TrooperType a, TrooperType b, TrooperType c)
 {
     if (a == b || b == c)
     {
         return(false);
     }
     if (!TypeQueue.Contains(a) || !TypeQueue.Contains(b) || !TypeQueue.Contains(c))
     {
         return(false);
     }
     for (var i = 0;; i = (i + 1) % TypeQueue.Count)
     {
         if ((TrooperType)TypeQueue[i] == a)
         {
             for (var j = (i + 1) % TypeQueue.Count;; j = (j + 1) % TypeQueue.Count)
             {
                 if (b == (TrooperType)TypeQueue[j])
                 {
                     return(true);
                 }
                 if (c == (TrooperType)TypeQueue[j])
                 {
                     return(false);
                 }
             }
         }
     }
 }
예제 #3
0
        public ActionResult <TrooperTypeResponse> AddTrooperType([FromBody] AddTrooperTypeRequest trooperTypeRequest)
        {
            // Creates a new TrooperType and sets its properties to match the request
            var trooperType = new TrooperType
            {
                Speciality = trooperTypeRequest.Speciality,
                TypeName   = trooperTypeRequest.TypeName,
                Weapon     = trooperTypeRequest.Weapon,
                CreatedAt  = DateTime.Now
            };

            // Adds the trooperType to the database
            _empireDbContext.TrooperTypes.Add(trooperType);
            // COMMIT in sql
            _empireDbContext.SaveChanges();
            // Creates a new object of type TrooperTypeResponse
            // and sets its properties to match the trooperType in the database
            var response = new TrooperTypeResponse
            {
                Speciality = trooperType.Speciality,
                TypeName   = trooperType.TypeName,
                Weapon     = trooperType.Weapon
            };

            //Returns HttpStatusCode 200 with the response in the Body
            return(Ok(response));
        }
예제 #4
0
파일: Trooper.cs 프로젝트: znsoft/AiCup
 public Trooper(long id, int x, int y, long playerId,
                int teammateIndex, bool isTeammate, TrooperType type, TrooperStance stance,
                int hitpoints, int maximalHitpoints, int actionPoints, int initialActionPoints,
                double visionRange, double shootingRange, int shootCost,
                int standingDamage, int kneelingDamage, int proneDamage, int damage,
                bool isHoldingGrenade, bool isHoldingMedikit, bool isHoldingFieldRation)
     : base(id, x, y)
 {
     this.playerId             = playerId;
     this.teammateIndex        = teammateIndex;
     this.isTeammate           = isTeammate;
     this.type                 = type;
     this.stance               = stance;
     this.hitpoints            = hitpoints;
     this.maximalHitpoints     = maximalHitpoints;
     this.actionPoints         = actionPoints;
     this.initialActionPoints  = initialActionPoints;
     this.visionRange          = visionRange;
     this.shootingRange        = shootingRange;
     this.shootCost            = shootCost;
     this.standingDamage       = standingDamage;
     this.kneelingDamage       = kneelingDamage;
     this.proneDamage          = proneDamage;
     this.damage               = damage;
     this.isHoldingGrenade     = isHoldingGrenade;
     this.isHoldingMedikit     = isHoldingMedikit;
     this.isHoldingFieldRation = isHoldingFieldRation;
 }
예제 #5
0
파일: IfBonus.cs 프로젝트: znsoft/AiCup
 bool IsBetween(TrooperType a, TrooperType b, TrooperType c)
 {
     if (a == b || b == c)
         return false;
     if (!TypeQueue.Contains(a) || !TypeQueue.Contains(b) || !TypeQueue.Contains(c))
         return false;
     for (var i = 0;; i = (i + 1)%TypeQueue.Count)
     {
         if ((TrooperType)TypeQueue[i] == a)
         {
             for (var j = (i + 1)%TypeQueue.Count;; j = (j + 1)%TypeQueue.Count)
             {
                 if (b == (TrooperType)TypeQueue[j])
                     return true;
                 if (c == (TrooperType)TypeQueue[j])
                     return false;
             }
         }
     }
 }
예제 #6
0
 public MyTrooper(Trooper trooper)
     : base(trooper.Id, trooper.X, trooper.Y)
 {
     this.playerId = trooper.PlayerId;
     this.teammateIndex = trooper.TeammateIndex;
     this.isTeammate = trooper.IsTeammate;
     this.type = trooper.Type;
     this.stance = trooper.Stance;
     this.hitpoints = trooper.Hitpoints;
     this.maximalHitpoints = trooper.MaximalHitpoints;
     this.actionPoints = trooper.ActionPoints;
     this.initialActionPoints = trooper.InitialActionPoints;
     this.visionRange = trooper.VisionRange;
     this.shootingRange = trooper.ShootingRange;
     this.shootCost = trooper.ShootCost;
     this.standingDamage = trooper.StandingDamage;
     this.kneelingDamage = trooper.KneelingDamage;
     this.proneDamage = trooper.ProneDamage;
     this.damage = trooper.Damage;
     this.isHoldingGrenade = trooper.IsHoldingGrenade;
     this.isHoldingMedikit = trooper.IsHoldingMedikit;
     this.isHoldingFieldRation = trooper.IsHoldingFieldRation;
 }
예제 #7
0
        void InitializeVariables()
        {
            this.troopers = world.Troopers;
            this.Bonuses  = world.Bonuses;
            this.Cells    = world.Cells;
            this.Width    = world.Width;
            this.Height   = world.Height;
            if (AlivePlayers == null)
            {
                AlivePlayers = new ArrayList();
                foreach (var pl in world.Players)
                {
                    AlivePlayers.Add(pl);
                }
            }
            if (map == null)
            {
                map = new int[Width, Height];
            }
            if (notFilledMap == null)
            {
                notFilledMap = new int[Width, Height];
            }
            for (var i = 0; i < Width; i++)
            {
                for (var j = 0; j < Height; j++)
                {
                    map[i, j]          = Cells[i][j] == 0 ? 0 : 1;
                    notFilledMap[i, j] = map[i, j];
                }
            }
            if (CellDanger == null)
            {
                CellDanger     = new double[Width, Height, 3];
                CellDangerFrom = new double[Width, Height, 3];
                CellDangerTo   = new double[Width, Height, 3];
                for (var i = 0; i < Width; i++)
                {
                    for (var j = 0; j < Height; j++)
                    {
                        if (notFilledMap[i, j] == 0)
                        {
                            for (var s = 0; s < 3; s++)
                            {
                                for (var x = 0; x < Width; x++)
                                {
                                    for (var y = 0; y < Height; y++)
                                    {
                                        if (notFilledMap[x, y] == 0)
                                        {
                                            for (var z = 0; z < 3; z++)
                                            {
                                                if (world.IsVisible(7, i, j, GetStance(s), x, y, GetStance(z)))
                                                {
                                                    CellDangerFrom[i, j, s] += 1;
                                                    CellDangerTo[x, y, z]   += 1;
                                                }
                                            }
                                        }
                                    }
                                }
                                CellDanger[i, j, s] = CellDangerTo[i, j, s] / CellDangerFrom[i, j, s];
                            }
                        }
                    }
                }
            }

            Opponents = new Trooper[0];
            Team      = new Trooper[0];
            Friends   = new Trooper[0];
            OpponentsMemoryAppearTime = new int[0];
            OpponentsMemoryType       = new TrooperType[0];

            foreach (var tr in troopers)
            {
                map[tr.X, tr.Y] = 1;
                if (tr.IsTeammate)
                {
                    Team = Append(Team, tr);
                    if (tr.Id != self.Id)
                    {
                        Friends = Append(Friends, tr);
                    }
                }
                else
                {
                    Opponents = Append(Opponents, tr);
                    OpponentsMemoryAppearTime = Append(OpponentsMemoryAppearTime, world.MoveIndex);
                    OpponentsMemoryType       = Append(OpponentsMemoryType, self.Type);
                }
            }

            if (MapHash == -1)
            {
                MapHash = GetMapHash();
#if DEBUG
                Console.WriteLine(MapHash);
#endif
            }

            // Менять радиус в зависимости от количества оставшихся ходов:
            // Тогда будет возможность отбежать обратно
            MaxTeamRadius = 2;
            if (Team.Count() > 3 /* && self.ActionPoints >= 2*GetMoveCost(self)*/)
            {
                MaxTeamRadius += 1;
            }
            if (Team.Count() > 4)
            {
                MaxTeamRadius += 0.5;
            }
            if (MapHash == CheeserMap)
            {
                MaxTeamRadius += 4;
            }

            // Загружаем труперов с прошлого хода, и сохраняем с текущего
            // past - трупер
            // when - время, в которое был последний раз виден трупер
            // who - кто его видел последний раз
            for (var i = 0; i < PastTroopersInfo.Count; i += 3)
            {
                var past = PastTroopersInfo[i] as Trooper;
                var when = (int)PastTroopersInfo[i + 1];
                var who  = (TrooperType)PastTroopersInfo[i + 2];
                if (world.MoveIndex - when > 2)
                {
                    continue;
                }

                if (!Opponents.Any(trooper => trooper.Id == past.Id) && !IsVisible(past.X, past.Y))
                {
                    Opponents = Append(Opponents, past);
                    OpponentsMemoryAppearTime = Append(OpponentsMemoryAppearTime, when);
                    OpponentsMemoryType       = Append(OpponentsMemoryType, who);
                    troopers = Append(troopers, past);
                }
            }
            PastTroopersInfo.Clear();
            for (var i = 0; i < Opponents.Count(); i++)
            {
                PastTroopersInfo.Add(GetClone(Opponents[i], 0));
                PastTroopersInfo.Add(OpponentsMemoryAppearTime[i]);
                PastTroopersInfo.Add(OpponentsMemoryType[i]);
            }

            if (changedCommander != -1 && world.MoveIndex - changedCommander >= 3)
            {
                ChangeCommander();
            }
            commander = GetCommander();

            danger = new int[Width, Height];
            foreach (var tr in Opponents)
            {
                for (var i = 0; i < Width; i++)
                {
                    for (var j = 0; j < Height; j++)
                    {
                        if (world.IsVisible(GetShootingRange(tr, tr.Stance), tr.X, tr.Y, tr.Stance, i, j, self.Stance))
                        {
                            danger[i, j]++;
                        }
                        if (world.IsVisible(GetVisionRange(tr, self, self.Stance), tr.X, tr.Y, tr.Stance, i, j, self.Stance))
                        {
                            danger[i, j]++;
                        }
                    }
                }
            }

            if (queue.Count == 0 || (long)queue[queue.Count - 1] != self.Id)
            {
                queue.Add(self.Id);
                TypeQueue.Add(self.Type);
            }
        }