Fix map rendering and AI bot bugs

This commit is contained in:
sokol
2026-02-21 20:42:58 +03:00
parent afebcbca1a
commit 4cb5be95f8
2 changed files with 43 additions and 13 deletions

View File

@@ -14,19 +14,30 @@ export class AIBot {
}
/**
* Execute AI turn
* Execute AI turn - makes ONE move then ends turn
*/
async playTurn() {
console.log(`AI Player ${this.playerId} thinking...`);
// Get all player cells
const playerCells = this.map.getPlayerCells(this.playerId);
if (playerCells.length === 0) return;
console.log(`AI Player ${this.playerId} has ${playerCells.length} cells`);
if (playerCells.length === 0) {
console.log(`AI Player ${this.playerId} has no cells, ending turn`);
this.gameUI.endTurn();
return;
}
// Find all possible moves
const moves = this.findPossibleMoves(playerCells);
console.log(`AI Player ${this.playerId} found ${moves.length} possible moves`);
if (moves.length === 0) {
// No moves available, end turn
console.log(`AI Player ${this.playerId} has no moves, ending turn`);
this.gameUI.endTurn();
return;
}
@@ -36,12 +47,20 @@ export class AIBot {
// Execute best move
const bestMove = moves[0];
console.log(`AI Player ${this.playerId} selected move: from (${bestMove.from.q},${bestMove.from.r}) to (${bestMove.to.q},${bestMove.to.r}), type=${bestMove.type}`);
// Wait for thinking time
await this.wait(this.thinkingTime);
// Execute the move directly without using executeMove helper
this.gameUI.selectedCell = bestMove.from;
this.gameUI.currentTarget = bestMove.to;
this.gameUI.executeAttack();
// Execute the move
this.executeMove(bestMove);
console.log(`AI Player ${this.playerId} executed move`);
// End turn after executing move
this.gameUI.endTurn();
}
/**