Пример #1
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;
        }
Пример #2
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;
                }
        }
Пример #3
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();
        }
        private void WritePlayers(Player[] players) {
            if (players == null) {
                WriteInt(-1);
            } else {
                int playerCount = players.Length;
                WriteInt(playerCount);

                for (int playerIndex = 0; playerIndex < playerCount; ++playerIndex) {
                    WritePlayer(players[playerIndex]);
                }
            }
        }
        private Player[] ReadPlayers() {
            int playerCount = ReadInt();
            if (playerCount < 0) {
                return null;
            }

            Player[] players = new Player[playerCount];

            for (int playerIndex = 0; playerIndex < playerCount; ++playerIndex) {
                players[playerIndex] = ReadPlayer();
            }

            return players;
        }
        private void WritePlayer(Player player) {
            if (player == null) {
                WriteBoolean(false);
            } else {
                WriteBoolean(true);

                WriteLong(player.Id);
                WriteBoolean(player.IsMe);
                WriteString(player.Name);
                WriteInt(player.GoalCount);
                WriteBoolean(player.IsStrategyCrashed);
                WriteDouble(player.NetTop);
                WriteDouble(player.NetLeft);
                WriteDouble(player.NetBottom);
                WriteDouble(player.NetRight);
                WriteDouble(player.NetFront);
                WriteDouble(player.NetBack);
                WriteBoolean(player.IsJustScoredGoal);
                WriteBoolean(player.IsJustMissedGoal);
            }
        }