Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package bots;
- import pirates.*;
- import java.util.*;
- public class MyBot implements PirateBot{
- static Location[] enemyPiratesLocations;
- static Location[] myPiratesLocations;
- Pirate[] defenders;
- Pirate[] attackers;
- Pirate[] helpers;
- static int[] capsuleStatus;
- static int[] enemyUsingMotherships;
- static int[] defendersNearMotherships;
- static int[] howManyPiratesPushEnemy;
- static int[] helpersNearCapsule;
- static int pushersCount=0;
- static int upHelpersCount=0;
- static int williamCount=0;
- static int[] piratesGoingToCapsule;
- static int[] piratesPushingCapsule;
- static int[] piratesPushingAstroids;
- static boolean upTRUEdownFalse;
- int defAmountClose=0;
- int defAmountFar=0;
- int countFirstDefender=0;
- static int leftright=-1;
- boolean AsteroidInPlace=false;
- static boolean isThereAnotherCapsuleClose=false;
- //Location[] astroidsLocations;
- public void doTurn(PirateGame game) //The turn function
- {
- leftright=-1;
- defAmountClose=0;
- defAmountFar=0;
- upTRUEdownFalse=false;
- isThereAnotherCapsuleClose=false;
- if(game.turn==1) {
- enemyPiratesLocations=new Location[game.getAllEnemyPirates().length];
- myPiratesLocations=new Location[game.getAllMyPirates().length];
- capsuleStatus=new int[game.getMyCapsules().length];
- piratesGoingToCapsule= new int[game.getMyCapsules().length];
- howManyPiratesPushEnemy= new int[game.getAllEnemyPirates().length];
- helpersNearCapsule= new int[game.getMyCapsules().length];
- piratesPushingCapsule= new int[game.getMyCapsules().length];
- piratesPushingAstroids=new int[game.getAllAsteroids().length];
- }
- pushersCount=0;
- upHelpersCount=0;
- williamCount=0;
- if(game.turn==1)
- {
- for(int i=0;i<game.getAllEnemyPirates().length;i++)
- {
- enemyPiratesLocations[i]=game.getAllEnemyPirates()[i].getLocation();
- }
- for(int i=0;i<game.getAllMyPirates().length;i++)
- {
- myPiratesLocations[i]=game.getAllMyPirates()[i].getLocation();
- }
- for(int i=0;i<capsuleStatus.length;i++)
- capsuleStatus[i]=0;
- for(int i=0;i<helpersNearCapsule.length;i++)
- {
- helpersNearCapsule[i]=0;
- }
- enemyUsingMotherships=new int[game.getEnemyMotherships().length];//
- defendersNearMotherships= new int[game.getEnemyMotherships().length];
- }
- //enemy using capsule===========================
- for(int i=0;i<enemyUsingMotherships.length;i++)//
- {
- enemyUsingMotherships[i]=0;
- }
- for(Pirate enemy:game.getEnemyLivingPirates())// : 0 , , 2 3 2
- {
- Mothership goingToMother=whichMotherGoingTo(enemy,400,game);//the cap where enemy is going
- if(goingToMother!=null)
- {
- int id= goingToMother.id;
- enemyUsingMotherships[id]++;
- }
- }
- for(int i:enemyUsingMotherships)
- {
- }
- for(Capsule myCapsule:game.getMyCapsules())
- {
- if(myCapsule.getLocation().equals(myCapsule.initialLocation))
- capsuleStatus[myCapsule.id]=0;
- }
- //defenders near motherships==============================
- for(int i=0;i<defendersNearMotherships.length;i++)//
- {
- defendersNearMotherships[i]=0;
- }
- for(int i=0;i<howManyPiratesPushEnemy.length;i++)
- howManyPiratesPushEnemy[i]=0;
- for(int i=0;i<piratesGoingToCapsule.length;i++)
- piratesGoingToCapsule[i]=0;
- for(Capsule capsule: game.getMyCapsules())//check how many helpers near capsule
- {
- for(Pirate pirate:game.getMyLivingPirates())
- {
- if(pirate.distance(capsule)<=game.pushDistance+game.pushRange&&!pirate.getLocation().equals(capsule.getLocation()))
- helpersNearCapsule[capsule.id]++;
- }
- }
- int numOfCapsNearMother=0;
- for(Mothership mother:game.getMyMotherships()){
- numOfCapsNearMother=0;
- for(Capsule capsule:game.getMyCapsules())
- {
- if(capsule.distance(mother)<3000)
- {
- numOfCapsNearMother++;
- }
- }
- if(numOfCapsNearMother>1)
- isThereAnotherCapsuleClose=true;
- }
- for(int i=0;i<piratesPushingCapsule.length;i++)
- {
- piratesPushingCapsule[i]=0;
- }
- for(int i=0;i<piratesPushingAstroids.length;i++)
- {
- piratesPushingAstroids[i]=0;
- }
- // for(Pirate pirate: game.getMyLivingPirates())
- // {
- // if(pirate.hasCapsule())
- // capsuleStatus[pirate.capsule.id]=1;
- // }
- Player player= game.getEnemy();
- Player player1 = game.getMyself();
- String id= player.botName;
- System.out.println(id);
- //System.out.println(id);
- if(id.equals("26078")){
- Pirate attacker1 =game.getAllMyPirates()[0];
- Pirate attacker2 =game.getAllMyPirates()[1];
- Pirate attacker3 =game.getAllMyPirates()[8];
- Pirate defender1 =game.getAllMyPirates()[2];
- Pirate defender2 =game.getAllMyPirates()[3];
- Pirate defender3 =game.getAllMyPirates()[4];
- Pirate helper1 = game.getAllMyPirates()[5];
- Pirate helper2 = game.getAllMyPirates()[6];
- Pirate helper3 = game.getAllMyPirates()[7];
- for (int i = 0; i < 2; i++) {
- game.getAllMyPirates()[i].sail(closestCapsuleAttack(game.getAllMyPirates()[i], game));
- if(game.getAllMyPirates()[i].hasCapsule()==true){
- game.getAllMyPirates()[i].sail(closestMother(game, game.getAllMyPirates()[i] ));
- }
- }
- attacker3.sail(closestCapsuleAttack(attacker3, game));
- if(attacker3.hasCapsule()==true)
- {
- attacker3.sail(closestMother(game, attacker3));
- }
- }
- else{
- int helpersInTeam=1;
- int defendersInTeam=2;
- int attackersInTeam=1;
- int groupSize=4;
- int defCount=0;
- int helpersCount=0;
- int attackersCount=0;
- int numOfGroupsByLength=game.getAllMyPirates().length/groupSize;//2
- int moduluLength=game.getAllMyPirates().length%groupSize;//
- int defLength=defendersInTeam*numOfGroupsByLength;
- int attackersLength=attackersInTeam*numOfGroupsByLength;
- int helpersLength=helpersInTeam*numOfGroupsByLength;
- if(moduluLength>=1&&numOfGroupsByLength>0)
- {
- helpersLength++;
- }
- if(moduluLength>=2&&numOfGroupsByLength>0)
- {
- defLength++;
- }
- if(moduluLength>=3&&numOfGroupsByLength>0)
- {
- defLength++;
- }
- if(game.getAllMyPirates().length>=1&&game.getAllMyPirates().length<4)
- attackersLength++;
- if(game.getAllMyPirates().length>=2&&game.getAllMyPirates().length<4)
- defLength++;
- if(game.getAllMyPirates().length>=3&&game.getAllMyPirates().length<4)
- helpersLength++;
- defenders= new Pirate[defLength];
- attackers= new Pirate[attackersLength];
- helpers= new Pirate[helpersLength];
- if(numOfGroupsByLength>0)
- {
- attackers[attackersCount]=game.getAllMyPirates()[0];
- attackersCount++;
- // System.out.println("ATTACKER");
- defenders[defCount]=game.getAllMyPirates()[1];
- defCount++;
- // System.out.println("DEFENDER");
- helpers[helpersCount]=game.getAllMyPirates()[2];
- helpersCount++;
- // System.out.println("HELPER");
- defenders[defCount]=game.getAllMyPirates()[3];
- defCount++;
- // System.out.println("DEFENDER");
- }
- for(int i=1;i<numOfGroupsByLength;i++)//
- {
- for(int k=0;k<groupSize;k++)//
- {
- if(k==0)
- {
- helpers[helpersCount]=game.getAllMyPirates()[groupSize*i+k];
- helpersCount++;
- // System.out.println("HELPER");
- }
- if(k==1)
- {
- defenders[defCount]=game.getAllMyPirates()[groupSize*i+k];
- defCount++;
- // System.out.println("DEFENDER");
- }
- if(k==2)
- {
- defenders[defCount]=game.getAllMyPirates()[groupSize*i+k];
- defCount++;
- // System.out.println("DEFENDER");
- }
- if(k==3)
- {
- attackers[attackersCount]=game.getAllMyPirates()[groupSize*i+k];
- attackersCount++;
- // System.out.println("ATTACKER");
- }
- }
- }
- int modulu=game.getAllMyPirates().length%groupSize;//
- if(numOfGroupsByLength>0){
- if(modulu>=1)
- {
- helpers[helpersCount]=game.getAllMyPirates()[numOfGroupsByLength*groupSize];
- helpersCount++;
- // System.out.println("HELPER");
- }
- if(modulu>=2)
- {
- defenders[defCount]=game.getAllMyPirates()[numOfGroupsByLength*groupSize+1];
- defCount++;
- // System.out.println("DEFENDER");
- }
- if(modulu>=3)
- {
- defenders[defCount]=game.getAllMyPirates()[numOfGroupsByLength*groupSize+2];
- defCount++;
- // System.out.println("DEFENDER");
- }
- }
- else//
- {
- if(modulu>=1)
- {
- attackers[attackersCount]=game.getAllMyPirates()[numOfGroupsByLength*groupSize];
- attackersCount++;
- }
- if(modulu>=2)
- {
- defenders[defCount]=game.getAllMyPirates()[numOfGroupsByLength*groupSize+1];
- defCount++;
- }
- if(modulu>=3)
- {
- helpers[helpersCount]=game.getAllMyPirates()[numOfGroupsByLength*groupSize+2];
- helpersCount++;
- }
- }
- // System.out.println(attackers.length);
- // System.out.println(defenders.length);
- // System.out.println(helpers.length);
- //ATTACKER CODE
- if(attackers.length==1&&game.getMyMotherships().length==0&&pushOut(attackers[0],game)==false)
- {
- }
- else if(game.getMyMotherships().length>0){
- for(int i=0;i<attackers.length;i++) {
- if(attackers[i].isAlive())
- attackerAction(attackers[i],game);
- }
- }
- //DEFENDER CODE
- if(defenders.length>0){
- Capsule enemyCapsule= closestCapsuleToEnemy(game);
- Mothership EnemyBase= relevantEnemyMothership(enemyCapsule, game);
- int enemyMoveCapsuleX= enemyCapsule.getLocation().row;
- int enemyMoveCapsuleY= enemyCapsule.getLocation().col;
- Location EnemyBaseDef= defMove(enemyMoveCapsuleX,enemyMoveCapsuleY,game,600,enemyCapsule);
- Location EnemyBaseDef2= defMove(enemyMoveCapsuleX,enemyMoveCapsuleY,game,1050,enemyCapsule);
- int defAmountClose=0;
- int defAmountFar=0;
- for(int i=0;i<defenders.length;i++) {
- if(id.equals("25774"))
- defenderAction(defenders[i],game);
- else if (id.equals("26075"))
- {
- }
- else
- defenderActionReal(defenders[i],game);
- //System.out.println(defenders.length);
- /*if(defenders[i].isAlive()&&pushOut(defenders[i],game)==false&&tryPushAstroidDefenders(defenders[i],game,enemyCapsule)==false) {
- //if(numberOfDefendersNearEnemyMothership(EnemyBase, defenders)[0]<2||(numberOfDefendersNearEnemyMothership(EnemyBase, defenders)[0]<=2&&defenders[i].distance(EnemyBase)<500&&defInside<2))
- if(defAmountClose<2)
- {
- defenders[i].sail(EnemyBaseDef);
- defAmountClose++;
- }
- else if(defAmountFar<2){
- if(isCloseToEnemy(defenders[i],game,1200,enemyCapsule)) {
- defenders[i].sail(enemyCapsule.getLocation());
- }
- else
- defenders[i].sail(EnemyBaseDef2);
- defAmountFar++;
- }
- }*/
- }
- }
- //HELPERS CODE
- if(helpers.length>0){
- for(Pirate helper:helpers)
- {
- if(helper.isAlive())
- attackerAction(helper,game);
- }
- /*Pirate[] pushers= new Pirate[helpers.length/2];
- Pirate[] upHelpers= new Pirate[helpers.length/2];
- for(int i=0;i<helpers.length/2;i++)//zoogi
- {
- pushers[i]=helpers[i];
- }
- int helperLength=helpers.length;
- if(helperLength%2==1)
- helperLength=helpers.length-1;
- for(int i=helpers.length/2;i<helperLength;i++)//zoogi
- {
- upHelpers[i-helpers.length/2]=helpers[i];
- }
- for(int i=0;i<helpers.length/2;i++)
- {
- //Capsule closestCap=closestCapsuleAttack(upHelpers[i],game);
- Location closestCap;
- if(closestAttacker(attackers,upHelpers[i],game).isAlive()==true)//where to go pirate or capsule
- closestCap=closestAttacker(attackers,upHelpers[i],game).getLocation();
- else
- closestCap=BestCapsule(upHelpers[i],game).getLocation();
- if(shouldIpushAstroid(game,upHelpers[i],closestCapsuleToEnemy(game))==false){
- if(canPushCapsuleNearEnemyHelperIneedToPee(upHelpers[i],game)==false)
- {
- //UpHelperCode
- if(isCapsuleOnCapsuleInitMotherLine(game,upHelpers[i])||pushers[i].distance(closestCap)<300)
- {
- if(pushers[i].isAlive()==false&&pushers[i].distance(closestCap)>400)
- upHelpers[i].sail(attackerFollowerMove(closestCap.getLocation().row,closestCap.getLocation().col,game,200,upHelpers[i]));
- else{
- //Location center= new Location(game.rows/2,game.cols/2);
- //double upD= attackersMoveUpper(closestCap.getLocation().row,closestCap.getLocation().col,game,800,upHelpers[i]).distance(center);
- //double lowD= attackersMoveLower(closestCap.getLocation().row,closestCap.getLocation().col,game,800,upHelpers[i]).distance(center);
- if(upTRUEdownFalse)
- upHelpers[i].sail(attackersMoveUpper(closestCap.getLocation().row,closestCap.getLocation().col,game,800,upHelpers[i] ));
- else
- upHelpers[i].sail(attackersMoveLower(closestCap.getLocation().row,closestCap.getLocation().col,game,800,upHelpers[i] ));
- }
- }
- else
- {
- if(upHelpers[i].distance(closestCap)<400)
- {
- //Capsule capsule=closestCapsuleAttack(upHelpers[i],game);
- // if(capsuleStatus[capsule.id]==2)
- // upHelpers[i].sail(attackerUpMother(capsule.initialLocation.row, capsule.initialLocation.col,game, closestMother(game,upHelpers[i])));
- // else
- upHelpers[i].sail(attackerFollowerMove(closestCap.getLocation().row,closestCap.getLocation().col,game,200,upHelpers[i]));
- //helper1.sail(capsule);
- }
- }
- }//pusherCode
- else//if upHelperPushedCapsule
- {
- capsuleStatus[closestCapsuleAttack(upHelpers[i], game).id]=3;//upHelper pushed
- }
- }
- // 0-onInit 1- nearHelpers 2-pusherPushed to upHelper 3-up helperPushed 4-pusher pushed to Mother
- int canPushCap=canPushCapsuleNearEnemy(pushers[i], game,450,upHelpers);
- System.out.println(canPushCap);
- if(shouldIpushAstroid(game,pushers[i],closestCapsuleToEnemy(game))==false&&canPushCap==0)
- {
- pushers[i].sail(attackerFollowerMove(closestCap.getLocation().row,closestCap.getLocation().col,game,200,pushers[i]));
- }
- else if(canPushCap==2)
- {
- capsuleStatus[closestCapsuleAttack(pushers[i], game).id]=2;//pusherPushed to Helper
- }
- else if(canPushCap==4)
- {
- capsuleStatus[closestCapsuleAttack(pushers[i], game).id]=4;//pusherPushed to mother
- }
- }*/
- }
- }
- for(int i=0;i<game.getAllEnemyPirates().length;i++)
- {
- enemyPiratesLocations[i]=game.getAllEnemyPirates()[i].getLocation();
- }
- for(int i=0;i<game.getAllMyPirates().length;i++)
- {
- myPiratesLocations[i]=game.getAllMyPirates()[i].getLocation();
- }
- for(int i=0;i<piratesGoingToCapsule.length;i++)
- {
- System.out.println(piratesGoingToCapsule[i]+" "+i);
- }
- }
- //functions
- ////////////////////////////////////////////////////
- public void attackerAction(Pirate pirate,PirateGame game)
- {
- Capsule goingToCap=null;
- Capsule pushingCap=null;
- if(game.getMyCapsules().length>1)
- pushingCap=closestCapsuleNotYou(pirate,game);
- else
- pushingCap=game.getMyCapsules()[0];
- if(shouldPushCapsule(pirate, pushingCap,game)==false)
- {
- if(pirate.capsule==null) //if doesnt have capsule
- {
- if(shouldIpushAstroid(game,pirate,closestEnemyCapsuleReal(pirate.getLocation(),game))==false){
- Capsule bestCap= BestCapsule(pirate, game);//TRY FIRST BEST CAP
- if(bestCap!=null&&piratesGoingToCapsule[bestCap.id]==0)
- {
- Location safeloc=safteyLoc(pirate.getLocation(), bestCap.getLocation(), 500, game);
- pirate.sail(safeloc);
- piratesGoingToCapsule[bestCap.id]++;
- goingToCap=bestCap;
- }
- else {
- for(Capsule capsule:game.getMyCapsules())
- {
- if(capsule.getLocation().equals(capsule.initialLocation)&&piratesGoingToCapsule[capsule.id]==0)//if no one goes to capsule and in init go to capsule
- {
- Location safeloc=safteyLoc(pirate.getLocation(), capsule.getLocation(), 500, game);
- pirate.sail(safeloc);
- piratesGoingToCapsule[capsule.id]++;
- goingToCap=capsule;
- }
- }
- }
- if(goingToCap==null)//if doesnt have capsule and doesnt need to get one be closest helper
- {
- //Capsule[] capsulesHelpers=new Capsule[game.getMyCapsules().length];//lowestHelpersCapsules
- //for(int i=0;i<game.getMyCapsules().length;i++)
- //{
- int minID=0;
- int minNum=100;
- //if has smallest amount be on i place and change to high number
- for(int k=0;k<helpersNearCapsule.length;k++)
- {
- if(helpersNearCapsule[k]<minNum)
- {
- minID=k;
- minNum=helpersNearCapsule[k];
- }
- }
- Capsule mostNeededCap=game.getMyCapsules()[minID];
- // }
- Pirate capholder=game.getMyLivingPirates()[0];
- for(Pirate capsuleHolder:game.getMyLivingPirates())
- {
- if(capsuleHolder.capsule==mostNeededCap)
- capholder=capsuleHolder;
- }
- Mothership mother= BestMother(pirate, game);//go to be a helper to the most needed capsule (pusher or uphelper)
- if(helpersNearCapsule[mostNeededCap.id]>=1) {//up helper
- Location safeUpHelper= safteyLoc(capholder.getLocation(), mother.getLocation(), game.pushDistance+capholder.maxSpeed, game);
- Location safeToHelper= safteyLoc(pirate.getLocation(),safeUpHelper,game.pirateMaxSpeed,game);
- pirate.sail(safeToHelper);
- }
- else//pusher
- {
- Location safeUpHelper= safteyLoc(capholder.getLocation(), mother.getLocation(), game.pirateMaxSpeed+capholder.maxSpeed, game);
- Location safeToHelper= safteyLoc(pirate.getLocation(),safeUpHelper,game.pirateMaxSpeed,game);
- pirate.sail(safeToHelper);
- }
- }
- }
- }
- else//if has capsule
- {
- piratesGoingToCapsule[pirate.capsule.id]++;
- Location safeloc=null;
- Mothership bestMother= BestMother(pirate, game);
- /*if(isThereAnotherCapsuleClose){
- leftright++;
- if(leftright>=1){
- leftright=1;
- safeloc=safteyLocCloseCapsule(pirate.getLocation(), bestMother.getLocation(), 300,leftright, game);
- }
- else if(leftright==0)
- {
- safeloc=safteyLocCloseCapsule(pirate.getLocation(), bestMother.getLocation(), 300,leftright, game);
- }
- }
- else
- {*/
- safeloc=safteyLoc(pirate.getLocation(), bestMother.getLocation(), pirate.maxSpeed+50, game);
- //}
- if(closestAsteroid(pirate,game)!=null&&pirate.canPush(closestAsteroid(pirate,game)))
- {
- if((closestAsteroid(pirate,game)).distance(bestMother)>200)
- pirate.push(closestAsteroid(pirate,game),bestMother.getLocation());
- else if(pushOutAster(pirate,game)==false)
- System.out.println("THERE IS NO WAY WE PRINT DAT ");
- }
- else
- pirate.sail(safeloc);
- }
- }
- }
- public boolean shouldPushCapsule(Pirate pirate,Capsule capsule,PirateGame game)
- {
- int enemyCounter=0;
- boolean isInDanger=false;
- for(Pirate enemy:game.getEnemyLivingPirates())
- {
- if(enemy.distance(pirate)<=game.pushRange+game.pirateMaxSpeed)
- {
- enemyCounter++;
- if(enemyCounter>=2)
- isInDanger=true;
- }
- }
- if(isInDanger==false)
- return false;
- Mothership mother= BestMother(pirate, game);
- //Location safteyHelper=safteyLoc(capsule.getLocation(), mother.getLocation(), game.pushDistance+game.pushRange, game);//optimal helper position
- for(Pirate pirate2:game.getMyLivingPirates())//find upHelpers
- {
- if(isSafeLoc(pirate2.getLocation(), game)&&pirate2.distance(capsule)<=game.pushRange+game.pushDistance&&pirate2.distance(capsule)>game.pirateMaxSpeed+100&&pirate2.distance(mother)<capsule.distance(mother))//if pirates safe and in range
- {
- for(Pirate allyWithCap:game.getMyLivingPirates())//check for closestPirate with capsule and in pushRange
- {
- if(allyWithCap.capsule!=null&&pirate.canPush(allyWithCap))
- {
- piratesPushingCapsule[allyWithCap.capsule.id]++;
- if(piratesPushingCapsule[allyWithCap.capsule.id]<=1){
- pirate.push(allyWithCap,pirate2.getLocation());//if close "uphelper" return true and push toward him
- return true;
- }
- }
- }
- }
- }
- for(Pirate allyWithCap:game.getMyLivingPirates())//push towrds mother if didnt push to helper
- {
- if(allyWithCap.capsule!=null&&pirate.canPush(allyWithCap))
- {
- Location motherSafe= safteyLoc(pirate.getLocation(),mother.getLocation(),pirate.pushDistance+allyWithCap.maxSpeed,game);
- piratesPushingCapsule[allyWithCap.capsule.id]++;
- if(piratesPushingCapsule[allyWithCap.capsule.id]<=1){
- pirate.push(allyWithCap,mother);
- return true;
- }
- }
- }
- return false;
- }
- ////////////////////////////////////////////////////
- public void defenderActionReal(Pirate pirate,PirateGame game) {
- Mothership enemyBestMother=null;
- for(int i=0;i<enemyUsingMotherships.length;i++)//each capsule, finds the enemyBestCapsule, the one that enemy goes to and doesnt have enough defenders
- {
- //Mothership mother= relevantEnemyMothership(game.getEnemyCapsules()[i],game);
- if(defendersNearMotherships[i]<enemyUsingMotherships[i]*2)
- {
- enemyBestMother=game.getEnemyMotherships()[i];
- defendersNearMotherships[i]++;
- break;
- }
- }
- if(enemyBestMother==null)
- {
- enemyBestMother=game.getEnemyMotherships()[0];//GET BEST CAPSULES Mothership(IN NEED TO DO)
- defendersNearMotherships[0]++;
- }
- Asteroid asteroid=closestAsteroidAlive(pirate,game);
- if(pirate.equals(closestDefenderToAstroid(game))&&asteroid!=null&&asteroid.getLocation().equals(asteroid.initialLocation))//CHECK FOR ASTROID ON BASE
- {
- if(pirate.canPush(asteroid)&&defendersNearMotherships[enemyBestMother.id]>=1)
- {
- pirate.push(asteroid,enemyBestMother);
- }
- else
- {
- Location astroSafe= trigoLocation(asteroid.getLocation().row,asteroid.getLocation().col,enemyBestMother.getLocation(),game.pushRange+asteroid.size,90);
- pirate.sail(safteyLoc(pirate.getLocation(),astroSafe,pirate.maxSpeed,game));
- }
- }
- else{
- if(asteroid!=null&&pirate.canPush(asteroid)&&asteroid.distance(enemyBestMother)<=170&&(asteroid.direction.row!=0||asteroid.direction.col!=0))
- {
- pirate.push(asteroid,asteroid);
- }
- else
- {
- if(IsStickybombOnMe(pirate, game)==true){
- Location StickyBombSuiciderLoc=safteyLocDef(pirate.getLocation(), closestEnemyCapsuleReal(pirate.getLocation(),game).getLocation(), pirate.maxSpeed, game);
- pirate.sail(StickyBombSuiciderLoc);
- }
- else{
- Capsule enemyBestCapsule= closestEnemyCapsuleReal(pirate.getLocation(),game);
- //System.out.println(enemyBestCapsule+" enemyBestCapsule");
- int enemyMoveCapsuleX= enemyBestCapsule.getLocation().row;
- int enemyMoveCapsuleY= enemyBestCapsule.getLocation().col;
- //System.out.println(defendersNearMotherships[mother.id]+" Num OF defenders");
- if(shouldPushToAstroid(pirate,game)==false&&pushOut(pirate,game)==false)//&&shouldIpushAstroid(game,pirate,enemyBestCapsule)==false)
- {
- //System.out.println("0"+" number");
- if(DefendersPushWormhole(pirate, game, enemyBestMother)==false) {
- // System.out.println("1"+" number");
- if(isCloseToEnemy(pirate, game, 1200, enemyBestMother))
- {
- Location safeMove=safteyLocDef(pirate.getLocation(),enemyBestCapsule.getLocation(),pirate.maxSpeed,game);
- pirate.sail(safeMove);
- }
- else
- {
- Location safeMove;
- Location defMoveloc=defMove(enemyMoveCapsuleX,enemyMoveCapsuleY,game,((defendersNearMotherships[enemyBestMother.id]-1)/2)*600+600,enemyBestCapsule);
- if(asteroid==null||asteroid.distance(enemyBestMother)>2500||(asteroid.direction.row==0&&asteroid.direction.col==0))//if asteroid is far
- safeMove=safteyLocDef(pirate.getLocation(),defMoveloc,pirate.maxSpeed,game);
- else if(pirate.pushReloadTurns<=5)//close asteroid
- safeMove=trigoLocation(enemyBestMother.getLocation().row,enemyBestMother.getLocation().col,asteroid.getLocation(),game.pushRange+asteroid.size,180);//safeMove=safteyLocDef(pirate.getLocation(),enemyBestMother.getLocation(),pirate.maxSpeed,game);
- else
- safeMove=safteyLocDef(pirate.getLocation(),defMoveloc,pirate.maxSpeed,game);
- pirate.sail(safeMove);
- }
- }
- }
- }
- }
- }
- }
- ////////////////////////////////////////////////////
- public void defenderActionNoAstroid(Pirate pirate, PirateGame game) {
- Capsule[] enemyCapsules=game.getEnemyCapsules();//Vectors!!!!!!!!!
- Capsule enemyBestCapsule=null;
- //for(int i=0;i<game.getEnemyLivingPirates().length;i++)
- // {
- //if(going_to_Capsule(game.getEnemyLivingPirates()[i], i, game)!=null)
- // {
- // enemyBestCapsule=going_to_Capsule(game.getEnemyLivingPirates()[i], i, game);
- // System.out.println(enemyBestCapsule);
- // break;
- // }
- // }
- if(enemyBestCapsule==null)
- {
- enemyBestCapsule=enemyBestCapsule(game);
- }
- //enemyBestCapsule= enemyBestCapsule(game);//Vectors!!!!!!!!
- Mothership enemyMothership=relevantEnemyMothership(enemyBestCapsule, game);
- int enemyMoveCapsuleX= enemyBestCapsule.getLocation().row;
- int enemyMoveCapsuleY= enemyBestCapsule.getLocation().col;
- Location EnemyBaseDef= defMove(enemyMoveCapsuleX,enemyMoveCapsuleY,game,600,enemyBestCapsule);
- Location EnemyBaseDef2= defMove(enemyMoveCapsuleX,enemyMoveCapsuleY,game,1050,enemyBestCapsule);
- if(pirate.isAlive()&&pushOut(pirate,game)==false&&DefendersPushWormholeFake(pirate,game,enemyMothership,enemyBestCapsule)==false)
- {
- if(defAmountClose<2)
- {
- if(isCloseToEnemyFake(pirate,game,400,enemyBestCapsule)) {
- pirate.sail(enemyBestCapsule.getLocation());
- }
- else
- pirate.sail(EnemyBaseDef);
- defAmountClose++;
- }
- else if(defAmountFar<2){
- if(isCloseToEnemyFake(pirate,game,1200,enemyBestCapsule)) {
- pirate.sail(enemyBestCapsule.getLocation());
- }
- else
- pirate.sail(EnemyBaseDef2);
- defAmountFar++;
- }
- }
- }
- private boolean isCloseToEnemyFake(Pirate pirate, PirateGame game,int radius, Capsule enemyCapsule)
- {
- Mothership Enemymother=relevantEnemyMothership(enemyCapsule, game);
- for (Pirate enemy: game.getEnemyLivingPirates())
- {
- if(pirate.distance(enemy)<radius&&pirate.distance(Enemymother)<1300)
- {
- return true;
- }
- }
- return false;
- }
- public boolean DefendersPushWormholeFake(Pirate pirate, PirateGame game,Mothership Emother,Capsule eCap)
- {
- if(game.getAllWormholes().length==0)
- return false;
- for(Capsule enemyCap:game.getEnemyCapsules()){
- if(enemyCap.distance(Emother)<pirate.maxSpeed*game.pushMaxReloadTurns)
- return false;
- }
- Wormhole wormhole=closestWormhole(pirate, game);
- if(wormhole==null)
- return false;
- if(pushOut(pirate, game)==false) {
- if(wormhole.distance(Emother)<1400&&(wormhole.getLocation().row!=0&&wormhole.getLocation().col!=0&&wormhole.getLocation().row!=game.rows&&wormhole.getLocation().col!=game.cols))
- {
- if(pushOutWormToCap(pirate,game,eCap)==false)
- {
- //if(pirate.distance(closestWormhole(pirate, game))-100>pirate.maxSpeed+50)
- // pirate.sail(closestWormhole(pirate, game));
- // else
- // pirate.sail(Emother);
- if(pirate.distance(closestWormhole(pirate, game))-100>pirate.maxSpeed+50)
- pirate.sail(closestWormhole(pirate, game));
- else
- {
- pirate.sail(myPiratesLocations[pirate.id]);
- }
- }
- return true;
- }
- return false;
- }
- return true;
- }
- public boolean DefendersPushWormhole(Pirate pirate, PirateGame game,Mothership Emother) {
- if(game.getAllWormholes().length==0)
- return false;
- Wormhole wormhole=closestWormhole(pirate, game);
- Capsule Ecap= closestCapsuleToEnemy(game);
- if(wormhole.distance(Emother)<2200&&closestEnemyCapsuleReal(pirate.getLocation(),game).distance(pirate)>1500) {
- if(pushOutWormToCap(pirate,game,Ecap)==false)
- {
- pirate.sail(wormhole.getLocation().towards(pirate.getLocation(),290));
- //System.out.println(trigoLocation(wormhole.getLocation().row,wormhole.getLocation().col , Emother.getLocation(), game.pushRange+0.0, 0.0)+" Trigo");
- }
- return true;
- }
- return false;
- }
- public Wormhole closestWormhole(Pirate pirate, PirateGame game)//real
- {
- Wormhole minWorm=null;
- double minDist= game.rows*game.rows+game.cols*game.cols;
- for(Wormhole worm: game.getAllWormholes())
- {
- if(worm.distance(pirate)<minDist)
- {
- minDist= worm.distance(pirate);
- minWorm= worm;
- }
- }
- return minWorm;
- }
- private boolean pushOutWormToCap(Pirate pirate,PirateGame game,Capsule Ecapsule)
- {
- for (Wormhole wormhole: game.getAllWormholes())
- {
- if(pirate.canPush(wormhole)){
- pirate.push(wormhole,Ecapsule);
- return true;
- }
- }
- return false;
- }
- private boolean pushOutWorm(Pirate pirate, PirateGame game)
- {
- for (Wormhole wormhole: game.getAllWormholes()) {
- //System.out.println(pirate.pushDistance);
- // Check if the pirate can push the enemy.
- if (pirate.canPush(wormhole)) {
- // Push enemy!
- if(distanceFromYasharWorm(game,wormhole)==1)
- {
- Location l1= new Location(0,wormhole.getLocation().col);
- pirate.push(wormhole,l1);
- // System.out.println(enemy.distance(pirate)+"dist enemy pirate");
- // System.out.println(enemy.distance(l1)+"dist enemy line");
- // System.out.println("pirate " + pirate + " pushes " + enemy + " towards " + l1);
- }
- if(distanceFromYasharWorm(game,wormhole)==2)
- {
- Location l2= new Location(wormhole.getLocation().row,0);
- pirate.push(wormhole,l2);
- // System.out.println("pirate " + pirate + " pushes " + enemy + " towards " + l2);
- }
- if(distanceFromYasharWorm(game,wormhole)==3)
- {
- Location l3= new Location(game.rows,wormhole.getLocation().col);
- pirate.push(wormhole,l3);
- // System.out.println("pirate " + pirate + " pushes " + enemy + " towards " + l3);
- }
- if(distanceFromYasharWorm(game,wormhole)==4)
- {
- Location l4= new Location(wormhole.getLocation().row,game.cols);
- pirate.push(wormhole,l4);
- // System.out.println("pirate " + pirate + " pushes " + enemy + " towards " + l4);
- }
- // Print a message.
- // Did push.
- return true;
- }
- }
- return false;
- }
- private double distanceFromYasharWorm(PirateGame game, Wormhole wormhole){
- int mindistance=game.rows;
- int distFromX= wormhole.getLocation().row;
- int distFromY= wormhole.getLocation().col;
- int distFromX6400=game.rows-wormhole.getLocation().row;
- int distFromY6400=game.cols-wormhole.getLocation().col;
- mindistance=Math.min(Math.min(distFromX, distFromY), Math.min(distFromX6400,distFromY6400));
- if(mindistance==distFromX)
- return 1;
- if(mindistance==distFromY)
- return 2;
- if(mindistance==distFromX6400)
- return 3;
- if(mindistance==distFromY6400)
- return 4;
- return 1;
- }
- public Capsule BestCapsule(Pirate pirate,PirateGame game)
- {
- double CapsuleGrade=0;
- double MaxGrade=0;
- Capsule bestCapsule=null;
- double MaxDist=Math.sqrt(game.rows*game.rows+game.cols*game.cols);
- for(Capsule capsule: game.getMyCapsules())
- {
- if(capsule.getLocation().equals(capsule.initialLocation))//check only capsules in init
- {
- CapsuleGrade=100;
- //check closest
- double distanceFromPirate= pirate.distance(capsule);
- double distanceFromClosestMother=capsule.distance(closestMother(capsule.getLocation(),game));
- int defAmount=howManyPiratesNearLocation(capsule.getLocation(),game.getEnemyLivingPirates(),1300);
- int attackersUsingCapsule=0;
- for(Mothership mother: game.getMyMotherships())
- {
- attackersUsingCapsule+=numOfPiratesOnLine(capsule.getLocation(),mother.getLocation(),attackers,600);
- }
- int helpersCount=howManyPiratesNearLocation(pirate.getLocation(),helpers,800);
- //CapsuleGrade= (1.0/distanceFromPirate)*15000+(1.0/distanceFromClosestMother)*20000+(1/defAmount)*20+(1/attackersUsingCapsule)*7.5;
- CapsuleGrade-= (distanceFromPirate*16/MaxDist)*3+(distanceFromClosestMother*8/MaxDist)*4+defAmount*8+Math.pow(attackersUsingCapsule*2,2)-helpersCount*5;
- if(CapsuleGrade>MaxGrade)
- {
- bestCapsule=capsule;
- MaxGrade=CapsuleGrade;
- }
- }
- }
- if(bestCapsule==null)
- return game.getMyCapsules()[0];
- return bestCapsule;
- }
- public Mothership BestMother(Pirate pirate,PirateGame game)
- {
- double MotherGrade=0;
- double MaxGrade=0;
- Mothership bestMother=null;
- double MaxDist=Math.sqrt(game.rows*game.rows+game.cols*game.cols);
- for(Mothership mother: game.getMyMotherships())
- {
- MotherGrade=100;
- //check closest
- double distanceFromPirate= pirate.distance(mother);
- //double distanceFromClosestMother=mother.distance(closestMother(capsule.getLocation(),game));
- int defAmount=howManyPiratesNearLocation(mother.getLocation(),game.getEnemyLivingPirates(),1300);
- int helpersCount=howManyPiratesNearLocation(pirate.getLocation(),game.getMyLivingPirates()/*helpers*/,800);
- //int attackersUsingCapsule=0;
- //attackersUsingCapsule+=numOfPiratesOnLine(capsule.getLocation(),mother.getLocation(),game.getMyLivingPirates()/*attackers*/,600);
- MotherGrade-= ((distanceFromPirate*10/MaxDist)*3+defAmount*6-helpersCount*6);
- if(MotherGrade>MaxGrade)
- {
- bestMother=mother;
- MaxGrade=MotherGrade;
- }
- }
- return bestMother;
- }
- public int numOfPiratesOnLine(Location startingLoc, Location endingLoc, Pirate[] pirates,int radius)
- {
- //get y=mx+n
- double m;
- if(startingLoc.row-endingLoc.row==0)
- m=0;
- else
- m= ((startingLoc.col-endingLoc.col)/(startingLoc.row-endingLoc.row));//shipooa(m)
- double n= startingLoc.col-m*startingLoc.row;
- int piratesCount=0;
- for(Pirate pirate: pirates)
- {
- double Distance= Math.abs(-m*pirate.getLocation().row+pirate.getLocation().col-n)/Math.sqrt(m*m+1);
- if(Distance<radius&&pirate.distance(endingLoc)<startingLoc.distance(endingLoc))
- piratesCount++;
- }
- return piratesCount;
- }
- private boolean tryPushAstroidAttack(Pirate pirate, PirateGame game,Mothership mother,Capsule capsule)
- {
- for (Asteroid asteroid : game.getLivingAsteroids()) {
- if (pirate.canPush(asteroid))
- {
- if(asteroid.distance(mother)<pirate.distance(mother)&&pirate.capsule!=null)
- {
- if(numOfPiratesOnLine(pirate.getLocation(),mother.getLocation(),game.getMyLivingPirates(),600)==1)
- {
- pirate.push(asteroid, mother);
- return true;
- }
- else
- {
- pushOutAster(pirate,game);
- return true;
- }
- }
- else if(pirate.capsule==null)
- {
- if(numOfPiratesOnLine(pirate.getLocation(),capsule.initialLocation,game.getMyLivingPirates(),600)==1)
- {
- pirate.push(asteroid, capsule);
- return true;
- }
- else
- {
- pushOutAster(pirate,game);
- return true;
- }
- }
- }
- }
- return false;
- }
- public int howManyPiratesNearLocation(Location l1, Pirate[] pirates,int radius)
- {
- int helpersCount=0;
- for(Pirate pirate2:pirates)
- {
- if(l1.distance(pirate2)<radius)
- helpersCount++;
- }
- return helpersCount;
- }
- public int howManyPiratesNearLocationAttacker(Location l1, Pirate[] pirates, int radius,Mothership mother)
- {
- int enemyCount=0;
- for(Pirate pirate2:pirates)
- {
- if(l1.distance(pirate2)<radius&&l1.distance(mother)>pirate2.distance(mother))
- enemyCount++;
- }
- return enemyCount;
- }
- public Pirate closestPirate(Location l1, Pirate[] pirates,PirateGame game)
- {
- Pirate minPirate=null;
- int minDist= game.rows*game.rows+game.cols*game.cols;
- for(Pirate pirate:pirates)
- {
- if(pirate.distance(l1)<minDist&&!pirate.getLocation().equals(l1))
- minPirate=pirate;
- }
- return minPirate;
- }
- public Mothership closestMother(Location distFrom, PirateGame game)
- {
- Mothership minMother=null;
- int minDist=game.rows*game.rows+game.cols*game.cols;
- for(Mothership mother: game.getMyMotherships())
- {
- if(distFrom.distance(mother)<minDist)
- {
- minDist=distFrom.distance(mother);
- minMother=mother;
- }
- }
- return minMother;
- }
- private int canPushCapsuleNearEnemy(Pirate pirate, PirateGame game,int radius,Pirate[] upHelpers){
- Capsule capsule= closestCapsuleAttack(pirate, game);
- int enemyCounter=0;
- for (Pirate enemy: game.getEnemyLivingPirates())
- {
- if(enemy.distance(capsule)<radius&&enemy.pushReloadTurns<=1)
- {
- enemyCounter++;
- if(enemyCounter>=2)
- return tryPushCapsuleStart(pirate,game,upHelpers);
- }
- }
- return 0;
- }
- private int tryPushCapsuleStart(Pirate pusher, PirateGame game,Pirate[] upHelpers)// 0-onInit 1- nearHelpers 2-pusherPushed to upHelper 3-up helperPushed 4-pusher pushed to Mother
- {
- Pirate helper1= closestUpHelper(game,pusher,upHelpers);//helper1
- //Pirate helper2= game.getAllMyPirates()[1];//helper2
- int enemyCounter=0;
- for (Pirate ally: game.getMyLivingPirates()){
- for(Pirate enemy: game.getEnemyLivingPirates()){
- if(ally.capsule!=null&&enemy.canPush(ally)){
- enemyCounter++;
- if(enemyCounter>=2)
- return 0;
- }
- }
- if(helper1!=null&&helper1.distance(ally)<=game.pushDistance+game.pirateMaxSpeed&&ally.capsule!=null&&pusher.canPush(ally))//if upHelpers canpush
- {
- pusher.push(ally,helper1.getLocation());
- return 2;
- }
- else if(ally.capsule!=null&&pusher.canPush(ally)){//pushed to mother
- pusher.push(ally,closestMother(game, pusher));
- return 4;
- }
- }
- return 0;
- }//end of tryPushCapsuleStart
- public boolean shouldIpushAstroid(PirateGame game,Pirate pirate,Capsule enemyCapsule)
- {
- Location defRow1;
- if(game.getEnemyCapsules().length==0)
- return false;
- Location EnemyBase= relevantEnemyMothership(enemyCapsule, game).getLocation();
- double DistanceCapMother= enemyCapsule.distance(EnemyBase);
- if(game.getLivingAsteroids().length==0)
- return false;
- if(enemyCapsule.getLocation().equals(enemyCapsule.initialLocation))
- return false;
- Asteroid aster= game.getLivingAsteroids()[0];
- for(int i=(int)(DistanceCapMother);i>0;i-=game.pirateMaxSpeed) {
- int enemyY= enemyCapsule.getLocation().col;
- int enemyX= enemyCapsule.getLocation().row;
- double zavit=(enemyY-EnemyBase.col+0.0)/(enemyX-EnemyBase.row);
- double zavitEnemyBase= Math.atan(zavit);
- int radius= i;
- if(enemyX<EnemyBase.row)
- {
- zavitEnemyBase=Math.PI+zavitEnemyBase;
- }
- int xRet=0;
- xRet= (int)(EnemyBase.row+radius*Math.cos(zavitEnemyBase));
- int yRet=0;
- yRet= (int)(EnemyBase.col+radius*Math.sin(zavitEnemyBase));
- defRow1= new Location(xRet,yRet);
- int Dcapsule=(int)(Math.sqrt(Math.pow(defRow1.row-enemyCapsule.getLocation().row, 2)+Math.pow(defRow1.col-enemyCapsule.getLocation().col, 2)));
- int Daster=(int)(Math.sqrt(Math.pow(defRow1.row-aster.getLocation().row, 2)+Math.pow(defRow1.col-aster.getLocation().col, 2))-game.pushRange);
- int capMaxSpeed= game.pirateMaxSpeed;
- int astroidMaxSpeed= aster.speed;
- int capTurns= Dcapsule/capMaxSpeed;
- int astroidTurns= Daster/astroidMaxSpeed;
- if(capTurns==astroidTurns&&pirate.canPush(aster))
- {
- Location l1= new Location(defRow1.row,defRow1.col);
- pirate.push(aster, l1);
- return true;
- }
- }
- return false;
- }
- private Pirate closestUpHelper(PirateGame game, Pirate pirate,Pirate[] upHelpers)
- {
- Pirate minPirate=null;
- int minDis= game.rows*game.rows+game.cols*game.cols;
- for(int i=0;i<upHelpers.length;i++)
- {
- if(upHelpers[i].distance(pirate)<minDis)
- {
- minDis=upHelpers[i].distance(pirate);
- minPirate=upHelpers[i];
- }
- }
- return minPirate;
- }
- private Location attackerFollowerMove(double capsuleX, double capsuleY,PirateGame game,double radius,Pirate pirate)
- {
- radius=game.pirateMaxSpeed;
- Location mother= closestMother(game, pirate).getLocation();
- double zavit=(capsuleY-mother.col)/(capsuleX-mother.row);
- double zavitEnemyBase;
- zavitEnemyBase= (Math.atan(zavit));
- if(capsuleX<mother.row)
- {
- zavitEnemyBase=Math.PI+zavitEnemyBase;
- }
- int xRet=0;
- xRet= (int)(capsuleX-radius*Math.cos(zavitEnemyBase));
- int yRet=0;
- yRet= (int)(capsuleY-radius*Math.sin(zavitEnemyBase));
- Location defRow1= new Location(xRet,yRet);
- return defRow1;
- }
- private Location attackersMoveUpper(double capsuleX, double capsuleY,PirateGame game,double radius,Pirate pirate){
- //radius=pirate.pushDistance+game.pirateMaxSpeed;
- radius= 743.303;
- Location mother= closestMother(game, pirate).getLocation();
- double zavit=(capsuleY-mother.col)/(capsuleX-mother.row);
- double zavitEnemyBase=(Math.atan(zavit)+Math.asin(550.0/800));
- if(capsuleX<mother.row)
- {
- zavitEnemyBase=Math.PI+zavitEnemyBase;
- }
- int xRet=0;
- xRet= (int)(capsuleX-radius*Math.cos(zavitEnemyBase));
- int yRet=0;
- yRet= (int)(capsuleY-radius*Math.sin(zavitEnemyBase));
- Location defRow1= new Location(xRet,yRet);
- return defRow1;
- }
- private Location attackersMoveLower(double capsuleX, double capsuleY,PirateGame game,double radius,Pirate pirate){
- //radius=pirate.pushDistance+game.pirateMaxSpeed;
- radius= 743.303;
- Location mother= closestMother(game, pirate).getLocation();
- double zavit=(capsuleY-mother.col)/(capsuleX-mother.row);
- double zavitEnemyBase=(Math.atan(zavit)-Math.asin(550.0/800));
- if(capsuleX<mother.row)
- {
- zavitEnemyBase=Math.PI+zavitEnemyBase;
- }
- int xRet=0;
- xRet= (int)(capsuleX-radius*Math.cos(zavitEnemyBase));
- int yRet=0;
- yRet= (int)(capsuleY-radius*Math.sin(zavitEnemyBase));
- Location defRow1= new Location(xRet,yRet);
- return defRow1;
- }
- private boolean isCapsuleOnCapsuleInitMotherLine(PirateGame game,Pirate pirate){
- Mothership mother= closestMother(game,pirate);
- Capsule capsule= closestCapsule(pirate,game);
- double shipoaCapMother;
- if(capsule.getLocation().col-mother.getLocation().col==0)
- shipoaCapMother=0;
- else
- shipoaCapMother=(capsule.getLocation().row-mother.getLocation().row)/(capsule.getLocation().col-mother.getLocation().col);
- double shipoaCapInitMother=(capsule.initialLocation.row-mother.getLocation().row)/(capsule.initialLocation.col-mother.getLocation().col);
- if(Math.abs(shipoaCapInitMother-shipoaCapMother)<0.1){
- return true;
- }
- return false;
- }
- private boolean canPushCapsuleNearEnemyHelperIneedToPee(Pirate pirate, PirateGame game){
- Capsule capsule= closestCapsuleAttack(pirate, game);
- int enemyCounter=0;
- for (Pirate enemy: game.getEnemyLivingPirates())
- {
- if((enemy.distance(capsule)<450&&enemy.pushReloadTurns<=1)||(capsule.distance(closestMother(game, pirate))<=800))
- {
- enemyCounter++;
- if(enemyCounter>=2&&tryPushCapsuleToMother(pirate,game)==true)
- return true;
- }
- }
- return false;
- }
- private boolean tryPushCapsuleToMother(Pirate pirate, PirateGame game)
- {
- Location l3=new Location(0,0);
- // Go over all enemies.
- Mothership mother= closestMother(game, pirate);
- l3=mother.getLocation();
- for (Pirate ally: game.getMyLivingPirates()) {
- // Check if the pirate can push the enemy.
- if (ally.capsule!=null&&pirate.canPush(ally))
- {
- // Push enemy!
- pirate.push(ally, l3);
- // Print a message.
- // System.out.println("pirate " + pirate + " pushes " + ally + " towards " + ally.initialLocation);
- // Did push.
- return true;
- }
- }
- // Didn't push.
- return false;
- }
- private Capsule closestCapsule(Pirate pirate,PirateGame game)
- {
- int capDist=pirate.distance(game.getMyCapsules()[0]);
- Capsule minCap=game.getMyCapsules()[0];
- for(int i=0;i<game.getMyCapsules().length;i++)
- {
- if(isArmedCapsule(game.getMyCapsules()[i],game)==false)
- {
- if(capDist>pirate.distance(game.getMyCapsules()[i]))
- {
- minCap=game.getMyCapsules()[i];
- capDist=pirate.distance(game.getMyCapsules()[i]);
- }
- }
- }
- return minCap;
- }
- private Capsule closestEnemyCapsule(Pirate pirate,PirateGame game,int half)
- {
- int capDist=pirate.distance(game.getEnemyCapsules()[0]);
- Capsule minCap=game.getEnemyCapsules()[0];
- for(int i=0;i<game.getEnemyCapsules().length;i++)
- {
- if(capDist>pirate.distance(game.getEnemyCapsules()[i]))
- {
- if(half==1&&game.getEnemyCapsules()[i].getLocation().col<game.cols/2)
- {
- minCap=game.getEnemyCapsules()[i];
- capDist=pirate.distance(game.getEnemyCapsules()[i]);
- }
- if(half==2&&game.getEnemyCapsules()[i].getLocation().col>game.cols/2)
- {
- minCap=game.getEnemyCapsules()[i];
- capDist=pirate.distance(game.getEnemyCapsules()[i]);
- }
- }
- }
- return minCap;
- }
- private Pirate closestAttacker(Pirate[] attackers,Pirate helper,PirateGame game)
- {
- int attDist=game.rows*game.rows+game.cols*game.cols;
- Pirate minAttacker=null;
- for(int i=0;i<attackers.length;i++)
- {
- if(attDist>helper.distance(attackers[i]))
- {
- minAttacker=attackers[i];
- attDist=helper.distance(attackers[i]);
- }
- }
- return minAttacker;
- }
- private boolean isArmedCapsule(Capsule capsule,PirateGame game)
- {
- int PeopleCount=0;
- for(Pirate ally : game.getMyLivingPirates())
- {
- if(capsule.distance(ally)<1000)
- PeopleCount++;
- }
- if(PeopleCount>=2)
- return true;
- return false;
- }
- private boolean isThereAnotherDefenderPushing(Pirate enemy, Pirate defender)
- {
- for(Pirate pirate:defenders)
- {
- if(!defender.equals(pirate)&&pirate.canPush(enemy))
- return true;
- }
- return false;
- }
- private boolean pushOut(Pirate pirate, PirateGame game)
- {
- for (Pirate enemy: game.getEnemyLivingPirates()) {
- if (pirate.canPush(enemy)&&enemy.capsule!=null&&isThereAnotherDefenderPushing(enemy,pirate)) {
- howManyPiratesPushEnemy[enemy.id]++;
- if(howManyPiratesPushEnemy[enemy.id]<=enemy.numPushesForCapsuleLoss){
- if(distanceFromYashar(enemy,game)==1)
- {
- Location l1= new Location(0,enemy.getLocation().col);
- pirate.push(enemy,l1);
- }
- if(distanceFromYashar(enemy,game)==2)
- {
- Location l2= new Location(enemy.getLocation().row,0);
- pirate.push(enemy,l2);
- }
- if(distanceFromYashar(enemy,game)==3)
- {
- Location l3= new Location(game.rows,enemy.getLocation().col);
- pirate.push(enemy,l3);
- }
- if(distanceFromYashar(enemy,game)==4)
- {
- Location l4= new Location(enemy.getLocation().row,game.cols);
- pirate.push(enemy,l4);
- }
- // Print a message.
- // Did push.
- return true;
- }
- }
- }
- return false;
- }
- private double distanceFromYashar(Pirate pirate,PirateGame game){
- int mindistance=game.rows;
- int distFromX= pirate.getLocation().row;
- int distFromY= pirate.getLocation().col;
- int distFromX6400=game.rows-pirate.getLocation().row;
- int distFromY6400=game.cols-pirate.getLocation().col;
- mindistance=Math.min(Math.min(distFromX, distFromY), Math.min(distFromX6400,distFromY6400));
- if(mindistance==distFromX)
- return 1;
- if(mindistance==distFromY)
- return 2;
- if(mindistance==distFromX6400)
- return 3;
- if(mindistance==distFromY6400)
- return 4;
- return 1;
- }
- private Mothership relevantEnemyMothership(Capsule enemyCapsule, PirateGame game) {
- Mothership minBase=null;
- int minDistance=game.rows*game.rows+game.cols*game.cols;
- for(int i=0;i<game.getEnemyMotherships().length;i++)
- {
- if(game.getEnemyMotherships()[i].distance(enemyCapsule)<minDistance)
- {
- minDistance=game.getEnemyMotherships()[i].distance(enemyCapsule);
- minBase=game.getEnemyMotherships()[i];
- }
- }
- return minBase;
- }
- private Capsule closestCapsuleToEnemy(PirateGame game)
- {
- int minDis=game.rows*game.rows+game.cols*game.cols;
- Capsule minCapsule=null;
- if(game.getEnemyCapsules().length==0)
- return null;
- if(game.getEnemyLivingPirates().length>0){
- for(int i=0;i<game.getEnemyCapsules().length;i++) {
- for(Pirate enemy: game.getEnemyLivingPirates())
- {
- if(enemy.distance(game.getEnemyCapsules()[i])<minDis)
- {
- minDis=enemy.distance(game.getEnemyCapsules()[i]);
- minCapsule=game.getEnemyCapsules()[i];
- }
- }
- }
- }
- else
- minCapsule=game.getEnemyCapsules()[0];
- return minCapsule;
- }
- private int[] numberOfDefendersNearEnemyMothership(Mothership EnemyBase, Pirate[] defenders) {
- int[] count= new int[2];
- int countClose=0;
- int countFar=0;
- for(int i=0;i<defenders.length;i++) {
- if(defenders[i].distance(EnemyBase)<=500) {
- countClose++;
- }
- if(defenders[i].distance(EnemyBase)<1300&&defenders[i].distance(EnemyBase)>500) {
- countFar++;
- }
- }
- count[0]=countClose;
- count[1]=countFar;
- return count;
- }
- private Location defMove(double enemyX, double enemyY,PirateGame game,double radius, Capsule enemyCapsule){
- Location EnemyBase= relevantEnemyMothership(enemyCapsule, game).getLocation();
- double zavit=(enemyY-EnemyBase.col)/(enemyX-EnemyBase.row);
- double zavitEnemyBase= Math.atan(zavit);
- if(enemyX<EnemyBase.row)
- {
- zavitEnemyBase=Math.PI+zavitEnemyBase;
- }
- int xRet=0;
- xRet= (int)(EnemyBase.row+radius*Math.cos(zavitEnemyBase));
- int yRet=0;
- yRet= (int)(EnemyBase.col+radius*Math.sin(zavitEnemyBase));
- Location defRow1= new Location(xRet,yRet);
- return defRow1;
- }
- private boolean isCloseToEnemy(Pirate pirate, PirateGame game,int radius, Mothership mother)
- {
- for (Pirate enemy: game.getEnemyLivingPirates())
- {
- if(pirate.distance(enemy)<radius&&pirate.distance(mother)<1500&&enemy.capsule!=null)
- {
- return true;
- }
- }
- return false;
- }
- private Mothership closestMother(PirateGame game,Pirate pirate)
- {
- Mothership minMother=null;
- int minDis= game.rows*game.rows;
- for(int i=0;i<game.getMyMotherships().length;i++)
- {
- if(game.getMyMotherships()[i].distance(pirate)<minDis)
- {
- minDis=game.getMyMotherships()[i].distance(pirate);
- minMother=game.getMyMotherships()[i];
- }
- }
- return minMother;
- }
- private Capsule closestCapsuleAttack(Pirate pirate,PirateGame game)
- {
- int capDist=game.rows*game.cols;
- Capsule minCap=null;
- for(int i=0;i<game.getMyCapsules().length;i++)
- {
- if(capDist>pirate.distance(game.getMyCapsules()[i]))
- {
- minCap=game.getMyCapsules()[i];
- capDist=pirate.distance(game.getMyCapsules()[i]);
- }
- }
- return minCap;
- }
- private boolean IsDefenderOnCapsuleMotherLine(Capsule capsule,Mothership mother,Pirate pirate){
- double shipoaCapMother=(capsule.getLocation().row-mother.getLocation().row)/(capsule.getLocation().col-mother.getLocation().col);
- double shipoaaHelperCapsule=(pirate.getLocation().row-capsule.getLocation().row)/(pirate.getLocation().col-capsule.getLocation().col);
- if(Math.abs(shipoaaHelperCapsule-shipoaCapMother)<0.1){
- return true;
- }
- return false;
- }
- private boolean tryPushAstroidAttack2(Pirate pirate, PirateGame game, Mothership mother,Capsule capsule)
- {
- for (Asteroid asteroid : game.getLivingAsteroids()) {
- // Check if the pirate can push the asteroid
- if (pirate.canPush(asteroid)) {
- // Push asteroid!
- if(asteroid.distance(mother)<pirate.distance(mother)){
- pirate.push(asteroid, mother);
- }
- else
- {
- if(pirate.capsule==null){
- int randomX= (int)(Math.random()*game.rows);
- int randomY= (int)(Math.random()*pirate.getLocation().col);
- Location loc= new Location(pirate.getLocation().row,0);
- pirate.push(asteroid, loc);
- }
- }
- // Print a message
- //System.out.println("pirate " + pirate + " pushes " + asteroid + " towards " + game.getEnemyCapsules()[0]);
- // Did push
- return true;
- }
- }
- return false;
- }
- private boolean tryPushAstroidDefenders(Pirate pirate, PirateGame game, Capsule capsule)
- {
- if( game.getLivingAsteroids().length==0)
- return false;
- for (Asteroid asteroid : game.getLivingAsteroids()) {
- // Check if the pirate can push the asteroid
- if (pirate.canPush(asteroid)) {
- // Push asteroid!
- pirate.push(asteroid, capsule);
- // Print a message
- // System.out.println("pirate " + pirate + " pushes " + asteroid + " towards " + game.getEnemyCapsules()[0]);
- // Did push
- return true;
- }
- }
- return false;
- }
- private boolean isCloseToAstroid(Pirate pirate, PirateGame game,Mothership mother)
- {
- for (Asteroid asteroid : game.getLivingAsteroids()) {
- // Check if the pirate can push the asteroid
- if (asteroid.distance(pirate)<650&&asteroid.distance(mother)<pirate.distance(mother)&&pirate.capsule!=null) {
- // Push asteroid!
- //pirate.push(asteroid, capsule);
- // Print a message
- //System.out.println("pirate " + pirate + " pushes " + asteroid + " towards " + game.getEnemyCapsules()[0]);
- // Did push
- return true;
- }
- if(asteroid.distance(pirate)<650&&asteroid.distance(mother)>pirate.distance(mother)&&pirate.capsule==null)
- return true;
- }
- return false;
- }
- private boolean pushOutAster(Pirate pirate, PirateGame game)
- {
- for (Asteroid asteroid: game.getLivingAsteroids()) {
- //System.out.println(pirate.pushDistance);
- // Check if the pirate can push the enemy.
- if (pirate.canPush(asteroid)) {
- // Push enemy!
- if(distanceFromYasharAster(game,asteroid)==1)
- {
- Location l1= new Location(0,asteroid.getLocation().col);
- pirate.push(asteroid,l1);
- // System.out.println(enemy.distance(pirate)+"dist enemy pirate");
- // System.out.println(enemy.distance(l1)+"dist enemy line");
- // System.out.println("pirate " + pirate + " pushes " + enemy + " towards " + l1);
- }
- if(distanceFromYasharAster(game,asteroid)==2)
- {
- Location l2= new Location(asteroid.getLocation().row,0);
- pirate.push(asteroid,l2);
- // System.out.println("pirate " + pirate + " pushes " + enemy + " towards " + l2);
- }
- if(distanceFromYasharAster(game,asteroid)==3)
- {
- Location l3= new Location(game.rows,asteroid.getLocation().col);
- pirate.push(asteroid,l3);
- // System.out.println("pirate " + pirate + " pushes " + enemy + " towards " + l3);
- }
- if(distanceFromYasharAster(game,asteroid)==4)
- {
- Location l4= new Location(asteroid.getLocation().row,game.cols);
- pirate.push(asteroid,l4);
- // System.out.println("pirate " + pirate + " pushes " + enemy + " towards " + l4);
- }
- // Print a message.
- // Did push.
- return true;
- }
- }
- return false;
- }
- private double distanceFromYasharAster(PirateGame game, Asteroid asteroid){
- int mindistance=game.rows;
- int distFromX= asteroid.getLocation().row;
- int distFromY= asteroid.getLocation().col;
- int distFromX6400=game.rows-asteroid.getLocation().row;
- int distFromY6400=game.cols-asteroid.getLocation().col;
- mindistance=Math.min(Math.min(distFromX, distFromY), Math.min(distFromX6400,distFromY6400));
- if(mindistance==distFromX)
- return 1;
- if(mindistance==distFromY)
- return 2;
- if(mindistance==distFromX6400)
- return 3;
- if(mindistance==distFromY6400)
- return 4;
- return 1;
- }
- private boolean tryPush(Pirate pirate,PirateGame game)
- {
- Location l1= new Location(pirate.getLocation().row,6400);
- for(Wormhole worm:game.getAllWormholes())
- {
- if(pirate.canPush(worm))
- {
- pirate.push(worm,l1);
- return true;
- }
- }
- return false;
- }
- private int MaxGvool(int m, int b, PirateGame game){
- int maxGvool;
- int x=0;
- if(m==0)
- return game.cols;
- else
- x = (game.cols-b)/m;
- if(x>game.cols || x<0 ){
- maxGvool = game.cols;
- }
- else{
- maxGvool = m*x + b;
- }
- return maxGvool;
- }
- private static void Prev_Loc(PirateGame game){
- Pirate[] pir = game.getEnemyLivingPirates();
- Location[] Pirate_LOC = new Location[pir.length];
- for(int i =0; i<Pirate_LOC.length; i++){
- Pirate_LOC[i] = pir[i].getLocation();
- }
- }
- private Capsule going_to_Capsule(Pirate p1, int index, PirateGame game){
- //Variables
- Location loc2 = p1.getLocation();
- Location loc1 = enemyPiratesLocations[index];
- int m;
- if(loc1.col-loc2.col==0)
- m=0;
- else
- m = (loc1.row - loc2.row)/ (loc1.col-loc2.col);
- int b = loc1.col - (loc1.row);
- int xInit = 0;
- if(m==0)
- xInit=0;
- else
- xInit=(-1)*(b/m);
- //(-1)*(b/m);
- int yy;
- // Checks the location ID
- Capsule[] Capsules_List = game.getEnemyCapsules();
- for(int i=0; i<Capsules_List.length;i++){
- Capsule cap = Capsules_List[i];
- for(int xx = xInit; xx<MaxGvool(m,b, game); xx++){
- yy = m*xx + b;
- if((yy == cap.initialLocation.row) && (xx == cap.initialLocation.col)){
- return cap;
- }
- }
- }
- return null;
- }
- ///////////////////////////Mothership///////////////////////////////////
- private Mothership going_to_Mothership(Pirate p1, PirateGame game){
- Location loc1 = p1.getLocation();
- Location loc2 = p1.initialLocation;
- int m = (loc1.row - loc2.row)/ (loc1.col-loc2.col);
- int b = loc1.col - (loc1.row);
- int xInit = (-1)*(b/m);
- int yy;
- //Checks the location ID
- Mothership[] Mothership_list = game.getEnemyMotherships();
- for(int i=0;i<game.getAllMotherships().length;i++){
- Mothership ship = Mothership_list[i];
- for(int xx = xInit; xx<MaxGvool(m,b, game); xx++){
- yy = m*xx + b;
- if((yy == ship.location.row) && (xx == ship.location.col)){
- return ship;
- }
- }
- }
- return null;
- }
- private Capsule enemyBestCapsule(PirateGame game) {
- int minDis=game.rows*game.rows+game.cols*game.cols;
- Capsule minCapsule=game.getEnemyCapsules()[0];
- for(int i=0;i<game.getEnemyCapsules().length;i++) {
- for(Mothership enemy: game.getEnemyMotherships())
- {
- if(enemy.distance(game.getEnemyCapsules()[i])<minDis)
- {
- minDis=enemy.distance(game.getEnemyCapsules()[i]);
- minCapsule=game.getEnemyCapsules()[i];
- }
- }
- }
- return minCapsule;
- }
- public Wormhole closestWormholeActiveSpagetti(Pirate pirate, PirateGame game)//real
- {
- Wormhole minWorm=null;
- double minDist= game.rows*game.rows+game.cols*game.cols;
- for(Wormhole worm: game.getActiveWormholes())
- {
- if(worm.distance(pirate)<minDist)
- {
- minDist= worm.distance(pirate);
- minWorm= worm;
- }
- }
- return minWorm;
- }
- private boolean pushOutNOCAPSULE(Pirate pirate, PirateGame game)
- {
- for (Pirate enemy: game.getEnemyLivingPirates()) {
- // Check if the pirate can push the enemy.
- if (pirate.canPush(enemy)) {
- // Push enemy!
- if(distanceFromYashar(enemy,game)==1)
- {
- Location l1= new Location(0,pirate.getLocation().col);
- pirate.push(enemy,l1);
- }
- if(distanceFromYashar(enemy,game)==2)
- {
- Location l2= new Location(pirate.getLocation().row,0);
- pirate.push(enemy,l2);
- }
- if(distanceFromYashar(enemy,game)==3)
- {
- Location l3= new Location(6400,pirate.getLocation().col);
- pirate.push(enemy,l3);
- }
- if(distanceFromYashar(enemy,game)==4)
- {
- Location l4= new Location(pirate.getLocation().row,6400);
- pirate.push(enemy,l4);
- }
- // Print a message.
- // Did push.
- return true;
- }
- }
- return false;
- }
- private boolean pushNoCapDown(Pirate pirate, PirateGame game)
- {
- for(Pirate enemy: game.getEnemyLivingPirates())
- {
- if(pirate.canPush(enemy)&&enemy.capsule!=null)
- {
- pirate.push(enemy,new Location(6400,3200));
- return true;
- }
- }
- return false;
- }
- public boolean pushWilliamEnemy(Pirate pirate,Capsule capsule,PirateGame game)
- {
- if(capsule==null)
- {
- if(pushOutNOCAPSULE(pirate,game)==false)
- return false;
- else
- return true;
- }
- else{
- for(Pirate enemy:game.getEnemyLivingPirates())
- {
- if(pirate.canPush(enemy))
- {
- pirate.push(enemy,capsule.initialLocation);
- return true;
- }
- }
- }
- return false;
- }
- public Location attackerUpMother(double myCapInitX, double myCapInitY,PirateGame game, Mothership mother)
- {
- double radius= game.pushDistance;
- double zavit=(myCapInitY-mother.getLocation().col)/(myCapInitX-mother.getLocation().row);
- double zavitEnemyBase= Math.atan(zavit)-Math.PI/2.0;
- if(myCapInitX<mother.getLocation().row)
- {
- zavitEnemyBase=Math.PI+zavitEnemyBase;
- }
- int xRet=0;
- xRet= (int)(mother.getLocation().row+radius*Math.cos(zavitEnemyBase));
- int yRet=0;
- yRet= (int)(mother.getLocation().col+radius*Math.sin(zavitEnemyBase));
- Location defRow1= new Location(xRet,yRet);
- return defRow1;
- }
- public Location attackerLowerMother(double myCapInitX, double myCapInitY,PirateGame game, Mothership mother)
- {
- double radius= game.pushDistance;
- double zavit=(myCapInitY-mother.getLocation().col)/(myCapInitX-mother.getLocation().row);
- double zavitEnemyBase= Math.atan(zavit)+Math.PI/2.0;
- if(myCapInitX<mother.getLocation().row)
- {
- zavitEnemyBase=Math.PI+zavitEnemyBase;
- }
- int xRet=0;
- xRet= (int)(mother.getLocation().row+radius*Math.cos(zavitEnemyBase));
- int yRet=0;
- yRet= (int)(mother.getLocation().col+radius*Math.sin(zavitEnemyBase));
- Location defRow1= new Location(xRet,yRet);
- return defRow1;
- }
- private Location trigoLocation(int nearLocX, int nearLocY,Location diractionLoc,double radius,double angle){
- double zavit=(nearLocY-diractionLoc.col+0.0)/(nearLocX+0.0-diractionLoc.row);
- if(nearLocX+0.0-diractionLoc.row==0)
- zavit=0;
- double zavitEnemyBase=(Math.atan(zavit)+(Math.PI/180.0)*angle+0.0);
- if(nearLocX<diractionLoc.row)
- {
- zavitEnemyBase=Math.PI+zavitEnemyBase;
- }
- int xRet=0;
- xRet= (int)(nearLocX-radius*Math.cos(zavitEnemyBase));
- int yRet=0;
- yRet= (int)(nearLocY-radius*Math.sin(zavitEnemyBase));
- Location defRow1= new Location(xRet,yRet);
- return defRow1;
- }
- private Mothership whichMotherGoingTo(Pirate pirate, int radius, PirateGame game)//IMPORTANT SHIT
- {
- //get pirate index in game.getmyallpirates
- int i=0;//the index
- for(i=0; i<game.getAllEnemyPirates().length;i++)
- {
- if(pirate.equals(game.getAllEnemyPirates()[i]))
- break;
- }
- Location prevLoc= enemyPiratesLocations[i];
- Location currentLoc= pirate.getLocation();
- double m;
- int x1= prevLoc.row;
- int y1= prevLoc.col;
- int x2=currentLoc.row;
- int y2= currentLoc.col;
- for(Mothership mother: game.getEnemyMotherships())
- {
- int x3=mother.getLocation().row;
- int y3= mother.getLocation().col;
- if(x2-x1==0)
- m=9999;
- else
- m=(y2-y1+0.0)/(x2-x1);
- double n= y1-m*x1;
- double D= Math.abs(-m*x3+y3-n)/Math.sqrt(m*m+1);
- if(D<radius&&mother.distance(currentLoc)<mother.distance(prevLoc))
- {
- return mother;
- }
- }
- return null;
- }
- private Capsule closestEnemyCapsuleReal(Location pirate,PirateGame game)
- {
- int minDis=game.rows*game.rows+game.cols*game.cols;
- Capsule minCapsule=null;
- for(int i=0;i<game.getEnemyCapsules().length;i++) {
- if(pirate.distance(game.getEnemyCapsules()[i])<minDis)
- {
- minDis=pirate.distance(game.getEnemyCapsules()[i]);
- minCapsule=game.getEnemyCapsules()[i];
- }
- }
- return minCapsule;
- }
- public void defenderAction(Pirate pirate, PirateGame game) {
- Capsule[] enemyCapsules=game.getEnemyCapsules();//Vectors!!!!!!!!!
- Capsule enemyBestCapsule=null;
- //for(int i=0;i<game.getEnemyLivingPirates().length;i++)
- // {
- //if(going_to_Capsule(game.getEnemyLivingPirates()[i], i, game)!=null)
- // {
- // enemyBestCapsule=going_to_Capsule(game.getEnemyLivingPirates()[i], i, game);
- // System.out.println(enemyBestCapsule);
- // break;
- // }
- // }
- if(enemyBestCapsule==null)
- {
- enemyBestCapsule=enemyBestCapsule(game);
- }
- //enemyBestCapsule= enemyBestCapsule(game);//Vectors!!!!!!!!
- Mothership enemyMothership=relevantEnemyMothership(enemyBestCapsule, game);
- int enemyMoveCapsuleX= enemyBestCapsule.getLocation().row;
- int enemyMoveCapsuleY= enemyBestCapsule.getLocation().col;
- Location EnemyBaseDef= defMove(enemyMoveCapsuleX,enemyMoveCapsuleY,game,600,enemyBestCapsule);
- Location EnemyBaseDef2= defMove(enemyMoveCapsuleX,enemyMoveCapsuleY,game,1050,enemyBestCapsule);
- if(pirate.isAlive()&&pushOut(pirate,game)==false&&tryPushAstroidDefenders(pirate,game,enemyBestCapsule)==false&&DefendersPushWormholeFake(pirate,game,enemyMothership,enemyBestCapsule)==false)
- {
- if(defAmountClose<2)
- {
- if(isCloseToEnemyFake(pirate,game,400,enemyBestCapsule)) {
- pirate.sail(enemyBestCapsule.getLocation());
- }
- else
- pirate.sail(EnemyBaseDef);
- defAmountClose++;
- }
- else if(defAmountFar<2){
- if(isCloseToEnemyFake(pirate,game,1200,enemyBestCapsule)) {
- pirate.sail(enemyBestCapsule.getLocation());
- }
- else
- pirate.sail(EnemyBaseDef2);
- defAmountFar++;
- }
- }
- }
- public Asteroid closestAsteroid(Pirate pirate, PirateGame game)//real
- {
- Asteroid minAsteroid=null;
- if(game.getAllAsteroids().length==0)
- return null;
- double minDist= game.rows*game.rows+game.cols*game.cols;
- for(Asteroid asteroid: game.getAllAsteroids())
- {
- if(asteroid.distance(pirate)<minDist)
- {
- minDist= asteroid.distance(pirate);
- minAsteroid= asteroid;
- }
- }
- return minAsteroid;
- }
- public Asteroid closestAsteroidAlive(Pirate pirate, PirateGame game)//real
- {
- Asteroid minAsteroid=null;
- if(game.getAllAsteroids().length==0)
- return null;
- double minDist= game.rows*game.rows+game.cols*game.cols;
- for(Asteroid asteroid: game.getLivingAsteroids())
- {
- if(asteroid.distance(pirate)<minDist)
- {
- minDist= asteroid.distance(pirate);
- minAsteroid= asteroid;
- }
- }
- return minAsteroid;
- }
- /*public Location safteyLocCloseCapsule(Location pirate,Location diractionLoc,double radius,int leftRight,PirateGame game)
- {
- int[] degrees=new int[360];
- degrees[0]=0;
- if(leftRight==1){
- for(int i=1;i<180;i+=2)//creating the degrees array
- {
- degrees[i]=i;
- degrees[i+180]= -1*i;
- }
- }
- else if (leftRight==0)
- {
- for(int i=1;i<180;i+=2)//creating the degrees array
- {
- degrees[i]=-1*i;
- degrees[i+180]= i;
- }
- }
- for(int i=0;i<degrees.length;i++)
- {
- if(isSafeLoc(trigoLocation(pirate.row,pirate.col,diractionLoc,radius,degrees[i]),game))
- return trigoLocation(pirate.row,pirate.col,diractionLoc,radius,degrees[i]);
- }
- return trigoLocation(pirate.getLocation().row,pirate.getLocation().col,diractionLoc,radius,180.0);
- }
- */
- public Location safteyLocDef(Location pirate,Location diractionLoc,double radius,PirateGame game)
- {
- //radius=game.pirateMaxSpeed;
- int[] degrees=new int[360];
- degrees[0]=0;
- int degreesCounter=1;
- for(int i=1;i<degrees.length-1;i+=2)//creating the degrees array
- {
- degrees[i]=degreesCounter;
- degrees[i+1]=degreesCounter*-1;
- degreesCounter++;
- }
- for(int i=0;i<degrees.length;i++)
- {
- if(isSafeLocDef(trigoLocation(pirate.row,pirate.col,diractionLoc,radius,degrees[i]),game))
- return trigoLocation(pirate.row,pirate.col,diractionLoc,radius,degrees[i]);
- }
- return trigoLocation(pirate.getLocation().row,pirate.getLocation().col,diractionLoc,radius,0.0);
- }
- public Location safteyLoc(Location pirate,Location diractionLoc,double radius,PirateGame game)
- {
- //radius=game.pirateMaxSpeed;
- int[] degrees=new int[360];
- degrees[0]=0;
- int degreesCounter=1;
- for(int i=1;i<degrees.length-1;i+=2)//creating the degrees array
- {
- degrees[i]=degreesCounter;
- degrees[i+1]=degreesCounter*-1;
- degreesCounter++;
- }
- for(int i=0;i<degrees.length;i++)
- {
- if(isSafeLoc(trigoLocation(pirate.row,pirate.col,diractionLoc,radius,degrees[i]),game))
- return trigoLocation(pirate.row,pirate.col,diractionLoc,radius,degrees[i]);
- }
- return trigoLocation(pirate.getLocation().row,pirate.getLocation().col,diractionLoc,radius,0.0);
- }
- public boolean isSafeLoc(Location loc,PirateGame game)
- {
- int enemyCount=0;
- for(Mothership mother: game.getAllMotherships())
- {
- if(mother.distance(loc)<game.pirateMaxSpeed)
- return true;
- }
- for(Pirate enemy: game.getEnemyLivingPirates())//enemy saftey
- {
- if(enemy.distance(loc)<=550&&enemy.pushReloadTurns<=1)
- {
- enemyCount++;
- if(enemyCount>=2)
- return false;
- }
- }
- if(loc.row<0||loc.col<0||loc.row>game.rows||loc.col>game.cols)
- return false;
- //check astroid
- for(Asteroid astroid:game.getLivingAsteroids())
- {
- int dirX=astroid.getLocation().row+(int)(astroid.direction.row*1);
- int dirY=astroid.getLocation().col+(int)(astroid.direction.col*1);
- Location asterDiraction= new Location(dirX,dirY);
- if(asterDiraction.distance(loc)<=astroid.size+200)
- return false;
- }
- //check wormhole
- for(Wormhole wormhole:game.getAllWormholes())
- {
- if(wormhole.turnsToReactivate<=1&&wormhole.distance(loc)<wormhole.size)
- return false;
- }
- return true;
- }
- public boolean isSafeLocDef(Location loc,PirateGame game)
- {
- int enemyCount=0;
- if(loc.row<0||loc.col<0||loc.row>game.rows||loc.col>game.cols)
- return false;
- //check astroid
- for(Asteroid astroid:game.getLivingAsteroids())
- {
- int dirX=astroid.getLocation().row+(int)(astroid.direction.row*1);
- int dirY=astroid.getLocation().col+(int)(astroid.direction.col*1);
- Location asterDiraction= new Location(dirX,dirY);
- if(asterDiraction.distance(loc)<=astroid.size+200)
- return false;
- }
- //check wormhole
- return true;
- }
- public Capsule closestCapsuleNotYou(Pirate pirate,PirateGame game)
- {
- int capDist=game.rows*game.rows+game.cols*game.cols;
- Capsule minCap=null;
- if(game.getMyCapsules().length==0)
- return null;
- for(int i=0;i<game.getMyCapsules().length;i++)
- {
- if(capDist>pirate.distance(game.getMyCapsules()[i])&&!pirate.getLocation().equals(game.getMyCapsules()[i].getLocation()))
- {
- minCap=game.getMyCapsules()[i];
- capDist=pirate.distance(game.getMyCapsules()[i]);
- }
- }
- return minCap;
- }
- public Pirate closestDefenderToAstroid(PirateGame game)
- {
- if(defenders.length==0)
- return null;
- if(game.getLivingAsteroids().length==0)
- return null;
- int minDis=game.rows*game.rows+game.cols*game.cols;
- Pirate minPirate=null;
- for(int i=0;i<defenders.length;i++)
- {
- if(defenders[i].distance(closestAsteroidAlive(defenders[i],game))<minDis)
- {
- minDis=defenders[i].distance(closestAsteroidAlive(defenders[i],game));
- minPirate=defenders[i];
- }
- }
- return minPirate;
- }
- public boolean shouldPushToAstroid(Pirate pirate, PirateGame game)
- {
- Asteroid astroid= closestAsteroidAlive(pirate,game);
- if(astroid==null)
- return false;
- for(Pirate enemy:game.getEnemyLivingPirates())
- {
- if(astroid.distance(enemy)-astroid.size<=pirate.pushDistance&&pirate.canPush(enemy))
- {
- piratesPushingAstroids[astroid.id]++;
- if(piratesPushingAstroids[astroid.id]<=1){
- pirate.push(enemy,astroid);
- return true;
- }
- }
- }
- return false;
- }
- public boolean IsStickybombOnMe(Pirate pirate, PirateGame game){
- for(StickyBomb stickybomb: game.getAllStickyBombs()){
- if(stickybomb.carrier==pirate){
- return true;
- }
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment