Example #1
0
        public bool TryStrikeWithoutTakeIfSwinging(AHock _hock, APuck _pk)
        {
            var hock       = _hock.Clone();
            var pk         = _pk.Clone();
            var bestProbab = 0.0;
            var swTime     = Inf;

            for (var sw = 0; sw <= Game.MaxEffectiveSwingTicks; sw++)
            {
                if (CanStrike(hock, pk))
                {
                    var pr = StrikeProbability(hock, GetPower(hock, sw + hock.Base.SwingTicks), pk.Goalie, -1, ActionType.Strike, 0, pk);
                    if (pr > bestProbab)
                    {
                        bestProbab = pr;
                        swTime     = sw;
                    }
                }
                hock.Move(0, 0);
                pk.Move(1);
            }

            if (swTime == Inf)
            {
                return(false);
            }
            if (swTime == 0)
            {
                move.Action = ActionType.Strike;
            }
            return(true);
        }
Example #2
0
 int GetTicksToPuckDirect(AHock _hock, APuck _puck, int limit)
 {
     var hock = _hock.Clone();
     var pk = _puck.Clone();
     int result;
     for (result = 0; result < limit && !CanStrike(hock, pk); result++)
     {
         hock.MoveTo(pk);
         pk.Move(1);
     }
     return result;
 }
Example #3
0
        int GetTicksToPuckDirect(AHock _hock, APuck _puck, int limit)
        {
            var hock = _hock.Clone();
            var pk   = _puck.Clone();
            int result;

            for (result = 0; result < limit && !CanStrike(hock, pk); result++)
            {
                hock.MoveTo(pk);
                pk.Move(1);
            }
            return(result);
        }
Example #4
0
        public bool TryStrikeWithoutTakeIfSwinging(AHock _hock, APuck _pk)
        {
            var hock = _hock.Clone();
            var pk = _pk.Clone();
            var bestProbab = 0.0;
            var swTime = Inf;

            for (var sw = 0; sw <= Game.MaxEffectiveSwingTicks; sw++)
            {
                if (CanStrike(hock, pk))
                {
                    var pr = StrikeProbability(hock, GetPower(hock, sw + hock.Base.SwingTicks), pk.Goalie, -1, ActionType.Strike, 0, pk);
                    if (pr > bestProbab)
                    {
                        bestProbab = pr;
                        swTime = sw;
                    }
                }
                hock.Move(0, 0);
                pk.Move(1);
            }

            if (swTime == Inf)
                return false;
            if (swTime == 0)
                move.Action = ActionType.Strike;
            return true;
        }
Example #5
0
        public bool TryStrikeWithoutTake(AHock _hock, APuck _pk)
        {
            if (!StrikePrimitiveValidate(_hock))
                return false;

            TimerStart();

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

            var bestTurn = 0.0;
            var bestSpUp = 0.0;
            var bestProbab = 0.0;
            var bestWait = Inf;
            var swTime = 0;
            var range = TurnRange(_hock.AAgility);

            const int turns = 9;
            const int spUps = 8;

            for (var moveDir = -1; moveDir <= 1; moveDir += 2)
            {
                for (var moveTurn = 0.0; moveTurn <= range + Eps; moveTurn += range/turns)
                {
                    var turn = moveDir*moveTurn;

                    for (var spUp = 0.0; spUp <= 1.0; spUp += 1.0/spUps)
                    {
                        var hock = _hock.Clone();
                        var pk = _pk.Clone();
                        var ticksWait = 0;
                        for (var startDist2 = hock.GetDistanceTo2(pk); !CanStrike(hock, pk) && ticksWait < 150; ticksWait++)
                        {
                            if (moveDir == moveDirBase || IsFinal() && moveTurn < range / 2)
                            {
                                var I = hock.Clone();
                                var p = pk.Clone();
                                for (var sw = 0; sw <= Game.MaxEffectiveSwingTicks; sw++)
                                {
                                    if (sw >= Game.SwingActionCooldownTicks && CanStrike(I, p))
                                    {
                                        var pr = StrikeProbability(I, GetPower(I, sw), p.Goalie, -1, ActionType.Strike, 0, p);
                                        if (pr > bestProbab)
                                        {
                                            bestProbab = pr;
                                            bestTurn = turn;
                                            bestSpUp = spUp;
                                            bestWait = ticksWait;
                                            swTime = sw;
                                        }
                                    }
                                    I.Move(0, 0);
                                    p.Move(1);
                                }
                            }
                            hock.Move(spUp, turn);
                            pk.Move(1);
                            var dist2 = hock.GetDistanceTo2(pk);
                            if (dist2 > startDist2)
                                break;
                            startDist2 = dist2;
                        }
                        if (CanStrike(hock, pk))
                        {
                            var p = StrikeProbability(hock, GetPower(hock, 0), pk.Goalie, -1, ActionType.Strike, 0, pk);
                            if (p > bestProbab)
                            {
                                bestProbab = p;
                                bestTurn = turn;
                                bestSpUp = spUp;
                                bestWait = ticksWait;
                                swTime = 0;
                            }
                        }
                    }
                }
            }
            Log("SWING " + TimerStop());

            if (bestWait == Inf)
                return false;
            move.Turn = bestTurn;
            move.SpeedUp = bestSpUp;

            if (bestWait == 0)
                move.Action = swTime == 0 ? ActionType.Strike : ActionType.Swing;
            return true;
        }
Example #6
0
        public bool TryStrikeWithoutTake(AHock _hock, APuck _pk)
        {
            if (!StrikePrimitiveValidate(_hock))
            {
                return(false);
            }

            TimerStart();

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

            var bestTurn   = 0.0;
            var bestSpUp   = 0.0;
            var bestProbab = 0.0;
            var bestWait   = Inf;
            var swTime     = 0;
            var range      = TurnRange(_hock.AAgility);

            const int turns = 9;
            const int spUps = 8;

            for (var moveDir = -1; moveDir <= 1; moveDir += 2)
            {
                for (var moveTurn = 0.0; moveTurn <= range + Eps; moveTurn += range / turns)
                {
                    var turn = moveDir * moveTurn;

                    for (var spUp = 0.0; spUp <= 1.0; spUp += 1.0 / spUps)
                    {
                        var hock      = _hock.Clone();
                        var pk        = _pk.Clone();
                        var ticksWait = 0;
                        for (var startDist2 = hock.GetDistanceTo2(pk); !CanStrike(hock, pk) && ticksWait < 150; ticksWait++)
                        {
                            if (moveDir == moveDirBase || IsFinal() && moveTurn < range / 2)
                            {
                                var I = hock.Clone();
                                var p = pk.Clone();
                                for (var sw = 0; sw <= Game.MaxEffectiveSwingTicks; sw++)
                                {
                                    if (sw >= Game.SwingActionCooldownTicks && CanStrike(I, p))
                                    {
                                        var pr = StrikeProbability(I, GetPower(I, sw), p.Goalie, -1, ActionType.Strike, 0, p);
                                        if (pr > bestProbab)
                                        {
                                            bestProbab = pr;
                                            bestTurn   = turn;
                                            bestSpUp   = spUp;
                                            bestWait   = ticksWait;
                                            swTime     = sw;
                                        }
                                    }
                                    I.Move(0, 0);
                                    p.Move(1);
                                }
                            }
                            hock.Move(spUp, turn);
                            pk.Move(1);
                            var dist2 = hock.GetDistanceTo2(pk);
                            if (dist2 > startDist2)
                            {
                                break;
                            }
                            startDist2 = dist2;
                        }
                        if (CanStrike(hock, pk))
                        {
                            var p = StrikeProbability(hock, GetPower(hock, 0), pk.Goalie, -1, ActionType.Strike, 0, pk);
                            if (p > bestProbab)
                            {
                                bestProbab = p;
                                bestTurn   = turn;
                                bestSpUp   = spUp;
                                bestWait   = ticksWait;
                                swTime     = 0;
                            }
                        }
                    }
                }
            }
            Log("SWING " + TimerStop());

            if (bestWait == Inf)
            {
                return(false);
            }
            move.Turn    = bestTurn;
            move.SpeedUp = bestSpUp;

            if (bestWait == 0)
            {
                move.Action = swTime == 0 ? ActionType.Strike : ActionType.Swing;
            }
            return(true);
        }