123
This commit is contained in:
10
server.js
10
server.js
@ -247,7 +247,10 @@ function makeAITurn(room) {
|
|||||||
// Используем заклинание
|
// Используем заклинание
|
||||||
const enemies = gameState.players.filter((p, i) => i !== aiPlayerIndex && p.health > 0);
|
const enemies = gameState.players.filter((p, i) => i !== aiPlayerIndex && p.health > 0);
|
||||||
if (enemies.length > 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;
|
let targetBoardIndex = -1;
|
||||||
|
|
||||||
if (playable.card.spellTarget === 'enemy_minion' || playable.card.spellTarget === 'any_minion') {
|
if (playable.card.spellTarget === 'enemy_minion' || playable.card.spellTarget === 'any_minion') {
|
||||||
@ -323,7 +326,10 @@ function performAIAttacks(room, aiPlayerIndex) {
|
|||||||
|
|
||||||
const minion = attackableMinions[attackIndex];
|
const minion = attackableMinions[attackIndex];
|
||||||
const boardIndex = aiPlayer.board.indexOf(minion);
|
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);
|
const targetPlayerIndex = gameState.players.indexOf(targetEnemy);
|
||||||
let targetBoardIndex = -1;
|
let targetBoardIndex = -1;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user