fix: Hex Wars - Mine-Feld wird Felsen, Kopf außerhalb Blast-Radius
This commit is contained in:
@@ -137,14 +137,20 @@ function explodeMine(grid, terrain, row, col, ownerId, oppId, exploded = new Set
|
||||
let destroyedByOwner = 0;
|
||||
let destroyedByOpp = 0;
|
||||
const blastCells = [];
|
||||
const chainMines = []; // Nachbar-Minen die ebenfalls zünden
|
||||
const chainMines = [];
|
||||
|
||||
// Das Mine-Feld selbst wird auch zu Felsen
|
||||
grid[row][col] = 0;
|
||||
terrain[row][col] = T_ROCK;
|
||||
blastCells.push([row, col]);
|
||||
|
||||
// Alle 8 Nachbarn werden zu Felsen — erst Ketten-Minen merken, dann umwandeln
|
||||
for (const [dr,dc] of DIRS8) {
|
||||
const r=row+dr, c=col+dc;
|
||||
if (r<0||r>=GRID||c<0||c>=GRID) continue;
|
||||
if (terrain[r][c] === T_ROCK) continue; // bereits Felsen, überspringen
|
||||
if (terrain[r][c] === T_ROCK) continue; // schon Felsen
|
||||
|
||||
// Merke ob da eine Mine lag (BEVOR wir terrain ändern)
|
||||
// Ketten-Mine merken BEVOR terrain geändert wird
|
||||
if (terrain[r][c] === T_MINE && !exploded.has(`${r},${c}`)) {
|
||||
chainMines.push([r,c]);
|
||||
}
|
||||
@@ -159,10 +165,8 @@ function explodeMine(grid, terrain, row, col, ownerId, oppId, exploded = new Set
|
||||
blastCells.push([r,c]);
|
||||
}
|
||||
|
||||
// Kettenexplosionen zünden
|
||||
// Kettenexplosionen
|
||||
for (const [mr,mc] of chainMines) {
|
||||
// terrain[mr][mc] ist jetzt bereits T_ROCK (oben gesetzt),
|
||||
// aber die Mine war dort — wir zünden sie trotzdem
|
||||
const chain = explodeMine(grid, terrain, mr, mc, ownerId, oppId, exploded);
|
||||
destroyedByOwner += chain.destroyedByOwner;
|
||||
destroyedByOpp += chain.destroyedByOpp;
|
||||
@@ -363,21 +367,25 @@ router.post('/:id/move', authenticate, (req, res) => {
|
||||
// Der alte Kopf (myHR, myHC) wird durch explodeMine nicht zerstört (Explosion trifft Nachbarn),
|
||||
// also ist er noch vorhanden — Kopf bleibt beim alten Kopf (vor dem Mine-Zug).
|
||||
// Falls kein alter Kopf bekannt: suche nächstes eigenes Feld neben der Mine.
|
||||
if (myHR !== null) {
|
||||
// Alten Kopf wiederherstellen — Mine-Feld selbst ist kein guter Ausgangspunkt
|
||||
if (game.owner_id === me) newOwnerHead = `${myHR},${myHC}`;
|
||||
else newOppHead = `${myHR},${myHC}`;
|
||||
} else {
|
||||
// Fallback: nächstes eigenes Feld neben der Mine suchen
|
||||
let fallbackHead = null;
|
||||
for (const [dr,dc] of DIRS8) {
|
||||
const nr=row+dr, nc=col+dc;
|
||||
if (nr>=0&&nr<GRID&&nc>=0&&nc<GRID&&grid[nr][nc]===me) { fallbackHead=`${nr},${nc}`; break; }
|
||||
// Kopf nach Explosion: erstes eigenes Feld das AUSSERHALB des 3x3-Radius der Mine liegt
|
||||
// (Mine + 8 Nachbarn sind alle Felsen — der Kopf muss weiter weg sein)
|
||||
let safeHead = null;
|
||||
// Alle eigenen Felder sammeln und nach Entfernung zur Mine sortieren
|
||||
const ownCells = [];
|
||||
for (let r=0;r<GRID;r++) for (let c=0;c<GRID;c++) {
|
||||
if (grid[r][c] === me) {
|
||||
const outside = Math.abs(r-row)>1 || Math.abs(c-col)>1;
|
||||
if (outside) ownCells.push([r, c, Math.abs(r-row)+Math.abs(c-col)]);
|
||||
}
|
||||
if (fallbackHead) {
|
||||
if (game.owner_id === me) newOwnerHead = fallbackHead;
|
||||
else newOppHead = fallbackHead;
|
||||
}
|
||||
// Nächstes eigenes Feld außerhalb des Radius (Manhattan-Distanz minimal)
|
||||
if (ownCells.length > 0) {
|
||||
ownCells.sort((a,b) => a[2]-b[2]);
|
||||
safeHead = `${ownCells[0][0]},${ownCells[0][1]}`;
|
||||
}
|
||||
if (safeHead) {
|
||||
if (game.owner_id === me) newOwnerHead = safeHead;
|
||||
else newOppHead = safeHead;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user