Ejemplo n.º 1
0
        public void Move(double speedUp, double turn)
        {
            if (speedUp < -1 || speedUp > 1 || turn - MyStrategy.Eps > MyStrategy.TurnRange(AAgility) || turn + MyStrategy.Eps < -MyStrategy.TurnRange(AAgility))
            {
                throw new Exception("AHo Move: " + speedUp + " " + turn);
            }

            speedUp = speedUp * AAgility / 100;
            if (CoolDown > 0)
            {
                CoolDown--;
            }
            if (KnockDown > 0)
            {
                KnockDown--;
                speedUp = 0;
                turn    = 0;
            }

            turn         += AngularSpeed;
            AngularSpeed *= AngularSpeedCoeff;
            var force = (speedUp >= 0 ? MyStrategy.Game.HockeyistSpeedUpFactor : MyStrategy.Game.HockeyistSpeedDownFactor) * speedUp;

            var dir = new Point(Angle).Normalized();

            Speed = (dir * force + Speed) * AHock.FrictionCoeff;
            Angle = MyStrategy.AngleNormalize(Angle + turn);

            X += Speed.X;
            Y += Speed.Y;
        }
Ejemplo n.º 2
0
        public double Stamina; // TODO: учитавать изменение?

        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.º 3
0
 public void MoveTo(Point to, int direction = 1)
 {
     if (direction > 0)
     {
         var turn = GetAngleTo(to);
         var spUp = MyStrategy.GetSpeedTo(turn);
         Move(spUp, MyStrategy.TurnNorm(turn, AAgility));
     }
     else
     {
         var turn = MyStrategy.RevAngle(GetAngleTo(to.X, to.Y));
         var spUp = -MyStrategy.GetSpeedTo(turn);
         Move(spUp, MyStrategy.TurnNorm(turn, AAgility));
     }
 }
Ejemplo n.º 4
0
        public void run()
        {
            try {
                remoteProcessClient.WriteTokenMessage(token);
                int teamSize = remoteProcessClient.ReadTeamSizeMessage();
                remoteProcessClient.WriteProtocolVersionMessage();
                Game game = remoteProcessClient.ReadGameContextMessage();

                IStrategy[] strategies = new IStrategy[teamSize];

                for (int strategyIndex = 0; strategyIndex < teamSize; ++strategyIndex)
                {
                    strategies[strategyIndex] = new MyStrategy();
                }

                PlayerContext playerContext;

                while ((playerContext = remoteProcessClient.ReadPlayerContextMessage()) != null)
                {
                    Hockeyist[] playerHockeyists = playerContext.Hockeyists;
                    if (playerHockeyists == null || playerHockeyists.Length != teamSize)
                    {
                        break;
                    }

                    Move[] moves = new Move[teamSize];

                    for (int hockeyistIndex = 0; hockeyistIndex < teamSize; ++hockeyistIndex)
                    {
                        Hockeyist playerHockeyist = playerHockeyists[hockeyistIndex];

                        Move move = new Move();
                        moves[hockeyistIndex] = move;
                        strategies[playerHockeyist.TeammateIndex].Move(
                            playerHockeyist, playerContext.World, game, move
                            );
                    }

                    remoteProcessClient.WriteMovesMessage(moves);
                }
            } finally {
                remoteProcessClient.Close();
            }
        }
Ejemplo n.º 5
0
        public void run()
        {
            try {
                remoteProcessClient.WriteTokenMessage(token);
                int teamSize = remoteProcessClient.ReadTeamSizeMessage();
                remoteProcessClient.WriteProtocolVersionMessage();
                Game game = remoteProcessClient.ReadGameContextMessage();

                IStrategy[] strategies = new IStrategy[teamSize];

                for (int strategyIndex = 0; strategyIndex < teamSize; ++strategyIndex) {
                    strategies[strategyIndex] = new MyStrategy();
                }

                PlayerContext playerContext;

                while ((playerContext = remoteProcessClient.ReadPlayerContextMessage()) != null) {
                    Hockeyist[] playerHockeyists = playerContext.Hockeyists;
                    if (playerHockeyists == null || playerHockeyists.Length != teamSize) {
                        break;
                    }

                    Move[] moves = new Move[teamSize];

                    for (int hockeyistIndex = 0; hockeyistIndex < teamSize; ++hockeyistIndex) {
                        Hockeyist playerHockeyist = playerHockeyists[hockeyistIndex];

                        Move move = new Move();
                        moves[hockeyistIndex] = move;
                        strategies[playerHockeyist.TeammateIndex].Move(
                                playerHockeyist, playerContext.World, game, move
                        );
                    }

                    remoteProcessClient.WriteMovesMessage(moves);
                }
            } finally {
                remoteProcessClient.Close();
            }
        }
Ejemplo n.º 6
0
        // TODO: не в том порядке обрабатывается отскок
        public int Move(int ticks, bool goalCheck = false)
        {
            var mayGoal    = -1;
            var breakCount = 0;

            var top    = MyStrategy.Game.RinkTop + MyStrategy.PuckRadius;
            var bottom = MyStrategy.Game.RinkBottom - MyStrategy.PuckRadius;
            var right  = MyStrategy.Game.RinkRight - MyStrategy.PuckRadius;
            var left   = MyStrategy.Game.RinkLeft + MyStrategy.PuckRadius;
            var opp    = IsDefend ? MyStrategy.My : MyStrategy.Opp;
            var isLeft = opp.NetFront > opp.NetBack;

            for (var tick = 1; tick <= ticks && (!goalCheck || breakCount < 1 || Goalie == null); tick++)
            {
                PuckLastTicks = tick;
                Speed         = Speed * APuck.FrictionCoeff;
                X            += Speed.X;
                Y            += Speed.Y;
                var psx = Speed.X;
                var psy = Speed.Y;
                if (Y < top)
                {
                    var penetration = top - Y;
                    Y        = top + PenetrationCoeff * penetration;
                    Speed.Y *= BoundSpeedChangeCoeff;
                    mayGoal  = tick;
                    breakCount++;
                }
                if (Y > bottom)
                {
                    var penetration = Y - bottom;
                    Y        = bottom - PenetrationCoeff * penetration;
                    Speed.Y *= BoundSpeedChangeCoeff;
                    mayGoal  = tick;
                    breakCount++;
                }
                if (X > right)
                {
                    var penetration = 0.0;//X - right;
                    X        = right - PenetrationCoeff * penetration;
                    Speed.X *= BoundSpeedChangeCoeff;
                    mayGoal  = tick;
                    breakCount++;
                }
                if (X < left)
                {
                    var penetration = 0.0;//left - X;
                    X        = left + PenetrationCoeff * penetration;
                    Speed.X *= BoundSpeedChangeCoeff;
                    mayGoal  = tick;
                    breakCount++;
                }

                if (IntersectPuckAngGoalie())
                {
                    return(0);
                }
                var dx = Math.Abs(X - opp.NetFront);

                if (Math.Abs((!isLeft ? (opp.NetFront - MyStrategy.PuckRadius) : (opp.NetFront + MyStrategy.PuckRadius)) - X) < 0.01 && // (это стена ворот)
                    MyStrategy.IsBetween(MyStrategy.Game.GoalNetTop + MyStrategy.PuckRadius, Y - (isLeft ? 1 : -1) * dx * psy / psx, MyStrategy.Game.GoalNetTop + MyStrategy.Game.GoalNetHeight - MyStrategy.PuckRadius) && // (в воротах)
                    (mayGoal == -1 || (mayGoal == tick && breakCount <= 1) || Goalie == null)    // (не от борта)
                    )
                {
                    return(1); // Goal !!
                }
                MyStrategy.GoalieMove(Goalie, 1, this);
            }
            return(0);
        }
Ejemplo n.º 7
0
 public APuck(Puck puck, Hockeyist goalie)
     : base(MyStrategy.Get(puck), MyStrategy.GetSpeed(puck), 0)
 {
     Goalie = MyStrategy.Get(goalie);
 }
Ejemplo n.º 8
0
 public Point PuckPos()
 {
     return(MyStrategy.GetPuckPos(this, Angle));
 }