Esempio n. 1
0
        public ClientUpdateDto PredictCollision()
        {
            var dDist         = 20;
            var activePlayers = _players.Where(p => p.IsAlive()).ToList();

            var allTrails = new List <TrailSegment>();

            foreach (var p in activePlayers)
            {
                var isSelf = p.GetId() == _botId;
                allTrails.AddRange(p.GetBike().GetTrailSegmentList(!isSelf));
            }

            var incCollision = _botBike.Collides(allTrails, dDist, out _) || _arena.CheckCollision(_botBike, dDist);

            if (!incCollision)
            {
                return(null);
            }

            var newVal    = _rand.Next(0, 2) == 0 ? -1 : 1;
            var updateDto = new ClientUpdateDto {
                PlayerId = _botId
            };

            if (_botBike.GetDir().X != 0)
            {
                updateDto.XDir = 0;
                updateDto.YDir = newVal;
            }
            else if (_botBike.GetDir().Y != 0)
            {
                updateDto.XDir = newVal;
                updateDto.YDir = 0;
            }

            return(RandomDirectionDto());
        }