Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package bots;
- import elf_kingdom.*;
- public class MyBot implements SkillzBot {
- /*
- TO DO:
- 1. build portals in places that they are hard to be destoyed and they are most effective in. Thats why we lose to the other bots.
- If we build attacking portals that are far from enemy elves and from enemy portals and from enemy's best defense portals(by slope)
- we start winning a lot.
- 2. Ice Wall
- 3. The elves are waiting for mana instead of attacking enemy super close portal!
- 4. First fight
- 5. Imporve Skie?
- */
- static Location[] enemyElvesLocations;
- static Location[] myElvesLocations;
- static boolean isElfTryingToBuildPortal;
- static Location enemyAttackingLoc;
- static int ActiontryToAttackEnemyElf=0;
- static int ActiontryToBuildPortalCauseCan=1;
- static int ActionDefPortal=2;
- static int ActionEnemyAttackingPortal=3;
- static int ActionEnemyElfAttacking=4;
- static int ActionBuildManaFountains=5;
- static int ActionDestroyEnemyManaFountains=6;
- static int ActionBuildAttackingPortals=7;
- static int ActionBuildAttackPortalWhenCan=8;
- static int ActionDestroyEnemyBuildings=9;
- static int ActionAttackEnemyCastle=10;
- public void doTurn(Game game) {
- System.out.println(isTherePortalNearEnemyCloseSpawnToCastle(game));
- System.out.println(whereToBuildManaFountain(game)+" where to build mana fountain");
- for(int i=0;i<=9;i++)
- System.out.println(numberOfElvesNeededForAction(i,game)+" action number "+i);
- if(game.turn==1)
- {
- turnOne(game);
- }
- if(EnemyThreatningPortal(game)!=null)
- enemyAttackingLoc=game.getMyCastle().getLocation().towards(EnemyThreatningPortal(game),game.lavaGiantAttackRange+game.getMyCastle().size);
- else
- enemyAttackingLoc=null;
- isElfTryingToBuildPortal=false;
- //System.out.println("Elves:");
- handleElvesNew(game);
- //System.out.println("");
- //System.out.println("Portals:");
- handlePortals(game);
- //END OF TURN RESET LOCATIONS OF ELVES
- for(int i=0;i<game.getAllEnemyElves().length;i++)//update enemyPirates Loc
- {
- enemyElvesLocations[i]=game.getAllEnemyElves()[i].getLocation();
- }
- for(int i=0;i<game.getAllMyElves().length;i++)//update myPirates Loc
- {
- myElvesLocations[i]=game.getAllMyElves()[i].getLocation();
- }
- }
- public static void turnOne(Game game)
- {
- enemyElvesLocations=new Location[game.getAllEnemyElves().length];
- myElvesLocations=new Location[game.getAllMyElves().length];
- for(int i=0;i<game.getAllEnemyElves().length;i++)
- {
- enemyElvesLocations[i]=game.getAllEnemyElves()[i].getLocation();
- }
- for(int i=0;i<game.getAllMyElves().length;i++)
- {
- myElvesLocations[i]=game.getAllMyElves()[i].getLocation();
- }
- }
- private void handlePortals(Game game) {
- for(Portal portal: game.getMyPortals())
- {
- IceOrFire(portal,game);
- }
- }
- public static void swapElves(Elf elf,Elf[] elvesForActions,int counter,int actionNum,Game game)
- {
- if(counter==elvesForActions.length)
- {
- return;
- }
- else if(elvesForActions[counter]==null)
- {
- elvesForActions[counter]=elf;
- return;
- }
- else if(elvesForActions[counter]!=elf&&isElfBetterAtAction(elf,elvesForActions[counter],actionNum,game))
- {
- Elf keeper=elvesForActions[counter];
- elvesForActions[counter]=elf;
- swapElves(keeper,elvesForActions,0,actionNum,game);
- }
- else
- {
- swapElves(elf,elvesForActions,counter+1,actionNum,game);
- }
- }
- public static void elvesDoAction(Elf[] elves,int action,Game game)
- {
- for(int i=0;i<elves.length;i++)
- {
- if(elves[i]!=null)
- {
- Elf elf=elves[i];
- System.out.println(elf+" is it smart "+isItSmartToBuildPortal(elf,game)+" is it safe "+isItSafeToBuildPortal(elf,game));
- if(elf.isBuilding)
- System.out.println(elf+" elf is building");
- ///**0**\\\ ---PRIVATE
- //if there is no enemy close to casle: Try to attack an Elf close to you\\
- else if(tryToAttackElf(elf,game))
- {
- attackEnemyElf(elf,game);
- System.out.println(elf+" Elf Attacking");
- }
- ////**1**\\\\---PRIVATE
- //if it is safe and smart and has mana build a portal
- else if(isItSmartToBuildPortal(elf,game)&&isItSafeToBuildPortal(elf,game)&&elf.canBuildPortal()&&!(elf.isBuilding)&&(game.getMyMana()>=(game.portalCost+game.lavaGiantCost-game.getMyself().manaPerTurn)&&(!shouldIbuildManaFountain(game)||game.getMyMana()>game.manaFountainCost)))
- {
- System.out.println(elf+" elf chose to build portal cause he has a lot of mana");
- elf.buildPortal();
- }
- else if(areTheyCloseFountainsToElf(elf,game))
- tryToDestroyEnemyCloseFountain(elf,game);
- else if(game.getEnemyCastle().currentHealth==75&&game.getMyself().manaPerTurn==0&&game.getMyself().mana==0)
- {
- if(areTheyCloseFountainsToElf(elf,game))
- tryToDestroyEnemyCloseFountain(elf,game);
- else
- elf.attack(game.getEnemyLavaGiants()[0]);
- }
- else if(game.getMyMana()==0&&game.getMyself().manaPerTurn==0)
- tryToAttackEnemyCastle(elf,game);
- ////**2**\\\\
- //if there is no portal defending go build one
- else if(action==ActionDefPortal)
- {
- System.out.println(elf+" elf chose to build def portal");
- buildDefPortal(elf,game);
- }
- ////**3**\\\\
- //Is there is a Close Enemy Portal To Castle\\
- else if(action==ActionEnemyAttackingPortal)
- {
- System.out.println(elf+" elf chose to destroy enemy elves attacking portal");
- destroyEnemysAttackingPortal(elf,game);
- }
- ////**4**\\\\
- //checking if enemy elf is on his way to attack our castle
- else if(action==ActionEnemyElfAttacking)//ACTION THAT DOES STUFF!!!!
- {
- GoingToEnemyAttackingElf(elf,game);
- System.out.println(elf+" going to def cause enemy elf attacking");
- }
- ////**5**\\\\
- //if there is no attack portal: Go build one\\
- else if(action==ActionBuildAttackingPortals)
- {
- System.out.println(elf+" elf chose to build attacking portal");
- tryToBuildAttackingPortal(elf,game);
- }
- ////**6**\\\\
- //if you are close to enemys castle and you can build portal, build one
- else if(isItSmartToBuildPortal(elf,game)&&isItSafeToBuildPortal(elf,game)&&elf.distance(game.getEnemyCastle())<elf.distance(game.getMyCastle()) && elf.canBuildPortal()&&game.getMyMana()>game.portalCost)
- {
- System.out.println(elf+" elf chose to build an attacking portal cause he can");
- elf.buildPortal();
- }
- ////**7**\\\\
- //if enemy has portals, try to destroy them
- else if(action==ActionDestroyEnemyBuildings)
- {
- System.out.println(elf+" elf chose to destroy enemys buildings");
- destroyEnemysBuilding(elf,game);
- }
- else if(action==ActionBuildManaFountains)
- {
- System.out.println(elf+" trying to build a mana fountain");
- tryToBuildManaFountain(elf,game);
- }
- else if(action==ActionDestroyEnemyManaFountains)
- {
- System.out.println(elf+" destroying enemy mana founctain");
- destroyEnemysFountains(elf,game);
- }
- ////**8**\\\\
- else//attack enemys castle at last
- {
- //System.out.println(elf+" elf chose to attack the castle");
- tryToAttackEnemyCastle(elf,game);
- }
- }
- }
- }
- public static void handleElvesNew(Game game)
- {
- Elf[] elvesNotUsed=new Elf[game.getMyLivingElves().length];
- boolean hasElvesForAction=false;
- for(int i=0;i<elvesNotUsed.length;i++)
- {
- elvesNotUsed[i]=game.getMyLivingElves()[i];
- }
- for(int i=0;i<=10;i++)//MAIN FOR 8 is number of actions
- {
- if(i!=ActiontryToAttackEnemyElf&&i!=ActiontryToBuildPortalCauseCan&&i!=ActionBuildAttackPortalWhenCan)//PRIVATE FUNCS
- {
- int numbOfElvesNeededForAction=numberOfElvesNeededForAction(i,game);
- if(numbOfElvesNeededForAction>0)
- {
- Elf[] elvesForActions=new Elf[numbOfElvesNeededForAction];
- for(int n=0;n<elvesNotUsed.length;n++)
- {
- if(elvesNotUsed[n]!=null)
- {
- swapElves(elvesNotUsed[n],elvesForActions,0,i,game);
- }
- }
- for(int k=0;k<elvesNotUsed.length;k++)
- {
- for(Elf elfUsed:elvesForActions)
- {
- if(elvesNotUsed[k]==elfUsed)
- {
- elvesNotUsed[k]=null;
- }
- }
- }
- //System.out.println("action numba "+i);
- //for(int k=0;k<elvesForActions.length;k++)
- // System.out.print(elvesForActions[k]+",");
- //System.out.println();
- //for(int k=0;k<elvesNotUsed.length;k++)
- // System.out.print(elvesNotUsed[k]+",");
- //System.out.println();
- elvesDoAction(elvesForActions,i,game);
- }
- }
- }
- for(int i=0;i<elvesNotUsed.length;i++)
- {
- if(elvesNotUsed[i]!=null)
- {
- tryToBuildAttackingPortal(elvesNotUsed[i],game);//deafult action
- }
- }
- }
- public static boolean isElfBetterAtAction(Elf elf,Elf elfCompare,int action,Game game)
- {
- double difference=elf.maxSpeed*1.5;
- if(action==ActionDefPortal) {//2
- Location loc=whereElfShouldBuildDefPortal(game);
- if(elf.distance(loc)+difference<elfCompare.distance(loc))
- return true;
- return false;
- }
- else if(action==ActionEnemyAttackingPortal) {//3
- //if elf needs help ++
- //&& other elf is far to another action's needed positions
- Portal port=closestEnemyPortalToOurCastle(game);
- if(elf.distance(port)+difference<elfCompare.distance(port))
- {
- return true;
- }
- return false;
- }
- else if(action==ActionEnemyElfAttacking) {//4
- Elf enemyElf=isThereEnemyElfAttacking(game);
- if(elf.distance(enemyElf)+difference<elfCompare.distance(enemyElf))
- {
- return true;
- }
- return false;
- }
- else if(action==ActionBuildAttackingPortals) {//if we dont have an attacking portal 5
- Location whereToBuildPort1=whereElfShouldBuildAttackPortal(elf,game);
- Location whereToBuildPort2=whereElfShouldBuildAttackPortal(elfCompare,game);
- if(elf.distance(whereToBuildPort1)+difference<elfCompare.distance(whereToBuildPort2))
- return true;
- return false;
- }
- else if(action==ActionDestroyEnemyBuildings) {//7
- Location l1=closestEnemyBuildingToMapObject(elf,game).getLocation();
- Location l2=closestEnemyBuildingToMapObject(elfCompare,game).getLocation();
- if(elf.distance(l1)+difference<elfCompare.distance(l2))
- return true;
- return false;
- }
- else if(action==ActionBuildManaFountains) {//9
- Location l1=whereToBuildManaFountain(game);
- if(elf.distance(l1)+difference<elfCompare.distance(l1))
- return true;
- return false;
- }
- else if(action==ActionDestroyEnemyManaFountains)
- {
- Location neededToDestroyEnemyMana=getEnemyBestManaFountain(game).getLocation();
- if(elf.distance(neededToDestroyEnemyMana)+difference<elfCompare.distance(neededToDestroyEnemyMana))
- return true;
- return false;
- }
- return false;
- }
- public static Building closestEnemyBuildingToMapObject(MapObject object,Game game)
- {
- //System.out.println(object+" OBJECT?!?!?!?!?!");
- if(game.getEnemyPortals().length==0&&game.getEnemyManaFountains().length==0)
- return null;
- Building mBuilding=null;
- if(game.getEnemyManaFountains().length>0)
- mBuilding=game.getEnemyManaFountains()[0];
- else
- mBuilding=game.getEnemyPortals()[0];
- for(Portal portal:game.getEnemyPortals())
- {
- if(portal.distance(object.getLocation())<mBuilding.distance(object.getLocation()))
- mBuilding=portal;
- }
- for(ManaFountain Fountain:game.getEnemyManaFountains())
- {
- if(Fountain.distance(object.getLocation())<mBuilding.distance(object.getLocation()))
- mBuilding=Fountain;
- }
- return mBuilding;
- }
- public static boolean areTheyCloseFountainsToElf(Elf elf,Game game)
- {
- for(ManaFountain mana:game.getEnemyManaFountains())
- {
- if(elf.inAttackRange(mana))
- {
- return true;
- }
- else if(elf.distance(mana)<=elf.maxSpeed*3)
- {
- return true;
- }
- else if(mana.distance(game.getMyCastle())<=mana.size*5)
- {
- return true;
- }
- }
- return false;
- }
- public static void tryToDestroyEnemyCloseFountain(Elf elf,Game game)
- {
- for(ManaFountain mana:game.getEnemyManaFountains())
- {
- if(elf.inAttackRange(mana))
- {
- elf.attack(mana);
- return;
- }
- else if(elf.distance(mana)<=elf.maxSpeed*3)
- {
- elf.moveTo(safteyLoc(elf.getLocation(),mana.getLocation(),elf.maxSpeed+50,game));
- return;
- }
- else if(mana.distance(game.getMyCastle())<=mana.size*5)
- {
- elf.moveTo(safteyLoc(elf.getLocation(),mana.getLocation(),elf.maxSpeed+50,game));
- return;
- }
- }
- }
- public static void buildDefPortal(Elf elf,Game game)
- {
- isElfTryingToBuildPortal=true;
- Location whereToBuildPort=whereElfShouldBuildDefPortal(game);
- if(elf.distance(whereToBuildPort)<=elf.maxSpeed*1.5 &&elf.canBuildPortal()&&!(elf.isBuilding)&&game.getMyMana()>=(game.portalCost))
- {
- //System.out.println("building def portal");
- elf.buildPortal();
- }
- else
- {
- //System.out.println("going to build def portal loc");
- elf.moveTo(safteyLoc(elf.getLocation(),whereToBuildPort,elf.maxSpeed+50,game));
- }
- }
- public static boolean isTherePortalNearEnemyCloseSpawnToCastle(Game game){
- int count=0;
- Elf CloseSpawiningElf=null;
- for(Elf enemyElf:game.getAllEnemyElves()){
- if(enemyElf.initialLocation.distance(game.getMyCastle())-game.getMyCastle().size-game.elfAttackRange<game.elfMaxSpeed*15){
- CloseSpawiningElf=enemyElf;
- }
- }
- if(CloseSpawiningElf==null)
- return false;
- for(Portal portal:game.getMyPortals()){
- if(portal.distance(CloseSpawiningElf.initialLocation)<game.iceTrollMaxSpeed+game.iceTrollAttackRange){
- count++;
- }
- }
- if(count==0)
- return true;
- return false;
- }
- public static void buildPortalToFuckEnemyElfWhenSpawned(Elf elf, Game game){
- Location PortalLocation=null;
- for(Elf enemyElf:game.getAllEnemyElves()){
- if(enemyElf.initialLocation.distance(game.getMyCastle())<game.elfMaxSpeed*10){
- PortalLocation=enemyElf.initialLocation;
- }
- }
- if(PortalLocation!=null){
- if(elf.distance(PortalLocation)<=elf.maxSpeed*1.5&&elf.canBuildPortal()&&game.getMyMana()>=game.manaFountainCost)
- {
- System.out.println("building spawn portal");
- elf.buildPortal();
- }
- else
- {
- System.out.println("going spawn portaln");
- if(elf.distance(PortalLocation)<=elf.maxSpeed*2)
- elf.moveTo(PortalLocation);
- else
- elf.moveTo(safteyLoc(elf.getLocation(),PortalLocation,elf.maxSpeed+50,game));
- }
- }
- }
- public static void destroyEnemysAttackingPortal(Elf elf,Game game)
- {
- Portal p=closestEnemyPortalToOurCastle(game);
- if(ClosestEnemyElfToOurCastle(game)!=null&&ClosestEnemyElfToOurCastle(game).distance(elf)<elf.distance(p)&&isThereEnemyElfAttacking(game)!=null)
- {
- GoingToEnemyAttackingElf(elf,game);
- //System.out.println("going to def cause enemy elf attacking");
- }
- //if can attack: Attack!
- else if(elf.inAttackRange(p)&&!(elf.isBuilding)&&isItSafeToAttackEnemyBuilding(elf,p,game)){
- elf.attack(p);
- }
- //if can't attack: move to portal
- else if(!(elf.isBuilding))
- {
- if(isItSmartToBuildPortal(elf,game)&&isItSafeToBuildPortal(elf,game)&&elf.canBuildPortal()&&!(elf.isBuilding)&&game.getMyMana()>(game.portalCost+10)&&NumberOfIceNeededForDefense(game)-allyIceAroundLoc(enemyAttackingLoc, game)<2)
- {
- //System.out.println("elf chose to build portal");
- elf.buildPortal();
- }
- else
- elf.moveTo(safteyLoc(elf.getLocation(),p.getLocation(),elf.maxSpeed+50,game));
- }
- }
- public static void tryToBuildAttackingPortal(Elf elf,Game game)
- {
- isElfTryingToBuildPortal=true;
- Location whereToBuildPort;
- int num=numOfEnoughClosePortalToEnemyCastle(game);
- if(num==0)
- whereToBuildPort=whereElfShouldBuildAttackPortal(elf,game);
- else
- whereToBuildPort=whereElfShouldBuildAttackPortalSides(elf,game);
- //System.out.println(isItSafeToBuildPortal(elf,game)+" FOR FUCKS SAKE IT IS SAFE TO BUILD A GOD DARN PORTAL");
- if(isItSmartToBuildPortal(elf,game)&&isItSafeToBuildPortal(elf,game)&&elf.distance(game.getEnemyCastle())<elf.distance(game.getMyCastle()) && elf.canBuildPortal()&&game.getMyMana()>game.portalCost)
- {
- elf.buildPortal();
- }
- else if(elf.distance(whereToBuildPort)<=elf.maxSpeed&&!elf.isBuilding)
- {
- if(isItSafeToBuildPortal(elf,game)&&isItSmartToBuildPortal(elf,game))
- {
- if(elf.canBuildPortal()&&game.getMyMana()>=game.portalCost)
- {
- elf.buildPortal();
- //System.out.println("elf is building a portal");
- }
- else
- {
- //System.out.println("elf is moving safetly to the loc");
- if(elf.distance(whereToBuildPort)<elf.maxSpeed*3&&isSafeLoc(whereToBuildPort,game))
- elf.moveTo(whereToBuildPort);
- else
- elf.moveTo(safteyLoc(elf.getLocation(),whereToBuildPort,elf.maxSpeed+50,game));
- }
- }
- else
- {
- whereToBuildPort=whereElfShouldBuildAttackPortalSides(elf,game);
- if(elf.distance(whereToBuildPort)<=elf.maxSpeed&&!elf.isBuilding)
- {
- if(isItSafeToBuildPortal(elf,game)&&isItSmartToBuildPortal(elf,game))
- {
- if(elf.canBuildPortal()&&game.getMyMana()>=game.portalCost)
- {
- elf.buildPortal();
- //System.out.println("elf is building a portal");
- }
- }
- else
- {
- //System.out.println("elf is moving safetly to the loc");
- if(elf.distance(whereToBuildPort)<elf.maxSpeed*3&&isSafeLoc(whereToBuildPort,game))
- elf.moveTo(whereToBuildPort);
- else
- elf.moveTo(safteyLoc(elf.getLocation(),whereToBuildPort,elf.maxSpeed+50,game));
- }
- }
- else
- {
- //System.out.println("elf is moving safetly to the loc");
- elf.moveTo(safteyLoc(elf.getLocation(),whereToBuildPort,elf.maxSpeed+50,game));
- }
- }
- }
- else if(!elf.isBuilding)
- {
- //System.out.println("elf is moving to the port loc");
- if(elf.distance(whereToBuildPort)<elf.maxSpeed*3&&isSafeLoc(whereToBuildPort,game))
- elf.moveTo(whereToBuildPort);
- else
- elf.moveTo(safteyLoc(elf.getLocation(),whereToBuildPort,elf.maxSpeed+50,game));
- }
- }
- public static void destroyEnemysBuilding(Elf elf,Game game)
- {
- Building enemyBuilding=closestEnemyBuildingToMapObject(elf,game);
- if(isItSafeToAttackEnemyBuilding(elf,enemyBuilding,game)&&elf.inAttackRange(enemyBuilding))
- {
- //System.out.println("ATTACKING ENEMY PORTAL");
- elf.attack(enemyBuilding);
- }
- //if not in Attack Range: move there
- else
- {
- //System.out.println("MOVING SAFTLEY TO ENEMYS CLOSEST PORTAL");
- elf.moveTo(safteyLoc(elf.getLocation(),enemyBuilding.getLocation(),elf.maxSpeed+50,game));
- }
- }
- public static void tryToAttackEnemyCastle(Elf elf,Game game)
- {
- //if elf in Attack Range: attack enemy Casle
- if (elf.inAttackRange(game.getEnemyCastle())&&(isSafeLoc(elf.getLocation(),game)||game.getEnemyCastle().currentHealth<=elf.attackMultiplier*elf.currentHealth))
- {
- elf.attack(game.getEnemyCastle());
- //.out.println("elf " + elf + " attacks " + game.getEnemyCastle());
- }
- //go back safely to My casle
- else {
- //System.out.println("moving saftley back to Base");
- elf.moveTo(safteyLoc(elf.getLocation(),game.getEnemyCastle().getLocation(),elf.maxSpeed+50,game));
- ////System.out.println("elf " + elf + " moves to " + game.getEnemyCastle());
- }
- }
- public static Portal portalToDestroy(Game game){
- if(closestEnemyPortalToOurCastle(game)==null)
- return null;
- Portal OEnemyPortal=game.getEnemyPortals()[0];
- for(Portal EnemyPortal : game.getEnemyPortals()){
- if(EnemyPortal.distance(game.getMyCastle())<EnemyPortal.distance(game.getEnemyCastle())){
- if(getEnemyLavaGiantsByPortal(game,EnemyPortal)>getEnemyLavaGiantsByPortal(game,OEnemyPortal)) {
- OEnemyPortal=EnemyPortal;
- }
- }
- }
- System.out.println(OEnemyPortal);
- if(OEnemyPortal.distance(game.getMyCastle())<OEnemyPortal.distance(game.getEnemyCastle()))
- return OEnemyPortal;
- else
- return null;
- }
- public static int numberOfElvesNeededForAction(int action, Game game) {
- /*Actions: NOT BY PRIORITY!!!
- *0: Attack enemy elf
- *1: Build on the way portal (A lot of mana)
- *2: Build defense portal
- *3: Destroy enemys attacking portal
- *4: Going to enemy attacking elf
- *5: Build attacking portal --> (first side?)
- *6: Building good portal
- *7: Destroy enemy portals (Any enemy portal)
- *8: Attack enemy castle
- *9: Build mana fountains
- *10: Destroy enemy mana fountains
- *switch 1/2/3 with 4?
- *
- */
- if(action==ActiontryToAttackEnemyElf||action==ActiontryToBuildPortalCauseCan||action==ActionBuildAttackPortalWhenCan)
- {
- //System.out.println("CALLING A PRIVATE ACTION ");
- return 0;
- }
- else if(action==ActionDefPortal) {//2
- // if elf needs help ++
- // && other elf is far to another action's needed positions
- if(isThereDefPortals(game))return 0;
- else return 1;
- }
- else if(action==ActionEnemyAttackingPortal) {//3
- //if elf needs help ++
- //&& other elf is far to another action's needed positions
- int count=0;
- Portal EnemyPortal=closestEnemyPortalToOurCastle(game);
- if(EnemyPortal==null||isThereClosePortalToCastle(game)==false)
- return 0;
- for(Elf EnemyElf:game.getEnemyLivingElves()) {
- if(EnemyElf.distance(EnemyPortal)<EnemyElf.maxSpeed*5)//&&isObjectGoingForwardMe(EnemyElf,EnemyPortal,game)) {
- count++;
- }
- if(portalToDestroy(game)!=null)
- return 1;
- return count;
- }
- else if(action==ActionEnemyElfAttacking) {
- // WHEN ICE WALL IS READY CHANGE
- // if elf needs help 1++ (until elf doesn't need help)
- // && other elf is not attacking (building attack portal);
- int dangerousElves = 0;
- for(Elf enemyElf: game.getEnemyLivingElves()) {
- if((enemyElf.distance(game.getMyCastle())-game.getMyCastle().size-enemyElf.attackRange)/enemyElf.maxSpeed<=15) {
- dangerousElves++;
- }
- }
- return dangerousElves;
- }
- else if(action==ActionBuildAttackingPortals) {
- //if we dont have an attacking portal
- // MAYBE DO THIS boolean enemyCastleAlmostDead = false;
- //*** CHEN DOES THIS but if there are left elves we add them to attack
- //if there are no attacking portals summon one elf
- if((numOfEnoughClosePortalToEnemyCastle(game) == 0))return game.getAllMyElves().length;
- //if there is atting portal and there is not many elfs return 0
- else if(numOfEnoughClosePortalToEnemyCastle(game) == 1) {
- return 1;
- }
- else
- return 0;
- }
- else if(action==ActionDestroyEnemyBuildings) {
- return game.getEnemyManaFountains().length+game.getEnemyPortals().length;
- }
- else if(action==ActionBuildManaFountains){
- if(shouldIbuildManaFountain(game)==false)
- return 0;
- else
- return 1;
- }
- else if(action==ActionDestroyEnemyManaFountains)
- {
- if(game.getEnemyManaFountains().length>0)
- return 1;
- else
- return 0;
- }
- return 0;
- }
- public static ManaFountain getEnemyBestManaFountain(Game game)
- {
- if(game.getEnemyManaFountains().length==0)
- return null;
- ManaFountain min=game.getEnemyManaFountains()[0];
- for(ManaFountain fount:game.getEnemyManaFountains())
- {
- if(fount.distance(game.getMyCastle())<min.distance(game.getMyCastle()))
- min=fount;
- }
- return min;
- }
- public static void destroyEnemysFountains(Elf elf,Game game)
- {
- ManaFountain min=getEnemyBestManaFountain(game);
- if(elf.inAttackRange(min)&&isItSafeToAttackEnemyBuilding(elf,min,game))
- elf.attack(min);
- else
- {
- elf.moveTo(safteyLoc(elf.getLocation(),min.getLocation(),elf.maxSpeed+50,game));
- }
- }
- public static void tryToBuildManaFountain(Elf elf, Game game) {
- Location manaFountainBuildLoc=whereToBuildManaFountain(game);
- System.out.println(elf.canBuildManaFountain());
- if(elf.distance(manaFountainBuildLoc)<=elf.maxSpeed*1.5&&elf.canBuildManaFountain()&&game.getMyMana()>=game.manaFountainCost)
- {
- System.out.println("building mana fountain");
- elf.buildManaFountain();
- }
- else
- {
- System.out.println("going to build mana fountain");
- if(elf.distance(manaFountainBuildLoc)<=elf.maxSpeed*2)
- elf.moveTo(manaFountainBuildLoc);
- else
- elf.moveTo(safteyLoc(elf.getLocation(),manaFountainBuildLoc,elf.maxSpeed+50,game));
- }
- }
- public static boolean isElfBuildingAt(Location loc,Game game)
- {
- for(Elf elf:game.getMyLivingElves())
- {
- if(elf.distance(loc)<=elf.maxSpeed&&elf.isBuilding)
- return true;
- }
- return false;
- }
- public static boolean shouldIbuildManaFountain(Game game) {
- Location locationToBuildManaFountain=whereToBuildManaFountain(game);
- if(!game.canBuildManaFountainAt(locationToBuildManaFountain)||game.getMyManaFountains().length>game.getMyPortals().length+2){
- return false;
- }
- if(locationToBuildManaFountain!=null) {
- if((game.getMyself().manaPerTurn<=game.getEnemy().manaPerTurn||game.getMyself().manaPerTurn==0)) {
- return true;
- }
- else if(game.getMyself().manaPerTurn>game.getEnemy().manaPerTurn) {
- if(game.getMyPortals().length>game.getMyManaFountains().length&&game.getMyMana()>game.manaFountainCost*1.5) { //note to change
- return true;
- }
- }
- }
- return false;
- }
- public static Location whereToBuildManaFountain(Game game) {
- Location whereToBuildManaFountain=null;
- for(Portal portal:game.getMyPortals()) {
- if(portal.distance(game.getMyCastle().getLocation())<game.manaFountainSize*5+game.getMyCastle().size) {
- whereToBuildManaFountain=trigoLocation(portal.getLocation().row,portal.getLocation().col,game.getEnemyCastle().getLocation(),portal.size+game.manaFountainSize+20,180);
- if(game.canBuildManaFountainAt(whereToBuildManaFountain)||isElfBuildingAt(whereToBuildManaFountain,game)) {
- return whereToBuildManaFountain;
- }
- }
- }
- //If there are no portals:
- int[] degrees=new int[360];
- degrees[0]=180;
- int degreesCounter=1;
- Castle myCastle=game.getMyCastle();
- int startingRad=20+myCastle.size;
- for(int i=1;i<degrees.length-1;i+=2)//creating the degrees array
- {
- degrees[i]=degreesCounter;
- degrees[i+1]=degreesCounter*-1;
- degreesCounter++;
- }
- boolean found=false;
- double MaxDist=myCastle.distance(game.getEnemyCastle())/2.5;
- Location locClose= game.getEnemyCastle().getLocation();
- for(int radius=startingRad;radius<MaxDist;radius+=game.manaFountainSize)
- {
- for(int i=0;i<degrees.length;i++)
- {
- Location loc=trigoLocation(myCastle.getLocation().row,myCastle.getLocation().col,locClose,radius,degrees[i]);
- if(game.canBuildManaFountainAt(loc)||isElfBuildingAt(loc,game))
- {
- return trigoLocation(myCastle.getLocation().row,myCastle.getLocation().col,locClose,radius,degrees[i]);
- }
- }
- }
- return trigoLocation(myCastle.getLocation().row,myCastle.getLocation().col,locClose,startingRad,0);
- }
- public static Elf closestEnemyElfToObject(MapObject object, Game game) {
- if(game.getEnemyLivingElves().length==0||object==null)
- return null;
- Elf mElf=game.getEnemyLivingElves()[0];
- for(Elf EnemyElf :game.getEnemyLivingElves())
- {
- if(EnemyElf.distance(object)+EnemyElf.maxSpeed*1.5<=mElf.distance(object))
- {
- mElf=EnemyElf;
- }
- }
- return mElf;
- }
- public static Location whereElfShouldBuildDefPortal(Game game)
- {
- int[] degrees=new int[360];
- degrees[0]=0;
- int degreesCounter=1;
- Castle myCastle=game.getMyCastle();
- int startingRad=game.manaFountainSize+game.portalSize+myCastle.size;
- for(int i=1;i<degrees.length-1;i+=2)//creating the degrees array
- {
- degrees[i]=degreesCounter;
- degrees[i+1]=degreesCounter*-1;
- degreesCounter++;
- }
- boolean found=false;
- double MaxDist=myCastle.distance(game.getEnemyCastle())/2.5;
- Location locClose;
- if(EnemyThreatningPortal(game)!=null&&EnemyThreatningPortal(game).distance(game.getMyCastle())<=myCastle.distance(game.getEnemyCastle())/2)
- locClose= EnemyThreatningPortal(game).getLocation();
- else
- locClose=game.getEnemyCastle().getLocation();
- for(int radius=startingRad;radius<MaxDist;radius+=game.portalSize)
- {
- for(int i=0;i<degrees.length;i++)
- {
- if(game.canBuildPortalAt(trigoLocation(myCastle.getLocation().row,myCastle.getLocation().col,locClose,radius,degrees[i])))
- {
- return trigoLocation(myCastle.getLocation().row,myCastle.getLocation().col,locClose,radius,degrees[i]);
- }
- }
- }
- return trigoLocation(myCastle.getLocation().row,myCastle.getLocation().col,locClose,startingRad,0);
- }
- public static boolean isThereDefPortals(Game game)
- {
- int counter=0;
- for(Portal portal:game.getMyPortals())
- {
- if(portal.distance(game.getMyCastle())-game.castleSize-game.lavaGiantAttackRange<=game.lavaGiantMaxSpeed*5)
- counter++;
- }
- if(counter>1||counter==1&&(isEnemyElfAttackingMyCastle(game)||EnemyLavaAttackingMyCastle(game)>2))
- return true;
- return false;
- }
- public static boolean isItSmartToBuildPortal(Elf elf, Game game)
- {
- for(Elf enemyElf: game.getEnemyLivingElves())
- {
- if((enemyElf.distance(elf)-enemyElf.attackRange)/enemyElf.maxSpeed<=game.iceTrollSummoningDuration+game.portalBuildingDuration&&enemyElf.currentHealth>game.portalMaxHealth*enemyElf.attackMultiplier&&isObjectGoingForwardMe(enemyElf,elf,game))
- {
- return false;
- }
- if(enemyElf.distance(elf)<=enemyElf.maxSpeed*2+enemyElf.attackRange)
- return false;
- }
- for(Portal portal:game.getMyPortals())
- {
- if(portal.distance(elf)<=portal.size*4&&elf.distance(game.getEnemyCastle())>elf.distance(game.getMyCastle()))
- return false;
- }
- ////System.out.println("smart building portal");
- return true;
- }
- public static boolean isItSafeToBuildPortal(Elf elf,Game game)
- {
- int enemyCounter=0;
- for(Elf enemyElf: game.getEnemyLivingElves())
- {
- if(enemyElf.distance(elf)<=enemyElf.maxSpeed*3+enemyElf.attackRange)
- {
- enemyCounter+=elf.attackMultiplier;
- }
- }
- for(IceTroll enemyIce: game.getEnemyIceTrolls())
- {
- if(enemyIce.distance(elf)<=enemyIce.attackRange+enemyIce.maxSpeed*3)
- {
- enemyCounter+=enemyIce.attackMultiplier;
- }
- }
- if(enemyCounter==0)
- return true;
- if(elf.currentHealth-enemyCounter*1.3>game.portalBuildingDuration)
- return true;
- return false;
- }
- public static boolean isItSafeToAttackEnemyBuilding(Elf elf,Building building,Game game)
- {
- int enemyCounter=0;
- for(Elf enemyElf: game.getEnemyLivingElves())
- {
- if(enemyElf.distance(elf)<=enemyElf.maxSpeed+enemyElf.attackRange)
- {
- enemyCounter+=elf.attackMultiplier;
- }
- }
- for(IceTroll enemyIce: game.getEnemyIceTrolls())
- {
- if(enemyIce.distance(elf)<=enemyIce.attackRange+enemyIce.maxSpeed)
- {
- enemyCounter+=enemyIce.attackMultiplier;
- }
- }
- if(enemyCounter==0)
- return true;
- if(elf.currentHealth-enemyCounter>building.currentHealth+2)
- return true;
- return false;
- }
- public static Location whereElfShouldBuildAttackPortalSides(Elf elf,Game game)
- {
- int[] degrees=new int[360];
- degrees[0]=180;
- int degreesCounter=179;
- Castle enemyCastle=game.getEnemyCastle();
- int startingRad=(int)(game.getMyCastle().distance(enemyCastle)/2.5);
- for(int i=1;i<degrees.length-1;i+=2)//creating the degrees array
- {
- degrees[i]=degreesCounter;
- degrees[i+1]=degreesCounter*-1;
- degreesCounter--;
- }
- boolean found=false;
- int MaxDist=game.getMyCastle().distance(enemyCastle)/2;
- for(int radius=startingRad;radius<=MaxDist;radius+=game.portalSize)
- {
- for(int i=1;i+1<degrees.length;i+=2)
- {
- Location loc1=trigoLocation(enemyCastle.getLocation().row,enemyCastle.getLocation().col,game.getMyCastle().getLocation(),radius,degrees[i]);
- Location loc2=trigoLocation(enemyCastle.getLocation().row,enemyCastle.getLocation().col,game.getMyCastle().getLocation(),radius,degrees[i+1]);
- if(game.canBuildPortalAt(loc1)&&game.canBuildPortalAt(loc2))
- {
- if(elf.distance(loc1)<elf.distance(loc2))
- return loc1;
- else
- return loc2;
- }
- }
- }
- return trigoLocation(enemyCastle.getLocation().row,enemyCastle.getLocation().col,elf.getLocation(),startingRad,0);
- }
- public static Location whereElfShouldBuildAttackPortal(Elf elf,Game game)
- {
- int[] degrees=new int[360];
- degrees[0]=0;
- int degreesCounter=1;
- Castle enemyCastle=game.getEnemyCastle();
- int startingRad=(int)(game.getMyCastle().distance(enemyCastle)/2.5);
- for(int i=1;i<degrees.length-1;i+=2)//creating the degrees array
- {
- degrees[i]=degreesCounter;
- degrees[i+1]=degreesCounter*-1;
- degreesCounter++;
- }
- boolean found=false;
- int MaxDist=game.getMyCastle().distance(enemyCastle)/2;
- for(int radius=startingRad;radius<=MaxDist;radius+=game.portalSize)
- {
- for(int i=0;i<degrees.length;i++)
- {
- if(game.canBuildPortalAt(trigoLocation(enemyCastle.getLocation().row,enemyCastle.getLocation().col,elf.getLocation(),radius,degrees[i])))
- {
- return trigoLocation(enemyCastle.getLocation().row,enemyCastle.getLocation().col,elf.getLocation(),radius,degrees[i]);
- }
- }
- }
- return trigoLocation(enemyCastle.getLocation().row,enemyCastle.getLocation().col,elf.getLocation(),startingRad,0);
- }
- public static Portal getClosestEnemyPortal(Elf elf,Game game)
- {
- if(game.getEnemyPortals().length==0)
- return null;
- Portal minP=game.getEnemyPortals()[0];
- for(Portal p : game.getEnemyPortals())
- {
- if(elf.distance(p)<elf.distance(minP))
- {
- minP=p;
- }
- }
- return minP;
- }
- public static Location whereFightWillHappen(Elf elf,Game game)
- {
- int xCenterOfFight=elf.getLocation().row;
- int yCenterOffFight=elf.getLocation().col;
- for(Elf allyElf : game.getMyLivingElves())
- {
- if(allyElf!=elf&&allyElf.distance(elf)<elf.maxSpeed*5+elf.attackRange)
- {
- xCenterOfFight=(xCenterOfFight+allyElf.getLocation().row)/2;
- yCenterOffFight=(yCenterOffFight+allyElf.getLocation().col)/2;
- }
- }
- for(Elf enemyElf : game.getEnemyLivingElves())
- {
- if(enemyElf.distance(elf)<elf.maxSpeed*5+elf.attackRange)
- {
- xCenterOfFight=(xCenterOfFight+enemyElf.getLocation().row)/2;
- yCenterOffFight=(yCenterOffFight+enemyElf.getLocation().col)/2;
- }
- }
- Location retLoc=new Location(xCenterOfFight,yCenterOffFight);
- return retLoc;
- }
- public static boolean isWorthAttacking(Elf elf,double agroLevel, Game game)
- {
- int allyElvesAround=1;
- int enemyElvesAround=0;
- int allyLivesAround=elf.currentHealth;
- int enemyLivesAround=0;
- int isFightUrgent = 0;
- Location fightLoc=whereFightWillHappen(elf,game);
- if(fightLoc.distance(game.getMyCastle()) - game.getMyCastle().size <= game.elfMaxSpeed * 2 + game.elfAttackRange) isFightUrgent = 1;
- if(elf.distance(fightLoc)>elf.maxSpeed*5+elf.attackRange)
- return false;
- for(Elf enemyElf : game.getEnemyLivingElves())
- {
- if(enemyElf.distance(fightLoc)<=elf.maxSpeed*5+elf.attackRange)
- {
- enemyElvesAround++;
- enemyLivesAround+=enemyElf.currentHealth;
- }
- }
- for(Elf allyElf : game.getMyLivingElves())
- {
- if(allyElf!=elf)
- {
- if(allyElf.distance(fightLoc)<=elf.maxSpeed*5+elf.attackRange)
- {
- allyElvesAround++;
- allyLivesAround+=allyElf.currentHealth;
- }
- }
- }
- if(allyLivesAround * (1 + (isFightUrgent * 0.4))<=enemyLivesAround)
- return false;
- for(IceTroll allyIce : game.getMyIceTrolls())
- {
- if(allyIce.distance(fightLoc)<=elf.maxSpeed*5+elf.attackRange)
- {
- if(allyIce.currentHealth-(allyIce.distance(fightLoc)/allyIce.maxSpeed)*game.iceTrollSuffocationPerTurn>0.5*game.iceTrollMaxHealth)
- {
- allyElvesAround++;
- allyLivesAround+=allyIce.currentHealth;
- }
- }
- }
- for(IceTroll enemyIce : game.getEnemyIceTrolls())
- {
- if(enemyIce.currentHealth-(enemyIce.distance(fightLoc)/enemyIce.maxSpeed)*game.iceTrollSuffocationPerTurn>0.5*game.iceTrollMaxHealth||enemyIce.attackRange>=enemyIce.distance(fightLoc))
- {
- enemyElvesAround++;
- enemyLivesAround+=enemyIce.currentHealth;
- }
- }
- if(allyElvesAround>=enemyElvesAround&&allyLivesAround*allyElvesAround*game.elfAttackMultiplier * (1 + (isFightUrgent * 0.4)) >enemyLivesAround*enemyElvesAround*agroLevel)
- {
- ////System.out.println("WORTH ATTACKING!");
- return true;
- }
- ////System.out.println("NOT WORTH ATTACKING!");
- return false;
- }
- public static Elf isThereEnemyElfAttacking(Game game)
- {
- Elf minElf=null;
- for(Elf enemyElf:game.getEnemyLivingElves())
- {
- if((enemyElf.distance(game.getMyCastle())-game.getMyCastle().size-enemyElf.attackRange)/enemyElf.maxSpeed<=15)
- {
- if(minElf==null)
- minElf=enemyElf;
- else
- {
- if(minElf.distance(game.getMyCastle())>enemyElf.distance(game.getMyCastle()))
- minElf=enemyElf;
- }
- }
- }
- return minElf;
- }
- public static void GoingToEnemyAttackingElf(Elf elf,Game game) {
- Elf enemyElf=isThereEnemyElfAttacking(game);
- if(elf.inAttackRange(enemyElf)&&isWorthAttacking(elf,1.2,game))
- elf.attack(enemyElf);
- else
- elf.moveTo(safteyLoc(elf.getLocation(),enemyElf.getLocation(),game.elfMaxSpeed,game));
- }
- public static Elf elfToFocus(Elf elf,Game game)
- {
- if(game.getEnemyLivingElves().length==0)
- return null;
- Elf elfToAttack=null;
- Location fightLocation=whereFightWillHappen(elf,game);
- for(Elf Eelf:game.getEnemyLivingElves())
- {
- if(elfToAttack==null)
- {
- if(Eelf.distance(fightLocation)<=Eelf.maxSpeed*3)
- elfToAttack=Eelf;
- }
- else if(Eelf.currentHealth<=elfToAttack.currentHealth-2&&Eelf.distance(fightLocation)<=Eelf.maxSpeed*5&&Eelf.distance(fightLocation)-Eelf.maxSpeed*3<elfToAttack.distance(fightLocation))
- elfToAttack=Eelf;
- }
- return elfToAttack;
- }
- public static boolean tryToAttackElf(Elf elf,Game game)
- {
- if(isWorthAttacking(elf,1.3,game)==false)
- return false;
- boolean attacked=false;
- Elf enemyElf=elfToFocus(elf,game);
- if(enemyElf==null)
- return false;
- if(elf.inAttackRange(enemyElf))
- {
- attacked=true;
- }
- //EXPLAIN!
- else if(enemyElf.distance(elf)<game.elfMaxSpeed*5+elf.attackRange&&isEnemyElfAttackingOurElf(enemyElf,game)==true || enemyElf.distance(elf)<=game.elfMaxSpeed+game.elfAttackRange||(enemyElf.distance(elf)<=game.elfMaxSpeed*2+game.elfAttackRange&&isObjectGoingForwardMe(enemyElf,elf,game)))
- {
- if(!(elf.distance(game.getMyCastle())>elf.distance(game.getEnemyCastle())&&isThereEnemyElfAttacking(game)!=null))
- attacked=true;
- }
- return attacked;
- }
- public static void attackEnemyElf(Elf elf,Game game) {
- Elf enemyElf=elfToFocus(elf,game);
- if(elf.inAttackRange(enemyElf))
- {
- //System.out.println("in Attack Range so attacking");
- elf.attack(enemyElf);
- }
- else {
- //System.out.println("moving to attack");
- elf.moveTo(enemyElf);
- }
- }
- public static boolean isEnemyElfAttackingOurElf(Elf enemyElf,Game game)
- {
- for(Elf elf : game.getMyLivingElves())
- {
- if(enemyElf.distance(elf)<=elf.maxSpeed+elf.attackRange)
- return true;
- }
- return false;
- }
- public static boolean isThereClosePortalToCastle(Game game)
- {
- boolean isThereClosePortal=false;
- for(Portal portal :game.getEnemyPortals())
- {
- if(portal.distance(game.getMyCastle())/portal.distance(game.getEnemyCastle())<=1)
- {
- isThereClosePortal=true;
- }
- }
- return isThereClosePortal;
- }
- public static Portal closestEnemyPortalToOurCastle(Game game)
- {
- if(game.getEnemyPortals().length==0)
- return null;
- Portal mPortal=game.getEnemyPortals()[0];
- for(Portal portal :game.getEnemyPortals())
- {
- if(portal.distance(game.getMyCastle())<=mPortal.distance(game.getMyCastle()))
- {
- mPortal=portal;
- }
- }
- return mPortal;
- }
- public static int numOfEnoughClosePortalToEnemyCastle(Game game)
- {
- int counter=0;
- for(Portal portal :game.getMyPortals())
- {
- if(portal.distance(game.getEnemyCastle())<=portal.distance(game.getMyCastle()))
- {
- counter++;
- }
- }
- return counter;
- }
- public static boolean isSafeLocForSike(Location loc, Location preLoc,Game game)
- {
- int enemyCount=0;
- for(Elf enemy: game.getEnemyLivingElves())//enemy saftey
- {
- double enemySpeed= enemy.maxSpeed;
- Location enemyNextLoc=enemy.getLocation().towards(preLoc,enemy.maxSpeed);
- // //System.out.println(enemySpeed+" id "+enemy.id);
- if(enemyNextLoc.distance(loc)<=enemy.attackRange*1.1)////////play with the numbers/////////
- {
- int allycount=0;
- for(Elf elf : game.getMyLivingElves())
- {
- if(elf.distance(loc)<=elf.attackRange*1.1)
- allycount++;
- }
- enemyCount++;
- //if(enemyCount>=2|| enemyCount==1 && enemy.currentHealth*1.5>=allycount*game.elfMaxHealth)
- return false;
- }
- }
- for(IceTroll enemy: game.getEnemyIceTrolls())//enemy saftey
- {
- double enemySpeed= enemy.maxSpeed;
- Location enemyNextLoc=enemy.getLocation().towards(preLoc,enemy.maxSpeed);
- // //System.out.println(enemySpeed+" id "+enemy.id);
- if(enemyNextLoc.distance(loc)<=enemy.attackRange*1.1)////////play with the numbers/////////
- {
- enemyCount++;
- if(enemyCount>=1)
- return false;
- }
- }
- if(loc.row<=0||loc.col<=0||loc.col>=game.cols||loc.row>=game.rows)
- return false;
- return true;
- }
- public static boolean isSafeLoc(Location loc,Game game)
- {
- int enemyCount=0;
- /*for(Mothership mother: game.getAllMotherships())
- {
- if(mother.distance(loc)<game.pirateMaxSpeed)
- return true;
- }//WTF*/
- for(Elf enemy: game.getEnemyLivingElves())//enemy saftey
- {
- double enemySpeed= enemy.maxSpeed;
- Location enemyNextLoc=enemy.getLocation().towards(loc,enemy.maxSpeed);
- // //System.out.println(enemySpeed+" id "+enemy.id);
- if(enemyNextLoc.distance(loc)<=enemy.attackRange*1.1+enemy.maxSpeed)////////play with the numbers/////////
- {
- int allycount=0;
- for(Elf elf : game.getMyLivingElves())
- {
- if(elf.distance(loc)<=elf.attackRange*1.1+enemy.maxSpeed)
- allycount++;
- }
- enemyCount++;
- if(enemyCount>=2|| enemyCount==1 && enemy.currentHealth*1.5>=allycount*game.elfMaxHealth)
- return false;
- }
- }
- for(IceTroll enemy: game.getEnemyIceTrolls())//enemy saftey
- {
- double enemySpeed= enemy.maxSpeed;
- Location enemyNextLoc=enemy.getLocation().towards(loc,enemy.maxSpeed);
- // //System.out.println(enemySpeed+" id "+enemy.id);
- if(enemyNextLoc.distance(loc)<=enemy.attackRange*1.1+enemy.maxSpeed)////////play with the numbers/////////
- {
- enemyCount++;
- if(enemyCount>=1)
- return false;
- }
- }
- if(loc.row<=0||loc.col<=0||loc.col>=game.cols||loc.row>=game.rows)
- return false;
- //if(loc.col<0+game.elfMaxSpeed*6||loc.row<0+game.elfMaxSpeed*6||loc.row>game.rows-game.elfMaxSpeed*6||loc.col>game.cols-game.elfMaxSpeed*6)
- //{
- // return false;
- //}
- //if(loc.row<0.6*game.elfAttackRange||loc.col<0.6*game.elfAttackRange||loc.row>game.rows-0.6*game.elfAttackRange||loc.col>game.cols-0.6*game.elfAttackRange)
- // return false;
- return true;
- }
- public static 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)
- {
- if(nearLocY>=diractionLoc.col)
- zavit=90;
- else
- zavit=-90;
- }
- 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;
- }
- public static int safteyRate(Location loc,Location preLoc,Game game)
- {
- int enemyCount=0;
- for(Elf enemy: game.getEnemyLivingElves())//enemy saftey
- {
- double enemySpeed= enemy.maxSpeed;
- Location enemyNextLoc=enemy.getLocation().towards(preLoc,enemy.maxSpeed);
- // //System.out.println(enemySpeed+" id "+enemy.id);
- if(enemyNextLoc.distance(loc)<=enemy.attackRange*1.1)////////play with the numbers/////////
- {
- int allycount=0;
- for(Elf elf : game.getMyLivingElves())
- {
- if(elf.distance(loc)<=elf.attackRange*1.1)
- allycount++;
- }
- enemyCount++;
- //if(enemyCount>=2|| enemyCount==1 && enemy.currentHealth*1.5>=allycount*game.elfMaxHealth)
- }
- }
- for(IceTroll enemy: game.getEnemyIceTrolls())//enemy saftey
- {
- double enemySpeed= enemy.maxSpeed;
- Location enemyNextLoc=enemy.getLocation().towards(preLoc,enemy.maxSpeed);
- // //System.out.println(enemySpeed+" id "+enemy.id);
- if(enemyNextLoc.distance(loc)<=enemy.attackRange*1.1)////////play with the numbers/////////
- {
- enemyCount++;
- }
- }
- if(loc.row<=0||loc.col<=0||loc.col>=game.cols||loc.row>=game.rows)
- return game.getEnemyIceTrolls().length+game.getEnemyLivingElves().length;
- return enemyCount;
- }
- public static Location safteyLoc(Location elf,Location diractionLoc,double radius2,Game game)
- {
- if(diractionLoc.row<=0||diractionLoc.col<=0||diractionLoc.col>=game.cols||diractionLoc.row>=game.rows)
- return diractionLoc;
- //radius=game.pirateMaxSpeed;
- int[] degrees=new int[360];
- degrees[0]=0;
- int degreesCounter=1;
- //radius=game.elfMaxSpeed;
- for(int i=1;i<degrees.length-1;i+=2)//creating the degrees array
- {
- degrees[i]=degreesCounter;
- degrees[i+1]=degreesCounter*-1;
- degreesCounter++;
- }
- Location loc=trigoLocation(elf.row,elf.col,diractionLoc,game.elfMaxSpeed,degrees[0]);
- int safteyRateInt=safteyRate(loc,elf,game);
- for(int radius=game.elfMaxSpeed;radius<=game.elfMaxSpeed*2;radius+=50)
- {
- for(int i=0;i<degrees.length;i++)
- {
- Location locToCheck=trigoLocation(elf.row,elf.col,diractionLoc,radius,degrees[i]);
- if(isSafeLocForSike(locToCheck,elf,game))
- {
- //if(isSafeLocForSike(trigoLocation(elf.row,elf.col,diractionLoc,radius+50,degrees[i]),elf,game))
- //{
- ////System.out.println(degrees[i]);
- if(closestAllyPortalToLoc(elf,game)!=null&&Math.abs(degrees[i])>90&&elf.distance(closestAllyPortalToLoc(elf,game))>=game.elfMaxSpeed*1.5)
- {
- if(diractionLoc==closestAllyPortalToLoc(elf,game))
- return locToCheck;
- else
- return safteyLoc(elf,closestAllyPortalToLoc(elf,game),game.elfMaxSpeed+50,game);
- }
- return locToCheck;
- //}
- }
- int safteyRateCurrent=safteyRate(locToCheck,elf,game);
- if(safteyRateInt>safteyRateCurrent&&safteyRateCurrent>=0)
- {
- loc=locToCheck;
- }
- }
- }
- //System.out.println("choses most safe loc");
- return loc;
- }
- public static Location closestAllyPortalToLoc(Location loc,Game game)
- {
- if(game.getMyPortals().length==0)
- return null;
- Portal maxPort=game.getMyPortals()[0];
- for(Portal portal:game.getMyPortals())
- {
- if(portal.distance(loc)<maxPort.distance(loc))
- maxPort=portal;
- }
- return maxPort.getLocation();
- }
- ///////////////////////////////////////////////////////////////////////////////////////////
- public static void IceOrFire(Portal portal, Game game){
- //System.out.println();
- //System.out.println(portal);
- //System.out.println();
- if(EnemyThreatningPortal(game)!=null)
- enemyAttackingLoc=game.getMyCastle().getLocation().towards(EnemyThreatningPortal(game),game.lavaGiantAttackRange+game.getMyCastle().size);
- else
- enemyAttackingLoc=null;
- if(game.getEnemyCastle().currentHealth<10){
- //System.out.println("Less than 10 life");
- if(portal==closestPortalToEnemyCastle(game)&&portal.canSummonLavaGiant()){
- portal.summonLavaGiant();
- }
- }
- ////**1**\\\\
- //if There is Enemy Elf Near Portal: summon Ice Troll
- ////////////////////////////////PLAY! MAYBE ANOTHE FUNCTION WITH HARSHER CONDITIONS///////////////////////////////////
- double numberOfIceToGo=NumberOfIceNeededForDefense(game)-allyIceAroundLoc(enemyAttackingLoc, game);
- if(IcePortal(game,portal))
- {
- System.out.println("number of ice to go: "+numberOfIceToGo);
- }
- ////System.out.println("number of ice needed for defense: "+NumberOfIceNeededForDefense(game));
- if(isThereEnemyElfNearPortal(portal,game)&&!AttackingPortalsSummonigFire(portal,game)&&numberOfIceToGo<3) {
- if(game.getMyMana()>=handleMana(portal,game)+game.iceTrollCost) {
- if(portal.canSummonIceTroll()){
- //System.out.println("I summon ice close enemy elf: "+portal);
- portal.summonIceTroll();
- }
- }
- }
- ////**3**\\\\
- //if portal is a defense portal, and we have enough mana: summon ice Troll
- else if(IcePortal(game,portal)&&numberOfIceToGo>1.5) {
- //if there aren't enough ice trolls or portal is attacked: summon ice trolls
- if(game.getMyMana()>=handleMana(portal,game)+game.iceTrollCost||(numberOfIceToGo>=3&&game.getMyMana()>=game.iceTrollCost)){//||(isEnemyElfAttackingMyCastle(game) && game.getMyMana() >= game.iceTrollCost)) {
- if(portal.canSummonIceTroll()){
- //System.out.println("I summon ice enemy attacking my castle: "+portal);
- portal.summonIceTroll();
- }
- }
- }
- /*else if(IcePortal(game,portal)&&numberOfIceToGo>=1&&game.getMyMana()>=game.iceTrollCost*3+handleMana(portal,game))
- if(portal.canSummonIceTroll())
- portal.summonIceTroll();
- */
- else if(isPortalNeededToHelpAllyElf(portal,game)&&allyIceAroundLoc(enemyAttackingLoc,game)>NumberOfIceNeededForDefense(game)&&isItWorthSummoningFire(closestPortalToEnemyCastle(game),game)<15){
- if(game.getMyMana()>=handleMana(portal,game)+game.lavaGiantCost)
- if(portal.canSummonLavaGiant()){
- //System.out.println("Sumonned lava to help elf: " +portal);
- portal.summonLavaGiant();
- }
- }
- ///**2**\\\\
- //if portal is an attack portal and we have enough mana: summon lava Giant
- else if(FirePortal(game, portal)&&numberOfIceToGo<1.5)
- {
- // //System.out.println("Fire: "+ portal);
- if(game.getMyMana() >= handleMana(portal,game)+game.lavaGiantCost)
- {
- if(portal.canSummonLavaGiant()){
- //System.out.println("I summon fire to attack: "+ portal);
- portal.summonLavaGiant();
- }
- }
- }
- }
- public static boolean isObjectGoingForwardMe(Elf enemy, GameObject obj,Game game)
- {
- if(!enemy.isAlive())
- return false;
- boolean returned=false;
- for(int i=0;i<game.getAllEnemyElves().length;i++)
- {
- if(game.getAllEnemyElves()[i]==enemy)
- {
- if(enemyElvesLocations[i].getLocation().row==enemy.getLocation().row&&enemyElvesLocations[i].getLocation().col==enemy.getLocation().col)
- returned= true;
- if(enemyElvesLocations[i].distance(obj)>=enemy.distance(obj))
- returned= true;
- else
- returned= false;
- }
- }
- return returned;
- }
- public static boolean isItWorthSummoningIceToDefPortal(Portal portal,Elf enemy,Game game)
- {
- if(enemy.distance(portal)-portal.size-enemy.attackRange<=enemy.maxSpeed*2)
- return true;
- for(IceTroll ice:game.getMyIceTrolls())
- {
- if(ice.distance(portal)<portal.distance(enemy)&&ice.distance(enemy)<portal.distance(enemy)&&ice.currentHealth>=game.iceTrollSummoningDuration)
- {
- //System.out.println(portal+" it is not worth summoning ice to def this portal");
- return false;
- }
- }
- return true;
- }
- public static boolean isThereEnemyElfNearPortal(Portal portal, Game game) {
- for(Elf enemyElf: game.getEnemyLivingElves()) {
- double distance=portal.distance(enemyElf)-portal.size-enemyElf.attackRange;
- double timeForEnemyElfToGetToPortal= distance/enemyElf.maxSpeed;
- double distancePortFromSpot=portal.size+enemyElf.attackRange-game.iceTrollAttackRange;
- int mana=game.defaultManaPerTurn;
- if(mana==0)
- mana=5;
- double turnsToStartSummoningIce=(-game.getMyMana()+(game.iceTrollCost))/mana;
- if(game.getMyMana()>=game.iceTrollCost)
- turnsToStartSummoningIce=0;
- double timeForIceToGetToPortal=turnsToStartSummoningIce+game.iceTrollSummoningDuration+distancePortFromSpot/game.iceTrollMaxSpeed;
- if(timeForIceToGetToPortal+2>=timeForEnemyElfToGetToPortal&&isObjectGoingForwardMe(enemyElf,portal,game)&&isItWorthSummoningIceToDefPortal(portal,enemyElf,game))
- {
- double minDist=portal.distance(enemyElf);
- boolean flag=true;
- for(Portal port:game.getMyPortals())
- {
- if(port!=portal&&port.distance(enemyElf)<minDist&&isObjectGoingForwardMe(enemyElf,port,game))
- flag=false;
- }
- if(flag==true)
- {
- //System.out.println("CLOSE ELF");
- return true;
- }
- }
- }
- return false;
- }
- public static int getIndexByPortal(Portal portal, Game game) {
- int index=0;
- for(int i=0;i<game.getMyPortals().length;i++) {
- if(game.getMyPortals()[i]==portal)
- index=i;
- }
- return index;
- }
- public static int allyIceAroundLoc(Location location, Game game) {
- if(EnemyThreatningPortal(game)==null){
- return game.getMyIceTrolls().length;
- }
- int allyIceAroundLoc=0;
- for(IceTroll Ice:game.getMyIceTrolls()) {
- ////System.out.println("ObjectdistanceFromALine: "+ObjectdistanceFromALine(Ice, EnemyThreatningPortal(game),game.getMyCastle()));
- if(Ice.distance(location)<Ice.maxSpeed*4/*&&ObjectdistanceFromALine(Ice, EnemyThreatningPortal(game),game.getMyCastle())<game.iceTrollMaxSpeed*4*/&&Ice.currentHealth>3) {
- allyIceAroundLoc++;
- }
- }
- return allyIceAroundLoc;
- }
- public static double ObjectdistanceFromALine(GameObject object, GameObject objectOnLine1 , GameObject objectOnLine2){
- //y=mx+b
- if(object==null||objectOnLine1==null||objectOnLine2==null)
- return 0;
- double m=getSlopeByTwoMapObjects(objectOnLine1,objectOnLine2);
- double b=objectOnLine1.getLocation().col-m*objectOnLine1.getLocation().row;
- double distance=Math.abs(-m*object.getLocation().row+object.getLocation().col-b)/Math.sqrt(m*m+1);
- return distance;
- }
- public static boolean isEnemyElfAttackingMyCastle(Game game){
- for(Elf elf : game.getEnemyLivingElves())
- {
- if(elf.distance(game.getMyCastle())<=elf.attackRange+elf.maxSpeed*5+game.getMyCastle().size)
- {
- //System.out.println("BASE IS BEING ATTACKED-- Enemy Elf");
- //System.out.println("BASE IS BEING ATTACKED-- Enemy Elf");
- //System.out.println("BASE IS BEING ATTACKED-- Enemy Elf");
- return true;
- }
- }
- return false;
- }
- public static int EnemyLavaAttackingMyCastle(Game game) {
- int lavaCounter=0;
- if(EnemyThreatningPortal(game)!=null)
- {
- enemyAttackingLoc=game.getMyCastle().getLocation().towards(EnemyThreatningPortal(game),game.lavaGiantAttackRange+game.getMyCastle().size);
- for(LavaGiant lava:game.getEnemyLavaGiants())
- {
- if(lava.currentHealth-(lava.distance(game.getMyCastle())-game.lavaGiantAttackRange-game.getMyCastle().size)/game.lavaGiantMaxSpeed/game.lavaGiantSuffocationPerTurn>=3)
- lavaCounter++;
- }
- }
- else
- {
- for(LavaGiant lava:game.getEnemyLavaGiants())
- {
- if(lava.currentHealth-(lava.distance(game.getMyCastle())-game.lavaGiantAttackRange-game.getMyCastle().size)/game.lavaGiantMaxSpeed/game.lavaGiantSuffocationPerTurn>=3)
- lavaCounter++;
- }
- }
- //System.out.println("Lava Counter: "+lavaCounter);
- if(lavaCounter>2) {
- System.out.println("BASE IS BEING ATTACKED-- Enemy Lava");
- //System.out.println("BASE IS BEING ATTACKED-- Enemy Lava");
- //System.out.println("BASE IS BEING ATTACKED-- Enemy Lava");
- }
- return lavaCounter;
- }
- //Fire\\
- public static boolean FirePortal(Game game, Portal portal) {
- if(portal==closestPortalToEnemyCastle(game)&&isItWorthSummoningFire(portal,game)>=10&&NumberOfIceNeededForDefense(game)-allyIceAroundLoc(enemyAttackingLoc,game)<3||isItWorthSummoningFire(portal,game)>15&&!IcePortal(game, portal)) {
- if(portal.canSummonLavaGiant()) {
- return true;
- }
- }
- return false;
- }
- public static Portal closestPortalToEnemyCastle(Game game){
- if(game.getMyPortals().length==0)
- return null;
- Portal mPortal=game.getMyPortals()[0];
- for(Portal portal :game.getMyPortals())
- {
- if(portal.distance(game.getEnemyCastle())<=mPortal.distance(game.getEnemyCastle())&&portal.canSummonLavaGiant())
- {
- mPortal=portal;
- }
- }
- return mPortal;
- }
- public static double isItWorthSummoningFire(Portal portal, Game game){
- return game.lavaGiantMaxHealth-(portal.distance(game.getEnemyCastle())-game.lavaGiantAttackRange-game.getEnemyCastle().size)/game.lavaGiantMaxSpeed/game.lavaGiantSuffocationPerTurn-numOfEnemyIceDefenders(portal,game);
- }
- public static int numOfEnemyIceDefenders(Portal portal, Game game){
- Location OurAttackingLoc=game.getEnemyCastle().getLocation().towards(portal,game.lavaGiantAttackRange+game.getEnemyCastle().size);
- int counter=0;
- for(IceTroll ice: game.getEnemyIceTrolls())
- {
- if(ice.distance(OurAttackingLoc)<game.iceTrollMaxSpeed*5+game.iceTrollAttackRange)
- counter++;
- }
- return counter;
- }
- //Ice\\
- public static boolean IcePortal(Game game, Portal portal) {
- if(IsThereAnEnemyAttackingElf(10,game)!=null) {
- if(portal==ClosestPortalToEnemyElf(game,ClosestEnemyElfToOurCastle(game))&&isObjectGoingForwardMe(ClosestEnemyElfToOurCastle(game),game.getMyCastle(),game)) {
- if(portal.canSummonIceTroll()){
- //System.out.println("This portal is ice for enemy attacking elf: "+portal);
- return true;
- }
- }
- }
- else if(allyIceAroundLoc(enemyAttackingLoc,game)<NumberOfIceNeededForDefense(game)){
- if(portal==PortalToDefenseFire(game))
- if(portal.canSummonIceTroll()){
- //System.out.println("This portal is ice for enemy attacking Lava: "+portal);
- return true;
- }
- }
- return false;
- }
- public static Portal[] getMyDefensePortals(Game game) {
- int DefensePortals=0;
- for(Portal portal : game.getMyPortals()) {
- if(portal.distance(game.getMyCastle()) < portal.distance(game.getEnemyCastle())) {
- DefensePortals++;
- }
- }
- Portal[] DefensePortals1=new Portal[DefensePortals];
- for(int i=0;i<DefensePortals1.length;i++) {
- for(Portal portal : game.getMyPortals()) {
- if(portal.distance(game.getMyCastle()) < portal.distance(game.getEnemyCastle()))
- DefensePortals1[i]=portal;
- }
- }
- return DefensePortals1;
- }
- public static Elf IsThereAnEnemyAttackingElf(int turns, Game game) {
- if(game.getEnemyLivingElves().length==0)
- return null;
- Elf elf=game.getEnemyLivingElves()[0];
- for(Elf EnemyElf: game.getEnemyLivingElves()) {
- if(EnemyElf.maxSpeed*turns>EnemyElf.distance(game.getMyCastle())) {
- if(EnemyElf.distance(game.getMyCastle())<elf.distance(game.getMyCastle())) {
- elf=EnemyElf;
- }
- }
- }
- if(elf.maxSpeed*turns>elf.distance(game.getMyCastle()))
- return elf;
- return null;
- }
- public static Portal PortalToDefenseFire(Game game) {
- if(game.getMyPortals().length==0||game.getEnemyPortals().length==0)
- return null;
- Portal SPortal=game.getMyPortals()[0];
- for(Portal portal : game.getMyPortals()) {
- if(portal.distance(game.getMyCastle().getLocation().towards(EnemyThreatningPortal(game), game.lavaGiantAttackRange+game.getMyCastle().size))<SPortal.distance(game.getMyCastle().getLocation().towards(EnemyThreatningPortal(game), game.lavaGiantAttackRange+game.getMyCastle().size)))
- SPortal=portal;
- }
- // //System.out.println("This is the portal to defense from: "+EnemyThreatningPortal(game));
- // //System.out.println("This is the Portal to defense Fire: "+SPortal);
- return SPortal;
- }
- public static Elf ClosestEnemyElfToOurCastle(Game game) {
- if(game.getEnemyLivingElves().length==0)
- return null;
- Elf OriginalEnemyElf=game.getEnemyLivingElves()[0];
- for(Elf EnemyElf:game.getEnemyLivingElves()) {
- if(EnemyElf.distance(game.getMyCastle())<=OriginalEnemyElf.distance(game.getMyCastle())) {
- OriginalEnemyElf=EnemyElf;
- }
- }
- return OriginalEnemyElf;
- }
- public static Portal ClosestPortalToEnemyElf(Game game, Elf elf) {
- if(game.getMyPortals().length==0)
- return null;
- Portal OriginalPortal=game.getMyPortals()[0];
- for(Portal portal:game.getMyPortals()) {
- if(portal.distance(elf)<=OriginalPortal.distance(elf))
- OriginalPortal=portal;
- }
- return OriginalPortal;
- }
- public static boolean isThereCloseEnemyPortalToCastle(Game game){
- boolean isThereClosePortal=false;
- for(Portal portal :game.getEnemyPortals())
- {
- if(game.lavaGiantMaxHealth-(portal.distance(game.getMyCastle())/game.lavaGiantMaxSpeed)/game.lavaGiantSuffocationPerTurn-allyIceAroundLoc(enemyAttackingLoc,game)>=3)
- {
- isThereClosePortal=true;
- }
- }
- return isThereClosePortal;
- }
- public static Portal EnemyThreatningPortal(Game game) {
- if(closestEnemyPortalToOurCastle(game)==null)
- return null;
- Portal OEnemyPortal=game.getEnemyPortals()[0];
- for(Portal EnemyPortal : game.getEnemyPortals()){
- if(getEnemyLavaGiantsByPortal(game,EnemyPortal)>getEnemyLavaGiantsByPortal(game,OEnemyPortal)) {
- OEnemyPortal=EnemyPortal;
- if(getEnemyLavaGiantsByPortal(game,EnemyPortal)>getEnemyLavaGiantsByPortal(game,OEnemyPortal)){
- }
- }
- }
- if(getEnemyLavaGiantsByPortal(game,OEnemyPortal)==0)
- return closestEnemyPortalToOurCastle(game);
- ////System.out.println("EnemyThreatningPortal: "+OEnemyPortal+" Lava for this portal: "+getEnemyLavaGiantsByPortal(game,OEnemyPortal));
- return OEnemyPortal;
- }
- public static double getSlopeByTwoMapObjects(MapObject FistObject,MapObject SecondObject) {
- double Slope;
- double DeltaY;
- double DeltaX;
- DeltaY=FistObject.getLocation().col-SecondObject.getLocation().col;
- DeltaX=FistObject.getLocation().row-SecondObject.getLocation().row;
- Slope=DeltaY/DeltaX;
- return Slope;
- }
- public static int getEnemyLavaGiantsByPortal(Game game, Portal portal) {
- if(portal==null)
- return 0;
- double slopePC=getSlopeByTwoMapObjects(portal,game.getMyCastle());
- int lavaGiantsOnSlope=0;
- for(LavaGiant LavaGiant : game.getEnemyLavaGiants()) {
- if(Math.abs(getSlopeByTwoMapObjects(LavaGiant,game.getMyCastle())-slopePC)<0.5) {
- lavaGiantsOnSlope++;
- }
- }
- return lavaGiantsOnSlope;
- }
- public static boolean isElfInNeedOfFire(Elf elf,Portal portal,Game game)
- {
- for(IceTroll enemyIce: game.getEnemyIceTrolls())
- {
- if(enemyIce.distance(elf)<=enemyIce.attackRange+enemyIce.maxSpeed*2&&enemyIce.currentHealth/enemyIce.suffocationPerTurn>=portal.distance(elf)/game.lavaGiantMaxSpeed)
- {
- return true;
- }
- }
- return false;
- }
- public static boolean isPortalNeededToHelpAllyElf(Portal portal,Game game)
- {
- if(game.getMyLivingElves().length==0)
- return false;
- Elf elfToHelp=null;
- for(Elf elf:game.getMyLivingElves())
- {
- if(isElfInNeedOfFire(elf,portal,game)==true)
- {
- elfToHelp=elf;
- }
- }
- if(elfToHelp==null)
- {
- return false;
- }
- IceTroll iceToDef=null;
- for(IceTroll enemyIce: game.getEnemyIceTrolls())
- {
- if(enemyIce.distance(elfToHelp)<=enemyIce.attackRange+enemyIce.maxSpeed*2&&enemyIce.currentHealth/enemyIce.suffocationPerTurn>=portal.distance(elfToHelp)/game.lavaGiantMaxSpeed+3)
- {
- iceToDef=enemyIce;
- }
- }
- if(iceToDef==null)
- return false;
- Portal bestP=null;
- double minDist=game.rows*game.rows;//biggy
- for(Portal myPort:game.getMyPortals())
- {
- if(myPort.distance(game.getEnemyCastle())>elfToHelp.distance(game.getEnemyCastle()))
- {
- //double elfDistLineFromIce=ObjectdistanceFromALine(elfToHelp,iceToDef,);
- double mMyPortCastle=getSlopeByTwoMapObjects(myPort,game.getEnemyCastle());
- double mElfCastle=getSlopeByTwoMapObjects(elfToHelp,game.getEnemyCastle());
- mMyPortCastle=Math.atan(mMyPortCastle);
- mElfCastle=Math.atan(mMyPortCastle);
- if(Math.abs(mMyPortCastle-mElfCastle)<=Math.PI/6 && myPort.distance(elfToHelp)<minDist && myPort.distance(elfToHelp)/game.lavaGiantMaxSpeed+game.lavaGiantSummoningDuration<elfToHelp.currentHealth)
- {
- minDist=myPort.distance(elfToHelp);
- bestP=myPort;
- }
- }
- }
- if(bestP!=null&&bestP==portal)
- {
- //System.out.println(bestP+" "+elfToHelp+" "+iceToDef+" this portal SHOULD SUMMON FIRE TO HELP ELF");
- return true;
- }
- return false;
- }
- public static boolean AttackingPortalsSummonigFire(Portal port,Game game){
- int countSuperAttackingPortals=0;
- boolean flag=false;
- for(Portal portal:game.getMyPortals()){
- if(portal.distance(game.getEnemyCastle())<=game.lavaGiantMaxSpeed*8+game.lavaGiantAttackRange+game.getEnemyCastle().size)
- {
- countSuperAttackingPortals++;
- if(portal==port)
- flag=true;
- }
- }
- if(countSuperAttackingPortals>1&&flag==true)
- return true;
- else
- return false;
- }
- public static double NumberOfIceNeededForDefense(Game game){
- if(EnemyThreatningPortal(game)!=null){
- double FinalLavaLife;
- double NumberOfIceNeededForDefense=0;
- if(game.getEnemyLavaGiants().length==0)
- return 0;
- LavaGiant maxLava=game.getEnemyLavaGiants()[0];
- for(LavaGiant lava:game.getEnemyLavaGiants())
- {
- if(lava.distance(game.getMyCastle())>maxLava.distance(game.getMyCastle()))
- maxLava=lava;
- }
- FinalLavaLife=maxLava.currentHealth-(maxLava.distance(game.getMyCastle().getLocation().towards(maxLava,game.castleSize+maxLava.attackRange)))/game.lavaGiantMaxSpeed/game.lavaGiantSuffocationPerTurn;
- //System.out.println(FinalLavaLife+" "+maxLava+" life that maxLava will have when close to my castle "+maxLava.currentHealth);
- NumberOfIceNeededForDefense=(FinalLavaLife*0.8)/3;
- //if(maxLava.distance(game.getMyCastle().getLocation().towards(maxLava,game.castleSize+maxLava.attackRange))/game.lavaGiantMaxSpeed/game.lavaGiantSuffocationPerTurn>game.iceTrollSummoningDuration*NumberOfIceNeededForDefense)
- // return 0;
- //if(game.getEnemyLavaGiants().length<3)
- // return EnemyLavaAttackingMyCastle(game);
- return NumberOfIceNeededForDefense;
- }
- return 0;
- }
- public static int getPortalImportance(Portal portal, Game game) {
- int importance;
- if(isThereEnemyElfNearPortal(portal,game)&&!AttackingPortalsSummonigFire(portal,game)) {
- importance=4;
- }
- else if(IcePortal(game,portal)) {
- importance=3;
- }
- else if(isPortalNeededToHelpAllyElf(portal,game)) {
- importance=2;
- }
- else if(FirePortal(game, portal)) {
- importance=1;
- }
- else
- importance=0;
- return importance;
- }
- public static int handleMana(Portal portal, Game game) {
- boolean EnemyElfNearPortal=false;
- for(Portal APortal: game.getMyPortals()){
- if(isThereEnemyElfNearPortal(APortal,game)&&!AttackingPortalsSummonigFire(APortal,game))
- EnemyElfNearPortal=true;
- }
- double iceToGo=NumberOfIceNeededForDefense(game)-allyIceAroundLoc(enemyAttackingLoc,game);
- int ManaSave = 0;
- int PortalImportance=getPortalImportance(portal,game);
- for(int i=getIndexByPortal(portal,game);i<game.getMyPortals().length;i++) {
- if(PortalImportance<getPortalImportance(game.getMyPortals()[i],game)) {
- if(getPortalImportance(game.getMyPortals()[i],game)==4){
- //System.out.println("Saving for Close elf");
- ManaSave+=game.iceTrollCost;
- }
- else if(getPortalImportance(game.getMyPortals()[i],game)==3){
- //System.out.println("Saving for defense");
- ManaSave+=game.iceTrollCost;
- }
- else if(getPortalImportance(game.getMyPortals()[i],game)==2){
- //System.out.println("Saving for Lava help");
- ManaSave+=game.lavaGiantCost;
- }
- else if(getPortalImportance(game.getMyPortals()[i],game)==1){
- //System.out.println("Saving mana to attack");
- ManaSave+=game.lavaGiantCost;
- }
- else
- ManaSave+=0;
- }
- }
- if(shouldIbuildManaFountain(game)&&!EnemyElfNearPortal&&(iceToGo<1.5||game.getMyself().manaPerTurn==0)){
- System.out.println("Saving for mana fountain");
- ManaSave+=game.manaFountainCost;
- }
- if(EnemyElfNearPortal&&ManaSave<game.iceTrollCost&&PortalImportance<3){
- //System.out.println("Saving for near elf");
- ManaSave+=game.iceTrollCost;
- }
- if(!isThereDefPortals(game)&&isElfTryingToBuildPortal){
- //System.out.println("Saving for defense portal");
- ManaSave+=game.portalCost;
- }
- if(isElfTryingToBuildPortal&&iceToGo<2.1) {
- //System.out.println("Saving for attack portal");
- ManaSave+=game.portalCost-game.getMyself().manaPerTurn;
- }
- System.out.println("ManaSave= "+ManaSave+" Portal: "+portal);
- return ManaSave;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement