Fix AI multiple moves and player colors

This commit is contained in:
sokol
2026-02-21 21:25:22 +03:00
parent 1d04a99bd7
commit f3be577a32
5 changed files with 105 additions and 40 deletions

View File

@@ -14,6 +14,8 @@ const CELL_TYPES = {
BLOCKED: 1, // Impassable terrain
PLAYER1: 2, // Player 1 owned
PLAYER2: 3, // Player 2 owned
PLAYER3: 4, // Player 3 owned
PLAYER4: 5, // Player 4 owned
};
/**
@@ -80,12 +82,17 @@ class HexCell {
}
isOwned() {
return this.type === CELL_TYPES.PLAYER1 || this.type === CELL_TYPES.PLAYER2;
return this.type === CELL_TYPES.PLAYER1 ||
this.type === CELL_TYPES.PLAYER2 ||
this.type === CELL_TYPES.PLAYER3 ||
this.type === CELL_TYPES.PLAYER4;
}
getOwner() {
if (this.type === CELL_TYPES.PLAYER1) return 1;
if (this.type === CELL_TYPES.PLAYER2) return 2;
if (this.type === CELL_TYPES.PLAYER3) return 3;
if (this.type === CELL_TYPES.PLAYER4) return 4;
return 0;
}
}
@@ -157,7 +164,14 @@ class HexMap {
* Get all cells owned by a player
*/
getPlayerCells(playerId) {
const targetType = playerId === 1 ? CELL_TYPES.PLAYER1 : CELL_TYPES.PLAYER2;
const typeMap = {
1: CELL_TYPES.PLAYER1,
2: CELL_TYPES.PLAYER2,
3: CELL_TYPES.PLAYER3,
4: CELL_TYPES.PLAYER4
};
const targetType = typeMap[playerId];
if (!targetType) return [];
return Array.from(this.cells.values()).filter(
cell => cell.type === targetType
);
@@ -265,6 +279,8 @@ class HexMap {
if (cell.type === CELL_TYPES.BLOCKED) return '██';
if (cell.type === CELL_TYPES.PLAYER1) return 'P1';
if (cell.type === CELL_TYPES.PLAYER2) return 'P2';
if (cell.type === CELL_TYPES.PLAYER3) return 'P3';
if (cell.type === CELL_TYPES.PLAYER4) return 'P4';
if (cell.dice.length > 0) return cell.getStrength().toString().padStart(2, ' ');
return ' ';
}
@@ -275,7 +291,13 @@ class HexMap {
setOwner(q, r, playerId) {
const cell = this.getCell(q, r);
if (cell && cell.isPassable()) {
cell.type = playerId === 1 ? CELL_TYPES.PLAYER1 : CELL_TYPES.PLAYER2;
const typeMap = {
1: CELL_TYPES.PLAYER1,
2: CELL_TYPES.PLAYER2,
3: CELL_TYPES.PLAYER3,
4: CELL_TYPES.PLAYER4
};
cell.type = typeMap[playerId] || CELL_TYPES.EMPTY;
return true;
}
return false;