예제 #1
0
 public void RemoveSawBonus()
 {
     foreach (var bonus in Bonuses.ToList())
     {
         if (bonus is Saw)
         {
             bonus.Cancel(this);
             Bonuses.Remove(bonus);
         }
     }
 }
예제 #2
0
 public void TickAction()
 {
     foreach (var bonus in Bonuses.ToList())
     {
         bonus.Tick++;
         if (bonus.Tick >= bonus.ActiveTicks)
         {
             bonus.Cancel(this);
             Bonuses.Remove(bonus);
         }
     }
 }
예제 #3
0
        public bool GameLoop()
        {
            foreach (var player in Players)
            {
                if (player.Pos.InCellCenter())
                {
                    var direction = SendTick(player);
                    if (direction != null)
                    {
                        player.ChangeDirection(direction.Value);
                    }
                }
            }

            foreach (var player in Players)
            {
                player.Move();
            }

            var playerToCaptured = new Dictionary <Player, HashSet <V> >();

            foreach (var player in Players)
            {
                player.RemoveSawBonus();
                if (player.Pos.InCellCenter())
                {
                    player.UpdateLines();
                    var captured = player.Territory.Capture(player.Lines);
                    playerToCaptured[player] = captured;
                    if (captured.Count > 0)
                    {
                        player.Lines.Clear();
                        player.TickScore += Env.NEUTRAL_TERRITORY_SCORE * captured.Count;
                    }
                }
            }

            foreach (var player in Players)
            {
                if (CheckLoss(player))
                {
                    Losers.Add(player);
                }
            }

            playerToCaptured = CollisionResolution(playerToCaptured);

            foreach (var player in Players)
            {
                if (player.IsAte(playerToCaptured))
                {
                    Losers.Add(player);
                }
            }

            foreach (var player in Players)
            {
                if (player.Pos.InCellCenter())
                {
                    if (!playerToCaptured.TryGetValue(player, out var captured))
                    {
                        captured = new HashSet <V>();
                    }

                    player.TickAction();

                    foreach (var bonus in Bonuses.ToList())
                    {
                        if (bonus.IsAte(player, captured))
                        {
                            bonus.Apply(player);
                            Bonuses.Remove(bonus);

                            if (bonus is Saw)
                            {
                                var line = player.GetDirectionLine();
                                foreach (var p in Players)
                                {
                                    if (p != player)
                                    {
                                        if (line.Any(point => p.Pos.IntersectsWith(point)))
                                        {
                                            Losers.Add(p);
                                            player.TickScore += Env.SAW_KILL_SCORE;
                                        }
                                        else
                                        {
                                            var removed = p.Territory.Split(line, player.Dir ?? throw new InvalidOperationException(), p);
                                            if (removed.Count > 0)
                                            {
                                                player.TickScore += Env.SAW_SCORE;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    if (captured.Count > 0)
                    {
                        player.Territory.Points.UnionWith(captured);
                        foreach (var p in Players)
                        {
                            if (p != player)
                            {
                                var removed = p.Territory.RemovePoints(captured);
                                player.TickScore += (Env.ENEMY_TERRITORY_SCORE - Env.NEUTRAL_TERRITORY_SCORE) * removed.Count;
                            }
                        }
                    }
                }
            }

            foreach (var loser in Losers)
            {
                Players.Remove(loser);
            }

            foreach (var player in Players)
            {
                player.Score    += player.TickScore;
                player.TickScore = 0;
            }

            GenerateBonus();

            Tick++;
            return(Players.Count == 0);
        }