Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void doTurn(PirateGame game)
- {
- int count=-1;
- Pirate h2l;
- Pirate l2h;
- int toDefend=(int)(Math.floor((game.getMyLivingPirates().length)/2.0));
- if(game.getAllEnemyPirates().length==0||game.getEnemyCapsules().length==0)
- toDefend=0;
- Pirate [] pirates;
- if(game.getEnemyCapsules().length==0)
- pirates=game.getMyLivingPirates();
- else
- {
- Mothership [] closestEnemyMothership = sortDistanceMotherships(game,game.getEnemyCapsules()[0].initialLocation,game.getEnemyMotherships());
- game.debug("defend: "+toDefend);
- pirates = sortDistance(game,closestEnemyMothership[0].getLocation(),game.getMyLivingPirates());
- }
- for (Pirate pirate:pirates)
- {
- h2l = HtoL(game, pirate);
- l2h = LtoH(game, pirate);
- count++;
- if(h2l == null && l2h == null)
- {
- if(!tryKill(game, pirate))
- if(!stick_bomb(game, pirate))
- if(!save(game,pirate))
- if(!pushToWin(game,pirate))
- if(!tryPush(game,pirate))
- if(!handleHolder(game,pirate))
- if(!raidEnemyCapsules(game,pirate))
- {
- // Try to push, if you didn't - take the Capsules and go to the Motherships.
- if (game.getMyCapsules().length==0)
- handleCapsules(pirate,game,false);
- else if(count<toDefend)
- handleCapsules(pirate,game,false);
- else
- handleCapsules(pirate,game,true);
- }
- }
- else if(h2l != null && l2h != null)
- {
- h2l.swapStates(l2h);
- }
- }
- }
- private Pirate HtoL(PirateGame game, Pirate pirate)
- {
- Pirate swapper = null;
- int count = 0;
- if(pirate.capsule == null&& pirate.stateName.equals("heavy"))
- {
- for(Pirate p:game.getMyLivingPirates())
- {
- if(p.capsule != null)
- {
- for(Pirate ep:game.getEnemyLivingPirates())
- {
- if(p.distance(ep)<=p.pushRange)
- count++;
- }
- if(count >= 2)
- {
- for(Pirate save:game.getMyLivingPirates())
- {
- if(save.capsule!=null&&save.stateName.equals("normal")&&save.id<swapper.id)
- swapper = save;
- }
- }
- }
- }
- }
- return swapper;
- }
- private Pirate LtoH(PirateGame game, Pirate pirate)
- {
- int count = 0;
- Pirate swapper = null;
- if(pirate.capsule != null&& pirate.stateName.equals("normal"))
- {
- for(Pirate p:game.getEnemyLivingPirates())
- {
- if(pirate.distance(p) <= p.pushRange)
- count++;
- }
- //add if pirate is going to die
- if(count >= 2)
- {
- for(Pirate p:game.getMyLivingPirates())
- {
- if(p != pirate&&(p.stateName.equals("heavy"))&&p.id>swapper.id&&p.id>pirate.id)
- swapper = p;
- }
- }
- }
- return swapper;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement