Fix attack and supply distribution rules

This commit is contained in:
sokol
2026-02-21 18:28:32 +03:00
parent 254287c124
commit dbe71dbda6

View File

@@ -402,24 +402,25 @@ class GameUI {
// Combat! Roll dice // Combat! Roll dice
const attackRoll = Math.floor(Math.random() * attackStrength) + 1; const attackRoll = Math.floor(Math.random() * attackStrength) + 1;
const defenseRoll = Math.floor(Math.random() * defenseStrength) + 1; const defenseRoll = Math.floor(Math.random() * defenseStrength) + 1;
this.log(`Attack: ${attackStrength} vs ${defenseStrength} | Roll: ${attackRoll} vs ${defenseRoll}`); this.log(`Attack: ${attackStrength} vs ${defenseStrength} | Roll: ${attackRoll} vs ${defenseRoll}`);
if (attackRoll > defenseRoll) { if (attackRoll > defenseRoll) {
// Attacker wins // Attacker wins
const remainingStrength = attackRoll - 1; const remainingStrength = attackRoll - 1;
attacker.setStrength(1); attacker.setStrength(1);
if (remainingStrength > 0) { if (remainingStrength > 0) {
defender.setStrength(remainingStrength); defender.setStrength(remainingStrength);
this.map.setOwner(defender.q, defender.r, this.currentPlayer); this.map.setOwner(defender.q, defender.r, this.currentPlayer);
this.log(`Victory! Captured cell with strength ${remainingStrength}`, 'victory'); this.log(`Victory! Captured cell with strength ${remainingStrength}`, 'victory');
} }
} else { } else {
// Defender wins // Defender wins - attacker loses all but 1 die
const remainingDefense = defenseRoll - attackRoll; const remainingDefense = defenseRoll - attackRoll;
defender.setStrength(Math.max(1, remainingDefense)); defender.setStrength(Math.max(1, remainingDefense));
this.log(`Attack repelled! Defender has ${Math.max(1, remainingDefense)} strength`, 'defeat'); attacker.setStrength(1); // Attacker reduced to 1
this.log(`Attack repelled! Attacker reduced to 1, Defender has ${Math.max(1, remainingDefense)} strength`, 'defeat');
} }
} else { } else {
// Move to empty cell - transfer attackStrength (original - 1) // Move to empty cell - transfer attackStrength (original - 1)
@@ -465,25 +466,26 @@ class GameUI {
distributeSupply(supply) { distributeSupply(supply) {
const playerCells = this.map.getPlayerCells(this.currentPlayer); const playerCells = this.map.getPlayerCells(this.currentPlayer);
// Find cells that can receive more dice // Find cells that can receive more dice
const eligibleCells = playerCells.filter(cell => !cell.isMaxStrength()); const eligibleCells = playerCells.filter(cell => !cell.isMaxStrength());
if (eligibleCells.length === 0 || supply === 0) return; if (eligibleCells.length === 0 || supply === 0) return;
// Distribute supply randomly among eligible cells // Distribute supply one by one to random eligible cells
let remainingSupply = supply; let remainingSupply = supply;
while (remainingSupply > 0 && eligibleCells.length > 0) { while (remainingSupply > 0 && eligibleCells.length > 0) {
// Pick random cell
const randomCell = eligibleCells[Math.floor(Math.random() * eligibleCells.length)]; const randomCell = eligibleCells[Math.floor(Math.random() * eligibleCells.length)];
const currentStrength = randomCell.getStrength(); const currentStrength = randomCell.getStrength();
if (currentStrength < 48) { if (currentStrength < 48) {
const addStrength = Math.min(remainingSupply, 48 - currentStrength); // Add 1 strength to this cell
const newStrength = currentStrength + addStrength; randomCell.setStrength(currentStrength + 1);
randomCell.setStrength(newStrength); remainingSupply--;
remainingSupply -= addStrength;
} }
// Remove cell from eligible if it's now at max strength
if (randomCell.isMaxStrength()) { if (randomCell.isMaxStrength()) {
eligibleCells.splice(eligibleCells.indexOf(randomCell), 1); eligibleCells.splice(eligibleCells.indexOf(randomCell), 1);
} }
@@ -530,7 +532,8 @@ class GameUI {
const endTurnBtn = document.getElementById('end-turn-btn'); const endTurnBtn = document.getElementById('end-turn-btn');
cancelBtn.disabled = !this.selectedCell; cancelBtn.disabled = !this.selectedCell;
endTurnBtn.disabled = !this.hasMoved; // End turn is always enabled
endTurnBtn.disabled = false;
} }
log(message, type = '') { log(message, type = '') {