예제 #1
0
        public override PlayerAction CornerDefense(Player player)
        {
            Pathfinding pathfinding = new Pathfinding();

            Point targetPoint = player.StartLocation;
            targetPoint.X = GameAI.PlayersTeam(player).TeamGoal.MiddlePoint.X + pathfinding.CalculateHorizontalDirection(GameAI.PlayersTeam(player).TeamGoal.MiddlePoint, new Point(12, 12)) * 7;

            return new PlayerAction(null, targetPoint, ActionType.Run);
        }
예제 #2
0
파일: AI.cs 프로젝트: Jecral/Football
        /* Returns all player from the team who have another horizontal direction to the target */
        public List<Player> PlayersWithOtherHorizontalDirection(Point targetPoint, int horizontalDirection, Team team)
        {
            Pathfinding pathfinding = new Pathfinding();
            List<Player> validPlayers = new List<Player>();

            foreach (Player player in team.Players)
            {
                int movementDirection = pathfinding.CalculateHorizontalDirection(player.Location, targetPoint);
                if (movementDirection != horizontalDirection)
                {
                    validPlayers.Add(player);
                }
            }

            return validPlayers;
        }
예제 #3
0
        public override PlayerAction ActionWeHaveBall(Player player, GameAction gameAction)
        {
            Goal enemyTeamGoal = GameAI.GetEnemyTeam(GameAI.PlayersTeam(player)).TeamGoal;
            Pathfinding pathfinding = new Pathfinding();
            int horizontalDistanceToBall = Math.Abs(GameAI.GameBall.XCoordinate - player.XCoordinate);

            int ballDistanceToOwnGoal = Math.Abs(GameAI.BallNextRoundLocation().X - player.XCoordinate);

            Point targetPoint = new Point();

            if (gameAction.GameStatus == Status.GoalKick)
            {
                targetPoint.X = player.Location.X + (pathfinding.CalculateHorizontalDirection(player.Location, enemyTeamGoal.MiddlePoint) * (player.MaxSpeed * 4));
            }
            else
            {
                if (ballDistanceToOwnGoal > 7)
                {
                    int verticalDistanceToStandardLocation = Math.Abs(player.Location.Y - player.StartLocation.Y);
                    targetPoint.Y = (verticalDistanceToStandardLocation > 4) ? player.StartLocation.Y : player.Location.Y;
                    targetPoint.X = GameAI.BallNextRoundLocation().X + ((pathfinding.CalculateHorizontalDirection(player.Location, GameAI.PlayersTeam(player).TeamGoal.MiddlePoint) * (player.MaxSpeed * 6)));
                }
                else
                {
                    targetPoint = GameAI.PlayersTeam(player).TeamGoal.MiddlePoint;
                    targetPoint.X -= (pathfinding.CalculateHorizontalDirection(player.Location, GameAI.PlayersTeam(player).TeamGoal.MiddlePoint) * 4);
                }
            }

            Rectangle rangeRectangle = RunRoom(GameAI.PlayersTeam(player));
            Point freePoint = SearchFreeTargetPoint(player, rangeRectangle, targetPoint, 2, 0);

            return new PlayerAction(null, freePoint, ActionType.Run);
        }
예제 #4
0
파일: AI.cs 프로젝트: Jecral/Football
        /* Returns the penalty kick point from this goal. */
        public Point PenaltyKickPoint(Goal goal)
        {
            Pathfinding pathfinding = new Pathfinding();

            Point penaltyKickPoint = goal.MiddlePoint;
            penaltyKickPoint.X += pathfinding.CalculateHorizontalDirection(goal.MiddlePoint, new Point(12, 12)) * 4;

            return penaltyKickPoint;
        }
예제 #5
0
        public override PlayerAction CornerAttack(Player player)
        {
            Pathfinding pathfinding = new Pathfinding();

            Team enemyTeam = GameAI.GetEnemyTeam(GameAI.PlayersTeam(player));
            Point targetPoint = player.StartLocation;
            targetPoint.X = enemyTeam.TeamGoal.XCoordinate + pathfinding.CalculateHorizontalDirection(enemyTeam.TeamGoal.MiddlePoint, new Point(12, 12)) * DefenceBallDistance;

            return new PlayerAction(null, targetPoint, ActionType.Run);
        }
예제 #6
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);
            }
        }
예제 #7
0
파일: PlayerAI.cs 프로젝트: Jecral/Football
        /// <summary>
        /// Returns a Run-PlayerAction where the player will run towards the goal in the parameters.
        /// </summary>
        /// <param name="player"></param>
        /// <param name="goal"></param>
        /// <returns></returns>
        public PlayerAction RunTowardsGoal(Player player, Goal goal)
        {
            Pathfinding pathfinding = new Pathfinding();

            Point targetPoint = player.Location;
            targetPoint.X += pathfinding.CalculateHorizontalDirection(player.Location, goal.MiddlePoint);
            int verticalDistanceToStandardLocation = Math.Abs(player.Location.Y - player.StartLocation.Y);
            if (verticalDistanceToStandardLocation > 4)
            {
                targetPoint.Y = player.StartLocation.Y;
            }

            return new PlayerAction(null, targetPoint, ActionType.Run);
        }
예제 #8
0
        private int AdjustXTargetPoint(Team playerTeam, bool onOwnSide, int distanceToOwnGoal)
        {
            Pathfinding pathfinding = new Pathfinding();

            //the keeper will run in the direction of the ball - only if the ball will be on the own side in the next round and is controlled by the enemy.
            int keeperDistanceToGoal;
            Goal enemyGoal = GameAI.GetEnemyTeam(playerTeam).TeamGoal;

            if (distanceToOwnGoal > 0)
            {
                keeperDistanceToGoal = playerTeam.TeamGoal.XCoordinate + pathfinding.CalculateHorizontalDirection(playerTeam.TeamGoal.Location, enemyGoal.Location) * (1 + distanceToOwnGoal / 5);
            }
            else
            {
                keeperDistanceToGoal = playerTeam.TeamGoal.XCoordinate + pathfinding.CalculateHorizontalDirection(playerTeam.TeamGoal.Location, enemyGoal.Location) * 1;
            }

            return keeperDistanceToGoal;
        }
예제 #9
0
파일: PlayerAI.cs 프로젝트: Jecral/Football
        /// <summary>
        /// Returns a PlayerAction wehre the player will pass to a point where another player will run to.
        /// </summary>
        /// <param name="rootPlayer"></param>
        /// <param name="targetPlayer"></param>
        /// <returns></returns>
        public PlayerAction PassIntoRunWay(Player rootPlayer, Player targetPlayer)
        {
            Pathfinding pathfinding = new Pathfinding();
            Team enemyTeam = GameAI.GetEnemyTeam(GameAI.PlayersTeam(rootPlayer));

            int gridDistance = Pathfinding.GridDistanceBetweenPoints(rootPlayer.Location, targetPlayer.Location);
            int runDistance = gridDistance / 2;

            Point targetPoint = targetPlayer.Location;
            targetPoint.X += pathfinding.CalculateHorizontalDirection(rootPlayer.Location, enemyTeam.TeamGoal.Location) * runDistance;
            targetPoint = SearchFreeTargetPoint(rootPlayer, targetPoint).Value;

            targetPlayer.WaitForBallAtPoint(targetPoint);

            return new PlayerAction(null, targetPoint, ActionType.Pass);
        }
예제 #10
0
파일: PlayerAI.cs 프로젝트: Jecral/Football
        /// <summary>
        /// Returns an action where the player will run to the penaly kick point of the goal in the parameter.
        /// </summary>
        /// <param name="player"></param>
        /// <param name="goal"></param>
        /// <returns></returns>
        public PlayerAction RunToPenaltyKickPoint(Player player, Goal goal)
        {
            Pathfinding pathfinding = new Pathfinding();
            Point targetPoint = goal.MiddlePoint;
            targetPoint.X += pathfinding.CalculateHorizontalDirection(goal.MiddlePoint, new Point(12, 12)) * 3;

            Point freePoint = SearchFreeTargetPoint(player, targetPoint).Value;

            return new PlayerAction(null, freePoint, ActionType.Run);
        }
예제 #11
0
파일: PlayerAI.cs 프로젝트: Jecral/Football
        /// <summary>
        /// Run to the enemy goal.
        /// </summary>
        /// <param name="player"></param>
        /// <returns></returns>
        public PlayerAction GoalKickAttack(Player player)
        {
            Pathfinding pathfinding = new Pathfinding();
            Goal enemyTeamGoal = GameAI.GetEnemyTeam(GameAI.PlayersTeam(player)).TeamGoal;
            Point targetPoint = new Point();

            int verticalDistanceToStandardLocation = Math.Abs(player.Location.Y - player.StartLocation.Y);
            targetPoint.Y = (verticalDistanceToStandardLocation > 3) ? player.StartLocation.Y : player.Location.Y;

            targetPoint.X = player.Location.X + (pathfinding.CalculateHorizontalDirection(player.Location, enemyTeamGoal.MiddlePoint) * (player.MaxSpeed * 4));

            Point freePoint = SearchFreeTargetPoint(player, RunRoom(GameAI.PlayersTeam(player)), targetPoint, 3, 0);

            return new PlayerAction(null, freePoint, ActionType.Run);
        }
예제 #12
0
파일: PlayerAI.cs 프로젝트: Jecral/Football
        /// <summary>
        /// For the case that the player has the ball and is not surrounded by enemies.
        /// </summary>
        /// <param name="player">The player who will execute the action.</param>
        /// <returns></returns>
        public virtual PlayerAction ActionWithBallNotSurrounded(Player player)
        {
            Pathfinding pathfinding = new Pathfinding();
            Team enemyTeam = GameAI.GetEnemyTeam(GameAI.PlayersTeam(player));

            int distanceToEnemyGoal = Math.Abs(player.XCoordinate - enemyTeam.TeamGoal.XCoordinate);

            //true if the player stands close to the enemy's goal but is not in a shoot position
            if (distanceToEnemyGoal < enemyTeam.TeamGoal.Height * 2)
            {
                if (!IsInShootPosition(player))
                {
                    return PassCloseToGoal(player);
                }
                else
                {
                    return Shoot(GameAI.PlayersTeam(player));
                }
            }
            else
            {
                Point targetPoint;
                if (IsDeepInEnemySide(player))
                {
                    return RunToPenaltyKickPoint(player, enemyTeam.TeamGoal);
                }
                else
                {
                    targetPoint = player.Location;
                    targetPoint.X = player.Location.X + pathfinding.CalculateHorizontalDirection(player.Location, enemyTeam.TeamGoal.MiddlePoint) * player.MaxSpeed * 4;

                    Point freePoint = SearchFreeTargetPoint(player, RunRoom(GameAI.PlayersTeam(player)), targetPoint, 4, 0);

                    return new PlayerAction(null, freePoint, ActionType.Run);
                }
            }
        }
예제 #13
0
파일: PlayerAI.cs 프로젝트: Jecral/Football
        /// <summary>
        /// For the case that the own team controls the ball and the enemy's goal is far away from the player.
        /// </summary>
        /// <param name="player">The player who will execute the action.</param>
        /// <param name="gameAction"></param>
        /// <returns></returns>
        public virtual PlayerAction ActionGoalFarAway(Player player, GameAction gameAction)
        {
            Goal enemyTeamGoal = GameAI.GetEnemyTeam(GameAI.PlayersTeam(player)).TeamGoal;
            Pathfinding pathfinding = new Pathfinding();

            int horizontalDistanceToBall = Math.Abs(GameAI.GameBall.XCoordinate - player.XCoordinate);
            int distanceToEnemyGoal = Math.Abs(enemyTeamGoal.XCoordinate - player.XCoordinate);
            int ballDistanceToEnemyGoal = Math.Abs(enemyTeamGoal.XCoordinate - GameAI.GameBall.XCoordinate);
            Point ballNextRoundLocation = GameAI.BallNextRoundLocation();

            Point targetPoint = new Point();

            int verticalDistanceToStandardLocation = Math.Abs(player.Location.Y - player.StartLocation.Y);
            targetPoint.Y = (verticalDistanceToStandardLocation > 3) ? player.StartLocation.Y : player.Location.Y;
            if (gameAction.GameStatus == Status.GoalKick)
            {
                targetPoint.X = player.Location.X + (pathfinding.CalculateHorizontalDirection(player.Location, enemyTeamGoal.MiddlePoint) * (player.MaxSpeed * 4));
            }
            else
            {
                targetPoint.X = ballNextRoundLocation.X + (pathfinding.CalculateHorizontalDirection(player.Location, enemyTeamGoal.MiddlePoint) * (player.MaxSpeed * 4));
            }
            Point freePoint = SearchFreeTargetPoint(player, RunRoom(GameAI.PlayersTeam(player)), targetPoint, 3, 0);

            return new PlayerAction(null, freePoint, ActionType.Run);
        }
예제 #14
0
파일: PlayerAI.cs 프로젝트: Jecral/Football
        /// <summary>
        /// For the case that the own team controls the ball and the player stands close to the enemy's goal.
        /// </summary>
        /// <param name="player"></param>
        /// <returns></returns>
        public virtual PlayerAction ActionGoalClose(Player player)
        {
            Pathfinding pathfinding = new Pathfinding();
            Goal enemyTeamGoal = GameAI.GetEnemyTeam(GameAI.PlayersTeam(player)).TeamGoal;

            Point ballNextRoundLocation = GameAI.BallNextRoundLocation();
            int ballDistanceToEnemyGoal = Math.Abs(enemyTeamGoal.XCoordinate - ballNextRoundLocation.X);

            Point targetPoint = player.Location;

            targetPoint.Y = enemyTeamGoal.MiddlePoint.Y + pathfinding.CalculateVerticalDirection(player.Location, enemyTeamGoal.MiddlePoint) * 3;
            if (ballDistanceToEnemyGoal > player.MaxSpeed * 2)
            {
                targetPoint.X = ballNextRoundLocation.X + (pathfinding.CalculateHorizontalDirection(player.Location, enemyTeamGoal.MiddlePoint) * 5);
            }

            Point freePoint = SearchFreeTargetPoint(player, RunRoom(GameAI.PlayersTeam(player)), targetPoint, 5, 3);

            return new PlayerAction(null, freePoint, ActionType.Run);
        }
예제 #15
0
파일: PlayerAI.cs 프로젝트: Jecral/Football
        /// <summary>
        /// For the case that the enemy has the ball and is far away.
        /// </summary>
        /// <param name="player">The player who will execute the action.</param>
        /// <param name="closestPlayerNextLocation"></param>
        /// <returns></returns>
        public virtual PlayerAction ActionEnemyFarAway(Player player, Point closestPlayerNextLocation)
        {
            Pathfinding pathfinding = new Pathfinding();

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

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