Пример #1
0
        private void _carMoveFunc(ACar model, int from, int to, int step, AMove m, PassedInfo passed, CarCallback callback)
        {
            model   = model.Clone();
            passed  = passed.Clone();
            m.Times = 0;

            for (var t = 0; t < from; t++)
            {
                if (!_modelMove(model, m, passed))
                {
                    return;
                }
                m.Times++;
            }

            for (var t = from; t <= to; t += step)
            {
                _movesStack.Add(m);
                callback(model, passed);
                _movesStack.Pop();
                for (var r = 0; r < step; r++)
                {
                    if (!_modelMove(model, m, passed))
                    {
                        return;
                    }
                    m.Times++;
                }
            }
        }
Пример #2
0
        private void _doRecursive(ACar model, int patternIndex, PassedInfo total)
        {
            model = model.Clone();
            total = total.Clone();

            if (patternIndex == _patterns.Length)
            {
                var m = LastStageMove.Clone();
                m.WheelTurn = _turnTo.Clone();

                if (m.IsUseNitro && (model.Speed.Length > 22 || m.EnginePower < 0))
                    return;

                var penalty = 0.0;

                for (var i = 0; ; i++)
                {
                    if (i == 200 && m.EnginePower >= 0 || i == 250 && m.EnginePower < 0)
                        return;

                    var dst = _turnTo.GetDistanceTo2(model);
                    if (dst < _needDist*_needDist)
                        break;

                    if (!_modelMove(model, m, total))
                    {
                        if (_useDist2 && m.EnginePower <= 1 && !LastStageMove.IsUseNitro)
                        {
                            if (dst < _needDist2 * _needDist2)
                            {
                                penalty = MagicConst.SecondDistDangerCoeff;
                                total.Importance -= penalty;
                                m.Times++;
                                break;
                            }
                        }
                        return;
                    }

                    m.Times++;
                }
                if (!total.WayPoint)
                    return;
                if (!MyStrategy.CheckVisibility(Self.Original, model, penalty > 0 ? _turnTo2 : _turnTo, 20))
                    return;

                if (model.EnginePower < 0)
                {
                    penalty += MagicConst.BackMoveDangerCoeff;
                    total.Importance -= MagicConst.BackMoveDangerCoeff;
                }

                if (total.Time - total.Importance < _bestTime - _bestImportance)
                {
                    _bestTime = total.Time;
                    _bestImportance = total.Importance;
                    _bestMovesStack = _movesStack.Clone();
                    _bestMovesStack.Add(m);
                    _bestMovesStack.Penalty = penalty;
                }
                return;
            }

            var pattern = _patterns[patternIndex];

            _carMoveFunc(model, pattern.From, pattern.To, pattern.Step,
                pattern.Move.Clone(), total, (aCar, passed) =>
                {
                    // ReSharper disable once ConvertToLambdaExpression
                    _doRecursive(aCar.Clone(), patternIndex + 1, passed.Clone());
                });
        }
Пример #3
0
        private void _doRecursive(ACar model, int patternIndex, PassedInfo total)
        {
            model = model.Clone();
            total = total.Clone();

            if (patternIndex == _patterns.Length)
            {
                var m = LastStageMove.Clone();
                m.WheelTurn = _turnTo.Clone();

                if (m.IsUseNitro && (model.Speed.Length > 22 || m.EnginePower < 0))
                {
                    return;
                }

                var penalty = 0.0;

                for (var i = 0; ; i++)
                {
                    if (i == 200 && m.EnginePower >= 0 || i == 250 && m.EnginePower < 0)
                    {
                        return;
                    }

                    var dst = _turnTo.GetDistanceTo2(model);
                    if (dst < _needDist * _needDist)
                    {
                        break;
                    }

                    if (!_modelMove(model, m, total))
                    {
                        if (_useDist2 && m.EnginePower <= 1 && !LastStageMove.IsUseNitro)
                        {
                            if (dst < _needDist2 * _needDist2)
                            {
                                penalty           = MagicConst.SecondDistDangerCoeff;
                                total.Importance -= penalty;
                                m.Times++;
                                break;
                            }
                        }
                        return;
                    }

                    m.Times++;
                }
                if (!total.WayPoint)
                {
                    return;
                }
                if (!MyStrategy.CheckVisibility(Self.Original, model, penalty > 0 ? _turnTo2 : _turnTo, 20))
                {
                    return;
                }

                if (model.EnginePower < 0)
                {
                    penalty          += MagicConst.BackMoveDangerCoeff;
                    total.Importance -= MagicConst.BackMoveDangerCoeff;
                }

                if (total.Time - total.Importance < _bestTime - _bestImportance)
                {
                    _bestTime       = total.Time;
                    _bestImportance = total.Importance;
                    _bestMovesStack = _movesStack.Clone();
                    _bestMovesStack.Add(m);
                    _bestMovesStack.Penalty = penalty;
                }
                return;
            }

            var pattern = _patterns[patternIndex];

            _carMoveFunc(model, pattern.From, pattern.To, pattern.Step,
                         pattern.Move.Clone(), total, (aCar, passed) =>
            {
                // ReSharper disable once ConvertToLambdaExpression
                _doRecursive(aCar.Clone(), patternIndex + 1, passed.Clone());
            });
        }
Пример #4
0
        private void _carMoveFunc(ACar model, int from, int to, int step, AMove m, PassedInfo passed, CarCallback callback)
        {
            model = model.Clone();
            passed = passed.Clone();
            m.Times = 0;

            for (var t = 0; t < from; t++)
            {
                if (!_modelMove(model, m, passed))
                    return;
                m.Times++;
            }

            for (var t = from; t <= to; t += step)
            {
                _movesStack.Add(m);
                callback(model, passed);
                _movesStack.Pop();
                for (var r = 0; r < step; r++)
                {
                    if (!_modelMove(model, m, passed))
                        return;
                    m.Times++;
                }
            }
        }