public void AssignTopPriorityPlayers() { // Search through queues for players with top priority var queues = PlayerQueue.GetQueues(); var prioritizedPlayers = new Queue <Player>(); Parallel.ForEach(queues, queue => { if (queue.Count > 0) { lock (queue) { long waitingTimeInMs = (DateTime.Now.Ticks - queue.Peek().QueueIngressTime) / 10_000; if (waitingTimeInMs > PlayerQueue.PlayerMaxWaitingTimeMs) { // Assign player as top priority, since it's been waiting for too long PlayerQueue.AssignTopPriorityToPlayer(queue.Dequeue()); } } } }); PlayerQueue.TryCreateMatchWithPriorityPlayers(_hostingEnvironment); }
public bool Apply(GameState state, PlayerQueue queue) { if (state.Opposition != TeamType.Other) { return(false); } var other = state.Current.OtherPlayers.OrderBy(player => player.DistanceToOwnGoal).ToList(); if (Role.Tackler.Apply(state, queue)) { other.Remove(other.FirstOrDefault(item => item.Id == ((Tackle)queue.Actions[0]).Target)); } if (Role.Sweeper.Apply(state, queue)) { other.Remove(state.Current.Ball.Owner); } Role.BallCatcher.Apply(state, queue); Role.Keeper.Apply(state, queue); foreach (var target in other) { if (queue.Count < 3) { break; } var defender = target.GetClosestBy(queue); queue.Dequeue(Actions.Move(defender, target)); } return(true); }
/// <summary>The central method that is used by the Game Engine to run the bot.</summary> public void Action(Common.Team myTeam, Common.Team enemyTeam, Common.Ball ball, Common.MatchInfo matchInfo) { try { var mapping = PlayerMapping.CreateForOwn(myTeam.Players, enemyTeam.Players); State.Add(myTeam, enemyTeam, ball, matchInfo); var fallen = State.Current.Players.Where(p => p.FallenTimer != 0).ToList(); var tackle = State.Current.Players.Where(p => p.TackleTimer != 0).ToList(); var queue = new PlayerQueue(State.Current.OwnPlayers); foreach (var scenario in Scenarios) { if (scenario.Apply(State, queue)) { break; } } mapping.Apply(queue.Actions); } catch (Exception x) { Log.Error(State.GetErrorMessage(), x); } finally { State.Current.Finish(); } }
public bool Apply(GameState state, PlayerQueue queue) { var current = state.Current; if (current.Ball.IsOther) { var tackle = queue.FirstOrDefault(player => player.CanTackle(current.Ball.Owner)); if (tackle != null) { queue.Dequeue(Actions.Tacle(tackle, current.Ball.Owner)); return true; } } if (current.Ball.Owner == null && state.CatchUps.Any(cu => cu.Player.Team == TeamType.Other)) { var target = state.CatchUps.FirstOrDefault(); if (target.Player.Team == TeamType.Other) { var tackle = queue.FirstOrDefault(player => player.CanTackle(target.Player)); if (tackle != null) { queue.Dequeue(Actions.Tacle(tackle, target.Player)); return true; } } } return false; }
public ERoomUser PeekAvaliblePlayer(EGameInfo gi) { ERoomUser result = null; //只剩一个人时,比赛也是结束了 if (PlayerQueue.Count + PlayerDoneQueue.Count == 1) { return(null); } while (PlayerQueue.Count > 0) { var Player = PlayerQueue.Peek(); if (Player.PlayerStauts == PlayerStauts.PrepareBet) { result = Player; break; } else { PlayerQuitQueue.Enqueue(PopPlayer(Player.PlayerStauts)); } } return(null); }
public bool Apply(GameState state, PlayerQueue queue) { var current = state.Current; if (current.Ball.IsOther) { var tackle = queue.FirstOrDefault(player => player.CanTackle(current.Ball.Owner)); if (tackle != null) { queue.Dequeue(Actions.Tacle(tackle, current.Ball.Owner)); return(true); } } if (current.Ball.Owner == null && state.CatchUps.Any(cu => cu.Player.Team == TeamType.Other)) { var target = state.CatchUps.FirstOrDefault(); if (target.Player.Team == TeamType.Other) { var tackle = queue.FirstOrDefault(player => player.CanTackle(target.Player)); if (tackle != null) { queue.Dequeue(Actions.Tacle(tackle, target.Player)); return(true); } } } return(false); }
public bool Apply(GameState state, PlayerQueue queue) { if (state.Opposition != TeamType.Other) { return false; } var other = state.Current.OtherPlayers.OrderBy(player => player.DistanceToOwnGoal).ToList(); if(Role.Tackler.Apply(state, queue)) { other.Remove(other.FirstOrDefault(item=> item.Id == ((Tackle)queue.Actions[0]).Target)); } if(Role.Sweeper.Apply(state, queue)) { other.Remove(state.Current.Ball.Owner); } Role.BallCatcher.Apply(state, queue); Role.Keeper.Apply(state, queue); foreach (var target in other) { if (queue.Count < 3) { break; } var defender = target.GetClosestBy(queue); queue.Dequeue(Actions.Move(defender, target)); } return true; }
/// <summary>The central method that is used by the Game Engine to run the bot.</summary> public void Action(Common.Team myTeam, Common.Team enemyTeam, Common.Ball ball, Common.MatchInfo matchInfo) { try { var mapping = PlayerMapping.CreateForOwn(myTeam.Players, enemyTeam.Players); State.Add(myTeam, enemyTeam, ball, matchInfo); var fallen = State.Current.Players.Where(p => p.FallenTimer != 0).ToList(); var tackle = State.Current.Players.Where(p => p.TackleTimer != 0).ToList(); var queue = new PlayerQueue(State.Current.OwnPlayers); foreach (var scenario in Scenarios) { if (scenario.Apply(State, queue)) { break; } } mapping.Apply(queue.Actions); } catch (Exception x) { Log.Error(State.GetErrorMessage(), x); } finally { State.Current.Finish(); } }
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 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."); }
private void RemoveUnitFromPlayerQueue(PlayerQueue player, UnitModelScript unitToRemove) { for (int i = 0; i < player.UnitsQueue.Count; i++) { var u = player.UnitsQueue.Dequeue(); if (u != unitToRemove) { player.UnitsQueue.Enqueue(u); } } }
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 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 StringBuilder DownloadAllMatches() { var sb = new StringBuilder(); // Get groups foreach (var match in PlayerQueue.GetMatches()) { // Parse data MatchUtils.AppendMatchToStringBuilder(sb, match); } return(sb); }
public SpotifyPlayerSession([NotNull] SpotifySession session, [NotNull] ISpotifyDevice sink, [NotNull] String sessionId, [NotNull] IPlayerSessionListener listener) { this.session = session; this.sink = sink; this.sessionId = sessionId; this.listener = listener; this.queue = new PlayerQueue(); Debug.WriteLine($"Created new session. id: {sessionId}"); //todo: clear sink }
public bool Apply(GameState state, PlayerQueue queue) { var ball = state.Current.Ball; if (ball.HasOwner || state.Current.OwnPlayers.Any(player => player.CanPickUpBall)) { return false; } var catchUp = state.CatchUps.FirstOrDefault(c => queue.Contains(c.Player)); if (catchUp != null) { queue.Dequeue(Actions.Move(catchUp.Player, catchUp.Position)); } return catchUp != null; }
public bool Apply(GameState state, PlayerQueue queue) { if (state.Current.Ball.IsOther) { var path = PlayerPath.Create(state.Current.Ball.Owner, Goal.Own.Center, 400, 40f); var sweeper = path.GetCatchUps(queue).FirstOrDefault(); if (sweeper != null) { return(queue.Dequeue(Actions.Move(sweeper.Player, sweeper.Position))); } } return(false); }
public bool Apply(GameState state, PlayerQueue queue) { if (state.Current.Ball.IsOther) { var path = PlayerPath.Create(state.Current.Ball.Owner, Goal.Own.Center, 400, 40f); var sweeper = path.GetCatchUps(queue).FirstOrDefault(); if (sweeper != null) { return queue.Dequeue(Actions.Move(sweeper.Player, sweeper.Position)); } } return false; }
public bool Apply(GameState state, PlayerQueue queue) { var owner = queue.FirstOrDefault(player => player.IsBallOwner); if (owner == null) { return false; } var candidates = new ActionCandidates(); // Just in case, if we don't find anything better. candidates.Add(-20000, Actions.ShootOnGoal(owner, Power.Maximum)); foreach (var generator in Generators) { generator.Generate(owner, state, candidates); } return queue.Dequeue(candidates.Best.Action); }
public void ReloadPlayer() { while (PlayerDoneQueue.Count > 0) { var p = PlayerDoneQueue.Dequeue(); if (p.PlayerStauts >= 0) { p.PlayerStauts = PlayerStauts.PrepareBet; PlayerQueue.Enqueue(p); } else { PlayerQuitQueue.Enqueue(p); } } }
public bool Apply(GameState state, PlayerQueue queue) { var ball = state.Current.Ball; if (ball.HasOwner || state.Current.OwnPlayers.Any(player => player.CanPickUpBall)) { return(false); } var catchUp = state.CatchUps.FirstOrDefault(c => queue.Contains(c.Player)); if (catchUp != null) { queue.Dequeue(Actions.Move(catchUp.Player, catchUp.Position)); } return(catchUp != null); }
public bool Apply(GameState state, PlayerQueue queue) { var current = state.Current; if (current.Ball.IsOwn || // if the other can not pick it up, and it's a goal, just let it go. (state.Path.End == BallPath.Ending.GoalOther && !state.CatchUps.Any(cu => cu.Player.Team == TeamType.Other))) { return false; } var pickup = queue.FirstOrDefault(player => player.CanPickUpBall); if (pickup != null) { queue.Dequeue(Actions.PickUpBall(pickup)); } return pickup != null; }
public ERoomUser PopPlayer(PlayerStauts playerStatus) { if (PlayerQueue.Count != 0) { var Player = PlayerQueue.Dequeue(); if (playerStatus == PlayerStauts.OffLine || playerStatus == PlayerStauts.GiveUp) { PlayerQuitQueue.Enqueue(Player); } else { PlayerDoneQueue.Enqueue(Player); } return(Player); } return(null); }
public bool Apply(GameState state, PlayerQueue queue) { var owner = queue.FirstOrDefault(player => player.IsBallOwner); if (owner == null) { return(false); } var candidates = new ActionCandidates(); // Just in case, if we don't find anything better. candidates.Add(-20000, Actions.ShootOnGoal(owner, Power.Maximum)); foreach (var generator in Generators) { generator.Generate(owner, state, candidates); } return(queue.Dequeue(candidates.Best.Action)); }
public bool Apply(GameState state, PlayerQueue queue) { if (queue.IsEmty) { return false; } var ball = state.Current.Ball.Position; if (!state.Current.Ball.HasOwner && state.CatchUps.Count > 0) { ball = state.CatchUps[0].Position; } var target = GetTarget(ball); var keeper = target.GetClosestBy(queue); queue.Dequeue(Actions.Move(keeper, target)); return true; }
/// <summary> /// 一局开始缓存玩家,根据GameInfo需要对玩家重新排列 /// </summary> /// <param name="PlayerList"></param> public void SetCachePlayer(List <ERoomUser> PlayerList, EGameInfo gi) { InitQueue(); var p = PlayerList[gi.FirstPlayerIndex]; PlayerQueue.Enqueue(p); int i = gi.FirstPlayerIndex + 1; while (PlayerQueue.Count < PlayerList.Count) { if (i == PlayerList.Count) { i = 0; } p = PlayerList[i]; PlayerQueue.Enqueue(p); } }
public bool Apply(GameState state, PlayerQueue queue) { if (!state.Current.Ball.IsOther || !queue.Any()) { return false; } var owner = state.Current.Ball.Owner; var target = owner.Position + owner.Velocity; // if the owner is moving away. if (owner.DistanceToOwnGoal > Goal.Own.GetDistance(target)) { // The sandwich can only work if the sandwicher is coming from the other side. var sandwicher = owner.GetClosestBy(queue.Where(player => player.DistanceToOwnGoal > owner.DistanceToOwnGoal)); if(sandwicher != null) { return queue.Dequeue(Actions.Move(sandwicher, owner)); } } return false; }
private static void ReadytoStartPlayer() { var context = new TictactoegameContext(); foreach (var item in context.Player.ToList()) { var playerQueue = new PlayerQueue(); playerQueue.PlayerId = item.PlayerId; playerQueue.CreatedDate = DateTime.Now; playerQueue.ModifiedDate = DateTime.Now; playerQueue.CreatedBy = item.UserName; playerQueue.ModifiedBy = item.UserName; playerQueue.RowGuid = Guid.NewGuid(); context.PlayerQueue.Add(playerQueue); } context.SaveChanges(); }
public bool Apply(GameState state, PlayerQueue queue) { if (state.Current.Ball.IsOther) { var freeMan = state.Current.Ball.Owner.GetOther(state.Current.OtherPlayers) .OrderBy(player => player.DistanceToOwnGoal) .Skip(Rank).FirstOrDefault(); var path = PlayerPath.Create(freeMan, Goal.Own.Center, 400, 40f); var manMarker = path.GetCatchUps(queue).FirstOrDefault(); if (manMarker != null) { return queue.Dequeue(Actions.Move(manMarker.Player, manMarker.Position)); } } return false; }
public bool Apply(GameState state, PlayerQueue queue) { if (state.Current.Ball.IsOther) { var freeMan = state.Current.Ball.Owner.GetOther(state.Current.OtherPlayers) .OrderBy(player => player.DistanceToOwnGoal) .Skip(Rank).FirstOrDefault(); var path = PlayerPath.Create(freeMan, Goal.Own.Center, 400, 40f); var manMarker = path.GetCatchUps(queue).FirstOrDefault(); if (manMarker != null) { return(queue.Dequeue(Actions.Move(manMarker.Player, manMarker.Position))); } } return(false); }
public bool Apply(GameState state, PlayerQueue queue) { foreach (var role in Roles) { role.Apply(state, queue); } var zones = Zones.Create(state); foreach (var zone in zones.SingleOccupiedByOwn) { var player = zone.Own.FirstOrDefault(); if (queue.Contains(player)) { queue.Dequeue(Actions.Move(player, zone.Target)); } } foreach (var zone in zones.NotOccupiedByOwn) { var closedBy = zone.Target.GetClosestBy(queue); if (closedBy != null) { queue.Dequeue(Actions.Move(closedBy, zone.Target)); } } if (zones.BallOwnerZone != null) { var closedBy = zones.BallOwnerZone.Target.GetClosestBy(queue); if (closedBy != null) { queue.Dequeue(Actions.Move(closedBy, zones.BallOwnerZone.Target)); } } foreach (var player in queue.ToList()) { queue.Dequeue(Actions.Wait(player)); } return(true); }
public bool Apply(GameState state, PlayerQueue queue) { foreach (var role in Roles) { role.Apply(state, queue); } var zones = Zones.Create(state); foreach (var zone in zones.SingleOccupiedByOwn) { var player = zone.Own.FirstOrDefault(); if (queue.Contains(player)) { queue.Dequeue(Actions.Move(player, zone.Target)); } } foreach (var zone in zones.NotOccupiedByOwn) { var closedBy = zone.Target.GetClosestBy(queue); if (closedBy != null) { queue.Dequeue(Actions.Move(closedBy, zone.Target)); } } if (zones.BallOwnerZone != null) { var closedBy = zones.BallOwnerZone.Target.GetClosestBy(queue); if (closedBy != null) { queue.Dequeue(Actions.Move(closedBy, zones.BallOwnerZone.Target)); } } foreach (var player in queue.ToList()) { queue.Dequeue(Actions.Wait(player)); } return true; }
public bool Apply(GameState state, PlayerQueue queue) { var current = state.Current; if (current.Ball.IsOwn || // if the other can not pick it up, and it's a goal, just let it go. (state.Path.End == BallPath.Ending.GoalOther && !state.CatchUps.Any(cu => cu.Player.Team == TeamType.Other))) { return(false); } var pickup = queue.FirstOrDefault(player => player.CanPickUpBall); if (pickup != null) { queue.Dequeue(Actions.PickUpBall(pickup)); } return(pickup != null); }
public bool Apply(GameState state, PlayerQueue queue) { if (queue.IsEmty) { return(false); } var ball = state.Current.Ball.Position; if (!state.Current.Ball.HasOwner && state.CatchUps.Count > 0) { ball = state.CatchUps[0].Position; } var target = GetTarget(ball); var keeper = target.GetClosestBy(queue); queue.Dequeue(Actions.Move(keeper, target)); return(true); }
public bool Apply(GameState state, PlayerQueue queue) { if (!state.Current.Ball.IsOther || !queue.Any()) { return(false); } var owner = state.Current.Ball.Owner; var target = owner.Position + owner.Velocity; // if the owner is moving away. if (owner.DistanceToOwnGoal > Goal.Own.GetDistance(target)) { // The sandwich can only work if the sandwicher is coming from the other side. var sandwicher = owner.GetClosestBy(queue.Where(player => player.DistanceToOwnGoal > owner.DistanceToOwnGoal)); if (sandwicher != null) { return(queue.Dequeue(Actions.Move(sandwicher, owner))); } } return(false); }
private void InitQueue() { PlayerQueue.Clear(); PlayerDoneQueue.Clear(); PlayerQuitQueue.Clear(); }
public void SetPlayersPerMatch(int playersPerMatch) { PlayerQueue.SetPlayersPerMatch(playersPerMatch); }
public void AddPlayer(Player player) { PlayerQueue.AddPlayerToQueue(player, _hostingEnvironment); }