Add weather rules and streamline setup
This commit is contained in:
@@ -28,6 +28,48 @@ function getLeafCounts(state: GameState) {
|
||||
return counts;
|
||||
}
|
||||
|
||||
function getColumnPresence(state: GameState, column: number) {
|
||||
const owners = new Set<PlayerId>();
|
||||
|
||||
for (let row = 0; row < state.config.rows; row += 1) {
|
||||
const ownerId = state.nodes.get(keyFor(row, column))?.ownerId;
|
||||
if (ownerId !== undefined) {
|
||||
owners.add(ownerId);
|
||||
}
|
||||
}
|
||||
|
||||
return [...owners];
|
||||
}
|
||||
|
||||
function applyColumnBaseEnergy(state: GameState, scores: number[], ownerId: PlayerId, playersPresent: PlayerId[]) {
|
||||
const contested = playersPresent.length > 1;
|
||||
|
||||
if (!contested) {
|
||||
scores[ownerId] += 1;
|
||||
return;
|
||||
}
|
||||
|
||||
if (state.activeRoundEffects.includes("stalemate")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (state.activeRoundEffects.includes("split_light")) {
|
||||
playersPresent.forEach((playerId) => {
|
||||
scores[playerId] += 0.5;
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (state.activeRoundEffects.includes("shared_light")) {
|
||||
playersPresent.forEach((playerId) => {
|
||||
scores[playerId] += 1;
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
scores[ownerId] += 1;
|
||||
}
|
||||
|
||||
function applyWeatherEffects(state: GameState, scores: number[], energySimulation: EnergySimulation) {
|
||||
if (state.activeRoundEffects.length === 0) {
|
||||
return;
|
||||
@@ -132,6 +174,7 @@ export function buildEnergySimulation(state: GameState): EnergySimulation {
|
||||
terminalRow: state.config.rows - 1,
|
||||
intercepted: false,
|
||||
ownerId: null,
|
||||
playersPresent: [],
|
||||
hitNode: null,
|
||||
rootKey: null,
|
||||
branchNodes: [],
|
||||
@@ -142,6 +185,7 @@ export function buildEnergySimulation(state: GameState): EnergySimulation {
|
||||
|
||||
const hitNode = parseKey(hitNodeKey);
|
||||
const ownerId = state.nodes.get(hitNodeKey)?.ownerId as PlayerId;
|
||||
const playersPresent = getColumnPresence(state, column);
|
||||
const branchNodes = [hitNode];
|
||||
const branchEdges = [];
|
||||
let cursor = hitNodeKey;
|
||||
@@ -153,12 +197,13 @@ export function buildEnergySimulation(state: GameState): EnergySimulation {
|
||||
cursor = parentKey;
|
||||
}
|
||||
|
||||
scores[ownerId] += 1;
|
||||
applyColumnBaseEnergy(state, scores, ownerId, playersPresent);
|
||||
columns.push({
|
||||
column,
|
||||
terminalRow: hitNode.row,
|
||||
intercepted: true,
|
||||
ownerId,
|
||||
playersPresent,
|
||||
hitNode,
|
||||
rootKey: cursor,
|
||||
branchNodes,
|
||||
|
||||
Reference in New Issue
Block a user