public static PlayerInfo Create(Common.Player player, Common.Ball ball, TeamType team, IEnumerable<Common.Player> other)
		{
			Guard.NotNull(player, "player");
			Guard.NotNull(ball, "ball");

			var tackled = other.Where(o => player.CanTackle(o)).ToList();
			if (tackled.Count > 0)
			{
			}

			var info = new PlayerInfo()
			{
				Id = PlayerMapping.GetId(player.PlayerType, team),
				Position = player.Position,
				Velocity = player.Velocity,
				IsBallOwner = player == ball.Owner,
				CanPickUpBall = player.CanPickUpBall(ball),
				CanBeTackled = tackled.Select(p => PlayerMapping.GetId(p.PlayerType, TeamType.Other)).ToList(),
				FallenTimer = player.FallenTimer,
				TackleTimer = player.TackleTimer,
			};
			info.DistanceToOwnGoal = Goal.Own.GetDistance(info);
			info.DistanceToOtherGoal = Goal.Other.GetDistance(info);
			return info;
		}
		public void Generate(PlayerInfo owner, GameState state, ActionCandidates candidates)
		{
			if (!owner.IsBallOwner || owner.CanBeTackled.Any()) { return; }

			foreach (var direction in WalkingDirections)
			{
				var target = owner.Position + direction;

				// Don't try to leave the field.
				if(Game.Field.IsOnField(target))
				{
					var dribble = PlayerPath.Create(owner, target, MaximumDribbleLength, Distance.Tackle);
					var catchUp = dribble.GetCatchUps(state.Current.OtherPlayers).FirstOrDefault();

					// don't start (too) short walks.
					if(catchUp == null || catchUp.Turn >= MinimumDribbleLength)
					{
						if (catchUp != null) { target = dribble[catchUp.Turn - 2]; }

						var action = Actions.Move(owner, target);
						var length = catchUp == null ? dribble.Count : catchUp.Turn - 1;
						candidates.Add(Evaluator.GetPositionImprovement(owner, target, length), action);
					}
				}
			}
		}
		public void Generate(PlayerInfo owner, GameState state, ActionCandidates candidates)
		{
			if (!owner.IsBallOwner) { return; }

			foreach (var pass in Velocities)
			{
				var path = BallPath.Create(owner.Position, pass, PickUpTimer, MaximumPathLength);

				// We don't want to risk passes ending up in our own goal.
				if (path.End != BallPath.Ending.GoalOwn)
				{
					var catchUp = path.GetCatchUps(state.Current.Players).FirstOrDefault();

					// safe to pass.
					if (catchUp == null || catchUp.Player.IsOwn && catchUp.Player != owner)
					{
						var length = catchUp == null ? path.Count : catchUp.Turn;
						var target = catchUp == null ? path.Last() : catchUp.Position;

						if (Distance.Between(target, owner) > MinimumPassDistance)
						{
							candidates.Add(
								Evaluator.GetPositionImprovement(owner, target, length),
								Actions.Shoot(owner, owner.Position + pass, PassPower));
						}
					}
				}
			}
		}
		public void Dequeue_ActionsNone_NothingChanges()
		{
			var player = new PlayerInfo() { Id = 4 };
			var queue = new PlayerQueue(player);

			Assert.IsFalse(queue.Dequeue(Actions.None), "Nothing should be de-queued.");
			Assert.AreEqual(1, queue.Count, "number of elements should still be 1.");
			Assert.AreEqual(0, queue.Actions.Count, "Should contain no actions.");
		}
		public void Dequeue_ActionsWait4_AddsOneAction()
		{
			var player = new PlayerInfo() { Id = 4 };
			var queue = new PlayerQueue(player);

			Assert.IsTrue(queue.Dequeue(Actions.Wait(player)), "Player 4 should be de-queued.");
			Assert.AreEqual(0, queue.Count, "number of elements should be 0.");
			Assert.AreEqual(1, queue.Actions.Count, "Should contain 1 action.");
		}
		public void Create_Player_ReachesTheTargetIn44Turns()
		{
			var player = new PlayerInfo()
			{
				Position = new Position(200, 200),
				Velocity = new Velocity(-2, 0),
			};

			var target = new Position(300, 200);

			var act = PlayerPath.Create(player, target, 100, Distance.Pickup);
			var exp = 44;
			Assert.AreEqual(exp, act.Count);
		}
		public void Generate(PlayerInfo owner, GameState state, ActionCandidates candidates)
		{
			if (!owner.IsBallOwner || owner.DistanceToOtherGoal > MaximumShootDistance) { return; }

			var veloTop = Goal.Other.Top - owner.Position;
			var veloBot = Goal.Other.Bottom - owner.Position;
			var goalAngle = Angle.Between(veloTop, veloBot);
			var power95Per = Power.Maximum * (0.5f * (float)goalAngle / (float)TwoStandardDeviation);

			var target = owner.Position + veloBot.Rotate((double)goalAngle * 0.5);

			var turns = (float)Distance.Between(owner, target) / (float)power95Per;

			if (turns <= PickUpTimer)
			{
				candidates.Add(float.MaxValue, Actions.Shoot(owner, target, power95Per));
				return;
			}
			else
			{
				foreach(var power in ShootPowers)
				{
					foreach (var goal in GoalTargets)
					{
						var velocity = Shoot.ToTarget(owner, goal, power);
						var path = BallPath.Create(owner.Position, velocity, 7, 200);
						var catchUp = path.GetCatchUps(state.Current.OtherPlayers).FirstOrDefault();
						if (catchUp == null)
						{
							candidates.Add(1000, Actions.Shoot(owner, goal, power));
							return;
						}
					}
				}
			}
		}
		public bool CanTackle(PlayerInfo other)
		{
			return CanBeTackled.Contains(other.Id);
		}
		public static IAction DropBall(PlayerInfo player) { return new DropBall(player.Id); }
		public static IAction Wait(PlayerInfo player) { return new Wait(player.Id); } 
		public static IAction Tacle(PlayerInfo player, PlayerInfo target) { return new Tackle(player.Id, target.Id); }
		public static IAction ShootOnGoal(PlayerInfo player, Power power) { return new ShootOnGoal(player.Id, power); }
		public static Shoot Shoot(PlayerInfo player, IPoint target, Power power) { return new Shoot(player.Id, target, power); }
		public static IAction PickUpBall(PlayerInfo player) { return new PickUpBall(player.Id); }
		public static IAction Move(PlayerInfo player, IPoint target) { return new Move(player.Id, target); }
Beispiel #16
0
 /// <summary>Get all players excluding the current.</summary>
 public static IEnumerable <PlayerInfo> GetOther(this PlayerInfo player, IEnumerable <PlayerInfo> players)
 {
     return(players.Where(p => p != player));
 }