Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using ElfKingdom;
- namespace MyBot
- {
- public class TutorialBot : ISkillzBot
- {
- bool DefenderCanBuild = true;
- bool EnemyIsBunker = true;
- ////Portal [] EnemysPortalArr = IfTheEnemyPlaysBunker(game.GetEnemyCastle(), game);
- public void DoTurn(Game game)
- {
- this.HandleattackElf(game);
- this.HandleDefeneElf(game);
- this.HandlePortals(game);
- //int num = IfTheEnemyPlaysBunker(game.GetEnemyCastle(), game);
- //PrintPortalArr(IfTheEnemyPlaysBunker(game.GetEnemyCastle(), game));
- }
- private void HandleDefeneElf(Game game)
- {
- Elf defenceElf = game.GetAllMyElves()[1];
- if (!defenceElf.IsAlive())
- return;
- Castle MyCastle = game.GetMyCastle();
- DefenderCanBuild = defenceElf.IsBuilding;
- bool defenceElfDidSomething = false;
- if (defenceElf.InRange(MyCastle, 1200) && defenceElf.CanBuildPortal() == true && !defenceElfDidSomething)
- {
- defenceElf.BuildPortal();
- defenceElfDidSomething = true;
- }
- if (MyAttackerCloseToEnemyPortal(defenceElf, game) == true && !defenceElfDidSomething)
- {
- defenceElf.Attack(GetEnemyClosePortalToMe(defenceElf, game));
- defenceElfDidSomething = true;
- }
- else
- {
- //System.Console.WriteLine("Distance: " + defenceElf.Distance(lavagiant));
- //System.Console.WriteLine("Can Build: " + DefenderCanBuild);
- /*foreach (Elf enemyelf in game.GetEnemyLivingElves())
- {
- if (CheckAttackForEnemyElf(defenceElf, game) && !defenceElfDidSomething)
- {
- defenceElf.Attack(GetCloserElfEnemyToMe(defenceElf, game));
- defenceElfDidSomething = true;
- break;
- }
- else
- {
- if (defenceElfDidSomething == false)
- {
- if (defenceElf.CanBuildPortal() && !IsPortalCloseToMe(defenceElf, game))
- {
- defenceElf.BuildPortal();
- defenceElfDidSomething = true;
- break;
- }
- }
- }
- }*/
- foreach (Elf enemyelf in game.GetEnemyLivingElves())
- {
- if (!CheckAttackForEnemyElf(defenceElf, game))
- {
- if (defenceElfDidSomething == false)
- {
- if (defenceElf.CanBuildPortal() && !IsPortalCloseToMe(defenceElf, game))
- {
- defenceElf.BuildPortal();
- defenceElfDidSomething = true;
- break;
- } //
- }
- }
- }
- foreach (LavaGiant lavagiant in game.GetEnemyLavaGiants())
- {
- if (defenceElf.InAttackRange(lavagiant) && !defenceElfDidSomething)
- {
- defenceElf.Attack(lavagiant);
- defenceElfDidSomething = true;
- break;
- }
- else
- {
- System.Console.WriteLine(HasPortalNextToLavaGainet(lavagiant, game));
- if (defenceElf.CanBuildPortal() && !IsPortalCloseToMe(defenceElf, game) && !HasPortalNextToLavaGainet(lavagiant, game) && !defenceElfDidSomething)
- {
- defenceElf.BuildPortal();
- defenceElfDidSomething = true;
- break;
- }
- }
- }
- if (defenceElf.IsBuilding == false && !defenceElfDidSomething)
- {
- if(GetEnemyClosePortalToMe(defenceElf, game) != null)
- {
- if (!defenceElf.InAttackRange(GetEnemyClosePortalToMe(defenceElf, game)))
- {
- defenceElf.MoveTo(GetEnemyClosePortalToMe(defenceElf, game));
- defenceElfDidSomething = true;
- }
- else
- {
- defenceElf.Attack(GetEnemyClosePortalToMe(defenceElf, game));
- defenceElfDidSomething = true;
- }
- }
- else
- {
- if (!defenceElf.InAttackRange(game.GetEnemyCastle()))
- {
- defenceElf.MoveTo(game.GetEnemyCastle());
- defenceElfDidSomething = true;
- }
- else
- {
- defenceElf.Attack(game.GetEnemyCastle());
- defenceElfDidSomething = true;
- }
- }
- }
- }
- }
- private void HandleattackElf(Game game)
- {
- Elf attackElf = game.GetAllMyElves()[0];
- if (!attackElf.IsAlive())
- return;
- Castle enemyCastle = game.GetEnemyCastle();
- Castle MyCastle = game.GetMyCastle();
- bool attackElfDidSomeThing = false;
- if (attackElf.InRange(MyCastle, 1200) && attackElfDidSomeThing == false && attackElf.CanBuildPortal() == true)
- {
- attackElf.BuildPortal();
- attackElfDidSomeThing = true;
- }
- if (MyAttackerCloseToEnemyPortal(attackElf, game) == true && attackElfDidSomeThing == false)
- {
- attackElf.Attack(GetEnemyClosePortalToMe(attackElf, game));
- attackElfDidSomeThing = true;
- }
- if (HowMuchElfEnemysNearAttacker(attackElf, game) <= 1 && attackElf.InRange(enemyCastle, 1000) && attackElfDidSomeThing == false)
- {
- if (attackElf.CanBuildPortal() && !IsPortalCloseToMe(attackElf, game))
- {
- attackElf.BuildPortal();
- attackElfDidSomeThing = true;
- }
- }
- if (attackElf.InAttackRange(enemyCastle) && attackElfDidSomeThing == false)
- {
- attackElf.Attack(enemyCastle);
- attackElfDidSomeThing = true;
- }
- int astratergia = 2;
- if (attackElfDidSomeThing == false)
- {
- if (astratergia == 1)
- foreach (Elf enemyelf in game.GetEnemyLivingElves())
- {
- if (!CheckAttackForEnemyElf(attackElf, game))
- {
- if (attackElfDidSomeThing == false)
- {
- if (attackElf.CanBuildPortal() && !IsPortalCloseToMe(attackElf, game))
- {
- attackElf.BuildPortal();
- attackElfDidSomeThing = true;
- break;
- } //
- }
- }
- }
- if (astratergia == 2)
- foreach (Elf enemyelf in game.GetEnemyLivingElves())
- {
- if (CheckAttackForEnemyElf(attackElf, game))
- {
- attackElf.Attack(GetCloserElfEnemyToMe(attackElf, game));
- attackElfDidSomeThing = true;
- break;
- }
- else
- {
- if (attackElfDidSomeThing == false)
- {
- if (attackElf.CanBuildPortal() && !IsPortalCloseToMe(attackElf, game))
- {
- attackElf.BuildPortal();
- attackElfDidSomeThing = true;
- break;
- }
- }
- }
- }
- if (astratergia == 3)
- foreach (LavaGiant lavagiant in game.GetEnemyLavaGiants())
- {
- if (attackElf.InAttackRange(lavagiant) && !attackElfDidSomeThing)
- {
- attackElf.Attack(lavagiant);
- attackElfDidSomeThing = true;
- break;
- }
- else
- {
- System.Console.WriteLine(HasPortalNextToLavaGainet(lavagiant, game));
- if (attackElf.CanBuildPortal() && !IsPortalCloseToMe(attackElf, game) && !HasPortalNextToLavaGainet(lavagiant, game) && !attackElfDidSomeThing)
- {
- attackElf.BuildPortal();
- attackElfDidSomeThing = true;
- break;
- }
- }
- }
- }
- if (attackElfDidSomeThing == false)
- {
- if (attackElf.InRange(enemyCastle, 1000))
- {
- if (!IsPortalCloseToMe(attackElf, game))
- {
- if (attackElf.CanBuildPortal())
- attackElf.BuildPortal();
- else
- attackElf.MoveTo(enemyCastle);
- attackElfDidSomeThing = true;
- }
- }
- if (attackElfDidSomeThing == false)
- {
- if (attackElf.InAttackRange(enemyCastle))
- attackElf.Attack(enemyCastle);
- else
- {
- attackElf.MoveTo(enemyCastle);
- }
- }
- }
- }
- /*private Portal[] IfTheEnemyPlaysBunker(Castle enemyCastle)
- {
- Portal[] EnemyClosePortals = new Portal[game.GetEnemyPortals().Length];
- for (int i = 0; i < EnemyClosePortals.Length; i++)
- {
- if (game.GetEnemyPortals()[i].InRange(enemyCastle, 1250))
- {
- EnemyClosePortals[i] = game.GetEnemyPortals()[i];
- System.Console.WriteLine("The Arr: " + EnemyClosePortals[i] + " \n");
- }
- }
- //int counter = 1;
- //System.Console.WriteLine("The Answer is aaaaa" + counter);
- /*for (int j = 0; j < EnemyClosePortals.Length -1; j++)
- {
- System.Console.WriteLine("J = " + j);
- //System.Console.WriteLine("The Answer is dsadasd " + counter);
- if (EnemyClosePortals[j].InRange(EnemyClosePortals[j + 1], 1250))
- counter++;
- }
- System.Console.WriteLine(counter);
- return EnemyClosePortals;
- }*/
- private bool IsPortalCloseToMe(Elf me, Game game)
- {
- foreach (Portal portal in game.GetMyPortals())
- {
- if (me.Distance(portal) < 1500)
- return true;
- }
- return false;
- }
- private Portal WhoIsFarthest(Portal[] arr, Game game)
- {
- int dist = 100000;
- Portal Farthest = null;
- for (int i = 0; i < arr.Length; i++)
- {
- if (dist > game.GetEnemyCastle().Distance(arr[i]))
- {
- dist = game.GetEnemyCastle().Distance(arr[i]);
- Farthest = arr[i];
- }
- }
- return Farthest;
- }
- private Portal GetEnemyClosePortalToMe(Elf me, Game game)
- {
- int dist = 100000;
- Portal closePortal = null;
- foreach (Portal enemyPortal in game.GetEnemyPortals())
- {
- if (dist > me.Distance(enemyPortal))
- {
- dist = me.Distance(enemyPortal);
- closePortal = enemyPortal;
- }
- }
- return closePortal;
- }
- private bool HasPortalNextToLavaGainet(LavaGiant enemyLava, Game game)
- {
- foreach (Portal myPortal in game.GetMyPortals())
- {
- if (enemyLava.InRange(myPortal, 1350))
- return true;
- }
- return false;
- }
- private void HandlePortals(Game game) //
- {
- // The Bot Crashed Here, need to check( Vs JavaGainet)
- Portal doItCheck = GetClosetPortalToMyCastle(game);
- //
- foreach (LavaGiant lavagiant in game.GetEnemyLavaGiants())
- {
- if (doItCheck.InRange(lavagiant, 1100))
- {
- if (doItCheck.CanSummonIceTroll())
- {
- doItCheck.SummonIceTroll();
- }
- }
- else
- {
- if (GetClosetPortalToEnemy(lavagiant, game).InRange(lavagiant, 800))
- {
- if (GetClosetPortalToEnemy(lavagiant, game).CanSummonIceTroll())
- {
- GetClosetPortalToEnemy(lavagiant, game).SummonIceTroll();
- }
- }
- }
- }
- foreach (Elf enemyElf in game.GetEnemyLivingElves())
- {
- if (GetClosetPortalToEnemyElf(enemyElf, game).InRange(enemyElf, 1100))
- {
- if (GetClosetPortalToEnemyElf(enemyElf, game).CanSummonIceTroll())
- {
- GetClosetPortalToEnemyElf(enemyElf, game).SummonIceTroll();
- }
- }
- /*else
- {
- if(GetClosetPortalToEnemy(lavagiant, game).InRange(lavagiant, 800))
- {
- if(GetClosetPortalToEnemy(lavagiant, game).CanSummonIceTroll())
- {
- GetClosetPortalToEnemy(lavagiant, game).SummonIceTroll();
- }
- }
- }*/
- }
- }
- public LavaGiant[] GetClosestLava(Location location, Game game)
- {
- int[] lavasDistance = new int[50];
- LavaGiant[] lavasDistanceX = game.GetMyLavaGiants();
- LavaGiant[] lavareturn = game.GetMyLavaGiants();
- for (int j = 0; j < lavasDistance.Length; j++) lavasDistance[j] = 0;
- int i = 0;
- foreach (LavaGiant lavagiant in game.GetEnemyLavaGiants())
- {
- lavasDistance[i] = lavagiant.Distance(location);
- lavasDistanceX[i] = lavagiant;
- i++;
- }
- int temp = 0;
- for (int write = 0; write < lavasDistance.Length; write++)
- {
- for (int sort = 0; sort < lavasDistance.Length - 1; sort++)
- {
- if (lavasDistance[sort] > lavasDistance[sort + 1])
- {
- temp = lavasDistance[sort + 1];
- lavasDistance[sort + 1] = lavasDistance[sort];
- lavasDistance[sort] = temp;
- }
- }
- }
- for (int x = 0; x < 4; x++)
- if (lavasDistance[x] == lavasDistanceX[x].Distance(location))
- lavareturn[x] = lavasDistanceX[x];
- return lavareturn;
- }
- public Portal GetClosetPortalToEnemyCastle(Castle enemyCastle, Game game)
- {
- int dist = 100000;
- Portal closePortal = null;
- Castle EnemyCastle = game.GetEnemyCastle();
- foreach (Portal portal in game.GetMyPortals())
- {
- if (dist > EnemyCastle.Distance(portal))
- {
- dist = EnemyCastle.Distance(portal);
- closePortal = portal;
- }
- }
- return closePortal;
- }
- public Portal GetClosetPortalToMyCastle(Game game)
- {
- int dist = 100000;
- Portal closePortal = null;
- Castle MyCastle = game.GetMyCastle();
- if(game.GetMyPortals() != null)
- {
- foreach (Portal portal in game.GetMyPortals())
- {
- if (dist > MyCastle.Distance(portal))
- {
- dist = MyCastle.Distance(portal);
- closePortal = portal;
- }
- }
- }
- return closePortal;
- }
- int lavas = 0;
- private void AttackersLava(Portal ClosetPortal, Game game)
- {
- if (ClosetPortal == null)
- return;
- if (ClosetPortal.CanSummonLavaGiant() && lavas < 3)
- {
- lavas++;
- ClosetPortal.SummonLavaGiant();
- }
- }
- private int HowMutchPortals(Game game)
- {
- int i = 0;
- foreach (Portal myPortals in game.GetMyPortals())
- {
- i++;
- }
- return i;
- }
- private bool ThereIsClosePortalEnemy(Elf me, Game game)
- {
- foreach (Portal enemyPortals in game.GetEnemyPortals())
- {
- if (me.InAttackRange(enemyPortals))
- return true;
- }
- return false;
- }
- private bool CheckAttackForEnemyElf(Elf attacker, Game game)
- {
- foreach (Elf enemy in game.GetEnemyLivingElves())
- {
- if (attacker.InAttackRange(enemy))
- return true;
- }
- return false;
- }
- private int HowMutchElfsNearCastle(Castle enemyCastle, Game game)
- {
- int counter = 0;
- foreach (Elf elf in game.GetMyLivingElves())
- {
- if (elf.InRange(enemyCastle, 1400))
- counter++;
- }
- return counter;
- }
- private Portal GetClosetPortalToEnemy(LavaGiant lavagiant, Game game)
- {
- int dist = 100000;
- Portal closePortal = null;
- foreach (Portal portal in game.GetMyPortals())
- {
- if (dist > lavagiant.Distance(portal))
- {
- dist = lavagiant.Distance(portal);
- closePortal = portal;
- }
- }
- return closePortal;
- }
- private Portal GetClosetPortalToEnemyElf(Elf enemy, Game game)
- {
- int dist = 100000;
- Portal closePortal = null;
- foreach (Portal portal in game.GetMyPortals())
- {
- if (dist > enemy.Distance(portal))
- {
- dist = enemy.Distance(portal);
- closePortal = portal;
- }
- }
- return closePortal;
- }
- private Elf GetCloserElfEnemyToMe(Elf me, Game game)
- {
- int dist = 100000;
- Elf EnemyCloser = null;
- foreach (Elf enemy in game.GetEnemyLivingElves())
- {
- if (dist > me.Distance(enemy))
- {
- dist = me.Distance(enemy);
- EnemyCloser = enemy;
- }
- }
- return EnemyCloser;
- }
- private int HowMuchElfEnemysNearAttacker(Elf Attacker, Game game)
- {
- int counter = 0;
- foreach (Elf elf in game.GetEnemyLivingElves())
- {
- if (Attacker.InRange(elf, 1500))
- counter++;
- }
- return counter;
- }
- /*private int HowMutchEnemysNearElf(Elf me, Game game)
- {
- int counter = 0;
- foreach (IceTroll elf in game.GetEnemyIceTrolls())
- {
- if (Attacker.InRange(elf, 1000))
- counter++;
- }
- return counter;
- }*/
- private bool MyAttackerCloseToEnemyPortal(Elf myAttacker, Game game)
- {
- foreach (Portal enemyPortal in game.GetEnemyPortals())
- {
- if (myAttacker.InAttackRange(enemyPortal))
- return true;
- }
- return false;
- }
- private Elf CheckWhichElfClosestToEnemyCastle(Castle enemyCastle, Game game)
- {
- int dist = 100000;
- Elf EnemyCloser = null;
- foreach (Elf me in game.GetMyLivingElves())
- {
- if (dist > enemyCastle.Distance(me))
- {
- dist = enemyCastle.Distance(me);
- EnemyCloser = me;
- }
- }
- return EnemyCloser;
- }
- private void SendHelpWhenEnemyElfDead(Game game)
- {
- Elf attackElf = game.GetAllMyElves()[0];
- Elf defenceElf = game.GetAllMyElves()[1];
- if (attackElf.IsAlive() == true || defenceElf.IsAlive() == true)
- {
- Elf attacker = CheckWhichElfClosestToEnemyCastle(game.GetEnemyCastle(), game);
- if (attacker.Distance(game.GetEnemyCastle()) <= 2000 && attacker.CanBuildPortal())
- {
- attacker.BuildPortal();
- }
- else
- {
- // newLocation = (game.GetEnemyCastle().Location.Row, game.GetEnemyCastle().Location.Col);
- //System.Console.WriteLine(game.GetEnemyCastle().Location.Row, game.GetEnemyCastle().Location.Col);
- Location newLocation = new Location(game.GetEnemyCastle().Location.Col, game.GetEnemyCastle().Location.Row);
- attacker.MoveTo(newLocation);
- }
- }
- }
- /*private bool IsMyElfUnderAttack(Game game)
- {
- foreach(Elf enemyElf in game.GetEnemyLivingElves())
- {
- for(int i = 0; i < game.GetEnemyLivingElves().Length; i++)
- {
- if(game.GetEnemyLivingElves[i].InAttackRange(enemyElf))
- Elf1 = game.GetEnemyLivingElves[i];
- }
- if(enemyElf.)
- }
- int dist = 100000;
- Elf EnemyCloser = null;
- foreach (Elf MyElf in game.GetMyLivingElves())
- {
- foreach(Elf EnemyElf in game.GetEnemyLivingElves())
- {
- if (dist > EnemyElf.Distance(me))
- {
- dist = enemyCastle.Distance(me);
- EnemyCloser = me;
- }
- }
- }
- }*/
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement