Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Pirates;
- namespace MyBot
- {
- public class TutorialBot : Pirates.IPirateBot
- {
- public int abs(int num)
- {
- if (num < 0)
- {
- num = num * -1;
- }
- return num;
- }
- public void radarattack(Pirate a, PirateGame game)
- {
- foreach (Aircraft b in game.GetEnemyLivingAircrafts())
- {
- if (b.Location.Col >= 2 && b.Location.Col <= 15 && b.Location.Row >= 15 && b.Location.Row <= 31)
- {
- if (doyouhaveatarget(a, game) != null)
- {
- attack(game, a, doyouhaveatarget(a, game));
- }
- else
- {
- Location loc = game.GetSailOptions(a, b)[0];
- if (a.GetLocation() != loc)
- {
- game.SetSail(a, loc);
- }
- }
- }
- }
- }
- public void handleDrones(List<Drone> d, PirateGame game)
- {
- int mapX = game.GetColCount() - 1;
- int mapY = game.GetRowCount() - 1;
- City myCity = game.GetMyCities()[0];
- Location myLoc = myCity.Location;
- game.Debug(myLoc);
- int cityX = myLoc.Col; // X
- int cityY = myLoc.Row; // Y
- bool rahok = false;
- foreach (Drone dro in d)
- {
- if (dro.Location.Col != 0 && dro.Location.Row != 0 && dro.Location.Col != mapX && dro.Location.Row != cityY)
- {
- // LEVEL 1
- if (abs(cityX - mapX) < cityX)
- {
- // Rahok
- Location loc = new Location(dro.Location.Row, mapX);
- game.Debug(loc);
- game.SetSail(dro, game.GetSailOptions(dro, loc)[0]);
- }
- else
- {
- //Karov
- Location loc = new Location(dro.Location.Col, 0);
- game.Debug(loc);
- game.SetSail(dro, game.GetSailOptions(dro, loc)[0]);
- }
- }
- else if (dro.Location.Row == cityY)
- {
- // LEVEL 3 OVERRIDE
- game.Debug("BLA BLA");
- game.Debug(game.GetSailOptions(dro, new Location(cityY, dro.Location.Col))[0]);
- game.SetSail(dro, game.GetSailOptions(dro, new Location(dro.Location.Row, cityX))[0]);
- }
- else if ((dro.Location.Col == mapX || dro.Location.Col == 0) && dro.Location.Row != cityY)
- {
- // LEVEL 2
- game.Debug("ahaln ma nishma");
- Location loc = new Location(cityY, dro.Location.Col);
- game.SetSail(dro, game.GetSailOptions(dro, loc)[0]);
- }
- else
- {
- // LEVEL 3
- game.Debug("HEY");
- game.Debug(game.GetSailOptions(dro, new Location(cityY, dro.Location.Col))[0]);
- game.SetSail(dro, game.GetSailOptions(dro, new Location(dro.Location.Row, cityX))[0]);
- }
- }
- }
- public int howmuchenemypiratesinthisisland(PirateGame game, Island a)
- {
- int count = 0;
- foreach (Pirate pirate in game.GetEnemyLivingPirates())
- {
- if (a.InControlRange(pirate))
- {
- count++;
- }
- }
- return count;
- }
- public void attack(PirateGame game, Pirate a, Aircraft enemy)
- {
- if (enemy.CurrentHealth > 0)
- game.Attack(a, enemy);
- }
- public Aircraft doyouhaveatarget(Pirate a, PirateGame game)
- {
- foreach (Aircraft enemy in game.GetEnemyLivingAircrafts())
- {
- if (a.InAttackRange(enemy))
- return enemy;
- }
- return null;
- }
- public Island fromwhichisland(Drone a, PirateGame game) // from which island do the drone start from?
- {
- foreach (Island b in game.GetAllIslands())
- {
- if (a.Distance(b) <= 3)
- {
- return b;
- }
- }
- return null;
- }
- public void DoTurn(PirateGame game)
- {
- foreach (Pirate pirate in game.GetMyLivingPirates())
- {
- City city = game.GetMyCities()[0]; // my city
- City city2 = game.GetEnemyCities()[0];//his cisy
- if (pirate.Id == 0) //coming to his city and attacking
- {
- Location loc = new Location(city2.GetLocation().Row - 2, city2.GetLocation().Col + 4);
- List<Location> sailOptions = game.GetSailOptions(pirate, loc);
- if (pirate.GetLocation() != sailOptions[0])
- {
- game.SetSail(pirate, sailOptions[0]);
- }
- radarattack(pirate, game);
- }
- else if (pirate.Id == 1) // coming to his city and attacking
- {
- Location loc = new Location(city2.GetLocation().Row + 3, city2.GetLocation().Col + 4);
- List<Location> sailOptions = game.GetSailOptions(pirate, loc);
- if (pirate.GetLocation() != sailOptions[0])
- {
- game.SetSail(pirate, sailOptions[0]);
- }
- radarattack(pirate, game);
- }
- // else if (pirate.Id == 2) // coming to my city and attacking
- // {
- // Location loc = new Location(city.GetLocation().Row, city.GetLocation().Col - 4);
- // List<Location> sailOptions = game.GetSailOptions(pirate, loc);
- // game.SetSail(pirate, sailOptions[0]);
- // foreach (Aircraft enemy in game.GetEnemyLivingAircrafts())
- // {
- // if (pirate.InAttackRange(enemy))
- // {
- // game.Attack(pirate, enemy);
- // game.Debug("pirate " + pirate + " attacks " + enemy);
- // }
- // }
- // }
- else if (pirate.Id == 3 || pirate.Id == 4 || pirate.Id == 2) // getting to the closest island, then attacking
- {
- Island closest = game.GetAllIslands()[0];
- int min = 999999999;
- List<Island> destinations = game.GetAllIslands();
- foreach (Island a in destinations)
- {
- if (pirate.Distance(a) < min && howmuchenemypiratesinthisisland(game, a) < 3 && a.Owner != game.GetMyself())
- {
- min = pirate.Distance(a);
- closest = a;
- }
- }
- List<Location> sailOptions = game.GetSailOptions(pirate, closest);
- if (doyouhaveatarget(pirate, game) != null)
- {
- attack(game, pirate, doyouhaveatarget(pirate, game));
- }
- else
- {
- if (pirate.GetLocation() != sailOptions[0])
- {
- game.SetSail(pirate, sailOptions[0]);
- }
- }
- }
- } // giant foreach
- handleDrones(game.GetMyLivingDrones(),game);
- }//doturn
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement