Beispiel #1
0
        public bool ShootOrTurn(FieldPlayer player, Position target)
        {
            var    playerNumber         = player.playerNumber;
            var    playerPosition       = player.position;
            double playerDirection      = player.direction;
            double destinationDirection = Math.Round(playerPosition.getAngle(target), 3);

            double distanceFCP = player.closestOpponentPlayerDistance;

            if (playerDirection == destinationDirection || distanceFCP <= 1.6)
            {
                if (distanceFCP <= 1.6)
                {
                    destination = player.team.getGoalCentre(Team.GoalType.THEIR_GOAL);
                    Random rnd = new Random();
                    destination.y += ((rnd.NextDouble() < 0.5) ? 2.0 : -2.0);
                }
                this.playerNumber = player.playerNumber;
                this.action       = Action.Kick;
                this.destination  = target;
                this.speed        = 100.0;
                Logger.log("Player " + playerNumber + " Kicks to " + destination, Logger.LogLevel.INFO);
                return(true);
            }
            else
            {
                this.playerNumber = player.playerNumber;;
                this.action       = Action.Turn;
                this.direction    = destinationDirection;
                Logger.log("Player " + playerNumber + " Turns by " + destinationDirection, Logger.LogLevel.INFO);
                return(true);
            }
        }
Beispiel #2
0
        public bool KickOrTurn(FieldPlayer player, Position target, double speed = 100.0)
        {
            var    playerNumber         = player.playerNumber;
            var    playerPosition       = player.position;
            double playerDirection      = player.direction;
            double destinationDirection = Math.Round(playerPosition.getAngle(target), 3);

            double distanceFCP = player.closestOpponentPlayerDistance;

            if (playerDirection == destinationDirection || distanceFCP <= 1.6)
            {
                this.playerNumber = player.playerNumber;
                this.action       = Action.Kick;
                this.destination  = target;
                this.speed        = speed;
                Logger.log("Player " + playerNumber + " Kicks to " + destination, Logger.LogLevel.INFO);
                return(true);
            }
            else
            {
                this.playerNumber = player.playerNumber;;
                this.action       = Action.Turn;
                this.direction    = destinationDirection;
                Logger.log("Player " + playerNumber + " Turns by " + destinationDirection, Logger.LogLevel.INFO);
                return(true);
            }
        }
Beispiel #3
0
        //------------------------- RequestPass ---------------------------------------
        //
        //  this tests to see if a pass is possible between the requester and
        //  the controlling player. If it is possible a message is sent to the
        //  controlling player to pass the ball asap.
        //-----------------------------------------------------------------------------
        public void RequestPass(FieldPlayer requester)
        {
            //maybe put a restriction here
            //if (RandFloat() > 0.1) return;

            if (IsPassSafeFromAllOpponents(controllingPlayer.position.ToVector(), requester.position.ToVector(), requester, 30.0))
            {
                //tell the player to make the pass
                //let the receiver know a pass is coming
                MessageDispatcher.instance.DispatchMsg(0.0, requester.playerNumber, controllingPlayer.playerNumber, Messages.MessageType.Msg_PassToMe, requester);
            }
        }
Beispiel #4
0
        public override bool Enter(Team team)
        {
            Logger.log("Team " + team.teamNumber + " enters KickOff state", Logger.LogLevel.INFO);

            team.SetControllingPlayer(null);
            team.receivingPlayer     = null;
            team.supportingPlayer    = null;
            team.playerClosestToBall = null;


            //these define the home regions for this state of each of the players
            int[] RightRegions = new int[6] {
                16, 20, 13, 7, 9, 3
            };
            int[] LeftRegions = new int[6] {
                35, 31, 38, 44, 42, 48
            };

            //set up the player's home regions
            if (team.playingDirection == Team.DirectionType.LEFT)
            {
                team.ChangePlayerHomeRegions(team, LeftRegions);
            }
            else
            {
                team.ChangePlayerHomeRegions(team, RightRegions);
            }

            foreach (Player player in team.Members.Values)
            {
                if (player.playerType == "P")
                {
                    FieldPlayer fieldPlayer = player as FieldPlayer;
                    if (!fieldPlayer.stateMachine.IsInState(DeadState.instance))
                    {
                        fieldPlayer.stateMachine.ChangeState(WaitState.instance);
                    }
                }
                else
                {
                    GoalKeeper keeper = player as GoalKeeper;
                    keeper.stateMachine.ChangeState(KeeperWaitState.instance);
                }
            }
            //just not to call execute method in changestate method
            return(false);
        }