private static Point ForwardAttack(Player player, PlaygroundZone currentPlayerZone, ref Point newPosition) { bool isHomeTeam = player.Type.ToString().Contains("Home"); bool isIntersectWithPartnerInZone = player.Type.ToString().Contains("Home") ? GameEngine.CurrentGame.TeamHome.Players.Where(p => p.CheckForIntersectionInZone(player) && !p.Equals(player)).Count() > 0 : GameEngine.CurrentGame.TeamAway.Players.Where(p => p.CheckForIntersectionInZone(player) && !p.Equals(player)).Count() > 0; if (!isIntersectWithPartnerInZone) { if (isHomeTeam) { if (currentPlayerZone.CheckForZoneIntersection(GameEngine.CurrentGame.Ball.Position)) { newPosition = BallInPlayerZone(player, currentPlayerZone); return(newPosition); } if (GameEngine.CurrentGame.Ball.Position.X > player.Position.X && player.Position.X < player.DefaultZone.RightBottom.X) { newPosition.X = player.SpeedPoints / (Double)200 + newPosition.X; newPosition.Y = GameEngine.CurrentGame.Ball.Position.Y > player.Position.Y ? player.SpeedPoints / (Double)200 + newPosition.Y : -player.SpeedPoints / (Double)200 + newPosition.Y; } else if (GameEngine.CurrentGame.Ball.Position.X < player.Position.X && player.Position.X > player.DefaultZone.LeftBottom.X) { newPosition.X = -player.SpeedPoints / (Double)400 + newPosition.X; newPosition.Y = GameEngine.CurrentGame.Ball.Position.Y > player.Position.Y ? player.SpeedPoints / (Double)400 + newPosition.Y : -player.SpeedPoints / (Double)400 + newPosition.Y; } } else { if (currentPlayerZone.CheckForZoneIntersection(GameEngine.CurrentGame.Ball.Position)) { newPosition = BallInPlayerZone(player, currentPlayerZone); return(newPosition); } if (GameEngine.CurrentGame.Ball.Position.X < player.Position.X && player.Position.X > player.DefaultZone.LeftBottom.X) { newPosition.X = -player.SpeedPoints / (Double)200 + newPosition.X; newPosition.Y = GameEngine.CurrentGame.Ball.Position.Y > player.Position.Y ? player.SpeedPoints / (Double)200 + newPosition.Y : -player.SpeedPoints / (Double)200 + newPosition.Y; } else if (GameEngine.CurrentGame.Ball.Position.X > player.Position.X && player.Position.X < player.DefaultZone.RightBottom.X) { newPosition.X = player.SpeedPoints / (Double)400 + newPosition.X; newPosition.Y = GameEngine.CurrentGame.Ball.Position.Y > player.Position.Y ? player.SpeedPoints / (Double)400 + newPosition.Y : -player.SpeedPoints / (Double)400 + newPosition.Y; } } } else { newPosition.X = 5 / (Double)200 + newPosition.X; newPosition.Y = 5 / (Double)200 + newPosition.Y; } return(newPosition); }
public void TestIntersectZone() { PlaygroundZone zone1 = new PlaygroundZone(); zone1.Id = 1; zone1.LeftBottom = new GalaxyFootball.Core.Concrete.Helper.Point(0, 0); zone1.LeftTop = new GalaxyFootball.Core.Concrete.Helper.Point(0, 233); zone1.RightBottom = new GalaxyFootball.Core.Concrete.Helper.Point(350, 0); zone1.RightTop = new GalaxyFootball.Core.Concrete.Helper.Point(300, 233); zone1.Center = new GalaxyFootball.Core.Concrete.Helper.Point(175, 116); zone1.Category = Core.Concrete.Helper.Enums.PlaygroundZoneCategory.DefenderZone; Assert.AreEqual(true, zone1.CheckForZoneIntersection(new Point(175, 116))); Assert.AreEqual(false, zone1.CheckForZoneIntersection(new Point(500, 500))); }
private static Point BallInPlayerZone(Player player, PlaygroundZone currentPlayerZone) { Point newPosition = player.Position; //if ball in current player zone => go to ball if (currentPlayerZone.CheckForZoneIntersection(GameEngine.CurrentGame.Ball.Position)) { newPosition.X = player.Position.X < GameEngine.CurrentGame.Ball.Position.X ? player.SpeedPoints / (Double)500 + newPosition.X : -player.SpeedPoints / (Double)500 + newPosition.X; newPosition.Y = player.Position.Y < GameEngine.CurrentGame.Ball.Position.Y ? player.SpeedPoints / (Double)500 + newPosition.Y : -player.SpeedPoints / (Double)500 + newPosition.Y; } return(newPosition); }
private static Point DefensiveStrategy(Player player) { PlaygroundZone currentPlayerZone = GameEngine.CurrentGame.Playground.Zones.Where(z => z.CheckForZoneIntersection(player.Position)).FirstOrDefault(); Point newPosition = player.Position; if (((player.Type.ToString().Contains("Home") && player.IsSelected) || player.Type.ToString().Contains("Away") || player.Type.ToString().Contains("Goalkeeper")) && GameEngine.CurrentGame.Ball.IsCanPick(player.Position)) { player.Pick(GameEngine.CurrentGame.Ball); newPosition = player.Position; } else if (player.Type.ToString().Contains("Goalkeeper")) { //if ball in current player zone => go to ball if (currentPlayerZone.CheckForZoneIntersection(GameEngine.CurrentGame.Ball.Position)) { newPosition.X = player.Position.X < GameEngine.CurrentGame.Ball.Position.X ? player.SpeedPoints / (Double)15 + newPosition.X : -player.SpeedPoints / (Double)15 + newPosition.X; newPosition.Y = player.Position.Y < GameEngine.CurrentGame.Ball.Position.Y ? player.SpeedPoints / (Double)15 + newPosition.Y : -player.SpeedPoints / (Double)15 + newPosition.Y; } return(newPosition); } else if (player.Type.ToString().Contains("Defender")) { return(DefenderDefensive(player, currentPlayerZone, ref newPosition)); } else if (player.Type.ToString().Contains("Midfielder")) { return(MidfielderDefensive(player, currentPlayerZone, ref newPosition)); } else if (player.Type.ToString().Contains("Forward")) { return(ForwardDefensive(player, currentPlayerZone, ref newPosition)); } return(newPosition); }
private static Point DefenderDefensive(Player player, PlaygroundZone currentPlayerZone, ref Point newPosition) { bool isHomeTeam = player.Type.ToString().Contains("Home"); bool isIntersectWithPartnerInZone = player.Type.ToString().Contains("Home") ? GameEngine.CurrentGame.TeamHome.Players.Where(p => p.CheckForIntersectionInZone(player) && !p.Equals(player)).Count() > 0 : GameEngine.CurrentGame.TeamAway.Players.Where(p => p.CheckForIntersectionInZone(player) && !p.Equals(player)).Count() > 0; if (!isIntersectWithPartnerInZone) { if (currentPlayerZone.CheckForZoneIntersection(GameEngine.CurrentGame.Ball.Position)) { newPosition = BallInPlayerZone(player, currentPlayerZone); return(newPosition); } if (isHomeTeam) { if (GameEngine.CurrentGame.Ball.Position.X > player.Position.X && player.DefaultZone.HorizontalNeighbour.CheckForZoneIntersection(GameEngine.CurrentGame.Ball.Position) && player.Position.X < player.DefaultZone.RightBottom.X) { newPosition.X = player.SpeedPoints / (Double)400 + newPosition.X; } else if (GameEngine.CurrentGame.Playground.Zones.Where(z => z.RightBottom.X == currentPlayerZone.RightBottom.X && !z.Equals(currentPlayerZone) && z.CheckForZoneIntersection(GameEngine.CurrentGame.Ball.Position)).Count() > 0 && GameEngine.CurrentGame.Ball.Position.X >= player.Position.X) { newPosition.X = player.Position.X < GameEngine.CurrentGame.Ball.Position.X ? player.SpeedPoints / (Double)400 + newPosition.X : -player.SpeedPoints / (Double)400 + newPosition.X; newPosition.Y = player.Position.Y < GameEngine.CurrentGame.Ball.Position.Y ? player.SpeedPoints / (Double)400 + newPosition.Y : -player.SpeedPoints / (Double)400 + newPosition.Y; } else if (GameEngine.CurrentGame.Ball.Position.X < player.Position.X && player.Position.X > 20) { newPosition.X = player.Position.X < GameEngine.CurrentGame.Ball.Position.X ? player.SpeedPoints / (Double)200 + newPosition.X : -player.SpeedPoints / (Double)200 + newPosition.X; newPosition.Y = player.Position.Y < GameEngine.CurrentGame.Ball.Position.Y ? player.SpeedPoints / (Double)200 + newPosition.Y : -player.SpeedPoints / (Double)200 + newPosition.Y; } return(newPosition); } else { if (GameEngine.CurrentGame.Ball.Position.X < player.Position.X && player.DefaultZone.HorizontalNeighbour.CheckForZoneIntersection(GameEngine.CurrentGame.Ball.Position) && player.Position.X > player.DefaultZone.LeftBottom.X) { newPosition.X = -player.SpeedPoints / (Double)400 + newPosition.X; } else if (GameEngine.CurrentGame.Playground.Zones.Where(z => z.RightBottom.X == currentPlayerZone.RightBottom.X && !z.Equals(currentPlayerZone) && z.CheckForZoneIntersection(GameEngine.CurrentGame.Ball.Position)).Count() > 0 && GameEngine.CurrentGame.Ball.Position.X <= player.Position.X) { newPosition.X = player.Position.X < GameEngine.CurrentGame.Ball.Position.X ? player.SpeedPoints / (Double)400 + newPosition.X : -player.SpeedPoints / (Double)400 + newPosition.X; newPosition.Y = player.Position.Y < GameEngine.CurrentGame.Ball.Position.Y ? player.SpeedPoints / (Double)400 + newPosition.Y : -player.SpeedPoints / (Double)400 + newPosition.Y; } else if (GameEngine.CurrentGame.Ball.Position.X > player.Position.X && player.Position.X < 1010) { newPosition.X = player.Position.X < GameEngine.CurrentGame.Ball.Position.X ? player.SpeedPoints / (Double)200 + newPosition.X : -player.SpeedPoints / (Double)200 + newPosition.X; newPosition.Y = player.Position.Y < GameEngine.CurrentGame.Ball.Position.Y ? player.SpeedPoints / (Double)200 + newPosition.Y : -player.SpeedPoints / (Double)200 + newPosition.Y; } return(newPosition); } } else { if ((player.Type.ToString().Contains("Home") && player.Position.X > player.DefaultZone.LeftBottom.X) || (player.Type.ToString().Contains("Away") && player.Position.X < player.DefaultZone.RightBottom.X)) { newPosition.X = player.Type.ToString().Contains("Home") ? -2 / (Double)200 + newPosition.X : 2 / (Double)200 + newPosition.X; } newPosition.Y = GameEngine.CurrentGame.Ball.Position.Y > player.Position.Y ? 2 / (Double)200 + newPosition.Y : -2 / (Double)200 + newPosition.Y; } return(newPosition); }