Esempio n. 1
0
        private static void PopulateMyHiddenTank(MyTank prevMyTank, List <Tree> trees, Direction?direction)
        {
            var prevMyTankStepPosition = prevMyTank.GetNextPositionNotCheckedForCanMove(direction);

            foreach (var tree in trees)
            {
                if (prevMyTankStepPosition != tree.Point)
                {
                    continue;
                }

                var thisHiddenMyTank = prevMyTank.DeepClone();
                thisHiddenMyTank.Point     = tree.Point;
                thisHiddenMyTank.Direction = direction;
                thisHiddenMyTank.UpdateElementByDirection();

                var cell = Field.GetCell(tree.Point);
                cell.Items.Insert(0, thisHiddenMyTank);
                State.ThisRound.MyTank = thisHiddenMyTank;

                if (State.PrevRound.CurrentMoveCommands.Contains(Direction.Act))
                {
                    var bulletPoint = BaseMobile.Shift(prevMyTank.Point, direction, Bullet.DefaultSpeed);

                    var bullet = new Bullet(Element.BULLET, bulletPoint);
                    bullet.Direction  = direction;
                    bullet.IsMyBullet = true;

                    var bulletCell = Field.GetCell(bulletPoint);
                    bulletCell.Items.Insert(0, bullet);
                    State.ThisRound.Bullets.Add(bullet);
                }
            }
        }
Esempio n. 2
0
        public static void CalculateTankShotPredictions(Point point, PredictionType type, Direction direction, BaseTank tank, int maxDepth = 1, List <Direction> command = null)
        {
            var startShotPoint = point;

            var startIndex = Math.Min(-1 - tank.ShotCountdownLeft, 1);

            //if (!tank.IsShotThisRound)
            //    return;


            for (var i = startIndex; i <= Bullet.DefaultSpeed * maxDepth; i++)
            {
                var shotPoint = BaseMobile.Shift(startShotPoint, direction);
                var shotCell  = Field.GetCell(shotPoint);

                var depth = (int)Math.Ceiling((decimal)i / 2);

                if (i >= -1)
                {
                    var actualDepth = Math.Max(1, tank.ShotCountdownLeft) + depth;
                    shotCell.AddPrediction(actualDepth, type, command);
                }

                if (shotCell.CanShootThrough)
                {
                    startShotPoint = shotPoint;
                }
                else
                {
                    break;
                }
            }
        }
Esempio n. 3
0
        private static void CalculateMyTankShotPredictions(Point point, Direction direction, List <Direction> command)
        {
            var startShotPoint = point;

            var startIndex = Math.Min(-1 - State.ThisRound.MyTank.ShotCountdownLeft, 1);

            for (var i = startIndex; i <= Bullet.DefaultSpeed * AppSettings.MyShotPredictionDepth; i++)
            {
                var shotPoint = BaseMobile.Shift(startShotPoint, direction);
                var shotCell  = Field.GetCell(shotPoint);

                var depth = (int)Math.Ceiling((decimal)i / 2);

                if (i >= -1)
                {
                    var actualDepth = (command.Count - 1) + Math.Max(0, State.ThisRound.MyTank.ShotCountdownLeft) + depth;

                    var directionActCommand = command.ToList();
                    directionActCommand.Add(Direction.Act);
                    shotCell.AddPrediction(actualDepth, PredictionType.MyShot, directionActCommand);
                }

                if (shotCell.CanShootThrough)
                {
                    startShotPoint = shotPoint;
                }
                else
                {
                    break;
                }
            }
        }
Esempio n. 4
0
        private static void PopulateMyTankUnderTrees()
        {
            Settings.Get.ShowMyTankUnderTree = false; //todo: temp
            if (!State.HasPrevRound || Settings.Get.ShowMyTankUnderTree || State.ThisRound.MyTank != null)
            {
                return;
            }

            var trees      = State.ThisRound.Trees;
            var prevMyTank = State.PrevRound.MyTank;

            if (prevMyTank == null)
            {
                return;
            }

            if (State.PrevRound.CurrentMoveCommands.Count == 1 && State.PrevRound.CurrentMoveCommands[0] == Direction.Act)
            {
                return;
            }

            var prevDirection          = State.PrevRound.CurrentMoveCommands.FirstOrDefault(x => BaseMobile.ValidDirections.Contains(x));
            var prevMyTankStepPosition = prevMyTank.GetNextPositionNotCheckedForCanMove(prevDirection);

            foreach (var tree in trees)
            {
                if (prevMyTankStepPosition == tree.Point)
                {
                    var thisHiddenMyTank = prevMyTank.DeepClone();
                    thisHiddenMyTank.Point            = tree.Point;
                    thisHiddenMyTank.CurrentDirection = prevDirection;

                    var cell = Field.GetCell(tree.Point);
                    cell.Items.Insert(0, thisHiddenMyTank);
                    State.ThisRound.MyTank = thisHiddenMyTank;

                    if (State.PrevRound.CurrentMoveCommands.Contains(Direction.Act))
                    {
                        var bulletPoint = BaseMobile.Shift(prevMyTank.Point, prevDirection, Bullet.DefaultSpeed);

                        var bullet = new Bullet(Element.BULLET, bulletPoint);
                        bullet.CurrentDirection = prevDirection;

                        var bulletCell = Field.GetCell(bulletPoint);
                        bulletCell.Items.Insert(0, bullet);
                        State.ThisRound.Bullets.Add(bullet);
                    }
                }
            }
        }
Esempio n. 5
0
        private static void PopulateAiTanksUnderTrees()
        {
            if (!State.HasPrevRound)
            {
                return;
            }

            var trees       = State.ThisRound.Trees;
            var prevAiTanks = State.PrevRound.AiTanks;

            foreach (var tree in trees)
            {
                var prevHiddenAiTank =
                    prevAiTanks.FirstOrDefault(b => b.GetNextPositionNotCheckedForCanMove() == tree.Point);

                if (prevHiddenAiTank == null)
                {
                    continue;
                }

                var thisHiddenAiTank = prevHiddenAiTank.DeepClone();
                thisHiddenAiTank.Point = tree.Point;

                var cell = Field.GetCell(tree.Point);
                cell.Items.Insert(0, thisHiddenAiTank);
                State.ThisRound.AiTanks.Add(thisHiddenAiTank);

                if (prevHiddenAiTank.IsShotThisRound && prevHiddenAiTank.Direction.HasValue)
                {
                    var bulletPoint = BaseMobile.Shift(prevHiddenAiTank.Point, prevHiddenAiTank.Direction,
                                                       Bullet.DefaultSpeed);

                    var bullet = new Bullet(Element.BULLET, bulletPoint);
                    bullet.Direction = prevHiddenAiTank.Direction;

                    var bulletCell = Field.GetCell(bulletPoint);
                    bulletCell.Items.Insert(0, bullet);
                    State.ThisRound.Bullets.Add(bullet);
                }
            }
        }
Esempio n. 6
0
        private static void CalculateEnemyShotForDirection(Point point, Direction direction, EnemyTank tank)
        {
            var startShotPoint = point;

            //var startIndex = Math.Min(-1 - tank.ShotCountdownLeft, 1);
            var startIndex = 1;

            for (var i = startIndex; i <= Bullet.DefaultSpeed * AppSettings.EnemyTankShotPredictionDepth; i++)
            {
                var shotPoint = BaseMobile.Shift(startShotPoint, direction);
                var shotCell  = Field.GetCell(shotPoint);

                if (shotCell.IsWall)
                {
                    break;
                }

                //var depth = (int)Math.Ceiling((decimal)i / 2);
                //var actualDepth = Math.Max(1, tank.ShotCountdownLeft) + depth;

                var depth = (int)Math.Ceiling((decimal)i / 2);

                var shotCountDownLeft = tank.ShotCountdownLeft;
                var actualDepth       = shotCountDownLeft + depth;

                shotCell.AddPrediction(actualDepth, PredictionType.EnemyShot);

                if (shotCell.CanShootThrough)
                {
                    startShotPoint = shotPoint;
                }
                else
                {
                    break;
                }
            }
        }
Esempio n. 7
0
        private static void CalculateMyShotsForDirection(Point point, Direction direction, List <Command> commands, List <Direction> command, bool correctFirstShotDepth = false)
        {
            var startShotPoint = point;

            //var startIndex = Math.Min(1 - State.ThisRound.MyTank.ShotCountdownLeft, 1);
            var startIndex = 1;

            for (var i = startIndex; i <= Bullet.DefaultSpeed * AppSettings.MyShotPredictionDepth; i++)
            {
                var shotPoint = BaseMobile.Shift(startShotPoint, direction);
                var shotCell  = Field.GetCell(shotPoint);

                if (shotCell.IsWall)
                {
                    break;
                }

                var depth = (int)Math.Ceiling((decimal)i / 2);
                if (correctFirstShotDepth)
                {
                    depth--;
                }

                var directionActCommand = command.ToList();
                directionActCommand.Add(Direction.Act);

                var directionActCommands = commands.ToList();
                directionActCommands.Add(new Command(directionActCommand.ToArray()));

                var commandRoundsCount = directionActCommands.Count;
                var shotDepth          = depth;

                //var depthShotDelay = commandRoundsCount + shotDepth;

                //var shotCountDownDifference = State.ThisRound.MyTank.ShotCountdownLeft - depthShotDelay;

                var notShotRoundsCount = directionActCommands.Count(x => !x.IsActCommand());
                var shotCountDownLeft  = Math.Max(State.ThisRound.MyTank.ShotCountdownLeft - notShotRoundsCount, 0);
                //var shotCountDownLeft = 0;

                var actualDepth = commandRoundsCount + shotDepth + shotCountDownLeft;

                //var currentDirectionStr = directionActCommand.CommandsToString();

                //var shotCellPredictions = shotCell.Predictions.MyShotPredictions
                //   .Where(x => x.Depth == actualDepth && x.Commands.AreSameCommands(directionActCommands))
                //    .ToList();

                //if (!shotCellPredictions.Any())
                shotCell.AddPrediction(actualDepth, PredictionType.MyShot, directionActCommands);

                if (shotCell.CanShootThrough)
                {
                    startShotPoint = shotPoint;
                }
                else
                {
                    break;
                }
            }
        }