private List <Pirate> InterceptCapsule() { // The destination is from the mothership towards the capsule var destination = game.GetEnemyMothership().Location.Towards(game.GetEnemyCapsule().InitialLocation, game.PushRange * 2); // Sort the pirates by their distance to the destination var pushers = myPirates.OrderBy(pirate => pirate.Distance(destination)).Take(game.NumPushesForCapsuleLoss); foreach (var pirate in pushers) { // Check if the pirate is in the destination if (pirate.Location.Equals(destination)) { var capsuleHolder = game.GetEnemyCapsule().Holder; if (capsuleHolder != null) { // Keep trying to push // Don't TryPush() inside the call to Print(). bool pushResult = TryPush(pirate, capsuleHolder); Print("Pirate " + pirate + " is at the interception and tried to push " + capsuleHolder + ":" + pushResult); Print("Pirate " + pirate + " reload turns: " + pirate.PushReloadTurns); } else { // Don't do anything, just wait. Print("Pirate " + pirate + " has arrived to the interception point " + destination + " and is awaiting the capsule to be taken."); } } else { // Sail towards the destination pirate.Sail(destination); Print("Pirate " + pirate + " sails to " + destination + " to intercept " + game.GetEnemyCapsule()); } } return(myPirates.Except(pushers).ToList()); }
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)); }
public void DoTurn(PirateGame game) { collector = game.GetAllMyPirates().ToList()[6]; tailGuard = game.GetAllMyPirates().ToList()[7]; bodyGuards = new List <Pirate>(); bodyGuards.Add(game.GetAllMyPirates().ToList()[5]); bodyGuards.Add(game.GetAllMyPirates().ToList()[4]); offsetX = 300; offsetY = 300; // Get one of my pirates. //Pirate pirate = game.GetMyLivingPirates()[0]; List <Pirate> defenders = game.GetAllMyPirates().ToList(); defenders.OrderBy(Pirate => Pirate.Location.Distance(game.GetEnemyCapsule().Location)); defenders.RemoveRange(4, 4); foreach (Pirate pirate in defenders) { if (pirate.IsAlive()) { if (!PushCarrier(pirate, game)) { // Enemy capsule defenders work Location start; if ((defenders[0].Equals(pirate) || defenders[1].Equals(pirate))) { if (defendFrom(game) == null) { start = generateStart(game, 0); pirate.Sail(start); } else { pirate.Sail(defendFrom(game)); } } else if (defenders[2].Equals(pirate) || defenders[3].Equals(pirate)) { if (defendFrom(game) == null) { start = generateStart(game, 400); pirate.Sail(start); } else { pirate.Sail(defendFrom(game)); } } /*else * { * if (pirate.Capsule == null) * { * Capsule capsule = game.GetMyCapsule(); * pirate.Sail(capsule); * } * else * { * Mothership mothership = game.GetMyMothership(); * // Go towards the mothership. * pirate.Sail(mothership); * } * * }*/ } } } Formation(game); }
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); } } } } } }
public int EnemyPirateNearEnemyCapsule(PirateGame game) { return(game.GetEnemyLivingPirates().Count(pirate => pirate.InRange(game.GetEnemyCapsule(), 500))); }
/// <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); }