public static Vector2 BestDirectionWingardium(Game game, Snaffle toShoot) { List <Entity> eBetween; Vector2 v = game.OpponentTeam.GoalCenterPosition; v.Y = toShoot.ActualPosition.Y; if (v.Y < game.OpponentTeam.Pole0.Y) { v.Y = game.OpponentTeam.Pole0.Y; } else if (v.Y > game.OpponentTeam.Pole1.Y) { v.Y = game.OpponentTeam.Pole1.Y; } eBetween = game.GetCollidableEntityBetween(toShoot.ActualPosition + toShoot.ActualVelocity, v); // Shoot to goal ////////////////////////////////////////////////////////// if ((!eBetween.Any() || !eBetween.Where(e => toShoot.Distance(e) < 8000).Any()) && toShoot.Distance(game.OpponentTeam.GoalCenterPosition) < 5000) { return(game.OpponentTeam.GoalCenterPosition); } else if (toShoot.Distance(game.OpponentTeam.GoalCenterPosition) < 4500) { // Try random place between poles's goal ////////////////////////////////////////////////////////// Game.Debug("Random Place between pole"); Random r = new Random(); for (int i = 0; i < 7; i++) { Vector2 rV = game.OpponentTeam.GoalCenterPosition; rV.Y = r.Next((int)game.OpponentTeam.Pole0.Y + 1, (int)game.OpponentTeam.Pole1.Y); if (!game.CollidableEntityBetween(toShoot.ActualPosition + toShoot.ActualVelocity, rV)) { return(rV); } } } // Try try all y possibility,and sort them to the nearest to the goal. List <Vector2> vList = Enumerable.Repeat(new Vector2(game.OpponentTeam.Pole0.X), (int)(Game.MapSize.Y)).ToList(); vList = vList.Select((e, i) => { e.Y = i; return(e); }).ToList(); vList = vList.Where(e => !game.CollidableEntityBetween(toShoot.ActualPosition, e)) .OrderBy(e => Vector2.Distance(e, game.OpponentTeam.GoalCenterPosition)).ToList(); if (vList.Any()) { return(vList.First()); } Game.Debug("Wingardium NO BEST SHOT FOUND : Default, goal.center shoot"); return(game.OpponentTeam.GoalCenterPosition); }
public static Vector2 BestDirectionToShoot(Game game, Snaffle toShoot) { List <Entity> eBetween; Vector2 v = game.OpponentTeam.GoalCenterPosition; v.Y = toShoot.ActualPosition.Y; if (v.Y < game.OpponentTeam.Pole0.Y) { v.Y = game.OpponentTeam.Pole0.Y; } else if (v.Y > game.OpponentTeam.Pole1.Y) { v.Y = game.OpponentTeam.Pole1.Y; } eBetween = game.GetCollidableEntityBetween(toShoot.ActualPosition + toShoot.ActualVelocity, v); // Shoot to goal ////////////////////////////////////////////////////////// if ((!eBetween.Any() || !eBetween.Where(e => toShoot.Distance(e) < 8000).Any()) && toShoot.Distance(game.OpponentTeam.GoalCenterPosition) < 5000) { return(game.OpponentTeam.GoalCenterPosition); } else if (toShoot.Distance(game.OpponentTeam.GoalCenterPosition) < 4500) { // Try random place between poles's goal ////////////////////////////////////////////////////////// Game.Debug("Random Place between pole"); Random r = new Random(); for (int i = 0; i < 7; i++) { Vector2 rV = game.OpponentTeam.GoalCenterPosition; rV.Y = r.Next((int)game.OpponentTeam.Pole0.Y + 1, (int)game.OpponentTeam.Pole1.Y); if (!game.CollidableEntityBetween(toShoot.ActualPosition + toShoot.ActualVelocity, rV)) { return(rV); } } } //Try pass to nearest wizard ////////////////////////////////////////////////////////// // Game.Debug("HERRE"); // Game.Debug("ddd.>" + toShoot.Id.ToString()); // List<Wizard> w = game.GetMyWizards() // .Where(e => e.Id != toShoot.Grabber.Id && !game.CollidableEntityBetween(toShoot.ActualPosition + toShoot.ActualVelocity, e.ActualPosition + e.ActualVelocity)) // .OrderBy(e => e.Distance(toShoot)).ToList(); // Game.Debug("HERE"); // if (w.Any()) // Game.Debug(" ccc >" + (toShoot.ActualPosition.X - w.First().ActualPosition.X).ToString()); // // if there is wizard AND if less than 2500 distance, and if not too far behind // if (w.Any() && toShoot.Distance(w.First().ActualPosition) < 5500 && // toShoot.ActualPosition.X - w.First().ActualPosition.X < -300) // return(w.First().ActualPosition + w.First().ActualVelocity); // Try to shoot to the next snaffle // ////////////////////////////////// // Try try all y possibility,and sort them to the nearest to the goal. List <Vector2> vList = Enumerable.Repeat(new Vector2(game.OpponentTeam.Pole0.X), (int)(Game.MapSize.Y)).ToList(); vList = vList.Select((e, i) => { e.Y = i; return(e); }).ToList(); vList = vList.Where(e => !game.CollidableEntityBetween(toShoot.ActualPosition, e)) .OrderBy(e => Vector2.Distance(e, game.OpponentTeam.GoalCenterPosition)).ToList(); if (vList.Any()) { return(vList.First()); } Game.Debug("NO BEST SHOT FOUND : Default, goal.center shoot"); return(game.OpponentTeam.GoalCenterPosition); }