Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.81 KB | None | 0 0
  1. public void doTurn(PirateGame game)
  2.     {
  3.         int count=-1;
  4.         Pirate h2l;
  5.         Pirate l2h;
  6.         int toDefend=(int)(Math.floor((game.getMyLivingPirates().length)/2.0));
  7.         if(game.getAllEnemyPirates().length==0||game.getEnemyCapsules().length==0)
  8.             toDefend=0;
  9.         Pirate [] pirates;
  10.         if(game.getEnemyCapsules().length==0)
  11.             pirates=game.getMyLivingPirates();
  12.         else
  13.         {
  14.             Mothership [] closestEnemyMothership = sortDistanceMotherships(game,game.getEnemyCapsules()[0].initialLocation,game.getEnemyMotherships());
  15.             game.debug("defend: "+toDefend);
  16.             pirates = sortDistance(game,closestEnemyMothership[0].getLocation(),game.getMyLivingPirates());
  17.         }
  18.        
  19.         for (Pirate pirate:pirates)
  20.         {
  21.             h2l = HtoL(game, pirate);
  22.             l2h = LtoH(game, pirate);
  23.             count++;
  24.             if(h2l == null && l2h == null)
  25.             {
  26.                 if(!tryKill(game, pirate))
  27.                     if(!stick_bomb(game, pirate))
  28.                         if(!save(game,pirate))
  29.                             if(!pushToWin(game,pirate))
  30.                                 if(!tryPush(game,pirate))
  31.                                     if(!handleHolder(game,pirate))
  32.                                         if(!raidEnemyCapsules(game,pirate))
  33.                                         {
  34.                         // Try to push, if you didn't - take the Capsules and go to the Motherships.
  35.                                             if (game.getMyCapsules().length==0)
  36.                                                 handleCapsules(pirate,game,false);
  37.                                             else if(count<toDefend)
  38.                                                 handleCapsules(pirate,game,false);
  39.                                             else
  40.                                                 handleCapsules(pirate,game,true);
  41.                                         }
  42.             }
  43.             else if(h2l != null && l2h != null)
  44.             {
  45.                 h2l.swapStates(l2h);
  46.             }
  47.         }
  48.     }
  49.  
  50.  
  51.  
  52.  
  53. private Pirate HtoL(PirateGame game, Pirate pirate)
  54.     {
  55.         Pirate swapper = null;
  56.         int count = 0;
  57.         if(pirate.capsule == null&& pirate.stateName.equals("heavy"))
  58.         {
  59.             for(Pirate p:game.getMyLivingPirates())
  60.             {
  61.                 if(p.capsule != null)
  62.                 {
  63.                     for(Pirate ep:game.getEnemyLivingPirates())
  64.                     {
  65.                         if(p.distance(ep)<=p.pushRange)
  66.                             count++;
  67.                     }
  68.                     if(count >= 2)
  69.                     {
  70.                         for(Pirate save:game.getMyLivingPirates())
  71.                         {
  72.                             if(save.capsule!=null&&save.stateName.equals("normal")&&save.id<swapper.id)
  73.                                 swapper = save;
  74.                         }
  75.                     }
  76.                 }
  77.             }
  78.         }
  79.         return swapper;
  80.     }
  81.     private Pirate LtoH(PirateGame game, Pirate pirate)
  82.     {
  83.         int count = 0;
  84.         Pirate swapper = null;
  85.         if(pirate.capsule != null&& pirate.stateName.equals("normal"))
  86.         {
  87.             for(Pirate p:game.getEnemyLivingPirates())
  88.             {
  89.                 if(pirate.distance(p) <= p.pushRange)
  90.                     count++;
  91.             }
  92.             //add if pirate is going to die
  93.             if(count >= 2)
  94.             {
  95.                 for(Pirate p:game.getMyLivingPirates())
  96.                 {
  97.                     if(p != pirate&&(p.stateName.equals("heavy"))&&p.id>swapper.id&&p.id>pirate.id)
  98.                         swapper = p;
  99.                 }
  100.             }
  101.         }
  102.        return swapper;
  103.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement