diff --git a/server.js b/server.js index 5688284..d013f0f 100644 --- a/server.js +++ b/server.js @@ -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;