2023-02-06 11:04:37 +00:00
|
|
|
class Continent {
|
|
|
|
constructor(name) {
|
|
|
|
this.name = name;
|
|
|
|
this.yield = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const REGIONS = {};
|
|
|
|
|
|
|
|
class Region {
|
|
|
|
constructor(name, continent) {
|
|
|
|
this.name = name;
|
|
|
|
this.owner = null;
|
|
|
|
this.strength = 0;
|
|
|
|
this.neighbours = new Set();
|
|
|
|
this.continent = continent;
|
|
|
|
|
|
|
|
REGIONS[name] = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
static setNeighbours(region1, region2) {
|
|
|
|
region1.neighbours.add(region2);
|
|
|
|
region2.neighbours.add(region1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static getRegion(name) {
|
|
|
|
return REGIONS[name];
|
|
|
|
}
|
|
|
|
|
|
|
|
claim(player) {
|
|
|
|
this.owner = player;
|
|
|
|
this.strength = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
reinforce(amount) {
|
|
|
|
this.strength += amount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-06 12:30:24 +00:00
|
|
|
const EAST = new Continent("East");
|
|
|
|
const WEST = new Continent("West");
|
|
|
|
|
|
|
|
const A = new Region("A", EAST);
|
|
|
|
const B = new Region("B", EAST);
|
|
|
|
const C = new Region("C", EAST);
|
|
|
|
const D = new Region("D", EAST);
|
2023-02-06 13:03:25 +00:00
|
|
|
const J = new Region("J", EAST);
|
2023-02-06 12:30:24 +00:00
|
|
|
|
|
|
|
const F = new Region("F", WEST);
|
|
|
|
const G = new Region("G", WEST);
|
|
|
|
const H = new Region("H", WEST);
|
|
|
|
const I = new Region("I", WEST);
|
2023-02-06 13:03:25 +00:00
|
|
|
const E = new Region("E", WEST);
|
2023-02-08 17:55:45 +00:00
|
|
|
|
2023-02-15 18:00:25 +00:00
|
|
|
Region.setNeighbours(A, B);
|
|
|
|
Region.setNeighbours(A, C);
|
|
|
|
Region.setNeighbours(B, C);
|
|
|
|
Region.setNeighbours(B, J);
|
|
|
|
Region.setNeighbours(C, D);
|
|
|
|
Region.setNeighbours(C, F);
|
|
|
|
Region.setNeighbours(E, J);
|
|
|
|
Region.setNeighbours(E, I);
|
|
|
|
Region.setNeighbours(E, H);
|
|
|
|
Region.setNeighbours(F, J);
|
|
|
|
Region.setNeighbours(F, G);
|
|
|
|
Region.setNeighbours(G, H);
|
|
|
|
Region.setNeighbours(G, I);
|
|
|
|
Region.setNeighbours(H, I);
|
|
|
|
|
2023-02-08 17:55:45 +00:00
|
|
|
function allRegionsClaimed() {
|
|
|
|
return Object.values(REGIONS).find((region) => region.owner === null) === undefined;
|
|
|
|
}
|
2023-02-10 15:47:21 +00:00
|
|
|
|
|
|
|
let allPlaced = false;
|
|
|
|
|
2023-02-13 14:55:25 +00:00
|
|
|
// In standard Risk, this is 5
|
|
|
|
const _REINFORCEMENT_MULTIPLIER = 1;
|
|
|
|
|
|
|
|
function reinforcementsRemaining() {
|
|
|
|
if (allPlaced) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
let totalStrength = Object.values(REGIONS)
|
|
|
|
.filter((region) => region.owner === us)
|
|
|
|
.reduce((counter, region) => counter + region.strength, 0);
|
|
|
|
let numPlayers = Object.values(players).length;
|
|
|
|
|
|
|
|
return _REINFORCEMENT_MULTIPLIER * (10 - numPlayers) - totalStrength;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-10 15:47:21 +00:00
|
|
|
function allReinforcementsPlaced() {
|
|
|
|
if (allPlaced) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
let totalStrength = Object.values(REGIONS).reduce(
|
|
|
|
(counter, region) => counter + region.strength,
|
|
|
|
0
|
|
|
|
);
|
|
|
|
let numPlayers = Object.values(players).length;
|
|
|
|
|
2023-02-13 14:55:25 +00:00
|
|
|
allPlaced =
|
|
|
|
totalStrength >= numPlayers * _REINFORCEMENT_MULTIPLIER * (10 - numPlayers);
|
2023-02-10 15:47:21 +00:00
|
|
|
return allPlaced;
|
|
|
|
}
|
|
|
|
}
|