public static Vector ChooseDirection(Player player, Ball ball) { var k1 = Line.K0(ball.Position, Field.MyGoal.Top); var k2 = Line.K0(ball.Position, Field.MyGoal.Bottom); var kball = ball.Velocity.Y / ball.Velocity.X; var lineball = Line.One(ball.Position, ball.Position + ball.Velocity); if ( ball.Owner == null && lineball.K >= Math.Min(k1, k2) && lineball.K <= Math.Max(k1, k2)) { var nball = Line.Normal(lineball, player.Position); var intpos = Line.Cross(lineball, nball); if (Field.Borders.Contains(intpos)) return intpos; return Line.Cross(lineball, Line.One(Field.MyGoal.Top, Field.MyGoal.Bottom)); } var line = Line.One(ball.Position, Field.MyGoal.Center); var n1 = Line.Normal(line, Field.MyGoal.Top); var n2 = Line.Normal(line, Field.MyGoal.Bottom); var a = Line.Cross(line, n1); var b = Line.Cross(line, n2); if (ball.GetDistanceTo(a) <= ball.GetDistanceTo(b)) return a; return b; }
public void DoAction(Game game, Player self) { var ball = game.Ball; var goal = Field.EnemyGoal.Center; if (ball.Owner == self) { var closestToGoal = goal.GetClosest(game.Enemy); if (closestToGoal.GetDistanceTo(goal) > Field.EnemyGoal.Height*0.7) { self.ActionShootGoal(); return; } var enemyToGoal = game.Enemy.Players .Where(pl => pl.Position.X > self.Position.X - 40) .Select(pl => new { pl, dist = pl.GetDistanceTo(self) }) .OrderBy(tp => tp.dist) .FirstOrDefault(); if (enemyToGoal != null && enemyToGoal.dist < 120) { self.ActionShoot(game.GetSmartShoot(self)); return; } var closestEnemy = self.GetClosest(game.Enemy); if (self.GetDistanceTo(closestEnemy) < 50) { self.ActionShoot(game.GetSmartShoot(self)); return; } self.ActionGo(goal); return; } if (Utility.TryField(game, self)) return; var centerX = goal.X*0.8; IPosition target; if (ball.Position.X > goal.X * 0.6) { var targetX = Math.Max(centerX, ball.Position.X * 0.95); var mul = ball.Position.Y < goal.Y ? 1 : -1; var targetY = goal.Y + Field.EnemyGoal.Height * 0.6 * mul; target = new Vector(targetX, targetY); } else { target = new Vector(centerX, goal.Y); } self.ActionGo(target); }
public static IList<Player> BehindOf(this Team enemies, Player player) { return (from p in enemies.Players let k = Line.K0(p.Position, player.Position) where k < -1d / 2d || k > 1d / 2d || (leftgoal && (p.Position.X > player.Position.X)) || (!leftgoal && (p.Position.X < player.Position.X)) select p).ToArray(); }
public static IList<Player> InFrontOf(this Team enemies, Player player) { return (from p in enemies.Players let k = Line.K0(p.Position, player.Position) where k > -1d / 2d && k < 1d / 2d where (!leftgoal && (p.Position.X > player.Position.X)) || (leftgoal && (p.Position.X < player.Position.X)) select p).ToArray(); }
private IEnumerable<PlayerDistance> PlayerDistanceToEnemy(IEnumerable<Player> Players, Player Enemy) { foreach (var player in Players) { yield return new PlayerDistance() { Player = player, Distance = player.GetDistanceTo(Enemy.Position), }; } }
public InventoryWindow(Player player) : this() { this.Human = player; this.InventoryItems.Text = string.Join("\n", Human.Inventory ); this.comboBoxEquip.Items.AddRange(this.ItemsNames()); this.pictureBox1.Load(EmptySlotPath); this.pictureBox2.Load(EmptySlotPath); this.pictureBox3.Load(EmptySlotPath); this.pictureBox4.Load(EmptySlotPath); this.SetUpEquipment(); }
public void DoAction(Game game, Player self) { var ball = game.Ball; var goal = Field.EnemyGoal.Center; if (ball.Owner == self) { var closestToGoal = goal.GetClosest(game.Enemy); if (closestToGoal.GetDistanceTo(goal) > Field.EnemyGoal.Height) { self.ActionShootGoal(); return; } var enemyToGoal = game.Enemy.Players .Where(pl => pl.Position.X > self.Position.X - 40) .Select(pl => new { pl, dist = pl.GetDistanceTo(self) }) .OrderBy(tp => tp.dist) .FirstOrDefault(); if (enemyToGoal != null && enemyToGoal.dist < 120) { self.ActionShoot(game.GetSmartShoot(self)); return; } var closestEnemy = self.GetClosest(game.Enemy); if (self.GetDistanceTo(closestEnemy) < 50) { self.ActionShoot(game.GetSmartShoot(self)); return; } var pos = self.GetCenterShootout(game.Enemy); if (self.Position.X < Field.Borders.Center.X * 0.75) { self.ActionShoot(pos); return; } self.ActionGo(pos); return; } if (Utility.TryField(game, self)) return; self.ActionGo(Field.MyGoal.GetClosest(game.Enemy)); }
public static Vector CoverAttacker(Player player, Team enemies) { Team friends = player.Team; switch (player.PlayerType) { case PlayerType.LeftForward: return Field.EnemyGoal.Left; case PlayerType.CenterForward: return Field.EnemyGoal.Center; case PlayerType.RightForward: return Field.EnemyGoal.Right; default: // todo: implement return player.Position; } }
public void DoAction(Game game, Player self) { var ball = game.Ball; var closestEnemy = self.GetClosest(game.Enemy); if (ball.Owner == self) { var sweeper = game.My.Sweeper(); if (sweeper.IsSafe(game, self)) { self.ActionShoot(sweeper, 50); } else { var pos = self.GetCenterShootout(game.Enemy); self.ActionShoot(pos); } return; } if (Utility.TryKeeper(game, self)) return; //if (ball.GetDistanceTo(Field.MyGoal) > 800) //{ // self.ActionGo(new Vector(Field.MyGoal.Height/2, Field.MyGoal.Center.Y)); //} //else //{ //get ball target var distanceCoeff = ball.Velocity.Length;// / ball.GetDistanceTo(self); var target = ball.Position.Y + ball.Velocity.Y * distanceCoeff; var y = Math.Max(Math.Min(target, Field.MyGoal.Bottom.Y), Field.MyGoal.Top.Y); var lenCoeff = ball.GetDistanceTo(Field.MyGoal.Center) * 2 / Field.MyGoal.Height; var x = Math.Min(ball.Position.X/lenCoeff, Field.MyGoal.Height / 2); self.ActionGo(new Vector(x, y)); //} }
public void DoAction(Game game, Player self) { var ball = game.Ball; if (ball.Owner == self) { var sweeper = game.My.Sweeper(); var defender = game.My.Defender(); if (sweeper.IsSafe(game, self)) { self.ActionShoot(sweeper, self.GetDistanceTo(sweeper) * 1.5f); } else if (defender.IsSafe(game, self)) { self.ActionShoot(defender, self.GetDistanceTo(defender) * 1.5f); } else { var pos = self.GetCenterShootout(game.Enemy); self.ActionShoot(pos); } return; } if (Utility.TryKeeper(game, self)) return; var ballPos = game.Ball.GetBallNextPosition(); var ballToGoalVector = ballPos - Field.MyGoal.Center; var keeperVectorScale = Field.MyGoal.Height/2/ballToGoalVector.Length; var keeperToGoalVector = ballToGoalVector * keeperVectorScale; var keeperPosition = Field.MyGoal.Center + keeperToGoalVector; self.ActionGo(keeperPosition); }
private static bool IsCandidate(Player ballOwener, Player candidate, float ownerDistanceGoal2) { var candidateDistanceGoal2 = (Field.EnemyGoal.Center - candidate.Position).LengthSquared; if (candidateDistanceGoal2 > ownerDistanceGoal2) { return false; } var ownDistance = (ballOwener.Position - candidate.Position).LengthSquared; if (ownDistance < MinimumPassDistanceSquared || ownDistance > MaximumPassDistanceSquared) { return false; } return true; }
public void Read(NetIncomingMessage msg) { this.PlayerCount = msg.ReadInt32(); this.Players = new Dictionary<long, Player>(); for (int i = 0; i < this.PlayerCount; i++) { long RUI = msg.ReadInt64(); Vector2 position = msg.ReadVector2(); Player player = new Player(RUI, playerTexture, new Color(msg.ReadByte(), msg.ReadByte(), msg.ReadByte())); player.Position = position; this.Players.Add(RUI, player); } }
public void DoAction(Player self, Pitch pitch) { self.ActionGo(position); }
private void MarkPlayer(Player target) { //add velocity shift var velocityDiff = target.Velocity - Self.Velocity; var velocityShift = velocityDiff.Length * velocityDiff.Length * 2.5; var targetPosition = target.Position + target.Velocity; var targetVector = Field.MyGoal.Position - targetPosition; targetVector = targetVector/targetVector.Length*(Constants.PlayerMaxTackleDistance + 5 + velocityShift); var goPos = target.Position + targetVector; //if target position is behind the ball than chase ball if (goPos.X*1.1 > Pitch.Ball.Position.X) { velocityDiff = Pitch.Ball.Velocity - Self.Velocity; velocityShift = velocityDiff.Length * velocityDiff.Length; targetPosition = Pitch.Ball.Position + Pitch.Ball.Velocity; targetVector = Field.MyGoal.Position - targetPosition; targetVector = targetVector / targetVector.Length * (Constants.BallMaxPickUpDistance - 5 + velocityShift); goPos = Pitch.Ball.Position + targetVector; } Self.ActionGo(goPos); //Debug("marking player"); }
public static Vector InterceptAttack(Player player, Ball ball)//, Team friends, Team enemies) { Team enemies = ball.Owner.Team; return ball.Position; }
public void DoAction(Game game, Player self) { }
public static Vector PickupBall(Player player, Ball ball)//, Team friends, Team enemies) { return ball.Position; }
/// <summary>Gets the safe angle/theta to shoot.</summary> public static Theta GetSafeTheta(IPosition ball, Player opponent, float power) { var dis2 = (ball.Position - opponent.Position).LengthSquared; return GetSafeTheta(dis2, power, opponent.FallenTimer); }
public static void RenderAll(Player player, Menu menu = null) { RB.Clear(Color.black); RenderMap(Engine.E.Map); RenderUI(player, menu); }
/// <summary> /// Public interface for adding objects. /// </summary> /// <param name="RUI">The key for the players dictionary</param> /// <param name="player">The player object</param> public void Add(long RUI, Player player) { players.Add(RUI, player); }
public void DoAction(Game game, Player self) { var ball = game.Ball; if (ball.Owner == self) { var defender = game.My.Defender(); if (defender.IsSafe(game, self)) { self.ActionShoot(defender, self.GetDistanceTo(defender) * 1.5f); } else { if (self.Position.X < Field.Borders.Center.X*0.2) { float yPos; var center = Field.Borders.Center; if (self.Position.Y > center.Y) { yPos = center.Y + center.Y/2; } else { yPos = center.Y - center.Y/2; } self.ActionShoot(new Vector(0, yPos)); return; } if (self.Position.X < Field.Borders.Center.X * 0.75) { var pos = self.GetCenterShootout(game.Enemy); self.ActionShoot(pos); return; } self.ActionShootGoal(); return; } return; } if (Utility.TryField(game, self)) return; var closestToGoal = Field.MyGoal.GetClosest(game.Enemy); IPosition target; if (ball.GetBallNextPosition().GetDistanceTo(Field.MyGoal) > closestToGoal.GetDistanceTo(Field.MyGoal)) { target = closestToGoal; } else { target = ball; } target = new Vector(target.Position.X*0.8, target.Position.Y); self.ActionGo(target); }
public void DoAction(Game game, Player self) { var ball = game.Ball; var goal = Field.EnemyGoal.Center; if (ball.Owner == self) { var closestToGoal = goal.GetClosest(game.Enemy); if (closestToGoal.GetDistanceTo(goal) > Field.EnemyGoal.Height * 0.8) { self.ActionShootGoal(); return; } var enemyToGoal = game.Enemy.Players .Where(pl => pl.Position.X > self.Position.X - 40) .Select(pl => new { pl, dist = pl.GetDistanceTo(self) }) .OrderBy(tp => tp.dist) .FirstOrDefault(); if (enemyToGoal != null && enemyToGoal.dist < 120) { self.ActionShoot(game.GetSmartShoot(self)); return; } var closestEnemy = self.GetClosest(game.Enemy); if (self.GetDistanceTo(closestEnemy) < 50) { self.ActionShoot(game.GetSmartShoot(self)); return; } self.ActionGo(Field.EnemyGoal.Bottom); return; } if (Utility.TryField(game, self)) return; IPosition target; if (game.InAttack) { if (ball.Position.X > goal.X * 0.6) { var centerX = goal.X * 0.82; var targetX = Math.Max(centerX, ball.Position.X * 0.95); var targetY = goal.Y - Field.EnemyGoal.Height * 0.75; target = new Vector(targetX, targetY); } else { target = new Vector(Field.Borders.Bottom.X, Field.MyGoal.Height * 0.7); } } else { var closestUpperPlayers = game.Enemy.Players .Where(pl => pl.Position.Y < Field.Borders.Center.Y) .Select(pl => new {pl, dist = pl.GetDistanceTo(Field.MyGoal.Top)}) .OrderBy(tp => tp.dist); if (closestUpperPlayers.Count() > 1) { target = closestUpperPlayers.Skip(1).First().pl; } else { target = new Vector(Field.Borders.Top.X, Field.MyGoal.Height * 0.7); } } self.ActionGo(target); }
public Game(Player player1, Player player2) { this.player1 = player1; this.player2 = player2; this.currentPlayer = player1; }