Example #1
0
 /* Returns a list with all players who will tackle in this round. */
 public List<Player> SearchTacklePlayers(Player[] allPlayers)
 {
     List<Player> tacklePlayers = new List<Player>();
     foreach (Player player in allPlayers)
     {
         ActionType type;
         Pathfinding pathfinding = new Pathfinding();
         //returns the last action type which the player will execute in this round.
         pathfinding.PlayerAtSpecificRound(player, 1, out type);
         if (type == ActionType.Tackle)
         {
             tacklePlayers.Add(player);
         }
     }
     return tacklePlayers;
 }
Example #2
0
        /* Returns all enemies which stands around this location in a specific range and specific round */
        public List<Player> SurroundingPlayers(Team enemyTeam, double range, Point location, int round)
        {
            List<Player> enemies = new List<Player>();
            Pathfinding pathfinding = new Pathfinding();
            foreach (Player player in enemyTeam.Players)
            {
                if (player.Position != PlayerPosition.Goalkeeper)
                {
                    ActionType type;
                    Point nextPoint = pathfinding.PlayerAtSpecificRound(player, round, out type);
                    double distance = Pathfinding.DistanceBetweenPoints(location, nextPoint);
                    if (distance <= range)
                    {
                        enemies.Add(player);
                    }
                }
            }

            return enemies;
        }
Example #3
0
        /* Returns all players from the list who will stand within a specific rectangle in a specific round. */
        public List<Player> PlayerInRectangle(List<Player> targetPlayers, Rectangle runRectangle, int round)
        {
            Pathfinding pathfinding = new Pathfinding();
            List<Player> playerInRectangle = new List<Player>();
            foreach (Player player in targetPlayers)
            {
                if (player.Position != PlayerPosition.Goalkeeper)
                {
                    ActionType type;
                    Point nextPoint = pathfinding.PlayerAtSpecificRound(player, round, out type);
                    if (runRectangle.Contains(nextPoint))
                    {
                        playerInRectangle.Add(player);
                    }
                }
            }

            return playerInRectangle;
        }
Example #4
0
        /* Returns the player's specific round position of the player from the team who will be the nearest to the root point.
         * Returns the ball's specific round position, if there will be no player in the run room. */
        public Point NextPointNearestPlayerInRunRoom(Point rootPoint, Rectangle runRoom, Team playerTeam, int round)
        {
            Pathfinding pathfinding = new Pathfinding();
            Team enemyTeam = GetEnemyTeam(playerTeam);
            ActionType type;

            List<Player> allEnemiesInRunRoom = PlayerInRectangle(enemyTeam.Players, runRoom, 1);
            Point closestPlayerNextLocation;

            // takes the ball's next round position if no enemy stands in the player's run room
            if (allEnemiesInRunRoom.Count == 0)
            {
                closestPlayerNextLocation = BallNextRoundLocation();
            }
            else
            {
                Player closestPlayerInRunRoom = NearestPlayersToPoint(allEnemiesInRunRoom, playerTeam.TeamGoal.MiddlePoint, 1, round, false).ElementAt(0);
                if (closestPlayerInRunRoom.IsMarkedUp)
                {
                    closestPlayerNextLocation = BallNextRoundLocation();
                }
                else
                {
                    closestPlayerNextLocation = pathfinding.PlayerAtSpecificRound(closestPlayerInRunRoom, round, out type);
                    closestPlayerInRunRoom.IsMarkedUp = true;
                }
            }

            return closestPlayerNextLocation;
        }
Example #5
0
        /* Returns a sorted list with a specific amount of team players depending on their distance to the targetpoint in X rounds. */
        public List<Player> NearestPlayersToPoint(List<Player> playerList, Point targetPoint, int playerCount, int round, bool involveGoalKeeper)
        {
            List<Player> nearestPlayers = new List<Player>();
            List<double> playerDistances = new List<double>();
            Pathfinding pathfinding = new Pathfinding();
            double currentDistance;
            Point nextStepPoint;
            foreach (Player player in playerList)
            {
                if (involveGoalKeeper || player.Position != PlayerPosition.Goalkeeper)
                {
                    ActionType type;
                    nextStepPoint = pathfinding.PlayerAtSpecificRound(player, round, out type);
                    currentDistance = Pathfinding.DistanceBetweenPoints(nextStepPoint, targetPoint);
                    if (nearestPlayers.Count == 0)
                    {
                        nearestPlayers.Add(player);
                        playerDistances.Add(currentDistance);
                    }
                    else
                    {
                        for (int i = 0; i <= playerDistances.Count; i++)
                        {
                            if (i == playerDistances.Count || currentDistance < playerDistances[i])
                            {
                                nearestPlayers.Insert(i, player);
                                playerDistances.Insert(i, currentDistance);
                                break;
                            }
                        }

                        //removes last player if there are too many players saved already.
                        if (nearestPlayers.Count > playerCount)
                        {
                            nearestPlayers.RemoveAt(nearestPlayers.Count - 1);
                            playerDistances.RemoveAt(playerDistances.Count - 1);
                        }
                    }
                }
            }

            return nearestPlayers;
        }
Example #6
0
        /* Returns the position where the goalkeeper of the team will be in x rounds. */
        public Point KeeperPosition(Team team, int round)
        {
            Player keeper = team.Goalkeeper;

            Pathfinding pathfinding = new Pathfinding();
            ActionType type;

            return pathfinding.PlayerAtSpecificRound(keeper, round, out type);
        }
Example #7
0
        /*Returns the location where the ball will be in the next round */
        public Point BallNextRoundLocation()
        {
            Point ballTarget;

            if (GameBall.HasPlayerContact && GameBall.LastPlayer != null)
            {
                Pathfinding pathfinding = new Pathfinding();
                ActionType type;
                //sets the balltarget to the point where the player who controls the ball at the moment will go to in the next round. */
                ballTarget = pathfinding.PlayerAtSpecificRound(GameBall.LastPlayer, 1, out type);
            }
            else if (GameBall.TargetPoint.HasValue)
            {
                Pathfinding pathfinding = new Pathfinding();
                Point tmpBallExactLocation = GameBall.ExactLocation;
                Point tmpBallGridLocation = pathfinding.GetGridLocation(tmpBallExactLocation);

                double[] direction = pathfinding.GetExactDirection(tmpBallExactLocation, pathfinding.GetExactLocation(GameBall.TargetPoint.Value));
                for (int i = 0; i < GameBall.Speed; i++)
                {
                    tmpBallExactLocation.X += (int)(direction[0] * 20);
                    tmpBallExactLocation.Y += (int)(direction[1] * 20);
                }
                ballTarget = pathfinding.GetGridLocation(tmpBallExactLocation);
            }
            else
            {
                ballTarget = GameBall.Location;
            }

            return ballTarget;
        }
Example #8
0
        public override PlayerAction ActionEnemyHasBall(Player player)
        {
            Pathfinding pathfinding = new Pathfinding();
            int enemyDistanceToOwnGoal;
            Team enemyTeam = GameAI.GetEnemyTeam(GameAI.PlayersTeam(player));

            List<Player> allEnemiesInRunRoom = GameAI.PlayerInRectangle(enemyTeam.Players, RunRoom(GameAI.PlayersTeam(player)), 1);
            Point closestPlayerNextLocation;

            if (allEnemiesInRunRoom.Count == 0)
            {
                closestPlayerNextLocation = GameAI.BallNextRoundLocation();
                enemyDistanceToOwnGoal = Math.Abs(closestPlayerNextLocation.X - GameAI.PlayersTeam(player).TeamGoal.MiddlePoint.X);
            }
            else
            {
                Player closestPlayerInRunRoom = GameAI.NearestPlayersToPoint(allEnemiesInRunRoom, GameAI.PlayersTeam(player).TeamGoal.MiddlePoint, 1, 1, false).ElementAt(0);
                ActionType type;
                closestPlayerNextLocation = pathfinding.PlayerAtSpecificRound(closestPlayerInRunRoom, 1, out type);

                enemyDistanceToOwnGoal = Math.Abs(closestPlayerNextLocation.X - GameAI.PlayersTeam(player).TeamGoal.XCoordinate);
            }

            if (enemyDistanceToOwnGoal > DefenceBallDistance )
            {
                Point targetPoint = player.Location;
                targetPoint.X = closestPlayerNextLocation.X + pathfinding.CalculateHorizontalDirection(player.Location, GameAI.PlayersTeam(player).TeamGoal.MiddlePoint) * DefenceBallDistance;
                int verticalDistanceToStandardLocation = Math.Abs(player.Location.Y - player.StartLocation.Y);
                targetPoint.Y = closestPlayerNextLocation.Y;

                return new PlayerAction(null, targetPoint, ActionType.Run);
            }
            else
            {
                List<Player> nearPlayers = GameAI.NearestPlayersToPoint(enemyTeam.Players, GameAI.PlayersTeam(player).TeamGoal.MiddlePoint, enemyTeam.Players.Count, 1, false);

                Player markPlayer = nearPlayers.ElementAt(0);
                foreach (Player nearPlayer in nearPlayers)
                {
                    if (!nearPlayer.IsMarkedUp)
                    {
                        markPlayer = nearPlayer;
                    }
                }

                markPlayer.IsMarkedUp = true;
                ActionType type;
                Point targetLocation = pathfinding.PlayerAtSpecificRound(markPlayer, 1, out type);

                int horizontalDistanceToPlayer = Math.Abs(GameAI.PlayersTeam(player).TeamGoal.MiddlePoint.X - targetLocation.X);
                if (horizontalDistanceToPlayer > 10)
                {
                    targetLocation.X = player.XCoordinate;
                }
                else
                {
                    targetLocation.X += pathfinding.CalculateHorizontalDirection(markPlayer.Location, GameAI.PlayersTeam(player).TeamGoal.MiddlePoint) * 2;
                }

                return new PlayerAction(null, targetLocation, ActionType.Run);
            }
        }
Example #9
0
        /// <summary>
        /// For the case that the enemy has the ball and is close to the own goal.
        /// </summary>
        /// <param name="player">The player who will execute the action</param>
        /// <returns></returns>
        public virtual PlayerAction ActionEnemyClose(Player player)
        {
            Pathfinding pathfinding = new Pathfinding();
            Team enemyTeam = GameAI.GetEnemyTeam(GameAI.PlayersTeam(player));
            ActionType type;

            List<Player> nearPlayersToPenaltyPoint = GameAI.NearestPlayersToPoint(enemyTeam, GameAI.PenaltyKickPoint(enemyTeam.TeamGoal), 2, 1, false);

            Player nearPlayer;
            if (nearPlayersToPenaltyPoint.ElementAt(0).Equals(player))
            {
                nearPlayer = nearPlayersToPenaltyPoint.ElementAt(1);
            }
            else
            {
                nearPlayer = nearPlayersToPenaltyPoint.ElementAt(0);
            }
            Point nextPlayerLocation = pathfinding.PlayerAtSpecificRound(nearPlayer, 1, out type);

            return new PlayerAction(null, nextPlayerLocation, ActionType.Run);
        }