Esempio n. 1
0
 public void ChangeSide()
 {
     this.MoveRegion          = this.MoveRegion.Mirror();
     this._xPlusActiveRegion  = PlayerRule.GetActiveRegion(true, this.MoveRegion);
     this._xMinusActiveRegion = PlayerRule.GetActiveRegion(false, this.MoveRegion);
     this.Default             = this.Default.Mirror();
     this.HalfDefault         = this.HalfDefault.Mirror();
     this.Destination         = this.Current = this.HalfDefault;
 }
Esempio n. 2
0
        /// <summary>
        /// Internal logic of the shoot.
        /// 射门的内部逻辑
        /// </summary>
        /// <param name="property">Represents the property id.</param>
        /// <param name="speed">Represents the football's speed.</param>
        /// <param name="fix">Represents the fix value.</param>
        private void InternalShoot(IState doneState, IManager manager, byte property, int speed, double fix, double coord)
        {
            // 球员朝向
            IPlayer gk = manager.Opponent.GetPlayersByPosition(Position.Goalkeeper)[0];

            Rotate(gk.Current);
            _match.Football.MoveTo(gk.Current);
            bool missFlag = false;

            // 射中门框
            if (_match.RandomPercent() < Defines.Shoot.ShootToFramePercentage)
            {
                _status.ShootStatus.ShootTargetIndex = 0;
                _status.ShootStatus.ShootTarget      = Match.Pitch.Goal.GetRandomDoorFrame(_match);
                missFlag = true;
            }
            else
            {
                int index = PlayerRule.GetShootTargetIndex(_match, _propCore[property], this, fix, coord);
                _status.ShootStatus.ShootTargetIndex = index;
                _status.ShootStatus.ShootTarget      = _match.Pitch.Goal.GetShootTargetByIndex(_match, index);
                _status.ShootStatus.ShootSpeed       = speed;
                if (index == 0 || index == 4)
                {
                    missFlag = true;
                    if (index == 4)
                    {
                        _match.Status.Break(EnumMatchBreakState.ShootFly);
                    }
                    else
                    {
                        _match.Status.Break(EnumMatchBreakState.Shooted);
                    }
                }
                else if (!gk.SkillEnable || gk.SkillLimitState != 0)
                {
                    _status.SetDoneState(doneState, EnumDoneStateFlag.Succ);
                    _status.ShootStatus.SuccFlag    = 1;
                    _status.ShootStatus.NewSuccRate = 100;
                    _status.ShootStatus.RawSuccRate = 0;
                    _match.Goal(manager);
                    return;
                }
            }
            if (missFlag)
            {
                _status.SetDoneState(doneState, EnumDoneStateFlag.Fail);
                _status.ShootStatus.SuccFlag    = 0;
                _status.ShootStatus.NewSuccRate = 0;
                _status.ShootStatus.RawSuccRate = 0;
                _match.MissGoal(manager, true);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 获取传球的目标点
        /// </summary>
        private Coordinate GetTarget()
        {
            Coordinate target = _status.PassStatus.PassTarget.Current;
            bool       isHome = Side == Base.Enum.Side.Home;

            if (target.Y < Defines.Pitch.PASS_PROTECTED_LINE || target.Y > Defines.Pitch.MAX_HEIGHT - Defines.Pitch.PASS_PROTECTED_LINE)
            {
                target = new Coordinate(target.X + (isHome ? 10 : -10), target.Y);
            }
            else
            {
                target = AI.Decides.Utility.GetPointWithRange(_status.PassStatus.PassTarget, _status.PassStatus.PassTarget.Destination, Defines.Player.PASS_AHEAD_RANGE);
                //Coordinate destTarget = _status.PassStatus.PassTarget.Destination;
                //double difFromX = this.Current.X - target.X;
                //double difFromY = this.Current.Y - target.Y;
                //double difDestX = destTarget.X - target.X;
                //double difDestY = destTarget.Y - target.Y;
                //if ((difFromX > 0 && difDestX > 0 || difFromX < 0 && difDestX < 0)
                //    && (difFromY > 0 && difDestY > 0 || difFromY < 0 && difDestY < 0))
                //    target = new Coordinate(target.X + (isHome ? 10 : -10), target.Y);
                //else
                //    target = AI.Decides.Utility.GetPointWithRange(_status.PassStatus.PassTarget, _status.PassStatus.PassTarget.Destination, Defines.Player.PASS_AHEAD_RANGE);
            }
            var pro = 50 + 0.25 * _propCore[PlayerProperty.Passing];

            if (pro > 90)
            {
                pro = 90;
            }
            #region Old
            //var pro = 50 + 0.2 * _propCore[PlayerProperty.Passing];
            //if (pro > 90)
            //{
            //    pro = 90;
            //}
            #endregion
            // 守门员不会传球失误
            if (_input.AsPosition != Position.Goalkeeper)
            {
                // 传球失误
                if (_match.RandomPercent() >= pro)
                {
                    target = PlayerRule.GetPassOffset(_match, this, target);
                    _status.PassStatus.IsPassFail = true;
                }
            }
            return(FixOffSide(target));
        }
Esempio n. 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PlayerStatus"/> class.
        /// </summary>
        /// <param name="player"><see cref="IPlayer"/></param>
        /// <param name="coordinate">Represents the player's default coordinate.</param>
        public PlayerStatus(IPlayer player, Coordinate curPoint, Coordinate halfDefault)
        {
            _player        = player;
            _defenceStatus = new DefenceStatus(_player);
            _passStatus    = new PassStatus(_player);
            SubState       = new SubStateObj();

            var side     = player.Side;
            var position = player.Input.AsPosition;

            if (position == Position.Goalkeeper)
            {
                this.MoveRegion = PlayerRule.GetGoalKeeperMoveRegion(position, side);
            }
            else
            {
                this.MoveRegion = MoveRegionCache.GetMoveRegion(curPoint);
                if (side == Side.Away)
                {
                    this.MoveRegion = this.MoveRegion.Mirror();
                }
            }
            this._xPlusActiveRegion  = PlayerRule.GetActiveRegion(true, this.MoveRegion);
            this._xMinusActiveRegion = PlayerRule.GetActiveRegion(false, this.MoveRegion);
            if (side == Side.Away)
            {
                curPoint    = curPoint.Mirror();
                halfDefault = halfDefault.Mirror();
            }
            this.Default      = curPoint;
            this.HalfDefault  = halfDefault;
            this.Acceleration = PlayerRule.GetAcceleration(player.PropCore[PlayerProperty.Speed, 0, -1, false], player.PropCore[PlayerProperty.Acceleration, 0, -1, false]);
            this.MaxSpeed     = PlayerRule.GetMaxSpeed(player.PropCore[PlayerProperty.Speed, 0, -1, false]);
            //this.Speed = PlayerRule.GetSpeed(player, this.MaxSpeed);
            this.Reset();
            this.Redecide();
        }
Esempio n. 5
0
		public void AddTurn(PlayerRule turn)
		{
			turns.Add(turn);
		}
Esempio n. 6
0
		public AIVariant(PlayerRule turn, VariantOffer offer)
			: this(turn)
		{
			this.offer = offer;
		}
Esempio n. 7
0
		public AIVariant(PlayerRule turn)
			:this()
		{
			AddTurn(turn);
		}
Esempio n. 8
0
        /// <summary>
        /// Moves current object.
        /// 球员移动
        /// </summary>
        public void Move()
        {
            // 判定当前球员是否移动出了可移动区域
            //ValidateOutofRegion();
            ValidateOutofRegionX();

            #region 球员旋转
            var angle = _status.Angle;
            Rotate(_status.Destination);

            if (Math.Abs(_status.Angle - angle) > 90)
            {
                DecreaseSpeed();    // decrease the speed while the player rotate large than 90 degree
                if (_status.IsAttackSide)
                {
                    return;
                }
            }
            #endregion

            #region 门将的后退
            if (_input.AsPosition == Position.Goalkeeper)
            {
                if (this.Side == Side.Home)
                {
                    _status.IsBackward = (_status.Destination.X < _status.Current.X);
                }
                else
                {
                    _status.IsBackward = (_status.Destination.X > _status.Current.X);
                }

                if (_status.Hasball) // 如果门将往球移动,则为站起状态
                {
                    _status.IsStantUp = false;
                }
            }
            #endregion

            #region 球员移动
            if (Status.DestinationDistanceZero)
            {
                Redecide();
                return;
            }

            // 当前回合可移动的距离
            double totalDistance  = Status.DestinationDistance;
            double topSpeed       = PlayerRule.GetSpeed(this, Speed + Acceleration * Defines.Match.ROUND_TIME);
            double passedDistance = (Speed + topSpeed) / 2 * Defines.Match.ROUND_TIME;
            passedDistance = Math.Max(0.51, passedDistance);
            if (passedDistance > totalDistance)
            {
                this._status.Current = this._status.Destination;
                Coordinate newCoor;
                if (this._status.Current.Regulate(out newCoor))
                {
                    this._status.Destination = this._status.Current = newCoor;
                    Redecide();
                }
                return;
            }

            // 将移动距离映射至坐标系上
            var changeX = Math.Abs(this._status.Destination.X - this._status.Current.X) * passedDistance / totalDistance;
            var changeY = Math.Abs(this._status.Destination.Y - this._status.Current.Y) * passedDistance / totalDistance;

            // 计算移动后坐标
            var x = _status.Current.X;
            var y = _status.Current.Y;
            x += (this._status.Destination.X > this._status.Current.X) ? changeX : -changeX;
            y += (this._status.Destination.Y > this._status.Current.Y) ? changeY : -changeY;

            // 防止守门员离开禁区 同时守门员持球时可以离开禁区 (解决门将无法接传球失误的球 2010-6-21 )
            if (this._input.AsPosition == Position.Goalkeeper && _status.Hasball == false)
            {
                var region = (Side == Base.Enum.Side.Home) ? _match.Pitch.HomePenaltyRegion : _match.Pitch.AwayPenaltyRegion;
                if (x < region.Start.X)
                {
                    x = region.Start.X;
                }
                if (x > region.End.X)
                {
                    x = region.End.X;
                }
                if (y < region.Start.Y)
                {
                    y = region.Start.Y;
                }
                if (y > region.End.Y)
                {
                    y = region.End.Y;
                }
            }

            // 修正最后坐标&速度
            this._status.Current = new Coordinate(x, y).Regulate();
            this._status.Speed   = topSpeed;
            #endregion
        }
Esempio n. 9
0
 public void Init()
 {
     PlayerRule.InitPassTarget(this);
 }