This commit is contained in:
2026-01-27 19:43:42 +03:00
parent 814abb60f3
commit f52d72ac09

View File

@ -247,7 +247,10 @@ function makeAITurn(room) {
// Используем заклинание
const enemies = gameState.players.filter((p, i) => i !== aiPlayerIndex && p.health > 0);
if (enemies.length > 0) {
const targetEnemy = enemies[0];
// Выбираем самого слабого врага (по здоровью), если одинаковое - случайно
const weakest = enemies.reduce((min, p) => (p.health < min.health ? p : min), enemies[0]);
const weakEnemies = enemies.filter(p => p.health === weakest.health);
const targetEnemy = weakEnemies[Math.floor(Math.random() * weakEnemies.length)];
let targetBoardIndex = -1;
if (playable.card.spellTarget === 'enemy_minion' || playable.card.spellTarget === 'any_minion') {
@ -323,7 +326,10 @@ function performAIAttacks(room, aiPlayerIndex) {
const minion = attackableMinions[attackIndex];
const boardIndex = aiPlayer.board.indexOf(minion);
const targetEnemy = enemies[0];
// Выбираем самого слабого врага (по здоровью), если одинаковое - случайно
const weakest = enemies.reduce((min, p) => (p.health < min.health ? p : min), enemies[0]);
const weakEnemies = enemies.filter(p => p.health === weakest.health);
const targetEnemy = weakEnemies[Math.floor(Math.random() * weakEnemies.length)];
const targetPlayerIndex = gameState.players.indexOf(targetEnemy);
let targetBoardIndex = -1;