Я сделал ИИ для копии Agar.io, и ИИ следует за ближайшей ячейкой, которая меньше, чем он пытается ее съесть, однако я хочу, чтобы она следовала за соседней ячейкой в зависимости от приоритета, поэтому не обязательно самая близкая ячейка к ИИ, например: ближайшая к ИИ ячейка меньше, чем та, которая находится немного дальше и намного больше, вместо этого выбирайте большую ячейку, исходя из того, что она имеет более высокий приоритет из-за своей массы.
Вот мой код. (если вам нужен полный класс, вот весь класс на pastebin. )
public void Update() {
if (this.mass > 3500) {
this.mass = 3500;
}
for (Cell cell : cells) {
if (this.checkCollide(cell.x, cell.y, cell.mass) && this != cell && this.mass > cell.mass + 10) {
if (1 / (this.mass / cell.mass) >= .4 && this.mass < 4000) {
addMass(cell.mass);
}
respawn(cell);
}
}
if (!isPlayer) {
if (goalReached) {
if (returnNearestCell() > -1) { // No Cell Found
if (!isTarget) {
target = cells.get(returnNearestCell());
isTarget = true;
targetType = "c";
} else if (isTarget && targetType.equals("c")) {
targetType = "n";
isTarget = false;
}
} else if (returnNearestCell() == -1) { // Cell Found
if (!isTarget) {
pTarget = Particle.particles.get(returnNearestP());
isTarget = true;
targetType = "p";
} else if (isTarget) {
targetType = "n";
isTarget = false;
}
}
goalReached = false;
} else {
double dx = 0;
double dy = 0;
if (targetType.equals("c")) {
if (returnNearestCell() > -1) {
target = cells.get(returnNearestCell());
dx = (target.x - this.x);
dy = (target.y - this.y);
} else {
goalReached = true;
}
} else if (targetType.equals("p")) {
pTarget = Particle.particles.get(returnNearestP());
dx = (pTarget.x - this.x);
dy = (pTarget.y - this.y);
} else {
goalReached = true;
}
double distance = Math.sqrt((dx) * (dx) + (dy) * (dy));
if (distance > 1) {
x += (dx) / distance * speed;
y += (dy) / distance * speed;
} else if (distance <= 1) {
goalReached = true;
}
}
} else {
double dx = (goalX - this.x);
double dy = (goalY - this.y);
this.x += (dx) * 1 / 50;
this.y += (dy) * 1 / 50;
// addMass(10);
}
}
ОБНОВЛЕНИЕ: это то, что я написал до сих пор для системы приоритетов, которую я затем могу вызвать в функции Update (), однако сейчас я не знаю, что делать дальше. .
public int targetPriority() {
int priority = 0;
int distance = 0;
int mass = 0;
List<Cell> possibleTarget = null;
int aPriority = 0;
int bPriority = 0;
int cPriority = 0;
for (Cell cell : cells) {
mass = cell.mass / 10;
distance = (int) Math.sqrt((this.x - cell.x) * (this.x - cell.x) + (cell.y - this.y) * (cell.y - this.y));
priority = distance - mass;
for (Cell A : possibleTarget) {
for (Cell B : possibleTarget) {
for (Cell C : possibleTarget) {
}
}
}
}
return priority;
}