v1
This commit is contained in:
parent
43a4d371a1
commit
e8f062415d
16 changed files with 900 additions and 306 deletions
|
|
@ -1,6 +1,6 @@
|
|||
export { availableMoves, AvailableMoves } from './src/available-moves';
|
||||
export { currentPlayers, ended, move, reconstructState, setup, stripSecret } from './src/engine';
|
||||
export { currentPlayers, ended, move, playersSortedByScore, reconstructState, setup, stripSecret } from './src/engine';
|
||||
export { Phase } from './src/gamestate';
|
||||
export type { GameState, Player } from './src/gamestate';
|
||||
export { GameEventName, LogItem } from './src/log';
|
||||
export { LogItem } from './src/log';
|
||||
export { Move, MoveName, Moves } from './src/move';
|
||||
|
|
|
|||
|
|
@ -3,14 +3,14 @@ import { cloneDeep, isEqual, range } from 'lodash';
|
|||
import seedrandom from 'seedrandom';
|
||||
import { availableMoves } from './available-moves';
|
||||
import { GameOptions, GameState, Phase, Player, PowerPlant, PowerPlantType, ResourceType } from './gamestate';
|
||||
import { GameEventName, LogItem } from './log';
|
||||
import { LogItem } from './log';
|
||||
import map from './map';
|
||||
import { Move, MoveName, Moves } from './move';
|
||||
import powerPlants from './powerPlants';
|
||||
import prices from './prices';
|
||||
import { asserts, shuffle } from './utils';
|
||||
|
||||
const playerColors = ['green', 'mediumorchid', 'red', 'dodgerblue', 'yellow', 'brown'];
|
||||
const playerColors = ['limegreen', 'mediumorchid', 'red', 'dodgerblue', 'yellow', 'brown'];
|
||||
|
||||
const coalResupply = [
|
||||
[3, 4, 3],
|
||||
|
|
@ -43,6 +43,7 @@ const uraniumResupply = [
|
|||
const citiesToStep2 = [10, 7, 7, 7, 6];
|
||||
const citiesToEndGame = [21, 17, 17, 15, 14];
|
||||
const cityIncome = [10, 22, 33, 44, 54, 65, 73, 82, 90, 98, 105, 112, 118, 124, 129, 134, 138, 142, 145, 148, 150];
|
||||
const regionsInPlay = [3, 3, 4, 5, 5];
|
||||
|
||||
export function setup(numPlayers: number, { fastBid = false }: GameOptions, seed?: string): GameState {
|
||||
seed = seed ?? Math.random().toString();
|
||||
|
|
@ -87,13 +88,50 @@ export function setup(numPlayers: number, { fastBid = false }: GameOptions, seed
|
|||
passed: false,
|
||||
skipAuction: false,
|
||||
citiesPowered: 0,
|
||||
resourcesUsed: [],
|
||||
}));
|
||||
|
||||
const playerOrder = shuffle(range(numPlayers), rng() + '');
|
||||
const startingPlayer = playerOrder[0];
|
||||
|
||||
const regions = map.cities
|
||||
.filter((c, i) => map.cities.findIndex((cc) => cc.region == c.region) == i)
|
||||
.map((c) => c.region);
|
||||
const regionConnections = regions.map((region) =>
|
||||
regions.filter(
|
||||
(area2) =>
|
||||
region != area2 &&
|
||||
(map.connections.some(
|
||||
(con) =>
|
||||
map.cities.find((city) => city.name == con.from)!.region == region &&
|
||||
map.cities.find((city) => city.name == con.to)!.region == area2
|
||||
) ||
|
||||
map.connections.some(
|
||||
(con) =>
|
||||
map.cities.find((city) => city.name == con.to)!.region == region &&
|
||||
map.cities.find((city) => city.name == con.from)!.region == area2
|
||||
))
|
||||
)
|
||||
);
|
||||
|
||||
const playRegions = new Set<string>();
|
||||
while (playRegions.size != regionsInPlay[players.length - 2]) {
|
||||
const region = regions[Math.floor(rng() * regions.length)];
|
||||
if (playRegions.size == 0 || regionConnections[regions.indexOf(region)].some((con) => playRegions.has(con))) {
|
||||
playRegions.add(region);
|
||||
}
|
||||
}
|
||||
|
||||
const filteredMap = cloneDeep(map);
|
||||
filteredMap.cities = filteredMap.cities.filter((city) => playRegions.has(city.region));
|
||||
filteredMap.connections = filteredMap.connections.filter(
|
||||
(con) =>
|
||||
playRegions.has(map.cities.find((city) => city.name == con.from)!.region) &&
|
||||
playRegions.has(map.cities.find((city) => city.name == con.to)!.region)
|
||||
);
|
||||
|
||||
const G: GameState = {
|
||||
map,
|
||||
map: filteredMap,
|
||||
players,
|
||||
playerOrder,
|
||||
currentPlayers: [startingPlayer],
|
||||
|
|
@ -120,9 +158,12 @@ export function setup(numPlayers: number, { fastBid = false }: GameOptions, seed
|
|||
seed,
|
||||
round: 1,
|
||||
auctionSkips: 0,
|
||||
citiesToStep2: citiesToStep2[numPlayers - 2],
|
||||
citiesToEndGame: citiesToEndGame[numPlayers - 2],
|
||||
resourceResupply: '',
|
||||
} as GameState;
|
||||
|
||||
G.log.push({ type: 'event', event: { name: GameEventName.GameStart } });
|
||||
G.log.push({ type: 'event', event: 'Game Start!' });
|
||||
|
||||
G.players[startingPlayer].availableMoves = availableMoves(G, G.players[startingPlayer]);
|
||||
|
||||
|
|
@ -172,25 +213,19 @@ export function move(G: GameState, move: Move, playerNumber: number, fake?: bool
|
|||
|
||||
const notPassed = G.players.filter((p) => !p.skipAuction);
|
||||
if (notPassed.length == 1) {
|
||||
G.log.push({
|
||||
type: 'move',
|
||||
player: playerNumber,
|
||||
move,
|
||||
simple: `${player.name} chooses Power Plant ${move.data}`,
|
||||
pretty: `${playerNameHTML(player)} chooses Power Plant <b>${move.data}</b>`,
|
||||
});
|
||||
|
||||
const winningPlayer = notPassed[0];
|
||||
winningPlayer.powerPlants.push(G.chosenPowerPlant);
|
||||
winningPlayer.money -= move.data;
|
||||
winningPlayer.skipAuction = true;
|
||||
|
||||
updatePlayerCapacity(winningPlayer);
|
||||
|
||||
removePowerPlant(G, G.chosenPowerPlant);
|
||||
G.chosenPowerPlant = G.currentBid = undefined;
|
||||
endAuction(G, winningPlayer, move.data);
|
||||
|
||||
if (G.round == 1) {
|
||||
G.playerOrder = cloneDeep(G.players)
|
||||
.sort(
|
||||
(a, b) =>
|
||||
Math.max(...a.powerPlants.map((pp) => pp.number)) -
|
||||
Math.max(...b.powerPlants.map((pp) => pp.number))
|
||||
)
|
||||
.map((p) => p.id)
|
||||
.reverse();
|
||||
setPlayerOrder(G);
|
||||
}
|
||||
|
||||
if (
|
||||
|
|
@ -198,27 +233,18 @@ export function move(G: GameState, move: Move, playerNumber: number, fake?: bool
|
|||
(G.players.length == 2 && winningPlayer.powerPlants.length == 4)
|
||||
) {
|
||||
addPowerPlant(G);
|
||||
G.players.forEach((p) => {
|
||||
p.bid = 0;
|
||||
p.passed = false;
|
||||
});
|
||||
|
||||
G.players.forEach((p) => {
|
||||
p.skipAuction = false;
|
||||
});
|
||||
G.phase = Phase.Resources;
|
||||
G.currentPlayers = [G.playerOrder[G.players.length - 1]];
|
||||
toResourcesPhase(G);
|
||||
}
|
||||
} else {
|
||||
G.log.push({
|
||||
type: 'move',
|
||||
player: playerNumber,
|
||||
move,
|
||||
simple: `${player.name} chooses Power Plant ${move.data} to initiate an auction`,
|
||||
pretty: `${playerNameHTML(player)} chooses Power Plant <b>${move.data}</b> to initiate an auction`,
|
||||
});
|
||||
}
|
||||
|
||||
G.log.push({
|
||||
type: 'move',
|
||||
player: playerNumber,
|
||||
move,
|
||||
simple: `${player.name} chooses power plant ${move.data} to initiate an auction`,
|
||||
pretty: `${playerNameHTML(player)} chooses power plant ${move.data} to initiate an auction`,
|
||||
});
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -232,7 +258,7 @@ export function move(G: GameState, move: Move, playerNumber: number, fake?: bool
|
|||
player: playerNumber,
|
||||
move,
|
||||
simple: `${player.name} bids $${move.data}`,
|
||||
pretty: `${playerNameHTML(player)} bids ${move.data}`,
|
||||
pretty: `${playerNameHTML(player)} bids <span style="color: green">$${move.data}</span>`,
|
||||
});
|
||||
|
||||
nextPlayerAuction(G);
|
||||
|
|
@ -243,6 +269,14 @@ export function move(G: GameState, move: Move, playerNumber: number, fake?: bool
|
|||
case MoveName.Pass: {
|
||||
asserts<Moves.MovePass>(move);
|
||||
|
||||
G.log.push({
|
||||
type: 'move',
|
||||
player: playerNumber,
|
||||
move,
|
||||
simple: `${player.name} passes`,
|
||||
pretty: `${playerNameHTML(player)} passes`,
|
||||
});
|
||||
|
||||
switch (G.phase) {
|
||||
case Phase.Auction: {
|
||||
if (G.chosenPowerPlant == undefined) {
|
||||
|
|
@ -253,16 +287,15 @@ export function move(G: GameState, move: Move, playerNumber: number, fake?: bool
|
|||
nextPlayerAuction(G);
|
||||
} else {
|
||||
if (G.auctionSkips == G.players.length) {
|
||||
G.log.push({
|
||||
type: 'event',
|
||||
event: `Everyone passed, removing lowest numbered Power Plant (${G.actualMarket[0].number})`,
|
||||
});
|
||||
G.actualMarket.shift();
|
||||
addPowerPlant(G);
|
||||
}
|
||||
|
||||
G.players.forEach((p) => {
|
||||
p.bid = 0;
|
||||
p.skipAuction = false;
|
||||
});
|
||||
G.phase = Phase.Resources;
|
||||
G.currentPlayers = [G.playerOrder[G.players.length - 1]];
|
||||
toResourcesPhase(G);
|
||||
}
|
||||
} else {
|
||||
player.passed = true;
|
||||
|
|
@ -270,14 +303,7 @@ export function move(G: GameState, move: Move, playerNumber: number, fake?: bool
|
|||
const notPassed = G.players.filter((p) => !p.passed && !p.skipAuction);
|
||||
if (notPassed.length == 1) {
|
||||
const winningPlayer = notPassed[0];
|
||||
winningPlayer.powerPlants.push(G.chosenPowerPlant);
|
||||
winningPlayer.money -= winningPlayer.bid;
|
||||
winningPlayer.skipAuction = true;
|
||||
|
||||
updatePlayerCapacity(winningPlayer);
|
||||
|
||||
removePowerPlant(G, G.chosenPowerPlant);
|
||||
G.chosenPowerPlant = G.currentBid = undefined;
|
||||
endAuction(G, winningPlayer, winningPlayer.bid);
|
||||
|
||||
if (
|
||||
winningPlayer.powerPlants.length > 4 ||
|
||||
|
|
@ -286,19 +312,16 @@ export function move(G: GameState, move: Move, playerNumber: number, fake?: bool
|
|||
G.currentPlayers = [winningPlayer.id];
|
||||
} else {
|
||||
addPowerPlant(G);
|
||||
G.players.forEach((p) => {
|
||||
p.bid = 0;
|
||||
p.passed = false;
|
||||
});
|
||||
|
||||
if (G.players.some((p) => !p.skipAuction)) {
|
||||
G.players.forEach((p) => {
|
||||
p.bid = 0;
|
||||
p.passed = false;
|
||||
});
|
||||
|
||||
nextPlayerAuction(G, true);
|
||||
} else {
|
||||
G.players.forEach((p) => {
|
||||
p.skipAuction = false;
|
||||
});
|
||||
G.phase = Phase.Resources;
|
||||
G.currentPlayers = [G.playerOrder[G.players.length - 1]];
|
||||
toResourcesPhase(G);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
@ -331,16 +354,19 @@ export function move(G: GameState, move: Move, playerNumber: number, fake?: bool
|
|||
if (G.players.filter((p) => !p.passed).length == 0) {
|
||||
const maxCities = Math.max(...G.players.map((p) => p.cities.length));
|
||||
if (G.step == 1) {
|
||||
if (maxCities >= citiesToStep2[G.players.length - 2]) {
|
||||
if (maxCities >= G.citiesToStep2) {
|
||||
G.actualMarket.shift();
|
||||
addPowerPlant(G);
|
||||
G.log.push({ type: 'event', event: `Starting Step 2` });
|
||||
G.step = 2;
|
||||
}
|
||||
}
|
||||
|
||||
if (maxCities >= citiesToEndGame[G.players.length - 2]) {
|
||||
if (maxCities >= G.citiesToEndGame) {
|
||||
G.phase = Phase.GameEnd;
|
||||
G.currentPlayers = [];
|
||||
calculateCitiesPowered(G);
|
||||
G.log.push({ type: 'event', event: `Game Ended!` });
|
||||
} else {
|
||||
G.players.forEach((p) => {
|
||||
p.passed = false;
|
||||
|
|
@ -363,32 +389,45 @@ export function move(G: GameState, move: Move, playerNumber: number, fake?: bool
|
|||
player.citiesPowered = 0;
|
||||
|
||||
if (G.players.filter((p) => !p.passed).length == 0) {
|
||||
G.coalMarket += Math.min(G.coalSupply, coalResupply[G.players.length - 2][G.step - 1]);
|
||||
G.coalMarket = Math.min(G.coalMarket, 24);
|
||||
G.coalSupply = Math.max(0, G.coalSupply - coalResupply[G.players.length - 2][G.step - 1]);
|
||||
|
||||
G.oilMarket += Math.min(G.oilSupply, oilResupply[G.players.length - 2][G.step - 1]);
|
||||
G.oilMarket = Math.min(G.oilMarket, 24);
|
||||
G.oilSupply = Math.max(0, G.oilSupply - oilResupply[G.players.length - 2][G.step - 1]);
|
||||
|
||||
G.garbageMarket += Math.min(G.garbageSupply, garbageResupply[G.players.length - 2][G.step - 1]);
|
||||
G.garbageMarket = Math.min(G.garbageMarket, 24);
|
||||
G.garbageSupply = Math.max(
|
||||
0,
|
||||
G.garbageSupply - garbageResupply[G.players.length - 2][G.step - 1]
|
||||
const coalResupplyValue = Math.min(
|
||||
G.coalSupply,
|
||||
coalResupply[G.players.length - 2][G.step - 1]
|
||||
);
|
||||
G.coalMarket += coalResupplyValue;
|
||||
G.coalSupply -= coalResupplyValue;
|
||||
|
||||
G.uraniumMarket += Math.min(G.uraniumSupply, uraniumResupply[G.players.length - 2][G.step - 1]);
|
||||
G.uraniumMarket = Math.min(G.uraniumMarket, 12);
|
||||
G.uraniumSupply = Math.max(
|
||||
0,
|
||||
G.uraniumSupply - uraniumResupply[G.players.length - 2][G.step - 1]
|
||||
const oilResupplyValue = Math.min(G.oilSupply, oilResupply[G.players.length - 2][G.step - 1]);
|
||||
G.oilMarket += oilResupplyValue;
|
||||
G.oilSupply -= oilResupplyValue;
|
||||
|
||||
const garbageResupplyValue = Math.min(
|
||||
G.garbageSupply,
|
||||
garbageResupply[G.players.length - 2][G.step - 1]
|
||||
);
|
||||
G.garbageMarket += garbageResupplyValue;
|
||||
G.garbageSupply -= garbageResupplyValue;
|
||||
|
||||
const uraniumResupplyValue = Math.min(
|
||||
G.uraniumSupply,
|
||||
uraniumResupply[G.players.length - 2][G.step - 1]
|
||||
);
|
||||
G.uraniumMarket += uraniumResupplyValue;
|
||||
G.uraniumSupply -= uraniumResupplyValue;
|
||||
|
||||
G.log.push({
|
||||
type: 'event',
|
||||
event: `Resupplying resources: [${coalResupplyValue}, ${oilResupplyValue}, ${garbageResupplyValue}, ${uraniumResupplyValue}]`,
|
||||
});
|
||||
|
||||
if (G.step < 3) {
|
||||
const powerPlant = G.futureMarket.pop()!;
|
||||
G.log.push({
|
||||
type: 'event',
|
||||
event: `Putting Power Plant ${powerPlant.number} on the bottom of the deck`,
|
||||
});
|
||||
G.powerPlantsDeck.push(powerPlant);
|
||||
} else {
|
||||
} else if (G.actualMarket.length > 0) {
|
||||
G.log.push({ type: 'event', event: `Discarding Power Plant ${G.actualMarket[0].number}` });
|
||||
G.actualMarket.shift();
|
||||
}
|
||||
|
||||
|
|
@ -396,22 +435,7 @@ export function move(G: GameState, move: Move, playerNumber: number, fake?: bool
|
|||
|
||||
G.round++;
|
||||
|
||||
G.playerOrder = cloneDeep(G.players)
|
||||
.sort((a, b) => {
|
||||
const citiesA = a.cities.length;
|
||||
const citiesB = b.cities.length;
|
||||
|
||||
if (citiesA == citiesB) {
|
||||
return (
|
||||
Math.max(...a.powerPlants.map((pp) => pp.number)) -
|
||||
Math.max(...b.powerPlants.map((pp) => pp.number))
|
||||
);
|
||||
}
|
||||
|
||||
return citiesA - citiesB;
|
||||
})
|
||||
.map((p) => p.id)
|
||||
.reverse();
|
||||
setPlayerOrder(G);
|
||||
|
||||
G.players.forEach((p) => {
|
||||
p.passed = false;
|
||||
|
|
@ -427,14 +451,6 @@ export function move(G: GameState, move: Move, playerNumber: number, fake?: bool
|
|||
}
|
||||
}
|
||||
|
||||
G.log.push({
|
||||
type: 'move',
|
||||
player: playerNumber,
|
||||
move,
|
||||
simple: `${player.name} passes`,
|
||||
pretty: `${playerNameHTML(player)} passes`,
|
||||
});
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -484,6 +500,15 @@ export function move(G: GameState, move: Move, playerNumber: number, fake?: bool
|
|||
});
|
||||
G.phase = Phase.Resources;
|
||||
G.currentPlayers = [G.playerOrder[G.players.length - 1]];
|
||||
|
||||
if (G.futureMarket.find((pp) => pp.number == 99)) {
|
||||
G.step = 3;
|
||||
G.actualMarket.shift();
|
||||
G.futureMarket.pop();
|
||||
|
||||
G.actualMarket = [...G.actualMarket, ...G.futureMarket];
|
||||
G.futureMarket = [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -491,8 +516,8 @@ export function move(G: GameState, move: Move, playerNumber: number, fake?: bool
|
|||
type: 'move',
|
||||
player: playerNumber,
|
||||
move,
|
||||
simple: `${player.name} discards power plant ${move.data}`,
|
||||
pretty: `${playerNameHTML(player)} discards power plant ${move.data}`,
|
||||
simple: `${player.name} discards Power Plant ${move.data}`,
|
||||
pretty: `${playerNameHTML(player)} discards Power Plant <b>${move.data}</b>`,
|
||||
});
|
||||
|
||||
break;
|
||||
|
|
@ -545,6 +570,15 @@ export function move(G: GameState, move: Move, playerNumber: number, fake?: bool
|
|||
});
|
||||
G.phase = Phase.Resources;
|
||||
G.currentPlayers = [G.playerOrder[G.players.length - 1]];
|
||||
|
||||
if (G.futureMarket.find((pp) => pp.number == 99)) {
|
||||
G.step = 3;
|
||||
G.actualMarket.shift();
|
||||
G.futureMarket.pop();
|
||||
|
||||
G.actualMarket = [...G.actualMarket, ...G.futureMarket];
|
||||
G.futureMarket = [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -553,7 +587,7 @@ export function move(G: GameState, move: Move, playerNumber: number, fake?: bool
|
|||
player: playerNumber,
|
||||
move,
|
||||
simple: `${player.name} discarded a ${move.data}`,
|
||||
pretty: `${playerNameHTML(player)} discarded a ${move.data}`,
|
||||
pretty: `${playerNameHTML(player)} discarded a <b>${move.data}</b>`,
|
||||
});
|
||||
|
||||
break;
|
||||
|
|
@ -595,8 +629,10 @@ export function move(G: GameState, move: Move, playerNumber: number, fake?: bool
|
|||
type: 'move',
|
||||
player: playerNumber,
|
||||
move,
|
||||
simple: `${player.name} buys ${move.data.resource} for ${price}`,
|
||||
pretty: `${playerNameHTML(player)} buys ${move.data.resource} for ${price}`,
|
||||
simple: `${player.name} buys ${move.data.resource} for $${price}`,
|
||||
pretty: `${playerNameHTML(player)} buys <b>${
|
||||
move.data.resource
|
||||
}</b> for <span style="color: green">$${price}</span>`,
|
||||
});
|
||||
|
||||
break;
|
||||
|
|
@ -618,8 +654,10 @@ export function move(G: GameState, move: Move, playerNumber: number, fake?: bool
|
|||
type: 'move',
|
||||
player: playerNumber,
|
||||
move,
|
||||
simple: `${player.name} builds on ${move.data.name} for ${move.data.price}`,
|
||||
pretty: `${playerNameHTML(player)} builds on ${move.data.name} for ${move.data.price}`,
|
||||
simple: `${player.name} builds on ${move.data.name} for $${move.data.price}`,
|
||||
pretty: `${playerNameHTML(player)} builds on <b>${move.data.name}</b> for <span style="color: green">$${
|
||||
move.data.price
|
||||
}</span>`,
|
||||
});
|
||||
|
||||
break;
|
||||
|
|
@ -660,7 +698,7 @@ export function move(G: GameState, move: Move, playerNumber: number, fake?: bool
|
|||
player: playerNumber,
|
||||
move,
|
||||
simple: `${player.name} uses Power Plant ${move.data.powerPlant}`,
|
||||
pretty: `${playerNameHTML(player)} uses Power Plant ${move.data.powerPlant}`,
|
||||
pretty: `${playerNameHTML(player)} uses Power Plant <b>${move.data.powerPlant}</b>`,
|
||||
});
|
||||
|
||||
break;
|
||||
|
|
@ -684,6 +722,10 @@ export function move(G: GameState, move: Move, playerNumber: number, fake?: bool
|
|||
|
||||
G.currentPlayers.forEach((p) => (G.players[p].availableMoves = availableMoves(G, G.players[p])));
|
||||
|
||||
const p = G.players.length - 2;
|
||||
const i = G.step - 1;
|
||||
G.resourceResupply = `[${coalResupply[p][i]}, ${oilResupply[p][i]}, ${garbageResupply[p][i]}, ${uraniumResupply[p][i]}]`;
|
||||
|
||||
return G;
|
||||
}
|
||||
|
||||
|
|
@ -695,9 +737,19 @@ export function moveAI(G: GameState, playerNumber: number): GameState {
|
|||
switch (G.phase) {
|
||||
case Phase.Auction: {
|
||||
if (availableMoves?.ChoosePowerPlant) {
|
||||
chosenMove = { name: MoveName.ChoosePowerPlant, data: chooseRandom(availableMoves.ChoosePowerPlant) };
|
||||
if (
|
||||
!availableMoves.Pass ||
|
||||
(Math.random() > 0.5 && player.money - availableMoves.ChoosePowerPlant[0] >= 20)
|
||||
) {
|
||||
chosenMove = {
|
||||
name: MoveName.ChoosePowerPlant,
|
||||
data: chooseRandom(availableMoves.ChoosePowerPlant),
|
||||
};
|
||||
} else {
|
||||
chosenMove = { name: MoveName.Pass, data: true };
|
||||
}
|
||||
} else if (availableMoves?.Bid) {
|
||||
if (!availableMoves.Pass || (Math.random() > 0.5 && player.money - 15 >= availableMoves?.Bid[0])) {
|
||||
if (!availableMoves.Pass || (Math.random() > 0.5 && player.money - availableMoves?.Bid[0] >= 15)) {
|
||||
chosenMove = { name: MoveName.Bid, data: availableMoves?.Bid[0] };
|
||||
} else {
|
||||
chosenMove = { name: MoveName.Pass, data: true };
|
||||
|
|
@ -874,6 +926,8 @@ function addPowerPlant(G: GameState) {
|
|||
G.step = 3;
|
||||
G.actualMarket.shift();
|
||||
}
|
||||
} else {
|
||||
G.log.push({ type: 'event', event: `Power Plant ${powerPlant.number} drawn from the deck.` });
|
||||
}
|
||||
|
||||
const market = [...G.actualMarket, ...G.futureMarket, powerPlant];
|
||||
|
|
@ -914,3 +968,137 @@ function playerNameHTML(player) {
|
|||
player.name
|
||||
}</span>`;
|
||||
}
|
||||
|
||||
export function playersSortedByScore(G: GameState) {
|
||||
return cloneDeep(G.players)
|
||||
.sort((p1, p2) => {
|
||||
if (p1.citiesPowered == p2.citiesPowered) {
|
||||
if (p1.money == p2.money) {
|
||||
return p1.cities.length - p2.cities.length;
|
||||
}
|
||||
|
||||
return p1.money - p2.money;
|
||||
}
|
||||
|
||||
return p1.citiesPowered - p2.citiesPowered;
|
||||
})
|
||||
.reverse();
|
||||
}
|
||||
|
||||
function calculateCitiesPowered(G: GameState) {
|
||||
G.players.forEach((player) => {
|
||||
player.citiesPowered = 0;
|
||||
|
||||
const permutations: PowerPlant[][] = [];
|
||||
for (let i = 0; i < Math.pow(2, player.powerPlants.length); i++) {
|
||||
const perm: PowerPlant[] = [];
|
||||
player.powerPlants.forEach((pp, index) => {
|
||||
if (i & Math.pow(2, index)) {
|
||||
perm.push(pp);
|
||||
}
|
||||
});
|
||||
permutations.push(perm);
|
||||
}
|
||||
|
||||
let max = 0;
|
||||
permutations.forEach((permutation) => {
|
||||
if (isValid(player, permutation)) {
|
||||
const citiesPowered = permutation.map((p) => p.citiesPowered).reduce((a, b) => a + b, 0);
|
||||
max = Math.max(max, citiesPowered);
|
||||
}
|
||||
});
|
||||
|
||||
player.citiesPowered = Math.min(player.cities.length, max);
|
||||
});
|
||||
}
|
||||
|
||||
function isValid(player: Player, powerPlants: PowerPlant[]) {
|
||||
const coalUsed = powerPlants
|
||||
.filter((pp) => pp.type == PowerPlantType.Coal)
|
||||
.map((pp) => pp.cost)
|
||||
.reduce((a, b) => a + b, 0);
|
||||
const oilUsed = powerPlants
|
||||
.filter((pp) => pp.type == PowerPlantType.Oil)
|
||||
.map((pp) => pp.cost)
|
||||
.reduce((a, b) => a + b, 0);
|
||||
const garbageUsed = powerPlants
|
||||
.filter((pp) => pp.type == PowerPlantType.Garbage)
|
||||
.map((pp) => pp.cost)
|
||||
.reduce((a, b) => a + b, 0);
|
||||
const uraniumUsed = powerPlants
|
||||
.filter((pp) => pp.type == PowerPlantType.Uranium)
|
||||
.map((pp) => pp.cost)
|
||||
.reduce((a, b) => a + b, 0);
|
||||
const hybridUsed = powerPlants
|
||||
.filter((pp) => pp.type == PowerPlantType.Hybrid)
|
||||
.map((pp) => pp.cost)
|
||||
.reduce((a, b) => a + b, 0);
|
||||
|
||||
if (
|
||||
coalUsed > player.coalLeft ||
|
||||
oilUsed > player.oilLeft ||
|
||||
garbageUsed > player.garbageLeft ||
|
||||
uraniumUsed > player.uraniumLeft
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (hybridUsed > player.coalLeft - coalUsed + player.oilLeft - oilUsed) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function toResourcesPhase(G: GameState) {
|
||||
G.players.forEach((p) => {
|
||||
p.bid = 0;
|
||||
p.passed = false;
|
||||
});
|
||||
|
||||
G.players.forEach((p) => {
|
||||
p.skipAuction = false;
|
||||
});
|
||||
|
||||
G.phase = Phase.Resources;
|
||||
G.currentPlayers = [G.playerOrder[G.players.length - 1]];
|
||||
|
||||
if (G.futureMarket.find((pp) => pp.number == 99)) {
|
||||
G.log.push({ type: 'event', event: `Starting Step 3` });
|
||||
G.step = 3;
|
||||
G.actualMarket.shift();
|
||||
G.futureMarket.pop();
|
||||
|
||||
G.actualMarket = [...G.actualMarket, ...G.futureMarket];
|
||||
G.futureMarket = [];
|
||||
}
|
||||
}
|
||||
|
||||
function endAuction(G: GameState, winningPlayer: Player, bid: number) {
|
||||
winningPlayer.powerPlants.push(G.chosenPowerPlant!);
|
||||
winningPlayer.money -= bid;
|
||||
winningPlayer.skipAuction = true;
|
||||
updatePlayerCapacity(winningPlayer);
|
||||
|
||||
removePowerPlant(G, G.chosenPowerPlant!);
|
||||
G.chosenPowerPlant = G.currentBid = undefined;
|
||||
}
|
||||
|
||||
function setPlayerOrder(G: GameState) {
|
||||
G.playerOrder = cloneDeep(G.players)
|
||||
.sort((a, b) => {
|
||||
const citiesA = a.cities.length;
|
||||
const citiesB = b.cities.length;
|
||||
|
||||
if (citiesA == citiesB) {
|
||||
return (
|
||||
Math.max(...a.powerPlants.map((pp) => pp.number)) -
|
||||
Math.max(...b.powerPlants.map((pp) => pp.number))
|
||||
);
|
||||
}
|
||||
|
||||
return citiesA - citiesB;
|
||||
})
|
||||
.map((p) => p.id)
|
||||
.reverse();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ export interface GameOptions {
|
|||
|
||||
export interface City {
|
||||
name: string;
|
||||
area: string;
|
||||
region: string;
|
||||
x: number;
|
||||
y: number;
|
||||
}
|
||||
|
|
@ -79,15 +79,16 @@ export interface Player {
|
|||
passed: boolean;
|
||||
skipAuction: boolean;
|
||||
citiesPowered: number;
|
||||
resourcesUsed: ResourceType[];
|
||||
}
|
||||
|
||||
export enum Phase {
|
||||
Order = 'order',
|
||||
Auction = 'auction',
|
||||
Resources = 'resources',
|
||||
Building = 'building',
|
||||
Bureaucracy = 'bureaucracy',
|
||||
GameEnd = 'gameEnd',
|
||||
Order = 'Order',
|
||||
Auction = 'Auction',
|
||||
Resources = 'Resources',
|
||||
Building = 'Building',
|
||||
Bureaucracy = 'Bureaucracy',
|
||||
GameEnd = 'Game End',
|
||||
}
|
||||
|
||||
// export interface HousePiece {
|
||||
|
|
@ -138,4 +139,7 @@ export interface GameState {
|
|||
seed: string;
|
||||
round: number;
|
||||
auctionSkips: number;
|
||||
citiesToStep2: number;
|
||||
citiesToEndGame: number;
|
||||
resourceResupply: string;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,29 +1,6 @@
|
|||
import { Phase } from './gamestate';
|
||||
import { Move } from './move';
|
||||
|
||||
export enum GameEventName {
|
||||
GameStart = 'Game Start!',
|
||||
GameEnd = 'Game End!',
|
||||
Upkeep = 'Upkeep',
|
||||
}
|
||||
|
||||
export declare namespace GameEvents {
|
||||
export interface GameStart {
|
||||
name: GameEventName.GameStart;
|
||||
}
|
||||
|
||||
export interface GameEnd {
|
||||
name: GameEventName.GameEnd;
|
||||
}
|
||||
|
||||
export interface Upkeep {
|
||||
name: GameEventName.Upkeep;
|
||||
interest: string;
|
||||
}
|
||||
}
|
||||
|
||||
type GameEvent = GameEvents.GameStart | GameEvents.GameEnd | GameEvents.Upkeep;
|
||||
|
||||
export type LogPhase = {
|
||||
type: 'phase';
|
||||
phase: Phase;
|
||||
|
|
@ -31,7 +8,7 @@ export type LogPhase = {
|
|||
|
||||
export type LogEvent = {
|
||||
type: 'event';
|
||||
event: GameEvent;
|
||||
event: string;
|
||||
};
|
||||
|
||||
export type LogMove = {
|
||||
|
|
|
|||
|
|
@ -3,48 +3,48 @@ import { Map } from './gamestate';
|
|||
const map: Map = {
|
||||
name: 'USA',
|
||||
cities: [
|
||||
{ name: 'Seattle', area: 'purple', x: 74, y: 129 },
|
||||
{ name: 'Portland', area: 'purple', x: 45, y: 197 },
|
||||
{ name: 'Boise', area: 'purple', x: 180, y: 250 },
|
||||
{ name: 'Billings', area: 'purple', x: 345, y: 210 },
|
||||
{ name: 'Cheyenne', area: 'purple', x: 410, y: 310 },
|
||||
{ name: 'Denver', area: 'purple', x: 400, y: 363 },
|
||||
{ name: 'Omaha', area: 'purple', x: 566, y: 323 },
|
||||
{ name: 'San Francisco', area: 'cyan', x: 48, y: 401 },
|
||||
{ name: 'Los Angeles', area: 'cyan', x: 116, y: 490 },
|
||||
{ name: 'San Diego', area: 'cyan', x: 157, y: 537 },
|
||||
{ name: 'Las Vegas', area: 'cyan', x: 200, y: 440 },
|
||||
{ name: 'Saltlake City', area: 'cyan', x: 266, y: 341 },
|
||||
{ name: 'Phoenix', area: 'cyan', x: 260, y: 516 },
|
||||
{ name: 'Santa Fe', area: 'cyan', x: 371, y: 465 },
|
||||
{ name: 'Kansas City', area: 'red', x: 587, y: 386 },
|
||||
{ name: 'Oklahoma City', area: 'red', x: 550, y: 467 },
|
||||
{ name: 'Dallas', area: 'red', x: 560, y: 534 },
|
||||
{ name: 'Houston', area: 'red', x: 569, y: 601 },
|
||||
{ name: 'Menphis', area: 'red', x: 678, y: 479 },
|
||||
{ name: 'Birmingham', area: 'red', x: 739, y: 516 },
|
||||
{ name: 'New Orleans', area: 'red', x: 674, y: 600 },
|
||||
{ name: 'Fargo', area: 'yellow', x: 551, y: 182 },
|
||||
{ name: 'Duluth', area: 'yellow', x: 637, y: 163 },
|
||||
{ name: 'Minneapolis', area: 'yellow', x: 621, y: 220 },
|
||||
{ name: 'Chicago', area: 'yellow', x: 716, y: 311 },
|
||||
{ name: 'St. Louis', area: 'yellow', x: 678, y: 392 },
|
||||
{ name: 'Cincinnati', area: 'yellow', x: 795, y: 378 },
|
||||
{ name: 'Knoxvile', area: 'yellow', x: 796, y: 452 },
|
||||
{ name: 'Detroit', area: 'brown', x: 803, y: 292 },
|
||||
{ name: 'Buffalo', area: 'brown', x: 913, y: 281 },
|
||||
{ name: 'Pittsburgh', area: 'brown', x: 884, y: 346 },
|
||||
{ name: 'Boston', area: 'brown', x: 1052, y: 282 },
|
||||
{ name: 'New York', area: 'brown', x: 1010, y: 320 },
|
||||
{ name: 'Philadelphia', area: 'brown', x: 985, y: 360 },
|
||||
{ name: 'Washington', area: 'brown', x: 934, y: 387 },
|
||||
{ name: 'Horecin', area: 'green', x: 969, y: 435 },
|
||||
{ name: 'Raleigh', area: 'green', x: 915, y: 467 },
|
||||
{ name: 'Atlanta', area: 'green', x: 801, y: 517 },
|
||||
{ name: 'Savannah', area: 'green', x: 867, y: 537 },
|
||||
{ name: 'Jacksonvile', area: 'green', x: 861, y: 589 },
|
||||
{ name: 'Tampa', area: 'green', x: 819, y: 651 },
|
||||
{ name: 'Miami', area: 'green', x: 883, y: 700 },
|
||||
{ name: 'Seattle', region: 'purple', x: 74, y: 129 },
|
||||
{ name: 'Portland', region: 'purple', x: 45, y: 197 },
|
||||
{ name: 'Boise', region: 'purple', x: 180, y: 250 },
|
||||
{ name: 'Billings', region: 'purple', x: 345, y: 210 },
|
||||
{ name: 'Cheyenne', region: 'purple', x: 410, y: 310 },
|
||||
{ name: 'Denver', region: 'purple', x: 400, y: 363 },
|
||||
{ name: 'Omaha', region: 'purple', x: 566, y: 323 },
|
||||
{ name: 'San Francisco', region: 'cyan', x: 48, y: 401 },
|
||||
{ name: 'Los Angeles', region: 'cyan', x: 116, y: 490 },
|
||||
{ name: 'San Diego', region: 'cyan', x: 157, y: 537 },
|
||||
{ name: 'Las Vegas', region: 'cyan', x: 200, y: 440 },
|
||||
{ name: 'Saltlake City', region: 'cyan', x: 266, y: 341 },
|
||||
{ name: 'Phoenix', region: 'cyan', x: 260, y: 516 },
|
||||
{ name: 'Santa Fe', region: 'cyan', x: 371, y: 465 },
|
||||
{ name: 'Kansas City', region: 'red', x: 587, y: 386 },
|
||||
{ name: 'Oklahoma City', region: 'red', x: 550, y: 467 },
|
||||
{ name: 'Dallas', region: 'red', x: 560, y: 534 },
|
||||
{ name: 'Houston', region: 'red', x: 569, y: 601 },
|
||||
{ name: 'Menphis', region: 'red', x: 678, y: 479 },
|
||||
{ name: 'Birmingham', region: 'red', x: 739, y: 516 },
|
||||
{ name: 'New Orleans', region: 'red', x: 674, y: 600 },
|
||||
{ name: 'Fargo', region: 'yellow', x: 551, y: 182 },
|
||||
{ name: 'Duluth', region: 'yellow', x: 637, y: 163 },
|
||||
{ name: 'Minneapolis', region: 'yellow', x: 621, y: 220 },
|
||||
{ name: 'Chicago', region: 'yellow', x: 716, y: 311 },
|
||||
{ name: 'St. Louis', region: 'yellow', x: 678, y: 392 },
|
||||
{ name: 'Cincinnati', region: 'yellow', x: 795, y: 378 },
|
||||
{ name: 'Knoxvile', region: 'yellow', x: 796, y: 452 },
|
||||
{ name: 'Detroit', region: 'brown', x: 803, y: 292 },
|
||||
{ name: 'Buffalo', region: 'brown', x: 913, y: 281 },
|
||||
{ name: 'Pittsburgh', region: 'brown', x: 884, y: 346 },
|
||||
{ name: 'Boston', region: 'brown', x: 1052, y: 282 },
|
||||
{ name: 'New York', region: 'brown', x: 1010, y: 320 },
|
||||
{ name: 'Philadelphia', region: 'brown', x: 985, y: 360 },
|
||||
{ name: 'Washington', region: 'brown', x: 934, y: 387 },
|
||||
{ name: 'Horecin', region: 'green', x: 969, y: 435 },
|
||||
{ name: 'Raleigh', region: 'green', x: 915, y: 467 },
|
||||
{ name: 'Atlanta', region: 'green', x: 801, y: 517 },
|
||||
{ name: 'Savannah', region: 'green', x: 867, y: 537 },
|
||||
{ name: 'Jacksonvile', region: 'green', x: 861, y: 589 },
|
||||
{ name: 'Tampa', region: 'green', x: 819, y: 651 },
|
||||
{ name: 'Miami', region: 'green', x: 883, y: 700 },
|
||||
],
|
||||
connections: [
|
||||
{ from: 'Seattle', to: 'Portland', cost: 3 },
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { cloneDeep } from 'lodash';
|
||||
import type { GameState } from './index';
|
||||
import * as engine from './src/engine';
|
||||
import { playersSortedByScore } from './src/engine';
|
||||
import type { LogMove } from './src/log';
|
||||
import { Move, MoveName } from './src/move';
|
||||
import { asserts } from './src/utils';
|
||||
|
|
@ -24,16 +24,7 @@ export async function move(G: GameState, move: Move, player: number) {
|
|||
export { ended, scores, stripSecret } from './src/engine';
|
||||
|
||||
export function rankings(G: GameState) {
|
||||
const sortedPlayers = cloneDeep(G.players)
|
||||
.sort((p1, p2) => {
|
||||
if (p1.citiesPowered == p2.citiesPowered) {
|
||||
return p1.money - p2.money;
|
||||
} else {
|
||||
return p1.citiesPowered - p2.citiesPowered;
|
||||
}
|
||||
})
|
||||
.map((pl) => pl.id)
|
||||
.reverse();
|
||||
const sortedPlayers = playersSortedByScore(G).map((pl) => pl.id);
|
||||
|
||||
return G.players.map((pl) => sortedPlayers.indexOf(pl.id) + 1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
<source src="../audio/notification.mp3" type="audio/mpeg" />
|
||||
<source src="../audio/notification.ogg" type="audio/ogg" />
|
||||
</audio>
|
||||
<svg id="scene" viewBox="0 0 1500 800" height="1200">
|
||||
<svg id="scene" viewBox="0 0 1500 800" height="700">
|
||||
<rect width="100%" height="100%" x="0" y="0" fill="yellowgreen" />
|
||||
|
||||
<rect width="185" height="40" x="10" y="10" rx="3" fill="goldenrod" />
|
||||
|
|
@ -52,6 +52,7 @@
|
|||
text-anchor="middle"
|
||||
style="font-size: 24px; font-family: monospace"
|
||||
letter-spacing="-3"
|
||||
:text-decoration="G && (index == G.citiesToStep2 || index == G.citiesToEndGame) ? 'underline' : ''"
|
||||
:x="265 + 33 * (index - 1)"
|
||||
y="35"
|
||||
fill="gold"
|
||||
|
|
@ -199,7 +200,29 @@
|
|||
</text>
|
||||
|
||||
<text x="955" y="14" font-weight="600" fill="black">Actual Market:</text>
|
||||
<text x="955" y="80" font-weight="600" fill="black">Future Market:</text>
|
||||
<text v-if="G && G.step < 3" x="955" y="80" font-weight="600" fill="black">Future Market:</text>
|
||||
|
||||
<template v-if="G">
|
||||
<template v-if="gameEnded(G)">
|
||||
<Button
|
||||
:transform="`translate(140, 580)`"
|
||||
:width="130"
|
||||
:text="'Final Score'"
|
||||
@click="endScoreVisible = true"
|
||||
/>
|
||||
</template>
|
||||
<template v-else>
|
||||
<text x="30" y="580" font-weight="600" fill="black" style="font-size: 32px">
|
||||
Step: {{ G.step }}
|
||||
</text>
|
||||
<text x="30" y="620" font-weight="600" fill="black" style="font-size: 32px">
|
||||
Phase: {{ G.phase }}
|
||||
</text>
|
||||
<text x="30" y="680" font-weight="600" fill="black" style="font-size: 24px">
|
||||
Resource Resupply: {{ G.resourceResupply }}
|
||||
</text>
|
||||
</template>
|
||||
</template>
|
||||
|
||||
<PassButton transform="translate(1355, 15)" :enabled="canPass()" @click="pass()" />
|
||||
<UndoButton transform="translate(1355, 56)" :enabled="canUndo()" @click="undo()" />
|
||||
|
|
@ -208,7 +231,7 @@
|
|||
<HelpButton transform="translate(1450, 80)" :isOn="!preferences.disableHelp" @click="toggleHelp()" />
|
||||
|
||||
<template v-if="G">
|
||||
<template v-if="G.phase == 'auction' && G.chosenPowerPlant">
|
||||
<template v-if="G.phase == 'Auction' && G.chosenPowerPlant">
|
||||
<text x="1220" y="14" font-weight="600" fill="black">Current Auction:</text>
|
||||
<Calculator
|
||||
v-if="canBid()"
|
||||
|
|
@ -221,11 +244,11 @@
|
|||
|
||||
<template v-for="city in G.map.cities">
|
||||
<circle
|
||||
:key="city.name + '_area'"
|
||||
:key="city.name + '_region'"
|
||||
r="25"
|
||||
:cx="city.x"
|
||||
:cy="city.y - 30"
|
||||
:fill="city.area"
|
||||
:fill="city.region"
|
||||
stroke="black"
|
||||
>
|
||||
<title>{{ city.name }}</title>
|
||||
|
|
@ -319,6 +342,7 @@
|
|||
:isCurrentPlayer="isCurrentPlayer(i)"
|
||||
:ended="gameEnded(G)"
|
||||
:isPlayer="player == i"
|
||||
:ranking="sortedPlayers.findIndex((x) => x.id == p.id) + 1"
|
||||
@powerPlantClick="powerPlantClick($event)"
|
||||
/>
|
||||
</template>
|
||||
|
|
@ -390,15 +414,6 @@
|
|||
/>
|
||||
</template>
|
||||
|
||||
<template v-if="G && gameEnded(G)">
|
||||
<Button
|
||||
:transform="`translate(140, 580)`"
|
||||
:width="130"
|
||||
:text="'Final Score'"
|
||||
@click="endScoreVisible = true"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<template v-if="!preferences.disableHelp">
|
||||
<rect
|
||||
v-if="canPass()"
|
||||
|
|
@ -424,17 +439,31 @@
|
|||
rx="2px"
|
||||
/>
|
||||
|
||||
<rect
|
||||
v-if="canChoose()"
|
||||
x="950"
|
||||
y="5"
|
||||
width="265"
|
||||
height="65"
|
||||
fill="none"
|
||||
stroke="blue"
|
||||
stroke-width="2px"
|
||||
rx="2px"
|
||||
/>
|
||||
<g v-if="G && canChoose()">
|
||||
<rect
|
||||
v-if="G.step < 3"
|
||||
x="950"
|
||||
y="5"
|
||||
width="265"
|
||||
height="65"
|
||||
fill="none"
|
||||
stroke="blue"
|
||||
stroke-width="2px"
|
||||
rx="2px"
|
||||
/>
|
||||
|
||||
<rect
|
||||
v-else
|
||||
x="950"
|
||||
y="5"
|
||||
width="200"
|
||||
height="120"
|
||||
fill="none"
|
||||
stroke="blue"
|
||||
stroke-width="2px"
|
||||
rx="2px"
|
||||
/>
|
||||
</g>
|
||||
|
||||
<rect
|
||||
v-if="canBuyResource()"
|
||||
|
|
@ -493,54 +522,33 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<!-- <div v-if="G" :class="['modal', { visible: endScoreVisible }]">
|
||||
<div v-if="G && gameEnded(G)" :class="['modal', { visible: endScoreVisible }]">
|
||||
<div class="modal-content">
|
||||
<span class="close" @click="endScoreVisible = false">×</span>
|
||||
<div class="modal-title">Final Score</div>
|
||||
<table class="final-score-table">
|
||||
<tr>
|
||||
<th><div>Player</div></th>
|
||||
<th v-for="player in G.players" :key="'FS' + player.id">
|
||||
<th v-for="player in sortedPlayers" :key="'FS' + player.id">
|
||||
<div :style="'background-color: ' + playerColors[player.id]">{{ player.name }}</div>
|
||||
</th>
|
||||
</tr>
|
||||
<tr
|
||||
v-for="(cat, i) in [
|
||||
'Money',
|
||||
'$10 containers',
|
||||
'$5/$10 containers',
|
||||
'$6 containers',
|
||||
'$4 containers',
|
||||
'$2 containers',
|
||||
'Discarded color',
|
||||
'Containers in Warehouses ($2 each)',
|
||||
'Containers on Ship ($3 each)',
|
||||
'Loans (-$11 each)',
|
||||
]"
|
||||
:key="'FC_' + cat">
|
||||
<tr v-for="(cat, i) in ['Cities Powered', 'Money', 'Total Cities']" :key="'FC_' + cat">
|
||||
<td>{{ cat }}</td>
|
||||
<td v-for="player in G.players" :key="'FS' + player.id + i">
|
||||
<div
|
||||
:style="i === 6 || i === 9 ? 'color: red;' : 'color: green;'"
|
||||
v-html="getFinalScoreHTML(player, i)" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Final Score</td>
|
||||
<td v-for="player in G.players" :key="'FS' + player.id + 'money'">
|
||||
<div style="font-weight: bold" :style="player.money < 0 ? 'color: red;' : 'color: green;'">
|
||||
{{ player.money > 0 ? '$' + player.money : '-$' + Math.abs(player.money) }}
|
||||
<td v-for="player in sortedPlayers" :key="'FS' + player.id + i">
|
||||
<div>
|
||||
{{ i == 0 ? player.citiesPowered : i == 1 ? player.money : player.cities.length }}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div> -->
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
import { Vue, Component, Prop, Watch, Provide, ProvideReactive } from 'vue-property-decorator';
|
||||
import { MoveName, ended, move as engineMove } from 'powergrid-engine';
|
||||
import { MoveName, ended, move as engineMove, playersSortedByScore } from 'powergrid-engine';
|
||||
import type { GameState } from 'powergrid-engine';
|
||||
import { EventEmitter } from 'events';
|
||||
import { Piece, UIData, Preferences } from '../types/ui-data';
|
||||
|
|
@ -548,7 +556,7 @@ import { Card, House, Coal, Oil, Garbage, Uranium } from './pieces';
|
|||
import { Button, PassButton, UndoButton, LogButton, SoundButton, HelpButton } from './buttons';
|
||||
import PlayerBoard from './PlayerBoard.vue';
|
||||
import Calculator from './Calculator.vue';
|
||||
import { GameEventName, LogMove } from 'powergrid-engine/src/log';
|
||||
import { LogMove } from 'powergrid-engine/src/log';
|
||||
import { City, Phase, PowerPlant, PowerPlantType, ResourceType } from 'powergrid-engine/src/gamestate';
|
||||
|
||||
@Component({
|
||||
|
|
@ -651,7 +659,7 @@ export default class Game extends Vue {
|
|||
offsetX = -15;
|
||||
offsetY = -34;
|
||||
} else {
|
||||
offsetX = 15;
|
||||
offsetX = 1;
|
||||
offsetY = -34;
|
||||
}
|
||||
|
||||
|
|
@ -769,14 +777,26 @@ export default class Game extends Vue {
|
|||
// Power Plants
|
||||
this.cards = [];
|
||||
this.G?.actualMarket.forEach((card, i) => {
|
||||
if (card.number != this.G?.chosenPowerPlant?.number) {
|
||||
this.cards.push({
|
||||
id: 'actual_' + i,
|
||||
x: 955 + i * 65,
|
||||
y: 24,
|
||||
powerPlant: card,
|
||||
isActualMarket: true
|
||||
});
|
||||
if (this.G!.step < 3) {
|
||||
if (card.number != this.G?.chosenPowerPlant?.number) {
|
||||
this.cards.push({
|
||||
id: 'actual_' + i,
|
||||
x: 955 + i * 65,
|
||||
y: 24,
|
||||
powerPlant: card,
|
||||
isActualMarket: true
|
||||
});
|
||||
}
|
||||
} else {
|
||||
if (card.number != this.G?.chosenPowerPlant?.number) {
|
||||
this.cards.push({
|
||||
id: 'actual_' + i,
|
||||
x: 955 + (i % 3) * 65,
|
||||
y: i < 3 ? 24 : 80,
|
||||
powerPlant: card,
|
||||
isActualMarket: true
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -883,8 +903,9 @@ export default class Game extends Vue {
|
|||
break;
|
||||
case PowerPlantType.Hybrid:
|
||||
const currentPlayer = this.G!.players[this.player!];
|
||||
resourcesSpent = Array(Math.min(powerPlant.cost, currentPlayer.coalLeft)).fill(ResourceType.Coal)
|
||||
.concat(Array(powerPlant.cost - Math.min(powerPlant.cost, currentPlayer.coalLeft)).fill(ResourceType.Oil));
|
||||
resourcesSpent = currentPlayer.resourcesUsed;
|
||||
resourcesSpent.sort();
|
||||
currentPlayer.resourcesUsed = [];
|
||||
|
||||
break;
|
||||
}
|
||||
|
|
@ -978,7 +999,9 @@ export default class Game extends Vue {
|
|||
const currentPlayer = this.G!.players[this.player!];
|
||||
const availableMoves = currentPlayer.availableMoves!;
|
||||
|
||||
if (this.G?.phase == Phase.Bureaucracy) {
|
||||
if (currentPlayer.resourcesUsed.length > 0) {
|
||||
return false;
|
||||
} else if (this.G?.phase == Phase.Bureaucracy) {
|
||||
return !!availableMoves[MoveName.UsePowerPlant] && availableMoves[MoveName.UsePowerPlant]!.find(p => p.powerPlant == powerPlant.number);
|
||||
} else if (this.G?.phase == Phase.Auction) {
|
||||
return !!availableMoves[MoveName.DiscardPowerPlant] && availableMoves[MoveName.DiscardPowerPlant]!.find(p => p == powerPlant.number);
|
||||
|
|
@ -1033,14 +1056,8 @@ export default class Game extends Vue {
|
|||
let logReversed: string[] = [];
|
||||
if (this.G && this.G.log) {
|
||||
this.G.log.forEach((log) => {
|
||||
if (log.type == 'phase') {
|
||||
logReversed.push('New phase: ' + log.phase);
|
||||
} else if (log.type == 'event') {
|
||||
if (log.event.name == GameEventName.Upkeep) {
|
||||
logReversed.push('New event: ' + log.event.interest);
|
||||
} else {
|
||||
logReversed.push('New event: ' + log.event.name);
|
||||
}
|
||||
if (log.type == 'event') {
|
||||
logReversed.push(log.event);
|
||||
} else if (log.type == 'move') {
|
||||
logReversed.push(log.pretty);
|
||||
}
|
||||
|
|
@ -1056,14 +1073,8 @@ export default class Game extends Vue {
|
|||
let logReversed: string[] = [];
|
||||
if (this.G && this.G.log) {
|
||||
this.G.log.forEach((log) => {
|
||||
if (log.type == 'phase') {
|
||||
logReversed.push('New phase: ' + log.phase);
|
||||
} else if (log.type == 'event') {
|
||||
if (log.event.name == GameEventName.Upkeep) {
|
||||
logReversed.push('New event: ' + log.event.interest);
|
||||
} else {
|
||||
logReversed.push('New event: ' + log.event.name);
|
||||
}
|
||||
if (log.type == 'event') {
|
||||
logReversed.push(log.event);
|
||||
} else if (log.type == 'move') {
|
||||
logReversed.push(log.simple);
|
||||
}
|
||||
|
|
@ -1080,11 +1091,8 @@ export default class Game extends Vue {
|
|||
this.emitter.emit('replaceLog', [...this.logReversedSimple].reverse());
|
||||
}
|
||||
|
||||
getCurrentPlayerMoves() {
|
||||
if (!this.canMove())
|
||||
return [];
|
||||
|
||||
return this.G!.players[this.player!].availableMoves!;
|
||||
get sortedPlayers() {
|
||||
return playersSortedByScore(this.G!);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
@ -1188,7 +1196,7 @@ text {
|
|||
display: none; /* Hidden by default */
|
||||
position: fixed; /* Stay in place */
|
||||
z-index: 1; /* Sit on top */
|
||||
padding-top: 100px; /* Location of the box */
|
||||
padding-top: 10vh; /* Location of the box */
|
||||
left: 0;
|
||||
top: 0;
|
||||
width: 100%; /* Full width */
|
||||
|
|
@ -1213,7 +1221,7 @@ text {
|
|||
}
|
||||
|
||||
.modal-log {
|
||||
max-height: calc(100% - 42px);
|
||||
max-height: calc(80vh - 75px);
|
||||
overflow: auto;
|
||||
border: 1px solid black;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@
|
|||
<g class="player-board">
|
||||
<rect width="350" height="100" x="0" y="0" fill="gold" :stroke="color" />
|
||||
<rect width="350" height="25" x="0" y="0" :fill="color" />
|
||||
<text x="5" y="13" font-weight="600" fill="black" :text-decoration="isCurrentPlayer ? 'underline' : ''">{{
|
||||
getPlayerName()
|
||||
}}</text>
|
||||
<text x="5" y="13" font-weight="600" fill="black" :text-decoration="isCurrentPlayer ? 'underline' : ''">
|
||||
{{ getPlayerName() }}
|
||||
</text>
|
||||
<text v-if="isPlayer || ended" x="250" y="13" font-weight="600" fill="black">Money: ${{ player.money }}</text>
|
||||
|
||||
<Card
|
||||
|
|
@ -14,13 +14,28 @@
|
|||
:owner="owner"
|
||||
:powerPlant="powerPlant"
|
||||
:canClick="canUse(powerPlant)"
|
||||
@click="$emit('powerPlantClick', powerPlant)"
|
||||
@click="powerPlantClick(powerPlant)"
|
||||
/>
|
||||
|
||||
<Coal :pieceId="'Coal' + player.id" :targetState="{ x: 5, y: 76 }" />
|
||||
<g v-if="canClickResources">
|
||||
<rect width="30" height="30" x="0" y="71" fill="none" stroke="blue" stroke-width="2px" rx="2px" />
|
||||
<rect width="30" height="30" x="70" y="71" fill="none" stroke="blue" stroke-width="2px" rx="2px" />
|
||||
</g>
|
||||
|
||||
<Coal
|
||||
:pieceId="'Coal' + player.id"
|
||||
:targetState="{ x: 5, y: 76 }"
|
||||
:canClick="canClickResources"
|
||||
@click="clickResource('coal')"
|
||||
/>
|
||||
<text text-anchor="middle" x="40" y="85" fill="black">{{ player.coalLeft }}</text>
|
||||
|
||||
<Oil :pieceId="'Oil' + player.id" :targetState="{ x: 75, y: 76 }" />
|
||||
<Oil
|
||||
:pieceId="'Oil' + player.id"
|
||||
:targetState="{ x: 75, y: 76 }"
|
||||
:canClick="canClickResources"
|
||||
@click="clickResource('oil')"
|
||||
/>
|
||||
<text text-anchor="middle" x="110" y="85" fill="black">{{ player.oilLeft }}</text>
|
||||
|
||||
<Garbage :pieceId="'Garbage' + player.id" :targetState="{ x: 145, y: 76 }" />
|
||||
|
|
@ -32,7 +47,7 @@
|
|||
</template>
|
||||
<script lang="ts">
|
||||
import { MoveName, Player } from 'powergrid-engine';
|
||||
import { PowerPlantType } from 'powergrid-engine/src/gamestate';
|
||||
import { PowerPlant, PowerPlantType, ResourceType } from 'powergrid-engine/src/gamestate';
|
||||
import { Vue, Component, Prop } from 'vue-property-decorator';
|
||||
import { Coal, Oil, Garbage, Uranium, Card } from './pieces';
|
||||
|
||||
|
|
@ -60,6 +75,11 @@ export default class PlayerBoard extends Vue {
|
|||
@Prop()
|
||||
isPlayer?: boolean;
|
||||
|
||||
@Prop()
|
||||
ranking?: number;
|
||||
|
||||
powerPlantClicked?: PowerPlant;
|
||||
|
||||
getPlayerName() {
|
||||
let name = '';
|
||||
if (this.isCurrentPlayer) {
|
||||
|
|
@ -68,7 +88,24 @@ export default class PlayerBoard extends Vue {
|
|||
|
||||
name += this.player.name;
|
||||
|
||||
if (this.player.skipAuction) {
|
||||
if (this.ended) {
|
||||
switch (this.ranking) {
|
||||
case 1:
|
||||
name += ' (1st)';
|
||||
break;
|
||||
case 2:
|
||||
name += ' (2nd)';
|
||||
break;
|
||||
case 3:
|
||||
name += ' (3rd)';
|
||||
break;
|
||||
case 4:
|
||||
case 5:
|
||||
case 6:
|
||||
name += ` (${this.ranking}th)`;
|
||||
break;
|
||||
}
|
||||
} else if (this.player.skipAuction) {
|
||||
name += ' (Skipping)';
|
||||
} else if (this.player.passed) {
|
||||
name += ' (Passed)';
|
||||
|
|
@ -114,5 +151,43 @@ export default class PlayerBoard extends Vue {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
powerPlantClick(powerPlant: PowerPlant) {
|
||||
if (powerPlant.type == PowerPlantType.Hybrid) {
|
||||
if (this.player.coalLeft == 0 || this.player.oilLeft == 0 || this.player.coalLeft + this.player.oilLeft == powerPlant.cost) {
|
||||
this.player.resourcesUsed = Array(Math.min(powerPlant.cost, this.player.coalLeft)).fill(ResourceType.Coal)
|
||||
.concat(Array(powerPlant.cost - Math.min(powerPlant.cost, this.player.coalLeft)).fill(ResourceType.Oil));
|
||||
this.$emit('powerPlantClick', powerPlant);
|
||||
} else {
|
||||
this.powerPlantClicked = powerPlant;
|
||||
this.player.resourcesUsed = Array(powerPlant.cost).fill(null);
|
||||
}
|
||||
} else {
|
||||
this.$emit('powerPlantClick', powerPlant);
|
||||
}
|
||||
}
|
||||
|
||||
get canClickResources() {
|
||||
return this.player.availableMoves && this.player.availableMoves['DiscardResources'] || this.player.resourcesUsed.some(r => r == null);
|
||||
}
|
||||
|
||||
clickResource(resourceType) {
|
||||
if (this.player.availableMoves && this.player.availableMoves['DiscardResources']) {
|
||||
this.$emit('discardResource', resourceType);
|
||||
} else if (this.player.resourcesUsed.some(r => r == null)) {
|
||||
const index = this.player.resourcesUsed.findIndex(r => r == null)!;
|
||||
this.player.resourcesUsed[index] = resourceType;
|
||||
|
||||
if (resourceType == 'coal') {
|
||||
this.player.coalLeft--;
|
||||
} else if (resourceType == 'oil') {
|
||||
this.player.oilLeft--;
|
||||
}
|
||||
|
||||
if (!this.player.resourcesUsed.some(r => r == null)) {
|
||||
this.$emit('powerPlantClick', this.powerPlantClicked);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
|||
115
viewer/src/components/pieces/Card.vue
Normal file
115
viewer/src/components/pieces/Card.vue
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
<template>
|
||||
<g v-if="powerPlant.number == 99" :id="elId" :transform="`translate(${currentX}, ${currentY})`">
|
||||
<rect width="60" height="40" :fill="getColor()" stroke="black" stroke-width="2" rx="4" />
|
||||
<text text-anchor="middle" x="30" y="20" fill="black">Step 3</text>
|
||||
</g>
|
||||
<g
|
||||
v-else
|
||||
:id="elId"
|
||||
:class="[{ canClick: canClick }]"
|
||||
:transform="`translate(${currentX}, ${currentY})`"
|
||||
@click="canClick && $emit('click')"
|
||||
>
|
||||
<rect width="60" height="40" :fill="getColor()" stroke="black" stroke-width="2" rx="4" />
|
||||
<g transform="translate(30, 10)">
|
||||
<text text-anchor="middle" x="1" y="1" fill="gray">{{ powerPlant.number }}</text>
|
||||
<text text-anchor="middle" fill="white">{{ powerPlant.number }}</text>
|
||||
</g>
|
||||
|
||||
<g :id="elId" :class="['piece']" transform="translate(40, 20) scale(0.035)">
|
||||
<path
|
||||
d="M187.698 263.636V456.017L3 341.204V169.522L80.8579 108.141L187.698 263.636Z"
|
||||
fill="white"
|
||||
stroke="white"
|
||||
stroke-width="12"
|
||||
stroke-miterlimit="10"
|
||||
/>
|
||||
<path
|
||||
d="M395.724 136.361V300.164L187.698 456.017V263.636L395.724 136.361Z"
|
||||
fill="white"
|
||||
stroke="white"
|
||||
stroke-width="12"
|
||||
stroke-miterlimit="10"
|
||||
/>
|
||||
<path
|
||||
d="M395.724 136.361L187.698 263.636L80.8579 108.141L304.771 4L395.724 136.361Z"
|
||||
fill="white"
|
||||
stroke="white"
|
||||
stroke-width="12"
|
||||
stroke-miterlimit="10"
|
||||
/>
|
||||
</g>
|
||||
<text text-anchor="middle" x="47" y="28" style="font-size: 12px" fill="black">{{
|
||||
powerPlant.citiesPowered
|
||||
}}</text>
|
||||
|
||||
<g transform="translate(5, 20)">
|
||||
<path :d="getResourcePath()" fill="white" />
|
||||
</g>
|
||||
<text v-if="powerPlant.cost > 0" text-anchor="middle" x="12.5" y="27.5" style="font-size: 12px" fill="black">{{
|
||||
powerPlant.cost
|
||||
}}</text>
|
||||
|
||||
<g transform="translate(24, 22)">
|
||||
<path d="M0,3 L8,3 L8,0 L14,6 L8,12 L8,9 L0,9Z" fill="white" />
|
||||
</g>
|
||||
|
||||
<defs>
|
||||
<linearGradient id="hybrid" x1="0" y1="0" x2="100%" y2="100%">
|
||||
<stop offset="50%" stop-color="brown" />
|
||||
<stop offset="50%" stop-color="#445" />
|
||||
</linearGradient>
|
||||
</defs>
|
||||
</g>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
import { PieceType } from '@/types/ui-data';
|
||||
import { PowerPlant, PowerPlantType } from 'powergrid-engine/src/gamestate';
|
||||
import { Component, Mixins, Prop } from 'vue-property-decorator';
|
||||
import Piece from './Piece.vue';
|
||||
|
||||
@Component({
|
||||
created(this: Card) {
|
||||
this.pieceType = PieceType.Card;
|
||||
}
|
||||
})
|
||||
export default class Card extends Mixins(Piece) {
|
||||
@Prop()
|
||||
owner?: number;
|
||||
|
||||
@Prop()
|
||||
powerPlant?: PowerPlant;
|
||||
|
||||
@Prop()
|
||||
canClick?: boolean;
|
||||
|
||||
getColor() {
|
||||
switch (this.powerPlant?.type) {
|
||||
case PowerPlantType.Coal: return 'brown';
|
||||
case PowerPlantType.Oil: return '#445';
|
||||
case PowerPlantType.Garbage: return 'goldenrod';
|
||||
case PowerPlantType.Uranium: return 'red';
|
||||
case PowerPlantType.Hybrid: return 'url(#hybrid)';
|
||||
case PowerPlantType.Wind: return 'limegreen';
|
||||
case PowerPlantType.Nuclear: return 'dodgerblue';
|
||||
}
|
||||
}
|
||||
|
||||
getResourcePath() {
|
||||
switch (this.powerPlant?.type) {
|
||||
case PowerPlantType.Coal: return 'M0,3 L7.5,0 L15,3 L15,12 L7.5,15 L0,12Z';
|
||||
case PowerPlantType.Oil: return 'M3,2 A6,3 0 0,1 12,2 L12,12 A6,3 0 0,1 3,12Z';
|
||||
case PowerPlantType.Garbage: return 'M0,3 A7.5,3 0 0,1 15,3 L15,12 A7.5,3 0 0,1 0,12Z';
|
||||
case PowerPlantType.Uranium: return 'M1,2 l4,-2 l6,0 l4,2 l0,11 l-4,2 l-6,0 l-4,-2Z';
|
||||
case PowerPlantType.Hybrid: return 'M0,3 L7.5,0 L15,3 L15,12 L7.5,15 L0,12Z M9,1 A6,3 0 0,1 18,1 L18,10 A6,3 0 0,1 10,10Z';
|
||||
case PowerPlantType.Wind: return '';
|
||||
case PowerPlantType.Nuclear: return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<style lang="scss">
|
||||
.canClick {
|
||||
cursor: pointer;
|
||||
}
|
||||
</style>
|
||||
37
viewer/src/components/pieces/Coal.vue
Normal file
37
viewer/src/components/pieces/Coal.vue
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<template>
|
||||
<g
|
||||
:id="elId"
|
||||
:class="[{ canClick: canClick }]"
|
||||
:transform="`translate(${currentX}, ${currentY}) scale(0.08)`"
|
||||
:opacity="transparent ? 0.3 : 1"
|
||||
@click="canClick && $emit('click')"
|
||||
>
|
||||
<path
|
||||
d="M136.8 21.2L43.1001 48.9L43.2001 167.2L135.2 210.3L228.8 174V55.7L136.8 21.2Z"
|
||||
fill="#5a2d0c"
|
||||
stroke="black"
|
||||
stroke-width="20"
|
||||
stroke-miterlimit="10"
|
||||
/>
|
||||
<path d="M135.2 210.3L43.2001 167.2L43.1001 48.8999L135.1 83.4999L135.2 210.3Z" fill="#70380f" />
|
||||
<path d="M135.1 83.5L43.1001 48.9L136.8 21.2L228.8 55.7L135.1 83.5Z" fill="#8b4513" />
|
||||
<path d="M228.8 55.7V174L135.2 210.3L135.1 83.5L228.8 55.7Z" fill="#5a2d0c" />
|
||||
|
||||
<title>Coal</title>
|
||||
</g>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
import { PieceType } from '@/types/ui-data';
|
||||
import { Component, Mixins, Prop } from 'vue-property-decorator';
|
||||
import Piece from './Piece.vue';
|
||||
|
||||
@Component({
|
||||
created(this: Coal) {
|
||||
this.pieceType = PieceType.Coal;
|
||||
}
|
||||
})
|
||||
export default class Coal extends Mixins(Piece) {
|
||||
@Prop()
|
||||
canClick?: boolean;
|
||||
}
|
||||
</script>
|
||||
37
viewer/src/components/pieces/Garbage.vue
Normal file
37
viewer/src/components/pieces/Garbage.vue
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<template>
|
||||
<g
|
||||
:id="elId"
|
||||
:class="[{ canClick: canClick }]"
|
||||
:transform="`translate(${currentX}, ${currentY})`"
|
||||
:opacity="transparent ? 0.3 : 1"
|
||||
@click="canClick && $emit('click')"
|
||||
>
|
||||
<path d="M2,5 A9,5,0 0,1 18,5 L18,15 A9,5 0 0,1 2,15Z" fill="none" stroke="black" stroke-miterlimit="0" />
|
||||
<path d="M2,5 A9,5 0 0,0 18,5 A9,5 0 0,0 2,5" fill="#FF0" />
|
||||
<path d="M2,5 A9,5 0 0,0 2,5 L2,15 A9,5,0 0,0 18,15 L18,5 A9,5 0 0,1 2,5" fill="url(#garbage-linear)" />
|
||||
|
||||
<title>Garbage</title>
|
||||
|
||||
<defs>
|
||||
<linearGradient id="garbage-linear" x1="0" y1="10" x2="20" y2="10" gradientUnits="userSpaceOnUse">
|
||||
<stop stop-color="#DD0" />
|
||||
<stop offset="1" stop-color="#AA0" />
|
||||
</linearGradient>
|
||||
</defs>
|
||||
</g>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
import { PieceType } from '@/types/ui-data';
|
||||
import { Component, Mixins, Prop } from 'vue-property-decorator';
|
||||
import Piece from './Piece.vue';
|
||||
|
||||
@Component({
|
||||
created(this: Garbage) {
|
||||
this.pieceType = PieceType.Garbage;
|
||||
}
|
||||
})
|
||||
export default class Garbage extends Mixins(Piece) {
|
||||
@Prop()
|
||||
canClick?: boolean;
|
||||
}
|
||||
</script>
|
||||
51
viewer/src/components/pieces/House.vue
Normal file
51
viewer/src/components/pieces/House.vue
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
<template>
|
||||
<g :id="elId" :class="['piece']" :transform="`translate(${currentX}, ${currentY}) scale(0.035)`">
|
||||
<!-- <path d="M15 0 L30 10 L30 30 L0 30 L0 10Z" :fill="color" stroke="black" /> -->
|
||||
<path
|
||||
d="M187.698 263.636V456.017L3 341.204V169.522L80.8579 108.141L187.698 263.636Z"
|
||||
:fill="color"
|
||||
stroke="#010101"
|
||||
stroke-width="12"
|
||||
stroke-miterlimit="10"
|
||||
/>
|
||||
<path
|
||||
d="M395.724 136.361V300.164L187.698 456.017V263.636L395.724 136.361Z"
|
||||
:fill="color"
|
||||
stroke="#010101"
|
||||
stroke-width="12"
|
||||
stroke-miterlimit="10"
|
||||
/>
|
||||
<path
|
||||
d="M395.724 136.361L187.698 263.636L80.8579 108.141L304.771 4L395.724 136.361Z"
|
||||
:fill="color"
|
||||
stroke="#010101"
|
||||
stroke-width="12"
|
||||
stroke-miterlimit="10"
|
||||
/>
|
||||
<title>{{ ownerName }}'s House</title>
|
||||
</g>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
import { PieceType } from '@/types/ui-data';
|
||||
import { Component, InjectReactive, Mixins, Prop } from 'vue-property-decorator';
|
||||
import Piece from './Piece.vue';
|
||||
|
||||
@Component({
|
||||
created(this: House) {
|
||||
this.pieceType = PieceType.House;
|
||||
}
|
||||
})
|
||||
export default class House extends Mixins(Piece) {
|
||||
@InjectReactive()
|
||||
readonly player!: number;
|
||||
|
||||
@Prop()
|
||||
color?: string;
|
||||
|
||||
@Prop()
|
||||
owner?: number;
|
||||
|
||||
@Prop()
|
||||
ownerName?: string;
|
||||
}
|
||||
</script>
|
||||
41
viewer/src/components/pieces/Hybrid.vue
Normal file
41
viewer/src/components/pieces/Hybrid.vue
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
<template>
|
||||
<g :id="elId" :class="['piece']" :transform="`translate(${currentX}, ${currentY})`">
|
||||
<g transform="scale(0.08)">
|
||||
<path
|
||||
d="M136.8 21.2L43.1001 48.9L43.2001 167.2L135.2 210.3L228.8 174V55.7L136.8 21.2Z"
|
||||
fill="#5a2d0c"
|
||||
stroke="black"
|
||||
stroke-width="20"
|
||||
stroke-miterlimit="10"
|
||||
/>
|
||||
<path d="M135.2 210.3L43.2001 167.2L43.1001 48.8999L135.1 83.4999L135.2 210.3Z" fill="#70380f" />
|
||||
<path d="M135.1 83.5L43.1001 48.9L136.8 21.2L228.8 55.7L135.1 83.5Z" fill="#8b4513" />
|
||||
<path d="M228.8 55.7V174L135.2 210.3L135.1 83.5L228.8 55.7Z" fill="#5a2d0c" />
|
||||
</g>
|
||||
|
||||
<g transform="translate(5, 0)">
|
||||
<path d="M6,4 A6,4,0 0,1 14,4 L14,16 A6,4 0 0,1 6,16Z" fill="none" stroke="black" />
|
||||
<path d="M6,4 A6,4 0 0,0 14,4 A6,4 0 0,0 6,4" fill="#556" />
|
||||
<path d="M6,4 A6,4 0 0,0 6,4 L6,16 A6,4,0 0,0 14,16 L14,4 A6,4 0 0,1 6,4" fill="url(#oil-linear)" />
|
||||
</g>
|
||||
|
||||
<title>Coal/Oil</title>
|
||||
</g>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
import { PieceType } from '@/types/ui-data';
|
||||
import { Component, Mixins } from 'vue-property-decorator';
|
||||
import Piece from './Piece.vue';
|
||||
import { Coal, Oil } from '.';
|
||||
|
||||
@Component({
|
||||
created(this: Hybrid) {
|
||||
this.pieceType = PieceType.Hybrid;
|
||||
},
|
||||
components: {
|
||||
Coal, Oil
|
||||
},
|
||||
})
|
||||
export default class Hybrid extends Mixins(Piece) {
|
||||
}
|
||||
</script>
|
||||
37
viewer/src/components/pieces/Oil.vue
Normal file
37
viewer/src/components/pieces/Oil.vue
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<template>
|
||||
<g
|
||||
:id="elId"
|
||||
:class="[{ canClick: canClick }]"
|
||||
:transform="`translate(${currentX}, ${currentY})`"
|
||||
:opacity="transparent ? 0.3 : 1"
|
||||
@click="canClick && $emit('click')"
|
||||
>
|
||||
<path d="M6,4 A6,4,0 0,1 14,4 L14,16 A6,4 0 0,1 6,16Z" fill="none" stroke="black" />
|
||||
<path d="M6,4 A6,4 0 0,0 14,4 A6,4 0 0,0 6,4" fill="#556" />
|
||||
<path d="M6,4 A6,4 0 0,0 6,4 L6,16 A6,4,0 0,0 14,16 L14,4 A6,4 0 0,1 6,4" fill="url(#oil-linear)" />
|
||||
|
||||
<title>Oil</title>
|
||||
|
||||
<defs>
|
||||
<linearGradient id="oil-linear" x1="0" y1="10" x2="20" y2="10" gradientUnits="userSpaceOnUse">
|
||||
<stop stop-color="#445" />
|
||||
<stop offset="1" stop-color="#223" />
|
||||
</linearGradient>
|
||||
</defs>
|
||||
</g>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
import { PieceType } from '@/types/ui-data';
|
||||
import { Component, Mixins, Prop } from 'vue-property-decorator';
|
||||
import Piece from './Piece.vue';
|
||||
|
||||
@Component({
|
||||
created(this: Oil) {
|
||||
this.pieceType = PieceType.Oil;
|
||||
}
|
||||
})
|
||||
export default class Oil extends Mixins(Piece) {
|
||||
@Prop()
|
||||
canClick?: boolean;
|
||||
}
|
||||
</script>
|
||||
32
viewer/src/components/pieces/Uranium.vue
Normal file
32
viewer/src/components/pieces/Uranium.vue
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<template>
|
||||
<g
|
||||
:id="elId"
|
||||
:class="[{ canClick: canClick }]"
|
||||
:transform="`translate(${currentX}, ${currentY})`"
|
||||
:opacity="transparent ? 0.3 : 1"
|
||||
@click="canClick && $emit('click')"
|
||||
>
|
||||
<path d="M3,3 l4,-2 l6,0 l4,2 l0,11 l-4,2 l-6,0 l-4,-2Z" fill="none" stroke="black" />
|
||||
<path d="M3,3 l4,-2 l6,0 l4,2 l0,2 l-4,2 l-6,0 l-4,-2 l0,-2" fill="#F00" />
|
||||
<path d="M3,5 l0,9 l4,2 l0,-9 l-4,-2" fill="#e60000" />
|
||||
<path d="M7,7 l6,0 l0,9 l-6,0 l0,-9" fill="#cc0000" />
|
||||
<path d="M13,7 l4,-2 l0,9 l-4,2 l0,-9" fill="#b30000" />
|
||||
|
||||
<title>Uranium</title>
|
||||
</g>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
import { PieceType } from '@/types/ui-data';
|
||||
import { Component, Mixins, Prop } from 'vue-property-decorator';
|
||||
import Piece from './Piece.vue';
|
||||
|
||||
@Component({
|
||||
created(this: Uranium) {
|
||||
this.pieceType = PieceType.Uranium;
|
||||
}
|
||||
})
|
||||
export default class Uranium extends Mixins(Piece) {
|
||||
@Prop()
|
||||
canClick?: boolean;
|
||||
}
|
||||
</script>
|
||||
|
|
@ -8,7 +8,7 @@ function launchSelfContained(selector = '#app') {
|
|||
|
||||
const emitter = launch(selector);
|
||||
|
||||
let gameState = setup(4, {});
|
||||
let gameState = setup(6, {});
|
||||
|
||||
for (let i = 0; i < gameState.players.length; i++) {
|
||||
gameState.players[i].name = `Player ${i + 1}`;
|
||||
|
|
@ -17,6 +17,7 @@ function launchSelfContained(selector = '#app') {
|
|||
let playerIndex = 0;
|
||||
|
||||
for (const player of gameState.players) {
|
||||
// if (player.id != playerIndex)
|
||||
player.isAI = true;
|
||||
}
|
||||
|
||||
|
|
@ -27,7 +28,7 @@ function launchSelfContained(selector = '#app') {
|
|||
|
||||
emitter.emit('state', cloneDeep(strip ? stripSecret(gameState, playerIndex) : gameState));
|
||||
|
||||
let delay = 800;
|
||||
let delay = 200;
|
||||
while (gameState.players.some((pl) => pl.isAI && pl.availableMoves)) {
|
||||
gameState = moveAI(
|
||||
gameState,
|
||||
|
|
@ -36,7 +37,7 @@ function launchSelfContained(selector = '#app') {
|
|||
let newState = cloneDeep(strip ? stripSecret(gameState, playerIndex) : gameState);
|
||||
console.log('new game state', newState);
|
||||
setTimeout(() => emitter.emit('state', newState), delay);
|
||||
delay += 800;
|
||||
delay += 200;
|
||||
}
|
||||
|
||||
console.log('available moves', gameState.players[playerIndex].availableMoves);
|
||||
|
|
@ -49,7 +50,7 @@ function launchSelfContained(selector = '#app') {
|
|||
emitter.emit('player', { index: playerIndex });
|
||||
emitter.emit('state', cloneDeep(strip ? stripSecret(gameState, playerIndex) : gameState));
|
||||
|
||||
let delay = 800;
|
||||
let delay = 200;
|
||||
while (gameState.players.some((pl) => pl.isAI && pl.availableMoves)) {
|
||||
gameState = moveAI(
|
||||
gameState,
|
||||
|
|
@ -57,7 +58,7 @@ function launchSelfContained(selector = '#app') {
|
|||
);
|
||||
let newState = cloneDeep(strip ? stripSecret(gameState, playerIndex) : gameState);
|
||||
setTimeout(() => emitter.emit('state', newState), delay);
|
||||
delay += 800;
|
||||
delay += 200;
|
||||
}
|
||||
|
||||
console.log('available moves', gameState.players[playerIndex].availableMoves);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue