Ejemplo n.º 1
0
 // Проверка движение хоккеиста
 void Research3(Hockeyist self)
 {
     var range = TurnRange(new AHock(self).AAgility);
     move.Turn = range / 2;
     move.SpeedUp = 0.8;
     var pl = new AHock(self);
     pl.Move(0.8, range / 2, 20);
 }
Ejemplo n.º 2
0
 public int GetTicksTo(Point to, Hockeyist my, bool tryDown = true)
 {
     var ho = new AHock(my);
     var up = GetTicksToUp(ho, to);
     var down = tryDown ? GetTicksToDown(ho, to) : Inf;
     if (up <= down)
         return up;
     return -down;
 }
Ejemplo n.º 3
0
		public HunterBehaviour (Hockeyist h) : base(h)
		{
			getThePuck = new GetThePuckBehaviour (h);
			strikePoints = new[]
			{
				new Point(attackLine, 650),
				new Point(attackLine, 250)
			};
		}
Ejemplo n.º 4
0
 public void Move(Hockeyist self, World world, Game game, Move move)
 {
     move.Action = ActionType.None;
     move.PassAngle = 0.0;
     move.PassPower = 0.0;
     move.SpeedUp = 0.0;
     move.TeammateIndex = -1;
     move.Turn = 0.0;
 }
Ejemplo n.º 5
0
 public AHock(Point pos, Point speed, double angle, double angularSpeed, int coolDown, int knockDown, double stamina, Hockeyist from)
     : base(pos, speed, angle)
 {
     Base = from;
     AngularSpeed = angularSpeed;
     Angle = angle;
     CoolDown = coolDown;
     KnockDown = knockDown;
     Stamina = stamina;
 }
Ejemplo n.º 6
0
        public double Stamina; // TODO: учитавать изменение?

        #endregion Fields

        #region Constructors

        public AHock(Hockeyist self)
            : base(MyStrategy.Get(self), MyStrategy.GetSpeed(self), self.Angle)
        {
            Base = self;
            AngularSpeed = self.AngularSpeed;
            Angle = self.Angle;
            CoolDown = self.RemainingCooldownTicks;
            KnockDown = self.RemainingKnockdownTicks;
            Stamina = self.Stamina;
        }
Ejemplo n.º 7
0
        public Point FindWayPoint(Hockeyist self)
        {
            var okDist = 5*HoRadius;

            var bestTime = Inf;
            Point sel = null;
            //TimerStart();
            var bot = Hockeyists.Count(x => !x.IsTeammate && IsInGame(x) && x.Y > RinkCenter.Y);
            var top = Hockeyists.Count(x => !x.IsTeammate && IsInGame(x) && x.Y <= RinkCenter.Y);

            foreach (Point p in WayPoints.ToArray().OrderBy(x => ((Point) x).GetDistanceTo(self)).Take(10))
            {
                var I = new AHock(self);
                if (p.GetDistanceTo2(I) <= okDist*okDist || MyRight() && I.X < p.X || MyLeft() && I.X > p.X)
                    continue;

                var cands = Hockeyists
                    .Where(x => !x.IsTeammate && IsInGame(x))
                    .Select(x => new AHock(x)).ToArray();

                var time = 0;
                var ok = true;
                while (p.GetDistanceTo2(I) > okDist*okDist && ok)
                {
                    I.MoveTo(p);
                    foreach (var c in cands)
                    {
                        c.MoveTo(I);
                        if (CanStrike(c, I.PuckPos()) // достанет шайбу
                            || CanStrike(c, I) // достанет меня
                            || I.GetDistanceTo2(c) <= 2*HoRadius*2*HoRadius // столкнется со мной
                            )
                        {
                            ok = false;
                            break;
                        }
                    }
                    time++;
                }
                if (ok)
                {
                    if (p.Y > RinkCenter.Y && bot > top || p.Y <= RinkCenter.Y && top > bot)
                        time *= 3;
                    if (time < bestTime)
                    {
                        bestTime = time;
                        sel = p.Clone();
                    }
                }
            }
            //Log("FindWayPoint " + TimerStop());
            return sel;
        }
Ejemplo n.º 8
0
        public bool FindPath(Hockeyist self, Point to, Point lookAt)
        {
            if (lookAt == null)
                return StopOn(new AHock(self), to);

            var okDist = HoRadius * 1.5;

            var minTime = Inf;
            var selTurn = 0.0;
            var selSpUp = 0.0;
            for (var dir = -1; dir <= 1; dir += 2)
            {
                var hock = new AHock(self);
                for (var ticksDirect = 0; ticksDirect < 100; ticksDirect++)
                {
                    var curTime = ticksDirect;
                    var ho = hock.Clone();
                    while (Math.Abs(ho.GetAngleTo(lookAt)) > Deg(8))
                    {
                        ho.Move(0, TurnNorm(ho.GetAngleTo(lookAt), ho.AAgility));
                        curTime++;
                    }
                    if (curTime < minTime && ho.GetDistanceTo(to) < okDist)
                    {
                        minTime = curTime;
                        if (ticksDirect == 0)
                        {
                            selSpUp = 0.0;
                            selTurn = TurnNorm(ho.GetAngleTo(lookAt), hock.AAgility);
                        }
                        else if (dir > 0)
                        {
                            selTurn = self.GetAngleTo(to.X, to.Y);
                            selSpUp = GetSpeedTo(selTurn);
                        }
                        else
                        {
                            selTurn = RevAngle(self.GetAngleTo(to.X, to.Y));
                            selSpUp = -GetSpeedTo(selTurn);
                        }
                    }
                    if (dir > 0)
                        GetTicksToUpN(hock, to, 0, 1);
                    else
                        GetTicksToDownN(hock, to, 0, 1);
                }
            }
            move.SpeedUp = selSpUp;
            move.Turn = selTurn;
            return minTime != Inf;
        }
Ejemplo n.º 9
0
        public void Move(Hockeyist self, World world, Game game, Move move)
        {
            if (self.State == HockeyistState.Swinging)
            {
                move.Action = ActionType.Strike;
                return;
            }

            if (world.Puck.OwnerPlayerId == self.PlayerId)
            {
                if (world.Puck.OwnerHockeyistId == self.Id)
                {
                    Player opponentPlayer = world.GetOpponentPlayer();

                    double netX = 0.5D * (opponentPlayer.NetBack + opponentPlayer.NetFront);
                    double netY = 0.5D * (opponentPlayer.NetBottom + opponentPlayer.NetTop);
                    netY += (self.Y < netY ? 0.5D : -0.5D) * game.GoalNetHeight;

                    double angleToNet = self.GetAngleTo(netX, netY);
                    move.Turn = angleToNet;

                    if (Math.Abs(angleToNet) < STRIKE_ANGLE)
                    {
                        move.Action = ActionType.Swing;
                    }
                }
                else
                {
                    Hockeyist nearestOpponent = getNearestOpponent(self.X, self.Y, world);
                    if (nearestOpponent != null)
                    {
                        if (self.GetDistanceTo(nearestOpponent) > game.StickLength)
                        {
                            move.SpeedUp = 1.0D;
                        }
                        else if (Math.Abs(self.GetAngleTo(nearestOpponent)) < 0.5D * game.StickSector)
                        {
                            move.Action = ActionType.Strike;
                        }
                        move.Turn = self.GetAngleTo(nearestOpponent);
                    }
                }
            }
            else
            {
                move.SpeedUp = 1.0D;
                move.Turn = self.GetAngleTo(world.Puck);
                move.Action = ActionType.TakePuck;
            }
        }
Ejemplo n.º 10
0
        public World(int tick, int tickCount, double width, double height, Player[] players, Hockeyist[] hockeyists,
                Puck puck) {
            this.tick = tick;
            this.tickCount = tickCount;
            this.width = width;
            this.height = height;

            this.players = new Player[players.Length];
            Array.Copy(players, this.players, players.Length);

            this.hockeyists = new Hockeyist[hockeyists.Length];
            Array.Copy(hockeyists, this.hockeyists, hockeyists.Length);

            this.puck = puck;
        }
Ejemplo n.º 11
0
        public Tuple<Point, int, int> GoToPuck(Hockeyist my, APuck pk, int ticksLimit = 300, bool tryDown = true)
        {
            if (my.Id == puck.OwnerHockeyistId)
                return new Tuple<Point, int, int>(null, 0, 0);

            if (ticksLimit == -1)
                ticksLimit = 300;

            const int noBs = 100;

            var res = Inf;
            var dir = 1;
            var owner = Hockeyists.FirstOrDefault(x => x.Id == puck.OwnerHockeyistId);
            var ho = owner == null ? null : new AHock(owner);
            if (pk == null)
                pk = new APuck(puck, OppGoalie);
            else
                ho = null;

            var result = new Point(pk);
            int tLeft = 0, tRight = ticksLimit;
            var pks = new APuck[tRight + 1];
            var hhs = new AHock[tRight + 1];
            pks[0] = pk.Clone();
            hhs[0] = ho;
            for (var i = 1; i <= tRight; i++)
            {
                pks[i] = pks[i - 1].Clone();
                hhs[i] = ho == null ? null : hhs[i - 1].Clone();
                PuckMove(1, pks[i], hhs[i]);
            }
            while (ticksLimit > noBs && tLeft <= tRight)
            {
                var c = (tLeft + tRight)/2;
                var needTicks = GetTicksTo(PuckMove(0, pks[c], hhs[c]), my, tryDown);
                if (Math.Abs(needTicks) < c)
                {
                    tRight = c - 1;
                    res = c;
                    result = PuckMove(0, pks[c], hhs[c]);
                    dir = needTicks >= 0 ? 1 : -1;
                }
                else
                {
                    tLeft = c + 1;
                }
            }
            const int by = 10;
            for (var c = 0; c <= noBs && c <= ticksLimit; c += c < by ? 1 : by)
            {
                var needTicks = GetTicksTo(PuckMove(0, pks[c], hhs[c]), my, tryDown);
                if (Math.Abs(needTicks) <= c)
                {
                    for (var i = 0; i < by; i++, c--)
                    {
                        if (Math.Abs(needTicks) <= c)
                        {
                            res = c;
                            result = PuckMove(0, pks[c], hhs[c]);
                            dir = needTicks >= 0 ? 1 : -1;
                        }
                    }
                    break;
                }
            }
            return new Tuple<Point, int, int>(result, dir, res);
        }
Ejemplo n.º 12
0
        public void Move(Hockeyist self, World world, Game game, Move move)
        {
            OP = world.GetOpponentPlayer();
            MP = world.GetMyPlayer();
            RinkMiddleHeight = (game.RinkTop + game.RinkBottom) / 2;
            RinkMiddleWidth = (game.RinkLeft + game.RinkRight) / 2;
            double TX;
            double TY;

            // 0. Таблица ударных позиций
            /*
            using (System.IO.StreamWriter sw = new System.IO.StreamWriter("Speed.txt"))
            {
                double[,] xy = new double[200, 200];
                for (double speed = 0.0; speed <= 70.0; speed += 1.0)
                    for (double y = game.RinkTop; y <= game.RinkBottom; y += 10.0)
                        for (double x = game.RinkLeft; x <= game.RinkRight; x += 10.0)
                        {
                            TX = OP.NetFront;
                            TY = (y <= RinkMiddleHeight) ? OP.NetBottom - 9 : OP.NetTop + 9;
                            if (CanShot(GetAngleBetween(x, y, TX, TY, 0), self.Radius, x, y, world.Puck.Radius,
                                speed, Math.PI / 3, OP.NetFront, (y >= RinkMiddleHeight) ? OP.NetBottom : OP.NetTop, game.GoalieMaxSpeed))
                                if (xy[(int)(x / 10), (int)(y / 10)] == 0)
                                    xy[(int)(x / 10), (int)(y / 10)] = speed;
                        }

                for (double y = game.RinkTop; y <= game.RinkBottom; y += 10.0)
                {
                    for (double x = game.RinkLeft; x <= game.RinkRight; x += 10.0)
                        sw.Write("{0} ", ((int)(xy[(int)(x / 10), (int)(y / 10)])).ToString("D2"));
                    sw.WriteLine();
                }
                return;
            }
            */

            // 1. Завершение удара
            // если идет замах более 13 тиков, то ударить
            if (self.LastAction == ActionType.Swing && world.Tick - self.LastActionTick >= 13.0)
            {
                move.Action = ActionType.Strike;
                return;
            }

            // 2. Назначение второго вратаря
            // TX, TY - координаты позиции второго вратаря
            TX = (MP.NetFront < RinkMiddleWidth) ? MP.NetFront + 80 : MP.NetFront - 80;
            TY = RinkMiddleHeight;

            // проверить является ли хоккеист ближайшим к позиции вратаря
            bool nearest = true;
            foreach (Hockeyist h in world.Hockeyists)
                if (self.GetDistanceTo(TX, TY) > h.GetDistanceTo(TX, TY) &&
                    h.PlayerId == MP.Id &&
                    h.Type != HockeyistType.Goalie)
                    nearest = false;

            // ближайщий к воротам не владеющий шайбой становится вторым вратарем
            if (world.Puck.OwnerPlayerId == MP.Id && world.Puck.OwnerHockeyistId != self.Id ||
                world.Puck.OwnerPlayerId != MP.Id && nearest)
            {
                if (self.GetDistanceTo(world.Puck) < game.StickLength &&
                    Math.Abs(self.GetAngleTo(world.Puck)) <= game.StickSector)
                {
                    if (world.Puck.SpeedX * world.Puck.SpeedX +
                        world.Puck.SpeedY * world.Puck.SpeedY < 12.0 * 12.0 &&
                        world.Puck.OwnerHockeyistId == -1)
                    {
                        move.Action = ActionType.TakePuck;
                        return;
                    }
                    else
                    {
                        move.Action = ActionType.Strike;
                        return;
                    }
                }

                if (self.GetDistanceTo(world.Puck) < 2.6 * game.StickLength &&
                    self.GetDistanceTo(TX, TY) < 1.2 * game.StickLength &&
                    world.Puck.OwnerHockeyistId != MP.Id)
                {
                    move.SpeedUp = 1.0;
                    move.Turn = self.GetAngleTo(world.Puck);
                    return;
                }
                else
                    if (self.GetDistanceTo(world.Puck) < 5 * game.StickLength && self.GetDistanceTo(TX, TY) < 30)
                    {
                        move.SpeedUp = 0.0;
                        move.Turn = self.GetAngleTo(world.Puck);
                    }
                    else
                        GoTo(self, TX, TY, 0, 0, 200, game, move);

                // выбрать первого попавшегося вражеского игрока и бить клюшкой
                foreach (Hockeyist h in world.Hockeyists)
                    if (h.IsTeammate == false &&
                        h.Type != HockeyistType.Goalie &&
                        h.State == HockeyistState.Active)
                        if (self.GetDistanceTo(h) < game.StickLength &&
                            Math.Abs(self.GetAngleTo(h)) <= game.StickSector)
                        {
                            move.Action = ActionType.Strike;
                            return;
                        }

                // вратарь ничего не делает
                return;
            }

            // 3. Отбор шайбы
            // наша команда не владеет шайбой
            if (world.Puck.OwnerPlayerId != MP.Id)
            {
                // двигаться к шайбе
                GoTo(self, world.Puck, 0, game, move);

                // если шайбой никто не владеет и она в пределах клюшки, подобрать
                if (world.Puck.OwnerHockeyistId == -1 &&
                    self.GetDistanceTo(world.Puck) < game.StickLength &&
                    Math.Abs(self.GetAngleTo(world.Puck)) <= game.StickSector)
                {
                    move.Action = ActionType.TakePuck;
                    return;
                }

                // если вражеский хоккеист в пределах клюшки, ударить его
                foreach (Hockeyist h in world.Hockeyists)
                    if (h.Id == world.Puck.OwnerHockeyistId)
                    {
                        // двигаться к владельцу шайбы
                        GoTo(self, h, 0, game, move);
                        if (self.GetDistanceTo(h) < game.StickLength &&
                            Math.Abs(self.GetAngleTo(h)) <= game.StickSector)
                        {
                            move.Action = ActionType.Strike;
                            return;
                        }
                    }

                // команда без шайбы, а хоккеист ничего не делает
                return;
            }

            // 4. Атака
            // наша команда владеет шайбой
            else
                // если хоккеист владеет шайбой
                if (world.Puck.OwnerHockeyistId == self.Id)
                {
                    TX = OP.NetFront;
                    TY = (world.Puck.Y <= RinkMiddleHeight) ? OP.NetBottom - 9 : OP.NetTop + 9;

                    // если можно забить страйком
                    if (CanShot(self, world.Puck, 20.0, Math.PI / 360.0, TX, TY, game.GoalieMaxSpeed))
                    {
                        move.Action = ActionType.Swing;
                        return;
                    }

                    // если можно забить пасом
                    if (CanShot(self, world.Puck, 15.0, Math.PI / 3.0, TX, TY, game.GoalieMaxSpeed))
                    {
                        move.PassPower = 1.0;
                        move.PassAngle = GetAngleBetween(world.Puck.X, world.Puck.Y,
                            TX, TY, self.Angle);
                        move.Action = ActionType.Pass;
                        return;
                    }

                    // ВЫБОР НАПРАВЛЕНИЯ
                    // нужно выбрать и ехать к ударной позиции
                    TX = RinkMiddleWidth;
                    TY = RinkMiddleHeight;
                    double dX = 110.0;
                    double X1 = 367.5;
                    double Y1 = 107.0;
                    double X2 = 267.5;
                    double Y2 = 207.0;
                    double t;
                    if (world.Puck.Y <= RinkMiddleHeight && OP.NetFront < RinkMiddleWidth)
                    {
                        if (world.Puck.X - dX >= game.RinkLeft + X1)
                        {
                            TX = world.Puck.X - dX;
                            TY = game.RinkTop + Y1;
                        }
                        else
                            if (world.Puck.X - dX >= game.RinkLeft + X2)
                            {
                                TX = world.Puck.X - dX;
                                t = (TX - game.RinkLeft - X2) / (X1 - X2);
                                TY = game.RinkTop + Y1 * t + Y2 * (1 - t);
                            }
                            else
                            {
                                TX = game.RinkLeft + X2;
                                TY = game.RinkTop + Y2;
                            }
                    }
                    if (world.Puck.Y <= RinkMiddleHeight && OP.NetFront >= RinkMiddleWidth)
                    {
                        if (world.Puck.X + dX <= game.RinkRight - X1)
                        {
                            TX = world.Puck.X + dX;
                            TY = game.RinkTop + Y1;
                        }
                        else
                            if (world.Puck.X + dX <= game.RinkRight - X2)
                            {
                                TX = world.Puck.X + dX;
                                t = (game.RinkRight - TX - X2) / (X1 - X2);
                                TY = game.RinkTop + Y1 * t + Y2 * (1 - t);
                            }
                            else
                            {
                                TX = game.RinkRight - X2;
                                TY = game.RinkTop + Y2;
                            }
                    }
                    if (world.Puck.Y > RinkMiddleHeight && OP.NetFront < RinkMiddleWidth)
                    {
                        if (world.Puck.X - dX >= game.RinkLeft + X1)
                        {
                            TX = world.Puck.X - dX;
                            TY = game.RinkBottom - Y1;
                        }
                        else
                            if (world.Puck.X - dX >= game.RinkLeft + X2)
                            {
                                TX = world.Puck.X - dX;
                                t = (TX - game.RinkLeft - X2) / (X1 - X2);
                                TY = game.RinkBottom - Y1 * t - Y2 * (1 - t);
                            }
                            else
                            {
                                TX = game.RinkLeft + X2;
                                TY = game.RinkBottom - Y2;
                            }
                    }
                    if (world.Puck.Y > RinkMiddleHeight && OP.NetFront >= RinkMiddleWidth)
                    {
                        if (world.Puck.X + dX <= game.RinkRight - X1)
                        {
                            TX = world.Puck.X + dX;
                            TY = game.RinkBottom - Y1;
                        }
                        else
                            if (world.Puck.X + dX <= game.RinkRight - X2)
                            {
                                TX = world.Puck.X + dX;
                                t = (game.RinkRight - TX - X2) / (X1 - X2);
                                TY = game.RinkBottom - Y1 * t - Y2 * (1 - t);
                            }
                            else
                            {
                                TX = game.RinkRight - X2;
                                TY = game.RinkBottom - Y2;
                            }
                    }

                    if (world.Puck.X > RinkMiddleWidth && OP.NetFront <= RinkMiddleWidth)
                    {
                        TX = world.Puck.X - dX;
                        Hockeyist hm = null;
                        foreach (Hockeyist h in world.Hockeyists)
                            if (h.IsTeammate == false &&
                                h.Type != HockeyistType.Goalie &&
                                (hm == null || self.GetDistanceTo(hm) > self.GetDistanceTo(h)))
                                hm = h;
                        if (hm.Y <= self.Y)
                            TY = game.RinkBottom - Y1;
                        else
                            TY = game.RinkTop + Y1;
                    }
                    if (world.Puck.X <= RinkMiddleWidth && OP.NetFront > RinkMiddleWidth)
                    {
                        TX = world.Puck.X + dX;
                        Hockeyist hm = null;
                        foreach (Hockeyist h in world.Hockeyists)
                            if (h.IsTeammate == false &&
                                h.Type != HockeyistType.Goalie &&
                                (hm == null || self.GetDistanceTo(hm) > self.GetDistanceTo(h)))
                                hm = h;
                        if (hm.Y <= self.Y)
                            TY = game.RinkBottom - Y1;
                        else
                            TY = game.RinkTop + Y1;
                    }

                    // ПРОДВИЖЕНИЕ
                    // если позиция далеко, ехать дальше
                    if (world.Puck.GetDistanceTo(TX, TY) >= 100.0)
                    {
                        move.SpeedUp = 1.0;
                        move.Action = ActionType.None;
                        move.Turn = self.GetAngleTo(TX, TY);
                    }

                    // около ударной позиции замедлиться, развернуться
                    // и замахнуться в верхнюю или нижнюю штангу
                    else
                    {
                        TY = (world.Puck.Y >= RinkMiddleHeight) ? OP.NetTop + 9 : OP.NetBottom - 9;
                        move.SpeedUp = 0.0;
                        move.Turn = self.GetAngleTo(OP.NetFront, TY);
                        if (Math.Abs(GetAngleBetween(world.Puck.X, world.Puck.Y,
                            OP.NetFront, TY, self.Angle)) <= Math.PI / 360.0)
                        {
                            move.Action = ActionType.Swing;
                            return;
                        }
                        else
                            move.Action = ActionType.None;
                    }

                    // можно отдать пас
                    foreach (Hockeyist h in world.Hockeyists)
                        if (h.IsTeammate == true &&
                            h.Type != HockeyistType.Goalie &&
                            h.State == HockeyistState.Active)
                            if (Math.Abs(self.GetAngleTo(h)) <= Math.PI / 90.0)
                            {
                                move.PassAngle = self.GetAngleTo(h);
                                move.PassPower = 0.75;
                                move.Action = ActionType.Pass;
                            }

                    // хоккеист владеет шайбой и при этом ничего не делает
                    return;
                }

                // хоккеист без шайбы атакует вражеских хоккеистов
                else
                {
                    // выбрать первого попавшегося вражеского игрока и бить клюшкой
                    foreach (Hockeyist h in world.Hockeyists)
                        if (h.IsTeammate == false &&
                            h.Type != HockeyistType.Goalie &&
                            h.State == HockeyistState.Active)
                        {
                            move.SpeedUp = 1.0;
                            move.Turn = self.GetAngleTo(h);
            //                            GoTo(self, h, 0, game, move);

                            if (self.GetDistanceTo(h) < game.StickLength &&
                                Math.Abs(self.GetAngleTo(h)) <= game.StickSector)
                                move.Action = ActionType.Strike;
                            else
                                move.Action = ActionType.TakePuck;
                            return;
                        }

                    // хоккеист без шайбы и при этом ничего не делает
                    return;
                }
        }
Ejemplo n.º 13
0
        public void Move(Hockeyist self, World world, Game game, Move move)
        {
            if (self.State == HockeyistState.Resting)
                return;

            ShowWindow();

            // // fill globals
            _strikePoint = null;
            Hockeyists = world.Hockeyists;
            MyRest = Hockeyists.Where(x => x.IsTeammate && x.State == HockeyistState.Resting).ToArray();
            this.puck = world.Puck;
            this.move = move;
            World = world;
            Game = game;
            Opp = world.GetOpponentPlayer();
            My = world.GetMyPlayer();
            RinkWidth = game.RinkRight - game.RinkLeft;
            RinkHeight = game.RinkBottom - game.RinkTop;
            OppGoalie = Hockeyists.FirstOrDefault(x => !x.IsTeammate && x.Type == HockeyistType.Goalie);
            MyGoalie = Hockeyists.FirstOrDefault(x => x.IsTeammate && x.Type == HockeyistType.Goalie);
            HoRadius = self.Radius;
            RinkCenter = new Point(game.RinkLeft + RinkWidth/2, game.RinkTop + RinkHeight/2);
            PuckRadius = puck.Radius;
            var friends = Hockeyists
                .Where(x => x.IsTeammate && x.Id != self.Id && x.Type != HockeyistType.Goalie && x.State != HockeyistState.Resting)
                .ToArray();
            var friend1 = friends.Count() < 2 || friends[0].TeammateIndex < friends[1].TeammateIndex ? friends[0] : friends[1];
            var friend2 = friends.Count() > 1 ? friends[0].TeammateIndex < friends[1].TeammateIndex ? friends[1] : friends[0] : null;
            FillWayPoints();
            // //

            if (Game.OvertimeTickCount == 200) // костыль чтобы пройти верификацию
                return;

            TimerStart();

            var hock = new AHock(self);
            var needSubst = NeedTrySubstitute(hock);

            if (My.IsJustMissedGoal || My.IsJustScoredGoal)
            {
                SubstSignal = false;
                StayOn(self, GetSubstitutePoint(hock).First, null);
                TrySubstitute(hock);
            }
            else
            {
                var range = TurnRange(hock.AAgility);
                move.SpeedUp = Inf;
                if (self.State == HockeyistState.Swinging && self.Id != puck.OwnerHockeyistId)
                {
                    if (!TryStrikeWithoutTakeIfSwinging(hock, new APuck(puck, OppGoalie)))
                        move.Action = ActionType.CancelStrike;
                }
                else if (puck.OwnerHockeyistId == self.Id)
                {
                    var wait = Inf;
                    double selTurn = 0, selSpeedUp = 0;
                    var willSwing = false;
                    var maxProb = 0.15;
                    var selAction = ActionType.Strike;
                    TimerStart();
                    if (self.State != HockeyistState.Swinging)
                    {
                        var spUps = self.RemainingCooldownTicks == 0 || Math.Abs(self.X - My.NetFront) < RinkWidth / 2
                            ? (Math.Abs(self.X - Opp.NetFront) < RinkWidth / 3 ? new[] { 0.0, 1.0 } : new[] { 1.0 })
                            : new[] { 1.0, 0.5, 0.0, -0.5 };

                        var moveDirBase = MyRight() && self.Y > RinkCenter.Y || MyLeft() && self.Y < RinkCenter.Y ? 1 : -1;

                        // если не замахнулся
                        for (var ticks = 0; ticks < 50; ticks++)
                        {
                            // если буду замахиваться (ТО В КОНЦЕ!!!), то нужно подождать минимум game.SwingActionCooldownTicks

                            const int turns = 4;
                            for (var moveDir = -1; moveDir <= 1; moveDir += 2)
                            {
                                for (var moveTurn = 0.0; moveTurn - Eps <= range; moveTurn += range/turns)
                                {
                                    var turn = moveDir*moveTurn;
                                    foreach (var spUp in spUps)
                                    {
                                        if (moveDir == moveDirBase || spUp <= Eps && IsFinal())
                                        {
                                            var end = ticks + game.SwingActionCooldownTicks;
                                            var start = Math.Max(0, end - game.MaxEffectiveSwingTicks);
                                            // когда начинаем замахиваться
                                            var p = ProbabStrikeAfter(end - start, self, new[]
                                            {
                                                new MoveAction {Ticks = start, SpeedUp = spUp, Turn = turn},
                                                new MoveAction {Ticks = end - start, SpeedUp = 0, Turn = 0},
                                            }, ActionType.Strike);
                                            if (p > maxProb)
                                            {
                                                wait = start;
                                                willSwing = true;
                                                maxProb = p;
                                                selTurn = turn;
                                                selSpeedUp = spUp;
                                                selAction = ActionType.Strike;
                                            }

                                            // если не буду
                                            p = ProbabStrikeAfter(0, self,
                                                new[] {new MoveAction {Ticks = ticks, SpeedUp = spUp, Turn = turn}},
                                                ActionType.Strike);
                                            if (p > maxProb)
                                            {
                                                wait = ticks;
                                                willSwing = false;
                                                maxProb = p;
                                                selTurn = turn;
                                                selSpeedUp = spUp;
                                                selAction = ActionType.Strike;
                                            }

                                            // если пасом
                                            p = ProbabStrikeAfter(0, self,
                                                new[] {new MoveAction {Ticks = ticks, SpeedUp = spUp, Turn = turn}},
                                                ActionType.Pass);
                                            if (p > maxProb)
                                            {
                                                wait = ticks;
                                                willSwing = false;
                                                maxProb = p;
                                                selTurn = turn;
                                                selSpeedUp = spUp;
                                                selAction = ActionType.Pass;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        // если уже замахнулся
                        for (var ticks = Math.Max(0, game.SwingActionCooldownTicks - self.SwingTicks); ticks < 80; ticks++)
                        {
                            var p = ProbabStrikeAfter(ticks + self.SwingTicks, self,
                                new[] {new MoveAction {Ticks = ticks, SpeedUp = 0, Turn = 0}}, ActionType.Strike);
                            if (p > maxProb)
                            {
                                wait = ticks;
                                willSwing = true;
                                maxProb = p;
                                selAction = ActionType.Strike;
                            }
                        }
                    }
                    Log("STRIKE   " + TimerStop());
                    if (wait < Inf)
                    {
                        SubstSignal = true;
                    }
                    drawInfo.Enqueue((wait == Inf ? 0 : maxProb) + "");
                    if (!willSwing && self.State == HockeyistState.Swinging)
                    {
                        move.Action = ActionType.CancelStrike;
                    }
                    else if (willSwing && wait == 0 && self.State != HockeyistState.Swinging)
                    {
                        move.Action = ActionType.Swing;
                    }
                    else if (wait == Inf)
                    {
                        var wayPoint = FindWayPoint(self);
                        if (wayPoint == null)
                        {
                            needPassQueue.Enqueue(Get(self));
                            if (!TryPass(hock))
                            {
                                var pt = Math.Abs(Opp.NetFront - self.X) < RinkWidth/3
                                    ? Get(friend2 == null || (MyLeft() ? friend2.X > friend1.X : friend2.X < friend1.X) ? friend1 : friend2)
                                    : GetStrikePoint();
                                DoMove(self, pt, 1);
                            }
                        }
                        else
                        {
                            DoMove(self, wayPoint, 1);
                        }
                    }
                    else if (wait == 0)
                    {
                        move.Action = selAction;
                        if (selAction == ActionType.Pass)
                        {
                            move.PassPower = 1;
                            move.PassAngle = PassAngleNorm(hock.GetAngleTo(GetStrikePoint()));
                        }
                    }
                    else
                    {
                        move.SpeedUp = selSpeedUp;
                        move.Turn = selTurn;
                    }
                }
                else if (puck.OwnerPlayerId != -1 || !TryStrikeWithoutTake(hock, new APuck(puck, OppGoalie)))
                {
                    var owner = Hockeyists.FirstOrDefault(x => x.Id == puck.OwnerHockeyistId);
                    var pk = new APuck(puck, MyGoalie) {IsDefend = true};

                    if (puck.OwnerPlayerId == Opp.Id && (CanStrike(self, owner) || CanStrike(self, puck)))
                    { // попытаться выбить
                        move.Action = ActionType.Strike;
                    }
                    else if (puck.OwnerPlayerId != self.PlayerId && CanStrike(self, puck))
                    {
                        // проверяем что не летит в чужие ворота
                        var cpk = new APuck(puck, OppGoalie);
                        if (cpk.Move(200, true) == 0)
                        {
                            if (pk.Move(200, goalCheck: true) == 1) // если вратарь не отобьёт
                                move.Action = ActionType.Strike;
                            else
                                move.Action = ActionType.TakePuck;
                        }
                    }
                    else
                    {
                        var toPuck = GoToPuck(self, null);
                        var toPuck1 = GoToPuck(friend1, null);
                        var toPuck2 = friend2 == null ? null : GoToPuck(friend2, null);
                        if (friend2 != null && toPuck1.Third < toPuck2.Third)
                        {
                            Swap(ref friend1, ref friend2);
                            Swap(ref toPuck1, ref toPuck2);
                        }
                        var def = GetDefendPos2();
                        var have = puck.OwnerPlayerId == My.Id;
                        // 1 - дольше всего идет до шайбы
                        var net = new Point(My.NetFront, RinkCenter.Y);
                        double ii = net.GetDistanceTo(self) < 300 ? 1.0 : 1.0;
                        double jj = net.GetDistanceTo(friend1) < 300 ? 1.0 : 1.0;

                        var myFirst = GetFirstOnPuck(new[] {self},
                            new APuck(puck, OppGoalie),
                            true, 100, false).Second == (friend2 == null ? -1 : friend2.Id);

                        if (have
                            ? (friend2 == null || ii*GetTicksTo(def, self) < jj*GetTicksTo(def, friend1)) // если я ближе, то иду на ворота
                            : toPuck.Third/ii > toPuck1.Third/jj) // если я дольше всего, то иду на ворота
                        {
                            if (needSubst && (SubstSignal || puck.OwnerPlayerId != Opp.Id && self.Y <= Game.RinkTop + 0.666 * RinkHeight || self.Y <= Game.SubstitutionAreaHeight + Game.RinkTop))
                            {
                                if (TrySubstitute(hock))
                                    SubstSignal = false;
                                else
                                    StayOn(self, GetSubstitutePoint(hock).First, null);
                            }
                            else
                            {
                                StayOn(self, def, Get(puck));
                            }
                        }
                            // иначе 1 идет на воротаpuck.OwnerPlayerId != My.Id
                        else if (friend2 == null
                            || (puck.OwnerPlayerId != My.Id && (
                               toPuck.Third < toPuck2.Third
                               //|| Math.Abs(Opp.NetFront - puck.X) < RinkWidth / 2 // шайба не у нас и на чужой половине
                               || !myFirst
                            )))
                        {
                            var bestTime = Inf;
                            double bestTurn = 0.0;
                            var needTime = GetFirstOnPuck(Hockeyists.Where(x => x.IsTeammate),
                                new APuck(puck, OppGoalie), true, -1).First;
                            var lookAt = new Point(Opp.NetFront, RinkCenter.Y);
                            for (var turn = -range; turn <= range; turn += range / 10)
                            {
                                var I = hock.Clone();
                                var P = new APuck(puck, OppGoalie);
                                for (var t = 0; t < needTime - 10 && t < 70; t++)
                                {
                                    if (CanStrike(I, P))
                                    {
                                        var cl = I.Clone();
                                        var tm = GetTicksToUp(cl, lookAt) + t;
                                        if (tm < bestTime)
                                        {
                                            bestTime = tm;
                                            bestTurn = turn;
                                        }
                                    }
                                    I.Move(0, turn);
                                    P.Move(1);
                                }
                            }
                            var i = hock.Clone();
                            var direct = MoveHockTo(i, toPuck.First);
                            direct += MoveHockTo(i, lookAt);
                            if (bestTime < direct && bestTime < Inf)
                            {
                                move.Turn = bestTurn;
                                move.SpeedUp = 0.0;
                            }
                            DoMove(self, toPuck.First, toPuck.Second);
                        }
                        else
                        {
                            if (needSubst && (SubstSignal || puck.OwnerPlayerId != Opp.Id && self.Y <= RinkCenter.Y || self.Y <= Game.SubstitutionAreaHeight + Game.RinkTop))
                            {
                                if (TrySubstitute(hock))
                                    SubstSignal = false;
                                else
                                    StayOn(self, GetSubstitutePoint(hock).First, null);
                            }
                            else
                            {
                                var c1 = new Point(RinkCenter.X, Game.RinkTop + 2*HoRadius);
                                var c2 = new Point(RinkCenter.X, Game.RinkBottom - 2*HoRadius);
                                var c = c1.GetDistanceTo(puck) > c2.GetDistanceTo(puck) ? c1 : c2;
                                var s = GetStrikePoint();
                                StayOn(self, c, s);
                            }
                        }
                    }
                }
                if (Eq(move.SpeedUp, Inf))
                    move.SpeedUp = 1;
            }

            Log(self.TeammateIndex + " >>>>>>>>>>>> " + TimerStop());
            if (move.Action != ActionType.None)
                Log(move.Action);
            #if DEBUG
            draw();
            Thread.Sleep(8);
            #endif
            drawInfo.Clear();
            needPassQueue.Clear();
        }
Ejemplo n.º 14
0
 public void Move(Hockeyist self, World world, Game game, Move move) {
     move.SpeedUp = -1.0D;
     move.Turn = Math.PI;
     move.Action = ActionType.Strike;
 }
        private void WriteHockeyists(Hockeyist[] hockeyists) {
            if (hockeyists == null) {
                WriteInt(-1);
            } else {
                int hockeyistCount = hockeyists.Length;
                WriteInt(hockeyistCount);

                for (int hockeyistIndex = 0; hockeyistIndex < hockeyistCount; ++hockeyistIndex) {
                    WriteHockeyist(hockeyists[hockeyistIndex]);
                }
            }
        }
Ejemplo n.º 16
0
        public void Move(Hockeyist self, World world, Game game, Move move)
        {
            Player OP = world.GetOpponentPlayer();
            Player MP = world.GetMyPlayer();
            double RinkMiddleHeight = (game.RinkTop + game.RinkBottom) / 2;
            double RinkMiddleWidth = (game.RinkLeft + game.RinkRight) / 2;
            double TargetX;
            double TargetY;

            // 1. Завершение удара
            // если идет замах более 13 тиков, то ударить
            if (self.LastAction == ActionType.Swing && world.Tick - self.LastActionTick >= 20)
            {
                move.Action = ActionType.Strike;
                return;
            }

            // 2. Назначение второго вратаря
            // NX, NY - координаты позиции второго вратаря
            double NX = (MP.NetFront < RinkMiddleWidth) ? MP.NetFront + 75 : MP.NetFront - 75;
            double NY = RinkMiddleHeight;

            // проверить является ли хоккеист ближайшим к позиции вратаря
            bool nearest = true;
            if (self.Id == world.Puck.OwnerHockeyistId) nearest = false;
            foreach (Hockeyist h in world.Hockeyists)
                if (h.IsTeammate &&
                    h.Id != self.Id &&
                    h.Type != HockeyistType.Goalie &&
                    h.Id != world.Puck.OwnerHockeyistId &&
                    h.GetDistanceTo(NX, NY) < self.GetDistanceTo(NX, NY))
                    nearest = false;

            // ближайщий к воротам не владеющий шайбой становится вторым вратарем
            if (nearest)
            {
                // двигаться к позиции второго вратаря
                move.SpeedUp = 1.0D;
                move.Turn = self.GetAngleTo(NX, NY);
                move.Action = ActionType.TakePuck;

                // приблизившись к позиции тормозить и разворачиваться
                if (self.GetDistanceTo(NX, NY) < 270)
                {
                    move.SpeedUp = -1.0D;
                    move.Turn = NormalizeAngle(self.GetAngleTo(NX, NY) + Math.PI);
                    move.Action = ActionType.TakePuck;
                }

                // полностью остановиться в небольшом радиусе от позиции
                if (self.GetDistanceTo(NX, NY) < 70)
                {
                    move.SpeedUp = 0.0D;
                    move.Turn = self.GetAngleTo(world.Puck);
                    if (self.GetDistanceTo(world.Puck) < game.StickLength)
                    {
                        if (world.Puck.SpeedX * world.Puck.SpeedX +
                            world.Puck.SpeedY * world.Puck.SpeedY < 12 * 12 &&
                            world.Puck.OwnerHockeyistId == -1)
                            move.Action = ActionType.TakePuck;
                        else
                            move.Action = ActionType.Strike;
                    }
                }
                return;
            }

            // 3. Отбор шайбы
            // наша команда не владеет шайбой
            if (world.Puck.OwnerPlayerId != MP.Id)
            {
                // двигаться к шайбе
                move.SpeedUp = 1.0D;
                move.Turn = self.GetAngleTo(world.Puck);

                // если шайбой никто не владеет и она в пределах клюшки, подобрать
                if (world.Puck.OwnerHockeyistId == -1 &&
                    self.GetDistanceTo(world.Puck) < game.StickLength &&
                    Math.Abs(self.GetAngleTo(world.Puck)) <= game.StickSector)
                {
                    move.Action = ActionType.TakePuck;
                    return;
                }

                // если вражеский хоккеист в пределах клюшки, ударить его
                foreach (Hockeyist h in world.Hockeyists)
                    if (!h.IsTeammate &&
                        self.GetDistanceTo(h) < game.StickLength &&
                        Math.Abs(self.GetAngleTo(h)) <= game.StickSector)
                        {
                            move.Action = ActionType.Strike;
                            return;
                        }

                move.Action = ActionType.None;
                return;
            }

            // 4. Атака
            // наша команда владеет шайбой
            else
            {
                // если хоккеист владеет шайбой
                if (self.Id == world.Puck.OwnerHockeyistId)
                {
                    // нужно выбрать и ехать к ударной позиции
                    double[,] XY = new double[4, 2] {
                    { 0.25, 0.30 }, { 0.75, 0.30 },
                    { 0.25, 0.70 }, { 0.75, 0.70 }
                    };

                    TargetX = RinkMiddleWidth;
                    TargetY = RinkMiddleHeight;

                    double SumY = 0.0;
                    int cnt = 0;
                    foreach (Hockeyist h in world.Hockeyists)
                        if (!h.IsTeammate && h.Type != HockeyistType.Goalie)
                        {
                            SumY += h.Y;
                            cnt++;
                        }
                    SumY /= cnt;

                    if (SumY > RinkMiddleHeight && OP.NetFront < RinkMiddleWidth)
                    {
                        TargetX = game.RinkRight * XY[0, 0] + game.RinkLeft * (1 - XY[0, 0]);
                        TargetY = game.RinkBottom * XY[0, 1] + game.RinkTop * (1 - XY[0, 1]);
                    }
                    if (SumY > RinkMiddleHeight && OP.NetFront >= RinkMiddleWidth)
                    {
                        TargetX = game.RinkRight * XY[1, 0] + game.RinkLeft * (1 - XY[1, 0]);
                        TargetY = game.RinkBottom * XY[1, 1] + game.RinkTop * (1 - XY[1, 1]);
                    }
                    if (SumY <= RinkMiddleHeight && OP.NetFront < RinkMiddleWidth)
                    {
                        TargetX = game.RinkRight * XY[2, 0] + game.RinkLeft * (1 - XY[2, 0]);
                        TargetY = game.RinkBottom * XY[2, 1] + game.RinkTop * (1 - XY[2, 1]);
                    }
                    if (SumY <= RinkMiddleHeight && OP.NetFront >= RinkMiddleWidth)
                    {
                        TargetX = game.RinkRight * XY[3, 0] + game.RinkLeft * (1 - XY[3, 0]);
                        TargetY = game.RinkBottom * XY[3, 1] + game.RinkTop * (1 - XY[3, 1]);
                    }

                    // около ударной позиции замедлиться, развернуться
                    // и замахнуться в верхнюю или нижнюю штангу
                    if (self.GetDistanceTo(TargetX, TargetY) <= 100)
                    {
                        move.SpeedUp = 0.1D;
                        if (self.Y >= RinkMiddleHeight)
                        {
                            move.Turn = self.GetAngleTo(OP.NetFront, OP.NetTop + 5);
                            if (Math.Abs(GetAngleBetween(world.Puck.X, world.Puck.Y,
                                OP.NetFront, OP.NetTop + 8, self.Angle)) <= Math.PI / 180.0D)
                            {
                                move.Action = ActionType.Swing;
                                return;
                            }
                        }
                        else
                        {
                            move.Turn = self.GetAngleTo(OP.NetFront, OP.NetBottom - 5);
                            if (Math.Abs(GetAngleBetween(world.Puck.X, world.Puck.Y,
                                OP.NetFront, OP.NetBottom - 8, self.Angle)) <= Math.PI / 180.0D)
                            {
                                move.Action = ActionType.Swing;
                                return;
                            }
                        }

                        // если удар не проходит, можно дать пас своему
                        foreach(Hockeyist h in world.Hockeyists)
                            if (h.IsTeammate &&
                                h.Id != self.Id &&
                                h.Type != HockeyistType.Goalie &&
                                Math.Abs(self.GetAngleTo(h)) < Math.PI / 60)
                            {
                                move.Action = ActionType.Pass;
                                move.PassAngle = GetAngleBetween(world.Puck.X, world.Puck.Y,
                                    h.X, h.Y, self.Angle);

                                move.PassPower = (10 -
                                    Math.Sqrt(self.SpeedX * self.SpeedX + self.SpeedY * self.SpeedY) *
                                    Math.Cos(GetAngleBetween(world.Puck.X, world.Puck.Y, h.X, h.Y, self.Angle) -
                                        self.GetAngleTo(self.X + self.SpeedX, self.Y + self.SpeedY))) / 15;
                                return;
                            }

                    }

                    // если позиция далеко, ехать дальше
                    move.SpeedUp = 1.0D;
                    move.Action = ActionType.None;
                    move.Turn = self.GetAngleTo(TargetX, TargetY);

                    // если можно забить пасом
                    double TX, TY;
                    TX = OP.NetFront;
                    if (world.Puck.Y <= RinkMiddleHeight) TY = OP.NetBottom - 5;
                    else TY = OP.NetTop + 5;

                    double cos = (TX - world.Puck.X) / world.Puck.GetDistanceTo(TX, TY);
                    double sin = (TY - world.Puck.Y) / world.Puck.GetDistanceTo(TX, TY);

                    double Speed = 14.0 +
                        Math.Sqrt(self.SpeedX * self.SpeedX + self.SpeedY * self.SpeedY) *
                        Math.Cos(GetAngleBetween(world.Puck.X, world.Puck.Y, TX, TY, self.Angle) -
                            self.GetAngleTo(self.X + self.SpeedX, self.Y + self.SpeedY));

                    double Vx = Speed * cos;
                    double Vy = (Math.Abs(Speed * sin) > game.GoalieMaxSpeed) ?
                        Speed * sin - Math.Sign(sin) * game.GoalieMaxSpeed : 0.0;

                    double x0 = Math.Abs(world.Puck.X - TX);
                    if (world.Puck.Y > OP.NetBottom || world.Puck.Y < OP.NetTop)
                        x0 *= (Math.Abs(OP.NetBottom - OP.NetTop - 2 * self.Radius)
                            / Math.Abs(TY - world.Puck.Y));
                    double y0 = 0;

                    double tmin = -x0 * Vx / (Vx * Vx + Vy * Vy);
                    double xmin = x0 + Vx * tmin;
                    double ymin = y0 + Vy * tmin;
                    double rmin = Math.Sqrt(xmin * xmin + ymin * ymin);

                    // если можно забить пасом
                    if (rmin >= world.Puck.Radius + self.Radius + 5)
                        if (Math.Abs(GetAngleBetween(world.Puck.X, world.Puck.Y,
                            TX, TY, self.Angle)) <= Math.PI / 3.0D)
                        {
                            move.PassAngle = GetAngleBetween(world.Puck.X, world.Puck.Y,
                                TX, TY, self.Angle);
                            move.PassPower = 1.0D;
                            move.Action = ActionType.Pass;
                            return;
                        }
                }

                // хоккеист без шайбы атакует вражеских хоккеистов
                else
                {
                    // выбрать ближайщего вражеского игрока и бить клюшкой
                    foreach (Hockeyist h in world.Hockeyists)
                        if (h.IsTeammate == false &&
                            h.Type != HockeyistType.Goalie &&
                            h.State == HockeyistState.Active)
                        {
                            move.SpeedUp = 1.0D;
                            move.Turn = self.GetAngleTo(h);
                            if (self.GetDistanceTo(h) < game.StickLength)
                                move.Action = ActionType.Strike;
                            else
                                move.Action = ActionType.TakePuck;
                            return;
                        }
                }
            }
        }
        public PlayerContext(Hockeyist[] hockeyists, World world) {
            this.hockeyists = new Hockeyist[hockeyists.Length];
            Array.Copy(hockeyists, this.hockeyists, hockeyists.Length);

            this.world = world;
        }
Ejemplo n.º 18
0
		Hockeyist teammate {get {return world.MyTeam ().First (x => x.Id == teammateId);}} //TODO: generalize this id + getter logic

		public PassThePuckBehaviour (Hockeyist me, Hockeyist teammate) : base(me)
		{
			this.teammateId = teammate.Id;
		}
Ejemplo n.º 19
0
 public void StayOn(Hockeyist self, Point to, Point lookAt)
 {
     if (!FindPath(self, to, lookAt))
         DoMove(self, to, GetTicksToUp(new AHock(self), to) < GetTicksToDown(new AHock(self), to) ? 1 : -1);
 }
Ejemplo n.º 20
0
		public GetThePuckBehaviour (Hockeyist h) : base(h)
		{
		}
Ejemplo n.º 21
0
		public DefenseBehaviour (Hockeyist h) : base(h)
		{
			passThePuck = new PassThePuckBehaviour (h, world.MyTeam().First (x => x.Id != h.Id));
		}
Ejemplo n.º 22
0
 // Проверка движение шайбы - OK
 void Research4(Hockeyist self)
 {
     if (TK(190))
     {
         __puck = new APuck(puck, OppGoalie);
         __puck.Move(10);
     }
     if (TK(190 + 10))
     {
     }
 }
Ejemplo n.º 23
0
		public HockeyistBehaviour (Hockeyist h)
		{
			this.hId = h.Id;
		}
Ejemplo n.º 24
0
        double ProbabStrikeAfter(int swingTime, Hockeyist self, IEnumerable<MoveAction> actions, ActionType actionType)
        {
            var I = new AHock(self);

            if (Math.Abs(My.NetFront - I.X) < RinkWidth / 3)
                return 0.0;

            var power = GetPower(I, swingTime);
            var totalTime = 0;
            var opps = Hockeyists
                .Where(x => !x.IsTeammate && IsInGame(x))
                .Select(x => new AHock(x))
                .ToArray();

            var goalie = Get(OppGoalie);
            foreach (var action in actions)
            {
                for (var i = 0; i < action.Ticks; i++)
                {
                    GoalieMove(goalie, 1, I.PuckPos());
                    I.Move(action.SpeedUp, action.Turn);
                    if (!Chase(opps, I))
                        return 0.0;
                }
                totalTime += action.Ticks;
            }
            var passAngle = PassAngleNorm(I.GetAngleTo(GetStrikePoint()));
            return StrikeProbability(I, power, goalie, totalTime, actionType, passAngle, null);
        }
		public ReachAndSlowdownBehaviour (Hockeyist me, Unit target, bool backwardsMovement) : base(me)
		{
			this.target = target;
		    this.backwardsMovement = backwardsMovement;
		}
Ejemplo n.º 26
0
        public void Move(Hockeyist self, World world, Game game, Move move)
        {
			world.SetCurrent();
			game.SetCurrent();

			if (!behaviours.ContainsKey (self.Id)) { //do we need to init behaviour?
				HockeyistBehaviour b = null;
				if (self.IsHunter ()) {
					b = new HunterBehaviour (self);
				} else {
					b = new DefenseBehaviour (self);
				}
				behaviours[self.Id] = b.Perform().GetEnumerator();
			} 

			{ //take corresponding actions
				var enumerator = behaviours [self.Id];
				enumerator.MoveNext ();
				enumerator.Current (move);
				return;
			}

//            const double speedKp = 0.005;
//            speedPID = new PID(speedKp, 1.0D);

            // TODO: Angle Max Output
            /*
            const double angleKp = 0.5;
            anglePID = new PID(angleKp, 1.0D);
             */

//            strikeDistanceFromNet = 385;
//            var opponentNetFront = _world.GetOpponentPlayer().NetFront;
//            attackLine = opponentNetFront - strikeDistanceFromNet < 0
//                ? opponentNetFront + strikeDistanceFromNet
//                : opponentNetFront - strikeDistanceFromNet;

//            attackPath = new Point[]
//            {
//                new Point(700, 250),
//                new Point(400, 250), 
//            };
				
            
//            decelerateLine = 550;
//            minStrikeLine = 200;

//            if (IsHunter())
            {
//                PerformAttack();
                /*
                if (world.Puck.OwnerHockeyistId == self.Id)
                {
                    PassThePuck();
                }
                else
                {
                    GoGetThePuck();
                }  
                 */
            }
        }
        private void WriteHockeyist(Hockeyist hockeyist) {
            if (hockeyist == null) {
                WriteBoolean(false);
            } else {
                WriteBoolean(true);

                WriteLong(hockeyist.Id);
                WriteLong(hockeyist.PlayerId);
                WriteInt(hockeyist.TeammateIndex);
                WriteDouble(hockeyist.Mass);
                WriteDouble(hockeyist.Radius);
                WriteDouble(hockeyist.X);
                WriteDouble(hockeyist.Y);
                WriteDouble(hockeyist.SpeedX);
                WriteDouble(hockeyist.SpeedY);
                WriteDouble(hockeyist.Angle);
                WriteDouble(hockeyist.AngularSpeed);
                WriteBoolean(hockeyist.IsTeammate);
                WriteEnum((sbyte?) hockeyist.Type);
                WriteInt(hockeyist.Strength);
                WriteInt(hockeyist.Endurance);
                WriteInt(hockeyist.Dexterity);
                WriteInt(hockeyist.Agility);
                WriteDouble(hockeyist.Stamina);
                WriteEnum((sbyte?) hockeyist.State);
                WriteInt(hockeyist.OriginalPositionIndex);
                WriteInt(hockeyist.RemainingKnockdownTicks);
                WriteInt(hockeyist.RemainingCooldownTicks);
                WriteInt(hockeyist.SwingTicks);
                WriteEnum((sbyte?) hockeyist.LastAction);
                if (hockeyist.LastActionTick == null) {
                    WriteBoolean(false);
                } else {
                    WriteBoolean(true);
                    WriteInt((int) hockeyist.LastActionTick);
                }
            }
        }
Ejemplo n.º 28
0
 public APuck(Puck puck, Hockeyist goalie)
     : base(MyStrategy.Get(puck), MyStrategy.GetSpeed(puck), 0)
 {
     Goalie = MyStrategy.Get(goalie);
 }
        private Hockeyist[] ReadHockeyists() {
            int hockeyistCount = ReadInt();
            if (hockeyistCount < 0) {
                return null;
            }

            Hockeyist[] hockeyists = new Hockeyist[hockeyistCount];

            for (int hockeyistIndex = 0; hockeyistIndex < hockeyistCount; ++hockeyistIndex) {
                hockeyists[hockeyistIndex] = ReadHockeyist();
            }

            return hockeyists;
        }