diff --git a/server.js b/server.js index d013f0f..8e40932 100644 --- a/server.js +++ b/server.js @@ -247,10 +247,15 @@ function makeAITurn(room) { // Используем заклинание const enemies = gameState.players.filter((p, i) => i !== aiPlayerIndex && p.health > 0); if (enemies.length > 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)]; + // Выбираем врага: 70% шанс выбрать самого слабого, 30% - случайно среди всех + let targetEnemy; + if (Math.random() < 0.7 && enemies.length > 1) { + const weakest = enemies.reduce((min, p) => (p.health < min.health ? p : min), enemies[0]); + const weakEnemies = enemies.filter(p => p.health === weakest.health); + targetEnemy = weakEnemies[Math.floor(Math.random() * weakEnemies.length)]; + } else { + targetEnemy = enemies[Math.floor(Math.random() * enemies.length)]; + } let targetBoardIndex = -1; if (playable.card.spellTarget === 'enemy_minion' || playable.card.spellTarget === 'any_minion') { @@ -277,7 +282,8 @@ function makeAITurn(room) { targetBoardIndex = -1; } - playSpell(room, aiPlayer.id, playable.index, gameState.players.indexOf(targetEnemy), targetBoardIndex); + const targetPlayerIndex = gameState.players.findIndex((p, i) => i !== aiPlayerIndex && p === targetEnemy); + playSpell(room, aiPlayer.id, playable.index, targetPlayerIndex, targetBoardIndex); actionsDone++; cardIndex++; setTimeout(playNextCard, 600); @@ -326,11 +332,16 @@ function performAIAttacks(room, aiPlayerIndex) { const minion = attackableMinions[attackIndex]; const boardIndex = aiPlayer.board.indexOf(minion); - // Выбираем самого слабого врага (по здоровью), если одинаковое - случайно - 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); + // Выбираем врага: 70% шанс выбрать самого слабого, 30% - случайно среди всех + let targetEnemy; + if (Math.random() < 0.7 && enemies.length > 1) { + const weakest = enemies.reduce((min, p) => (p.health < min.health ? p : min), enemies[0]); + const weakEnemies = enemies.filter(p => p.health === weakest.health); + targetEnemy = weakEnemies[Math.floor(Math.random() * weakEnemies.length)]; + } else { + targetEnemy = enemies[Math.floor(Math.random() * enemies.length)]; + } + const targetPlayerIndex = gameState.players.findIndex((p, i) => i !== aiPlayerIndex && p === targetEnemy); let targetBoardIndex = -1; // Выбираем цель: сначала слабые миньоны, потом герой