Implement BlindFury

This commit is contained in:
henriquenakashima 2020-09-24 01:01:21 -04:00
parent 626f465ca0
commit 281ad2dbc5
13 changed files with 82 additions and 21 deletions

View file

@ -6,18 +6,29 @@ public class AIUtils {
public static BattleHero GetNearestHero(MonsterViewpoint viewpoint,
BattleParticipant owner) {
int ownerPosition = GetMonsterPosition(viewpoint, owner);
return GetNearestEnemy(ownerPosition, viewpoint.Heroes);
}
int nearestHeroIndex = -1;
public static BattleMonster GetNearestMonster(MonsterViewpoint viewpoint,
BattleParticipant owner) {
int ownerPosition = GetHeroPosition(viewpoint, owner);
return GetNearestEnemy(ownerPosition, viewpoint.Monsters);
}
private static ParticipantT GetNearestEnemy<ParticipantT>(
int ownerPosition, ParticipantT[] otherTeam)
where ParticipantT : BattleParticipant{
int nearestIndex = -1;
int nearestDistance = int.MaxValue;
for (int i = 0; i < viewpoint.Heroes.Length; i++) {
if (!viewpoint.Heroes[i].IsAlive()) continue;
for (int i = 0; i < otherTeam.Length; i++) {
if (!otherTeam[i].IsAlive()) continue;
int distance = System.Math.Abs(i - ownerPosition);
if (distance < nearestDistance) {
nearestHeroIndex = i;
nearestIndex = i;
nearestDistance = distance;
}
}
return HeroAtIndex(nearestHeroIndex, viewpoint);
return ParticipantAtIndex(nearestIndex, otherTeam);
}
public static BattleHero GetFarthestHero(MonsterViewpoint viewpoint,
@ -34,7 +45,7 @@ public class AIUtils {
farthestDistance = distance;
}
}
return HeroAtIndex(farthestHeroIndex, viewpoint);
return ParticipantAtIndex(farthestHeroIndex, viewpoint.Heroes);
}
private static int GetMonsterPosition(MonsterViewpoint viewpoint, BattleParticipant monster) {
@ -44,6 +55,13 @@ public class AIUtils {
return -1;
}
private static int GetHeroPosition(MonsterViewpoint viewpoint, BattleParticipant hero) {
for (int i = 0; i < viewpoint.Heroes.Length; i++) {
if (viewpoint.Heroes[i] == hero) return i;
}
return -1;
}
public static BattleHero GetHeroWithHighestHP(MonsterViewpoint viewpoint) {
int highestHPHeroIndex = -1;
int highestHP = -1;
@ -55,11 +73,12 @@ public class AIUtils {
highestHP = heroHP;
}
}
return HeroAtIndex(highestHPHeroIndex, viewpoint);
return ParticipantAtIndex(highestHPHeroIndex, viewpoint.Heroes);
}
private static BattleHero HeroAtIndex(int index, MonsterViewpoint viewpoint) {
private static ParticipantT ParticipantAtIndex<ParticipantT>(int index, ParticipantT[] team)
where ParticipantT : BattleParticipant {
if (index == -1) return null;
return viewpoint.Heroes[index];
return team[index];
}
}