예제 #1
0
        public async Task <IActionResult> Edit(Guid id, [Bind("ID,LastName,FirstMidName,EnrollmentDate")] Campers campers)
        {
            if (id != campers.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(campers);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CampersExists(campers.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(campers));
        }
예제 #2
0
        public async Task <IActionResult> Create([Bind("ID,LastName,FirstMidName,EnrollmentDate")] Campers campers)
        {
            if (ModelState.IsValid)
            {
                campers.ID = Guid.NewGuid();
                _context.Add(campers);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(campers));
        }
예제 #3
0
        public string GetSummary()
        {
            var sb = new StringBuilder();

            if (Camps != null && Camps.Count > 0)
            {
                sb.Append(String.Join(",", Camps.Select(c => c.Name)));
            }
            else
            {
                sb.Append("(none)");
            }
            sb.Append(" for ");
            if (Campers != null && Campers.Count > 0)
            {
                sb.Append(String.Join(",", Campers.Select(c => c.Name)));
            }
            else
            {
                sb.Append("(no one)");
            }
            return(sb.ToString());
        }
예제 #4
0
        public bool DoTurn(Squad squad)
        {
            if (squad.HasCapsule)
            {
                PirateShip CapsuleHolder     = squad.First(x => x.HasCapsule);
                Mothership ClosestMothership = Bot.Engine.MyMotherships.Nearest(CapsuleHolder);
                Squad      Boosters          = squad.Filter(x => x.UniqueId != CapsuleHolder.UniqueId && x.PushReloadTurns <= 0 && (true || x.Distance(ClosestMothership) - CapsuleHolder.Distance(ClosestMothership) < x.PushRange))
                                               .OrderBy(x => x.Distance(CapsuleHolder)).Take(System.Math.Max(MaxPushes, CapsuleHolder.NumberOfPushesForCapsuleLoss - 1)).ToList();
                int  BoostingDistance = Bot.Engine.GetDistanceAgainst(Boosters, CapsuleHolder);
                bool ShouldPush;
                {
                    Squad        EnemyPirates = Bot.Engine.EnemyLivingPirates.Filter(x => x.Distance(CapsuleHolder) <= x.PushRange + x.MaxSpeed);
                    PirateShip[] Campers;
                    Bot.Engine.CheckForCamper(CampDuration, out Campers);
                    bool ExistsDeeperCamp = Campers.Any(x =>
                    {
                        bool IsFurther              = !EnemyPirates.ContainsPirate(x);
                        bool IsCloserToMothership   = EnemyPirates.All(y => x.Distance(ClosestMothership) < y.Distance(ClosestMothership));
                        Squad LocalBunk             = Bot.Engine.EnemyLivingPirates.Filter(y => y.Distance(CapsuleHolder) <= y.PushRange + y.MaxSpeed && Bot.Engine.GetCampLength(y) >= CampDuration);
                        bool MeetsBunkerRequirement = IsBunker(LocalBunk, LocalBunk.Middle, CapsuleHolder.NumberOfPushesForCapsuleLoss);

                        return(IsFurther && IsCloserToMothership && MeetsBunkerRequirement);
                    });

                    bool IsSafeAfterBoost;
                    {
                        Location NewLocation = (Location)(((Point)CapsuleHolder).InDirection(ClosestMothership, BoostingDistance + CapsuleHolder.MaxSpeed));
                        Squad    LocalBunk   = Bot.Engine.EnemyLivingPirates.Filter(y => y.Distance(CapsuleHolder) <= y.PushRange + y.MaxSpeed && Bot.Engine.GetCampLength(y) >= CampDuration);
                        IsSafeAfterBoost = !IsBunker(LocalBunk, NewLocation, CapsuleHolder.NumberOfPushesForCapsuleLoss);
                    }

                    ShouldPush = CapsuleHolder.Distance(ClosestMothership) <= ClosestMothership.UnloadRange + CapsuleHolder.MaxSpeed + BoostingDistance - 1 ||
                                 (IsBunker(EnemyPirates, CapsuleHolder) && ((!ExistsDeeperCamp && IsSafeAfterBoost) || IgnoreDeeperCamps));
                }

                if (ShouldPush)
                {
                    Boosters = Boosters.Where(x => x.CanPush(CapsuleHolder)).ToList();
                    Boosters.ForEach(x => x.Push(CapsuleHolder, ClosestMothership));
                    CapsuleHolder.Sail(ClosestMothership);
                }
                else
                {
                    CapsuleHolder.Sail(ClosestMothership, x =>
                    {
                        if (x is Pirate pirate)
                        {
                            return(IsBunker(x, CapsuleHolder.NumberOfPushesForCapsuleLoss) ? AvoidingDistance : 0);
                        }
                        return(0);
                    }, true);
                    foreach (PirateShip p in Boosters)
                    {
                        p.Sail(CapsuleHolder.ExpectedLocation);
                    }
                }
                foreach (PirateShip p in squad.FilterOutBySquad(Boosters.AddPirates(CapsuleHolder)))
                {
                    p.Sail(capsule.InitialLocation);
                }
                return(true);
            }
            else if (capsule.IsAlive())
            {
                foreach (PirateShip p in squad)
                {
                    p.Sail(capsule, EnableWarps: true);
                }
                return(true);
            }
            else
            {
                foreach (PirateShip p in squad)
                {
                    p.Sail(capsule.InitialLocation, EnableWarps: true);
                }
                return(true);
            }
            return(false);
        }