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

@@ -98,10 +98,6 @@ class GameUI {
for (let i = 1; i <= this.playerCount; i++) {
const typeSelect = document.getElementById(`player${i}-type`);
this.playerTypes[i] = typeSelect.value;
if (this.playerTypes[i] === 'ai') {
this.aiBots[i] = new AIBot(i, this.map, this);
}
}
// Show game screen
@@ -120,6 +116,14 @@ class GameUI {
this.hasMoved = false;
this.isAIThinking = false;
// Initialize AI bots AFTER map is created
this.aiBots = {};
for (let i = 1; i <= this.playerCount; i++) {
if (this.playerTypes[i] === 'ai') {
this.aiBots[i] = new AIBot(i, this.map, this);
}
}
// Initialize starting positions for all players
this.initializePlayers();
@@ -193,11 +197,18 @@ class GameUI {
const canvasHeight = this.canvas.height;
const sqrt3 = Math.sqrt(3);
const mapWidth = HEX_SIZE * sqrt3 * (MAP_SIZE + MAP_SIZE/2);
const mapHeight = HEX_SIZE * 1.5 * (MAP_SIZE - 1) + HEX_SIZE * 2;
// Calculate map bounds with proper padding for hex visibility
// For pointy-top hex: width = sqrt(3) * size, height = 2 * size
// Rightmost hex (q=19, r=19): x = HEX_SIZE * sqrt3 * (19 + 19/2) = HEX_SIZE * sqrt3 * 28.5
// Leftmost hex (q=0, r=0): x = 0
// Add padding for full hex visibility (hex radius on each side)
const hexPadding = HEX_SIZE * 1.5; // Extra padding for hex radius
const mapWidth = HEX_SIZE * sqrt3 * ((MAP_SIZE - 1) + (MAP_SIZE - 1) / 2);
const mapHeight = HEX_SIZE * 1.5 * (MAP_SIZE - 1);
this.offsetX = (canvasWidth - mapWidth) / 2 + HEX_SIZE * sqrt3;
this.offsetY = (canvasHeight - mapHeight) / 2 + HEX_SIZE;
this.offsetX = hexPadding;
this.offsetY = hexPadding;
}
setupEventListeners() {