// Returns the remaining pirates.
        private List <Pirate> ManageCapsulePirates()
        {
            // Use camelCase for variable names (enemies, myMothership, capsulePirates, capsuleHolder, closeEnemy, etc.)
            var Enemies      = game.GetEnemyLivingPirates();
            var MyMothership = game.GetMyMothership();

            // Take the closest 2 pirates to the capsule.
            var CapsulePirates = myPirates.OrderBy(pirate => pirate.Distance(game.GetMyCapsule())).Take(2);
            // Seperate them to holder and pusher.
            var CapsuleHolder = CapsulePirates.Where(pirate => pirate.HasCapsule()).FirstOrDefault();

            // Too many if's and else's in this function...
            // Seems like if (capsuleHolder != null), then you're always sending him to the Mothership,
            // so CapsuleHolder.Sail(MyMothership); can be outside some if/else combos.
            // See the changes I made - I think it simplifies the code but doesn't change what it does.

            // if there's no holder, send both to pick it up.
            if (CapsuleHolder == null)
            {
                foreach (Pirate pirate in CapsulePirates)
                {
                    // Impressive - saving time.
                    // But you seem to have this in 3 different places: game.GetMyCapsule().InitialLocation.Towards(mothership, game.CapsulePickupRange-1)
                    // So why not put it into a util function GetCapsulePickupLocation().
                    pirate.Sail(GetCapsulePickupLocation());
                }
            }
            else  // else, send them to the mothership.
            {
                CapsuleHolder.Sail(MyMothership);

                var CapsulePusher = CapsulePirates.Where(pirate => pirate != CapsuleHolder).FirstOrDefault();
                if (CapsulePusher != null)
                {
                    // Get the closest enemy.
                    var CloseEnemy = Enemies.OrderBy(enemy => enemy.Distance(CapsuleHolder)).FirstOrDefault();
                    // if the holder can reach the Mothership with one push, push him.
                    // or if there's a threat from a close enemy, push the holder.
                    if (CapsulePusher.CanPush(CapsuleHolder) &&
                        (CapsuleHolder.Distance(MyMothership) < MyMothership.UnloadRange + CapsulePusher.PushDistance + CapsuleHolder.MaxSpeed ||
                         CloseEnemy != null && CapsuleHolder.InRange(CloseEnemy, CloseEnemy.PushRange + CloseEnemy.MaxSpeed)))
                    {
                        CapsulePusher.Push(CapsuleHolder, MyMothership);
                    }
                    else  // if it's safe, sail normally to the MotherShip.
                    {
                        CapsulePusher.Sail(CapsuleHolder);
                    }
                }
            }
            // Remove the used pirates from the pirates array.
            return(myPirates.Except(CapsulePirates).ToList());
        }
Exemplo n.º 2
0
 void Formation(PirateGame game)
 {
     if (collector.IsAlive())
     {
         if (collector.Capsule == null)
         {
             if (!TryPush(collector, game))
             {
                 collector.Sail(game.GetMyCapsule());
             }
         }
         else
         {
             if (!TryPush(collector, game))
             {
                 collector.Sail(game.GetMyMothership().Location);
             }
         }
     }
     else
     {
         Pirate temp = collector;
         for (int i = 0; i < 2; i++)
         {
             if (bodyGuards[i].IsAlive() && !collector.IsAlive())
             {
                 collector     = bodyGuards[i];
                 bodyGuards[i] = temp;
                 break;
             }
         }
     }
     if (bodyGuards[0].IsAlive())
     {
         if (!TryPush(bodyGuards[0], game))
         {
             bodyGuards[0].Sail(new Location(collector.Location.Row + offsetY, collector.Location.Col - offsetX));
         }
     }
     if (bodyGuards[1].IsAlive())
     {
         if (!TryPush(bodyGuards[1], game))
         {
             bodyGuards[1].Sail(new Location(collector.Location.Row + offsetY, collector.Location.Col + offsetX));
         }
     }
     if (tailGuard.IsAlive())
     {
         if (!TryPush(tailGuard, game))
         {
             tailGuard.Sail(new Location(collector.Location.Row + offsetY, collector.Location.Col));
         }
     }
 }
Exemplo n.º 3
0
        private Location generateStart(PirateGame game, int range)
        {
            int row = 0;
            int col = 0;

            if (game.GetEnemyMothership().Location.Col > game.GetMyMothership().Location.Col)
            {
                col = game.GetEnemyMothership().Location.Col - 1001 + range;
            }
            else
            {
                col = game.GetEnemyMothership().Location.Col + 1001 - range;
            }

            if (game.GetEnemyCapsule().InitialLocation.Row > game.GetMyCapsule().InitialLocation.Row)
            {
                row = game.GetEnemyMothership().Location.Row + 1001 - range;
            }
            else
            {
                row = game.GetEnemyMothership().Location.Row - 1001 + range;
            }
            return(new Location(row, col));
        }
Exemplo n.º 4
0
        public void HandlePirates(PirateGame game)
        {
            foreach (Pirate pirate in game.GetMyLivingPirates())
            {
                if (!TryPush(pirate, game))
                {
                    if (game.GetMyCapsule().Holder == null) //WE HAVE NO CAPSULE
                    {
                        if (pirate == xClosestToY(game.GetMyCapsule(), game.GetMyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate)
                        {
                            pirate.Sail(game.GetMyCapsule().InitialLocation);
                        }
                        else if (game.GetEnemyCapsule().Holder == null) //WE DONT HAVE, ENEMY DONT HAVE CAPSULE
                        {
                            System.Console.WriteLine($"STATE: WE DONT HAVE, ENEMY DONT HAVE");
                            if (pirate == xClosestToY(game.GetMyCapsule(), game.GetMyLivingPirates().Cast <GameObject>().ToList())[1] as Pirate)
                            {
                                Pirate first = xClosestToY(game.GetMyCapsule(), game.GetMyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate;
                                pirate.Sail(first);
                            }
                            // SENDS CLOSEST PIRATE 1&2 TO- CLOSEST ENEMY TO CLOSEST ENEMY CAPSULE
                            else if (xClosestToY(xClosestToY(game.GetEnemyCapsule().InitialLocation, game.GetEnemyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate, game.GetMyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate == pirate || xClosestToY(xClosestToY(game.GetEnemyCapsule().InitialLocation, game.GetEnemyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate, game.GetMyLivingPirates().Cast <GameObject>().ToList())[1] as Pirate == pirate)
                            {
                                pirate.Sail(xClosestToY(game.GetEnemyCapsule().InitialLocation, game.GetEnemyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate);
                            }
                            else
                            {
                                pirate.Sail(xClosestToY(xClosestToY(game.GetMyCapsule(), game.GetMyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate, game.GetEnemyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate);
                            }
                        }
                        else //WE NO HAVE, ENEMY HAVE CAPSULE
                        {
                            System.Console.WriteLine($"STATE: WE DONT HAVE, ENEMY HAVE");
                            if (pirate == xClosestToY(game.GetMyCapsule(), game.GetMyLivingPirates().Cast <GameObject>().ToList())[1] as Pirate)
                            {
                                Pirate first = xClosestToY(game.GetMyCapsule(), game.GetMyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate;
                                pirate.Sail(first);
                            }
                            else
                            {
                                pirate.Sail(game.GetEnemyCapsule().Holder);
                            }
                        }
                    }
                    // SEMI DONE
                    else //WE HAVE CAPSULE
                    {
                        if (pirate.HasCapsule())
                        {
                            pirate.Sail(game.GetMyMothership());
                        }
                        else if (game.GetEnemyCapsule().Holder == null) //WE HAVE, ENEMY DONT HAVE CAPSULE
                        {
                            System.Console.WriteLine($"STATE: WE HAVE, ENEMY DONT HAVE");

                            // IF SHAMEN CHECKS IF A PIRATE IS THE CLOSEST TO INITIAL OF CAPSULE AND PERFECT ROTATION POSSIBLE and CHECKS FOR CLOSEST PIRATE
                            if (game.GetMyCapsule().Holder.Distance(game.GetMyMothership()) + game.GetMyMothership().Distance(game.GetMyCapsule().InitialLocation) > game.GetMyCapsule().InitialLocation.Distance(xClosestToY(game.GetMyCapsule().InitialLocation, game.GetMyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate) && pirate == xClosestToY(game.GetMyMothership(), game.GetMyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate)
                            {
                                pirate.Sail(game.GetMyCapsule().InitialLocation);
                            }
                            else if (xClosestToY(game.GetMyCapsule().Holder, game.GetMyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate == pirate)
                            {
                                pirate.Sail(game.GetMyCapsule().Holder);
                            }
                            // SENDS CLOSEST PIRATE 1&2 TO- CLOSEST ENEMY TO CLOSEST ENEMY CAPSULE
                            else if (xClosestToY(xClosestToY(game.GetEnemyCapsule().InitialLocation, game.GetEnemyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate, game.GetMyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate == pirate || xClosestToY(xClosestToY(game.GetEnemyCapsule().InitialLocation, game.GetEnemyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate, game.GetMyLivingPirates().Cast <GameObject>().ToList())[1] as Pirate == pirate)
                            {
                                pirate.Sail(xClosestToY(game.GetEnemyCapsule().InitialLocation, game.GetEnemyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate);
                            }
                            else // ALL OTHER PIRATES (NOT DONE BITCHLAL)
                            {
                                pirate.Sail(xClosestToY(xClosestToY(game.GetMyCapsule(), game.GetMyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate, game.GetEnemyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate);
                            }
                        }
                        else //WE HAVE, ENEMY HAVE CAPSULE
                        {
                            System.Console.WriteLine($"STATE: WE HAVE, ENEMY HAVE");
                            // IF SHAMEN CHECKS IF A PIRATE IS THE CLOSEST TO INITIAL OF CAPSULE AND PERFECT ROTATION POSSIBLE and CHECKS FOR CLOSEST PIRATE
                            if (game.GetMyCapsule().Holder.Distance(game.GetMyMothership()) + game.GetMyMothership().Distance(game.GetMyCapsule().InitialLocation) > game.GetMyCapsule().InitialLocation.Distance(xClosestToY(game.GetMyCapsule().InitialLocation, game.GetMyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate) && pirate == xClosestToY(game.GetMyMothership(), game.GetMyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate)
                            {
                                pirate.Sail(game.GetMyCapsule().InitialLocation);
                            }
                            else if (xClosestToY(game.GetMyCapsule().Holder, game.GetMyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate == pirate)
                            {
                                pirate.Sail(game.GetMyCapsule().Holder);
                            }
                            // CHECKS IF THE PIRATE IS CLOSE TO HOLDER IF HE DOES AND WE HAVE LESS PIRATES THAN THEM PIRATE GOES TO DEFEND OR SOMETHING
                            else if (EnemyCloseToOurCapsule(game) > 1 && pirate.Distance(game.GetMyCapsule().Holder) < 900 && pirate != game.GetMyCapsule().Holder&& AllyCloseToOurCapsule(game) + 1 < EnemyCloseToOurCapsule(game))
                            {
                                pirate.Sail(game.GetMyCapsule().Holder);
                            }
                            // SENDS THE 1st & 2nd CLOSEST PIRATES TO ENEMY CAPSULE
                            else if (xClosestToY(game.GetEnemyCapsule().Holder, game.GetMyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate == pirate || xClosestToY(game.GetEnemyCapsule().Holder, game.GetMyLivingPirates().Cast <GameObject>().ToList())[1] as Pirate == pirate)
                            {
                                pirate.Sail(game.GetEnemyCapsule().Holder);
                            }
                            // GOES TO ENEMY MOTHERSHIP IN ORDER TO DEFEND
                            else if (game.GetEnemyCapsule().Holder.InRange(game.GetEnemyMothership(), 1500) && pirate.InRange(game.GetEnemyMothership(), 1200))
                            {
                                pirate.Sail(game.GetEnemyCapsule().Holder);
                            }
                            // CHECKS IF ENEMY PIRATE IS IN RANGE OF OUR MS, IF SO, CLOSEST PIRATE TO THIS ENEMY WILL GO TO HIM
                            else if ((xClosestToY(game.GetMyMothership(), game.GetEnemyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate).InRange(game.GetMyMothership(), 800) && xClosestToY((xClosestToY(game.GetMyMothership(), game.GetEnemyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate), game.GetMyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate == pirate)
                            {
                                pirate.Sail((xClosestToY(game.GetMyMothership(), game.GetEnemyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate));
                            }
                            // LETS SAIL TO CLOSEST ENEMY PIRATE AND F**K HIN IN THE ASS HOLEEEEE !Q!!:)
                            else
                            {
                                pirate.Sail(xClosestToY(pirate, game.GetEnemyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Makes the pirate try to push an enemy pirate. Returns true if it did.
        /// </summary>
        /// <param name="pirate">The pushing pirate.</param>
        /// <param name="game">The current game state.</param>
        /// <returns>true if the pirate pushed.</returns>
        private bool TryPush(Pirate pirate, PirateGame game)
        {
            foreach (Pirate ally in game.GetMyLivingPirates())
            {
                // IF WE HAVE CAP AND PIRATE IS THE CAPSULE HOLDER RETURN FALSE
                if (game.GetMyCapsule().Holder != null && game.GetMyCapsule().Holder == pirate)
                {
                    return(false);
                }
                // IF WE HAVE CAP AND PIRATE CAN PUSH CAP HOLDER AND HE IS THE CLOSEST TO HIM WE RETURN TRUE
                if (game.GetMyCapsule().Holder != null && ally.CanPush(game.GetMyCapsule().Holder) && PiratesInRangeOfPush(game, game.GetMyCapsule().Holder)[0] == pirate)
                {
                    ally.Push(game.GetMyCapsule().Holder, game.GetMyMothership());
                    System.Console.WriteLine($"pirate:{ally} did push capholder: {game.GetMyCapsule().Holder} to MOTHERSHIP");
                    return(true);
                }
                // IF WE DONT HAVE CAPSULE AND WE CAN PUSH THE CLOSEST PIRATE TO CAP LOCATION THAN DO IT!
                if (game.GetMyCapsule().Holder == null && ally.CanPush(xClosestToY(game.GetMyCapsule().InitialLocation, game.GetMyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate))
                {
                    if ((xClosestToY(game.GetMyCapsule().InitialLocation, game.GetMyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate).Distance(game.GetMyCapsule().InitialLocation) >= game.PirateMaxSpeed * 3 && ally.CanPush(xClosestToY(game.GetMyCapsule().InitialLocation, game.GetMyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate) && xClosestToY(game.GetMyCapsule().InitialLocation, game.GetMyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate == ally)
                    {
                        ally.Push(xClosestToY(game.GetMyCapsule().InitialLocation, game.GetMyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate, game.GetMyCapsule().InitialLocation);
                        System.Console.WriteLine($"pirate:{ally} did push closest to cap: {game.GetMyCapsule().Holder} to CAP");
                        return(true);
                    }
                }
            }

            //WE PREFFER TO PUSH OURSELVES FIRST!
            foreach (Pirate enemy in game.GetEnemyLivingPirates())
            {
                //TODO :  IF TIGBORET PUSH HIM TO BUY SOME TIME

                // IF ENEMY HAS CAP AND WE HAVE MORE THAN 2 TO DROP HIS CAP
                if (game.GetEnemyCapsule().Holder != null && enemy == game.GetEnemyCapsule().Holder&& PiratesInRangeOfPush(game, enemy).Count > 1 && pirate.CanPush(enemy))
                {
                    pirate.Push(enemy, EnemyCanExplode(game, enemy));
                    return(true);
                }
                // IF ENEMY CAN GO OUT OF MAP KICK HIM!
                if (!EnemyCanExplode(game, enemy).Equals(enemy.InitialLocation.Add(enemy.InitialLocation)))
                {
                    if (isOneFromThisList(game, PiratesInRangeOfPush(game, enemy), pirate))
                    {
                        pirate.Push(enemy, EnemyCanExplode(game, enemy));
                        return(true);
                    }
                }



                // Check if the pirate can push the enemy.

                /*if (pirate.CanPush(enemy))
                 * {
                 *  // Push enemy!
                 *  //***POSSIBLE BUG***
                 *  pirate.Push(enemy, EnemyCanExplode(game, enemy));
                 *
                 *  // Print a message.
                 *  System.Console.WriteLine("pirate " + pirate + " pushes " + enemy + " towards " + EnemyCanExplode(game, enemy));
                 *
                 *  // Did push.
                 *  return true;
                 * }*/
            }

            // Didn't push.
            return(false);
        }