Randomize map option
This commit is contained in:
parent
749ae0164b
commit
58a14c07f4
9 changed files with 1335 additions and 171 deletions
|
|
@ -21,11 +21,13 @@
|
|||
"dependencies": {
|
||||
"@types/lodash": "^4.14.149",
|
||||
"@types/seedrandom": "^2.4.27",
|
||||
"delaunator": "^5.0.0",
|
||||
"lodash": "^4.17.15",
|
||||
"seedrandom": "^3.0.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/chai": "^4.1.2",
|
||||
"@types/delaunator": "^5.0.0",
|
||||
"@types/mocha": "^2.2.48",
|
||||
"@types/node": "^13.11.0",
|
||||
"@typescript-eslint/eslint-plugin": "^4.25.0",
|
||||
|
|
|
|||
104
engine/pnpm-lock.yaml
generated
104
engine/pnpm-lock.yaml
generated
|
|
@ -1,7 +1,8 @@
|
|||
lockfileVersion: 5.3
|
||||
lockfileVersion: 5.4
|
||||
|
||||
specifiers:
|
||||
'@types/chai': ^4.1.2
|
||||
'@types/delaunator': ^5.0.0
|
||||
'@types/lodash': ^4.14.149
|
||||
'@types/mocha': ^2.2.48
|
||||
'@types/node': ^13.11.0
|
||||
|
|
@ -9,6 +10,7 @@ specifiers:
|
|||
'@typescript-eslint/eslint-plugin': ^4.25.0
|
||||
'@typescript-eslint/parser': ^4.25.0
|
||||
chai: ^4.1.2
|
||||
delaunator: ^5.0.0
|
||||
eslint: ^6.8.0
|
||||
eslint-plugin-import: ^2.20.2
|
||||
eslint-plugin-node: ^11.1.0
|
||||
|
|
@ -23,23 +25,25 @@ specifiers:
|
|||
dependencies:
|
||||
'@types/lodash': 4.14.170
|
||||
'@types/seedrandom': 2.4.29
|
||||
delaunator: 5.0.0
|
||||
lodash: 4.17.21
|
||||
seedrandom: 3.0.5
|
||||
|
||||
devDependencies:
|
||||
'@types/chai': 4.2.19
|
||||
'@types/delaunator': 5.0.0
|
||||
'@types/mocha': 2.2.48
|
||||
'@types/node': 13.13.52
|
||||
'@typescript-eslint/eslint-plugin': 4.33.0_dcbb4cce6641cdd6be5162ff8bba7aa7
|
||||
'@typescript-eslint/parser': 4.33.0_eslint@6.8.0+typescript@4.3.5
|
||||
'@typescript-eslint/eslint-plugin': 4.33.0_3s5uzttgihg5npsrml7yxot2u4
|
||||
'@typescript-eslint/parser': 4.33.0_ormy72tqrapqsntr3tx5lktgaq
|
||||
chai: 4.3.4
|
||||
eslint: 6.8.0
|
||||
eslint-plugin-import: 2.23.4_eslint@6.8.0
|
||||
eslint-plugin-import: 2.23.4_inh3l5yejh4yosh34bfcghfssa
|
||||
eslint-plugin-node: 11.1.0_eslint@6.8.0
|
||||
eslint-plugin-promise: 4.3.1
|
||||
eslint-plugin-standard: 4.1.0_eslint@6.8.0
|
||||
mocha: 5.2.0
|
||||
ts-node: 10.0.0_7f3a40866f3835940b4e71342642ba8d
|
||||
ts-node: 10.0.0_p45ebbtpha2zic2ooe2cmqv2ru
|
||||
typescript: 4.3.5
|
||||
|
||||
packages:
|
||||
|
|
@ -138,6 +142,13 @@ packages:
|
|||
}
|
||||
dev: true
|
||||
|
||||
/@types/delaunator/5.0.0:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-00nrXdKbhF9FQsq6MskmdUgEqd5MWzA+x8CoDt8OJqbS4QB528SgkOfEcnQMa2sIg2XTKowwwVQx8iGsAX6CAQ==,
|
||||
}
|
||||
dev: true
|
||||
|
||||
/@types/json-schema/7.0.7:
|
||||
resolution:
|
||||
{
|
||||
|
|
@ -177,7 +188,7 @@ packages:
|
|||
}
|
||||
dev: false
|
||||
|
||||
/@typescript-eslint/eslint-plugin/4.33.0_dcbb4cce6641cdd6be5162ff8bba7aa7:
|
||||
/@typescript-eslint/eslint-plugin/4.33.0_3s5uzttgihg5npsrml7yxot2u4:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-aINiAxGVdOl1eJyVjaWn/YcVAq4Gi/Yo35qHGCnqbWVz61g39D0h23veY/MA0rFFGfxK7TySg2uwDeNv+JgVpg==,
|
||||
|
|
@ -191,8 +202,8 @@ packages:
|
|||
typescript:
|
||||
optional: true
|
||||
dependencies:
|
||||
'@typescript-eslint/experimental-utils': 4.33.0_eslint@6.8.0+typescript@4.3.5
|
||||
'@typescript-eslint/parser': 4.33.0_eslint@6.8.0+typescript@4.3.5
|
||||
'@typescript-eslint/experimental-utils': 4.33.0_ormy72tqrapqsntr3tx5lktgaq
|
||||
'@typescript-eslint/parser': 4.33.0_ormy72tqrapqsntr3tx5lktgaq
|
||||
'@typescript-eslint/scope-manager': 4.33.0
|
||||
debug: 4.3.1
|
||||
eslint: 6.8.0
|
||||
|
|
@ -206,7 +217,7 @@ packages:
|
|||
- supports-color
|
||||
dev: true
|
||||
|
||||
/@typescript-eslint/experimental-utils/4.33.0_eslint@6.8.0+typescript@4.3.5:
|
||||
/@typescript-eslint/experimental-utils/4.33.0_ormy72tqrapqsntr3tx5lktgaq:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-zeQjOoES5JFjTnAhI5QY7ZviczMzDptls15GFsI6jyUOq0kOf9+WonkhtlIhh0RgHRnqj5gdNxW5j1EvAyYg6Q==,
|
||||
|
|
@ -227,7 +238,7 @@ packages:
|
|||
- typescript
|
||||
dev: true
|
||||
|
||||
/@typescript-eslint/parser/4.33.0_eslint@6.8.0+typescript@4.3.5:
|
||||
/@typescript-eslint/parser/4.33.0_ormy72tqrapqsntr3tx5lktgaq:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-ZohdsbXadjGBSK0/r+d87X0SBmKzOq4/S5nzK6SBgJspFo9/CUDJ7hjayuze+JK7CZQLDMroqytp7pOcFKTxZA==,
|
||||
|
|
@ -640,17 +651,28 @@ packages:
|
|||
{
|
||||
integrity: sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==,
|
||||
}
|
||||
peerDependencies:
|
||||
supports-color: '*'
|
||||
peerDependenciesMeta:
|
||||
supports-color:
|
||||
optional: true
|
||||
dependencies:
|
||||
ms: 2.0.0
|
||||
dev: true
|
||||
|
||||
/debug/3.1.0:
|
||||
/debug/3.1.0_supports-color@5.4.0:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==,
|
||||
}
|
||||
peerDependencies:
|
||||
supports-color: '*'
|
||||
peerDependenciesMeta:
|
||||
supports-color:
|
||||
optional: true
|
||||
dependencies:
|
||||
ms: 2.0.0
|
||||
supports-color: 5.4.0
|
||||
dev: true
|
||||
|
||||
/debug/3.2.7:
|
||||
|
|
@ -658,6 +680,11 @@ packages:
|
|||
{
|
||||
integrity: sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==,
|
||||
}
|
||||
peerDependencies:
|
||||
supports-color: '*'
|
||||
peerDependenciesMeta:
|
||||
supports-color:
|
||||
optional: true
|
||||
dependencies:
|
||||
ms: 2.1.3
|
||||
dev: true
|
||||
|
|
@ -701,6 +728,15 @@ packages:
|
|||
object-keys: 1.1.1
|
||||
dev: true
|
||||
|
||||
/delaunator/5.0.0:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-AyLvtyJdbv/U1GkiS6gUUzclRoAY4Gs75qkMygJJhU75LW4DNuSF2RMzpxs9jw9Oz1BobHjTdkG3zdP55VxAqw==,
|
||||
}
|
||||
dependencies:
|
||||
robust-predicates: 3.0.1
|
||||
dev: false
|
||||
|
||||
/diff/3.5.0:
|
||||
resolution:
|
||||
{
|
||||
|
|
@ -820,17 +856,37 @@ packages:
|
|||
dependencies:
|
||||
debug: 2.6.9
|
||||
resolve: 1.20.0
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
dev: true
|
||||
|
||||
/eslint-module-utils/2.6.1:
|
||||
/eslint-module-utils/2.6.1_a3yyay6sz2tmw2st2mhd2zy7wi:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-ZXI9B8cxAJIH4nfkhTwcRTEAnrVfobYqwjWy/QMCZ8rHkZHFjf9yO4BzpiF9kCSfNlMG54eKigISHpX0+AaT4A==,
|
||||
}
|
||||
engines: { node: '>=4' }
|
||||
peerDependencies:
|
||||
'@typescript-eslint/parser': '*'
|
||||
eslint-import-resolver-node: '*'
|
||||
eslint-import-resolver-typescript: '*'
|
||||
eslint-import-resolver-webpack: '*'
|
||||
peerDependenciesMeta:
|
||||
'@typescript-eslint/parser':
|
||||
optional: true
|
||||
eslint-import-resolver-node:
|
||||
optional: true
|
||||
eslint-import-resolver-typescript:
|
||||
optional: true
|
||||
eslint-import-resolver-webpack:
|
||||
optional: true
|
||||
dependencies:
|
||||
'@typescript-eslint/parser': 4.33.0_ormy72tqrapqsntr3tx5lktgaq
|
||||
debug: 3.2.7
|
||||
eslint-import-resolver-node: 0.3.4
|
||||
pkg-dir: 2.0.0
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
dev: true
|
||||
|
||||
/eslint-plugin-es/3.0.1_eslint@6.8.0:
|
||||
|
|
@ -847,22 +903,27 @@ packages:
|
|||
regexpp: 3.2.0
|
||||
dev: true
|
||||
|
||||
/eslint-plugin-import/2.23.4_eslint@6.8.0:
|
||||
/eslint-plugin-import/2.23.4_inh3l5yejh4yosh34bfcghfssa:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-6/wP8zZRsnQFiR3iaPFgh5ImVRM1WN5NUWfTIRqwOdeiGJlBcSk82o1FEVq8yXmy4lkIzTo7YhHCIxlU/2HyEQ==,
|
||||
}
|
||||
engines: { node: '>=4' }
|
||||
peerDependencies:
|
||||
'@typescript-eslint/parser': '*'
|
||||
eslint: ^2 || ^3 || ^4 || ^5 || ^6 || ^7.2.0
|
||||
peerDependenciesMeta:
|
||||
'@typescript-eslint/parser':
|
||||
optional: true
|
||||
dependencies:
|
||||
'@typescript-eslint/parser': 4.33.0_ormy72tqrapqsntr3tx5lktgaq
|
||||
array-includes: 3.1.3
|
||||
array.prototype.flat: 1.2.4
|
||||
debug: 2.6.9
|
||||
doctrine: 2.1.0
|
||||
eslint: 6.8.0
|
||||
eslint-import-resolver-node: 0.3.4
|
||||
eslint-module-utils: 2.6.1
|
||||
eslint-module-utils: 2.6.1_a3yyay6sz2tmw2st2mhd2zy7wi
|
||||
find-up: 2.1.0
|
||||
has: 1.0.3
|
||||
is-core-module: 2.4.0
|
||||
|
|
@ -872,6 +933,10 @@ packages:
|
|||
read-pkg-up: 3.0.0
|
||||
resolve: 1.20.0
|
||||
tsconfig-paths: 3.9.0
|
||||
transitivePeerDependencies:
|
||||
- eslint-import-resolver-typescript
|
||||
- eslint-import-resolver-webpack
|
||||
- supports-color
|
||||
dev: true
|
||||
|
||||
/eslint-plugin-node/11.1.0_eslint@6.8.0:
|
||||
|
|
@ -1739,7 +1804,7 @@ packages:
|
|||
dependencies:
|
||||
browser-stdout: 1.3.1
|
||||
commander: 2.15.1
|
||||
debug: 3.1.0
|
||||
debug: 3.1.0_supports-color@5.4.0
|
||||
diff: 3.5.0
|
||||
escape-string-regexp: 1.0.5
|
||||
glob: 7.1.2
|
||||
|
|
@ -2096,6 +2161,13 @@ packages:
|
|||
glob: 7.1.7
|
||||
dev: true
|
||||
|
||||
/robust-predicates/3.0.1:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-ndEIpszUHiG4HtDsQLeIuMvRsDnn8c8rYStabochtUeCvfuvNptb5TUbVD68LRAILPX7p9nqQGh4xJgn3EHS/g==,
|
||||
}
|
||||
dev: false
|
||||
|
||||
/run-async/2.4.1:
|
||||
resolution:
|
||||
{
|
||||
|
|
@ -2407,7 +2479,7 @@ packages:
|
|||
is-number: 7.0.0
|
||||
dev: true
|
||||
|
||||
/ts-node/10.0.0_7f3a40866f3835940b4e71342642ba8d:
|
||||
/ts-node/10.0.0_p45ebbtpha2zic2ooe2cmqv2ru:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-ROWeOIUvfFbPZkoDis0L/55Fk+6gFQNZwwKPLinacRl6tsxstTF1DbAcLKkovwnpKMVvOMHP1TIbnwXwtLg1gg==,
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import { GameMap, maps, mapsRecharged } from './maps';
|
|||
import { Move, MoveName, Moves } from './move';
|
||||
import { indiaPowerPlants, powerPlants } from './powerPlants';
|
||||
import prices from './prices';
|
||||
import { createRandomizedMap } from './randomizeMap';
|
||||
import { asserts, shuffle } from './utils';
|
||||
|
||||
export const playerColors = ['limegreen', 'mediumorchid', 'red', 'dodgerblue', 'yellow', 'brown'];
|
||||
|
|
@ -83,6 +84,7 @@ export function setup(
|
|||
showMoney = false,
|
||||
useNewRechargedSetup = true,
|
||||
trackTotalSpent = true,
|
||||
randomizeMap = false,
|
||||
}: GameOptions,
|
||||
seed?: string,
|
||||
forceDeck?: PowerPlant[],
|
||||
|
|
@ -95,30 +97,6 @@ export function setup(
|
|||
variant == 'original' ? maps.find((m) => m.name == map)! : mapsRecharged.find((m) => m.name == map)!
|
||||
);
|
||||
|
||||
if (chosenMap.layout == 'Portrait') {
|
||||
chosenMap.viewBox = chosenMap.viewBox || [1480, 1060];
|
||||
chosenMap.adjustRatio = chosenMap.adjustRatio || [1, 1];
|
||||
chosenMap.playerOrderPosition = chosenMap.playerOrderPosition || [1160, 160];
|
||||
chosenMap.cityCountPosition = chosenMap.cityCountPosition || [0, 0];
|
||||
chosenMap.powerPlantMarketPosition = chosenMap.powerPlantMarketPosition || [745, 0];
|
||||
chosenMap.mapPosition = chosenMap.mapPosition || [0, 0];
|
||||
chosenMap.buttonsPosition = chosenMap.buttonsPosition || [1305, 0];
|
||||
chosenMap.playerBoardsPosition = chosenMap.playerBoardsPosition || [1105, 240];
|
||||
chosenMap.roundInfoPosition = chosenMap.roundInfoPosition || [20, 920];
|
||||
chosenMap.supplyPosition = chosenMap.supplyPosition || [675, 920];
|
||||
} else {
|
||||
chosenMap.viewBox = chosenMap.viewBox || [1465, 860];
|
||||
chosenMap.adjustRatio = chosenMap.adjustRatio || [1, 1];
|
||||
chosenMap.playerOrderPosition = chosenMap.playerOrderPosition || [1160, 140];
|
||||
chosenMap.cityCountPosition = chosenMap.cityCountPosition || [0, 0];
|
||||
chosenMap.powerPlantMarketPosition = chosenMap.powerPlantMarketPosition || [745, 0];
|
||||
chosenMap.mapPosition = chosenMap.mapPosition || [-10, 0];
|
||||
chosenMap.buttonsPosition = chosenMap.buttonsPosition || [1305, 0];
|
||||
chosenMap.playerBoardsPosition = chosenMap.playerBoardsPosition || [1105, 200];
|
||||
chosenMap.roundInfoPosition = chosenMap.roundInfoPosition || [20, 590];
|
||||
chosenMap.supplyPosition = chosenMap.supplyPosition || [0, 720];
|
||||
}
|
||||
|
||||
let actualMarket: PowerPlant[];
|
||||
let futureMarket: PowerPlant[];
|
||||
let powerPlantsDeck: PowerPlant[];
|
||||
|
|
@ -173,6 +151,8 @@ export function setup(
|
|||
totalSpentResources: 0,
|
||||
}));
|
||||
|
||||
const p = players.length - 2;
|
||||
|
||||
const playerOrder = range(numPlayers);
|
||||
const startingPlayer = playerOrder[0];
|
||||
|
||||
|
|
@ -216,46 +196,80 @@ export function setup(
|
|||
];
|
||||
}
|
||||
|
||||
chosenMap.cities = chosenMap.cities.map((city) => ({
|
||||
...city,
|
||||
x: city.x * chosenMap.adjustRatio![0],
|
||||
y: city.y * chosenMap.adjustRatio![1],
|
||||
}));
|
||||
let finalMap: GameMap;
|
||||
if (randomizeMap) {
|
||||
finalMap = createRandomizedMap(chosenMap, regionsInPlay[p], rng);
|
||||
} else {
|
||||
chosenMap.cities = chosenMap.cities.map((city) => ({
|
||||
...city,
|
||||
x: city.x * chosenMap.adjustRatio![0],
|
||||
y: city.y * chosenMap.adjustRatio![1],
|
||||
}));
|
||||
|
||||
const regions = chosenMap.cities
|
||||
.filter((c, i) => chosenMap.cities.findIndex((cc) => cc.region == c.region) == i)
|
||||
.map((c) => c.region);
|
||||
const connections = chosenMap.connections.map((con) =>
|
||||
con.nodes.map((n) => chosenMap.cities.find((city) => city.name == n)!.region)
|
||||
);
|
||||
const regionConnections = regions.map((region) =>
|
||||
regions.filter(
|
||||
(area2) => region != area2 && connections.some((con) => con.includes(region) && con.includes(area2))
|
||||
)
|
||||
);
|
||||
const regions = chosenMap.cities
|
||||
.filter((c, i) => chosenMap.cities.findIndex((cc) => cc.region == c.region) == i)
|
||||
.map((c) => c.region);
|
||||
const connections = chosenMap.connections.map((con) =>
|
||||
con.nodes.map((n) => chosenMap.cities.find((city) => city.name == n)!.region)
|
||||
);
|
||||
const regionConnections = regions.map((region) =>
|
||||
regions.filter(
|
||||
(area2) => region != area2 && connections.some((con) => con.includes(region) && con.includes(area2))
|
||||
)
|
||||
);
|
||||
|
||||
const playRegions = new Set<string>();
|
||||
while (playRegions.size != Math.min(regionsInPlay[players.length - 2], regions.length)) {
|
||||
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 playRegions = new Set<string>();
|
||||
while (playRegions.size != Math.min(regionsInPlay[p], regions.length)) {
|
||||
const region = regions[Math.floor(rng() * regions.length)];
|
||||
if (
|
||||
playRegions.size == 0 ||
|
||||
regionConnections[regions.indexOf(region)].some((con) => playRegions.has(con))
|
||||
) {
|
||||
playRegions.add(region);
|
||||
|
||||
// Avoid italy Red Green Blue
|
||||
if (chosenMap.name === 'Italy') {
|
||||
if (playRegions.has('red') && playRegions.has('green') && playRegions.has('blue')) {
|
||||
playRegions.clear();
|
||||
// Avoid italy Red Green Blue
|
||||
if (chosenMap.name === 'Italy') {
|
||||
if (playRegions.has('red') && playRegions.has('green') && playRegions.has('blue')) {
|
||||
playRegions.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const filteredMap = cloneDeep(chosenMap);
|
||||
filteredMap.cities = filteredMap.cities.filter((city) => playRegions.has(city.region));
|
||||
filteredMap.connections = filteredMap.connections.filter((con) =>
|
||||
con.nodes
|
||||
.map((n) => chosenMap.cities.find((city) => city.name == n)!.region)
|
||||
.every((r) => playRegions.has(r))
|
||||
);
|
||||
|
||||
finalMap = filteredMap;
|
||||
}
|
||||
|
||||
const filteredMap = cloneDeep(chosenMap);
|
||||
filteredMap.cities = filteredMap.cities.filter((city) => playRegions.has(city.region));
|
||||
filteredMap.connections = filteredMap.connections.filter((con) =>
|
||||
con.nodes.map((n) => chosenMap.cities.find((city) => city.name == n)!.region).every((r) => playRegions.has(r))
|
||||
);
|
||||
|
||||
const p = players.length - 2;
|
||||
if (finalMap.layout == 'Portrait') {
|
||||
finalMap.viewBox = finalMap.viewBox || [1480, 1060];
|
||||
finalMap.adjustRatio = finalMap.adjustRatio || [1, 1];
|
||||
finalMap.playerOrderPosition = finalMap.playerOrderPosition || [1160, 160];
|
||||
finalMap.cityCountPosition = finalMap.cityCountPosition || [0, 0];
|
||||
finalMap.powerPlantMarketPosition = finalMap.powerPlantMarketPosition || [745, 0];
|
||||
finalMap.mapPosition = finalMap.mapPosition || [0, 0];
|
||||
finalMap.buttonsPosition = finalMap.buttonsPosition || [1305, 0];
|
||||
finalMap.playerBoardsPosition = finalMap.playerBoardsPosition || [1105, 240];
|
||||
finalMap.roundInfoPosition = finalMap.roundInfoPosition || [20, 920];
|
||||
finalMap.supplyPosition = finalMap.supplyPosition || [675, 920];
|
||||
} else {
|
||||
finalMap.viewBox = finalMap.viewBox || [1465, 860];
|
||||
finalMap.adjustRatio = finalMap.adjustRatio || [1, 1];
|
||||
finalMap.playerOrderPosition = finalMap.playerOrderPosition || [1160, 140];
|
||||
finalMap.cityCountPosition = finalMap.cityCountPosition || [0, 0];
|
||||
finalMap.powerPlantMarketPosition = finalMap.powerPlantMarketPosition || [745, 0];
|
||||
finalMap.mapPosition = finalMap.mapPosition || [-10, 0];
|
||||
finalMap.buttonsPosition = finalMap.buttonsPosition || [1305, 0];
|
||||
finalMap.playerBoardsPosition = finalMap.playerBoardsPosition || [1105, 200];
|
||||
finalMap.roundInfoPosition = finalMap.roundInfoPosition || [20, 590];
|
||||
finalMap.supplyPosition = finalMap.supplyPosition || [0, 720];
|
||||
}
|
||||
|
||||
const coalMarket = chosenMap.startingResources ? chosenMap.startingResources[0] : 24;
|
||||
const oilMarket = chosenMap.startingResources ? chosenMap.startingResources[1] : 18;
|
||||
|
|
@ -278,7 +292,7 @@ export function setup(
|
|||
const uraniumPrices = cloneDeep(chosenMap.uraniumPrices ?? prices.uranium);
|
||||
|
||||
const G: GameState = {
|
||||
map: forceMap || filteredMap,
|
||||
map: forceMap || finalMap,
|
||||
players,
|
||||
playerOrder,
|
||||
currentPlayers: [startingPlayer],
|
||||
|
|
@ -323,7 +337,7 @@ export function setup(
|
|||
paymentTable: cityIncome,
|
||||
variant,
|
||||
minimunBid: 0,
|
||||
plantDiscountActive: variant == 'recharged' && (forceMap || filteredMap).name != 'China',
|
||||
plantDiscountActive: variant == 'recharged' && (forceMap || finalMap).name != 'China',
|
||||
cardsLeft: powerPlantsDeck.length,
|
||||
nextCardWeak: variant == 'recharged',
|
||||
card39Bought: false,
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ export interface GameOptions {
|
|||
showMoney?: boolean;
|
||||
useNewRechargedSetup?: boolean;
|
||||
trackTotalSpent?: boolean;
|
||||
randomizeMap?: boolean;
|
||||
}
|
||||
|
||||
export enum ResourceType {
|
||||
|
|
|
|||
|
|
@ -62,6 +62,13 @@ export enum Cities {
|
|||
export const map: GameMap = {
|
||||
name: 'Spain & Portugal',
|
||||
cities: [
|
||||
{ name: Cities.Evora, region: Regions.Yellow, x: 890, y: 1780 },
|
||||
{ name: Cities.Faro, region: Regions.Yellow, x: 822, y: 2348 },
|
||||
{ name: Cities.Portimao, region: Regions.Yellow, x: 592, y: 2218 },
|
||||
{ name: Cities.Setubal, region: Regions.Yellow, x: 578, y: 1864 },
|
||||
{ name: Cities.Lisboa, region: Regions.Yellow, x: 572, y: 1586 },
|
||||
{ name: Cities.Porto, region: Regions.Yellow, x: 736, y: 1052 },
|
||||
{ name: Cities.Braga, region: Regions.Yellow, x: 990, y: 828 },
|
||||
{ name: Cities.Gerona, region: Regions.Pink, x: 3728, y: 666 },
|
||||
{ name: Cities.Barcelona, region: Regions.Pink, x: 3538, y: 848 },
|
||||
{ name: Cities.Tarragona, region: Regions.Pink, x: 3312, y: 970 },
|
||||
|
|
@ -97,13 +104,6 @@ export const map: GameMap = {
|
|||
{ name: Cities.Cadiz, region: Regions.Red, x: 1290, y: 2552 },
|
||||
{ name: Cities.Sevilla, region: Regions.Red, x: 1390, y: 2168 },
|
||||
{ name: Cities.Huelva, region: Regions.Red, x: 1082, y: 2196 },
|
||||
{ name: Cities.Evora, region: Regions.Yellow, x: 890, y: 1780 },
|
||||
{ name: Cities.Faro, region: Regions.Yellow, x: 822, y: 2348 },
|
||||
{ name: Cities.Portimao, region: Regions.Yellow, x: 592, y: 2218 },
|
||||
{ name: Cities.Setubal, region: Regions.Yellow, x: 578, y: 1864 },
|
||||
{ name: Cities.Lisboa, region: Regions.Yellow, x: 572, y: 1586 },
|
||||
{ name: Cities.Porto, region: Regions.Yellow, x: 736, y: 1052 },
|
||||
{ name: Cities.Braga, region: Regions.Yellow, x: 990, y: 828 },
|
||||
],
|
||||
connections: [
|
||||
{ nodes: [Cities.Huelva, Cities.Faro], cost: 6 },
|
||||
|
|
|
|||
289
engine/src/randomizeMap.ts
Normal file
289
engine/src/randomizeMap.ts
Normal file
|
|
@ -0,0 +1,289 @@
|
|||
import Delaunator from 'delaunator';
|
||||
import { upperFirst } from 'lodash';
|
||||
import seedrandom from 'seedrandom';
|
||||
import { City, Connection, GameMap } from './maps';
|
||||
|
||||
const widthByRegions = [420, 490, 490];
|
||||
const heightByRegions = [490, 560, 700];
|
||||
|
||||
export function createRandomizedMap(map: GameMap, regionCount: number, rng: seedrandom.prng) {
|
||||
const regions = [...new Set(map.cities.map((c) => c.region))];
|
||||
const cities = Array(7 * regionCount)
|
||||
.fill(0)
|
||||
.map((_) => ({ name: '', region: '', x: 0, y: 0 }));
|
||||
const width = widthByRegions[regionCount - 3];
|
||||
const height = heightByRegions[regionCount - 3];
|
||||
const gridCellSize = 70;
|
||||
const gridWidth = Math.ceil(width / gridCellSize);
|
||||
const gridHeight = Math.ceil(height / gridCellSize);
|
||||
const gridLength = gridWidth * gridHeight;
|
||||
const grid = Array(gridLength).fill(-1);
|
||||
|
||||
map.mapPosition = [100, 200];
|
||||
map.layout = 'Portrait';
|
||||
|
||||
let emptyGrids = Array(gridLength)
|
||||
.fill(0)
|
||||
.map((_, i) => i);
|
||||
cities.forEach((city, i) => {
|
||||
const emptyGrid = emptyGrids[Math.floor(rng() * emptyGrids.length)];
|
||||
const emptyGridY = Math.floor(emptyGrid / gridWidth);
|
||||
const emptyGridX = emptyGrid % gridWidth;
|
||||
city.x = Math.floor(emptyGridX * 2 * gridCellSize);
|
||||
city.y = Math.floor(emptyGridY * gridCellSize);
|
||||
if (emptyGridY % 2 === 0) {
|
||||
city.x += gridCellSize;
|
||||
}
|
||||
|
||||
var t = rng() * 2 * Math.PI;
|
||||
var r = (rng() * gridCellSize) / 2;
|
||||
city.x += r * Math.cos(t);
|
||||
city.y += r * Math.sin(t);
|
||||
|
||||
emptyGrids = emptyGrids.filter((g) => g !== emptyGrid);
|
||||
grid[emptyGrid] = i;
|
||||
});
|
||||
|
||||
const cityDists: number[][] = Array(cities.length)
|
||||
.fill(0)
|
||||
.map((_) => Array(cities.length).fill(0));
|
||||
const cityConnections: boolean[][] = Array(cities.length)
|
||||
.fill(0)
|
||||
.map((_) => Array(cities.length).fill(null));
|
||||
const d = Delaunator.from(
|
||||
cities,
|
||||
(c: City) => c.x,
|
||||
(c: City) => c.y
|
||||
);
|
||||
for (let i = 0; i < d.triangles.length; i += 3) {
|
||||
const city1 = cities[d.triangles[i]];
|
||||
const city2 = cities[d.triangles[i + 1]];
|
||||
const city3 = cities[d.triangles[i + 2]];
|
||||
|
||||
let dist = cityDists[d.triangles[i]][d.triangles[i + 1]];
|
||||
const dist12Squared = dist
|
||||
? Math.pow(dist, 2)
|
||||
: Math.pow(city1.x - city2.x, 2) + Math.pow(city1.y - city2.y, 2);
|
||||
const dist12 =
|
||||
dist ||
|
||||
(cityDists[d.triangles[i + 1]][d.triangles[i]] = cityDists[d.triangles[i]][d.triangles[i + 1]] =
|
||||
Math.sqrt(dist12Squared));
|
||||
|
||||
dist = cityDists[d.triangles[i]][d.triangles[i + 2]];
|
||||
const dist13Squared = dist
|
||||
? Math.pow(dist, 2)
|
||||
: Math.pow(city1.x - city3.x, 2) + Math.pow(city1.y - city3.y, 2);
|
||||
const dist13 =
|
||||
dist ||
|
||||
(cityDists[d.triangles[i + 2]][d.triangles[i]] = cityDists[d.triangles[i]][d.triangles[i + 2]] =
|
||||
Math.sqrt(dist13Squared));
|
||||
|
||||
dist = cityDists[d.triangles[i + 1]][d.triangles[i + 2]];
|
||||
const dist23Squared = dist
|
||||
? Math.pow(dist, 2)
|
||||
: Math.pow(city2.x - city3.x, 2) + Math.pow(city2.y - city3.y, 2);
|
||||
const dist23 =
|
||||
dist ||
|
||||
(cityDists[d.triangles[i + 2]][d.triangles[i + 1]] = cityDists[d.triangles[i + 1]][d.triangles[i + 2]] =
|
||||
Math.sqrt(dist23Squared));
|
||||
|
||||
// arccos((P122 + P132 - P232) / (2 * P12 * P13))
|
||||
const angle1 = Math.acos((dist12Squared + dist13Squared - dist23Squared) / (2 * dist12 * dist13));
|
||||
const angle2 = Math.acos((dist12Squared + dist23Squared - dist13Squared) / (2 * dist12 * dist23));
|
||||
const angle3 = Math.PI - angle1 - angle2;
|
||||
|
||||
const maxAngle = (105 * Math.PI) / 180;
|
||||
if (cityConnections[d.triangles[i]][d.triangles[i + 1]] !== false && angle3 < maxAngle) {
|
||||
cityConnections[d.triangles[i]][d.triangles[i + 1]] = true;
|
||||
cityConnections[d.triangles[i + 1]][d.triangles[i]] = true;
|
||||
} else {
|
||||
cityConnections[d.triangles[i]][d.triangles[i + 1]] = false;
|
||||
cityConnections[d.triangles[i + 1]][d.triangles[i]] = false;
|
||||
}
|
||||
|
||||
if (cityConnections[d.triangles[i]][d.triangles[i + 2]] !== false && angle2 < maxAngle) {
|
||||
cityConnections[d.triangles[i]][d.triangles[i + 2]] = true;
|
||||
cityConnections[d.triangles[i + 2]][d.triangles[i]] = true;
|
||||
} else {
|
||||
cityConnections[d.triangles[i]][d.triangles[i + 2]] = false;
|
||||
cityConnections[d.triangles[i + 2]][d.triangles[i]] = false;
|
||||
}
|
||||
|
||||
if (cityConnections[d.triangles[i + 1]][d.triangles[i + 2]] !== false && angle1 < maxAngle) {
|
||||
cityConnections[d.triangles[i + 1]][d.triangles[i + 2]] = true;
|
||||
cityConnections[d.triangles[i + 2]][d.triangles[i + 1]] = true;
|
||||
} else {
|
||||
cityConnections[d.triangles[i + 1]][d.triangles[i + 2]] = false;
|
||||
cityConnections[d.triangles[i + 2]][d.triangles[i + 1]] = false;
|
||||
}
|
||||
}
|
||||
|
||||
let maxDist = 0;
|
||||
let minDist = 1000;
|
||||
for (let i = 0; i < cities.length; i++) {
|
||||
for (let j = 0; j < i; j++) {
|
||||
if (cityConnections[i][j]) {
|
||||
const dist = cityDists[i][j];
|
||||
maxDist = Math.max(maxDist, dist);
|
||||
minDist = Math.min(minDist, dist);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const centroids =
|
||||
regionCount === 5
|
||||
? [
|
||||
[width / 4, height / 4],
|
||||
[width / 4, (3 * height) / 4],
|
||||
[width / 2, height / 2],
|
||||
[(3 * width) / 4, height / 4],
|
||||
[(3 * width) / 4, (3 * height) / 4],
|
||||
]
|
||||
: regionCount === 4
|
||||
? [
|
||||
[width / 4, height / 4],
|
||||
[width / 4, (3 * height) / 4],
|
||||
[(3 * width) / 4, height / 4],
|
||||
[(3 * width) / 4, (3 * height) / 4],
|
||||
]
|
||||
: [
|
||||
[width / 4, height / 4],
|
||||
[width / 2, height / 2],
|
||||
[(3 * width) / 4, (3 * height) / 4],
|
||||
];
|
||||
const indexes = bkmeans(
|
||||
cities.map((c) => [c.x, c.y]),
|
||||
regionCount,
|
||||
centroids,
|
||||
cityConnections
|
||||
);
|
||||
const countRegions = Array(regionCount).fill(0);
|
||||
cities.forEach((city, index) => {
|
||||
city.region = regions[indexes[index]];
|
||||
city.name = upperFirst(city.region) + ' ' + (countRegions[indexes[index]]++ + 1);
|
||||
});
|
||||
|
||||
const connections: Connection[] = [];
|
||||
for (let i = 0; i < cities.length; i++) {
|
||||
for (let j = 0; j < i; j++) {
|
||||
if (cityConnections[i][j]) {
|
||||
const city1 = cities[i];
|
||||
const city2 = cities[j];
|
||||
const dist = cityDists[i][j];
|
||||
connections.push({
|
||||
nodes: [city1.name, city2.name],
|
||||
cost: Math.floor((5 * dist) / gridCellSize),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
map.cities = cities;
|
||||
map.connections = connections;
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
function bkmeans(
|
||||
points: number[][],
|
||||
regions: number,
|
||||
centroids: number[][],
|
||||
connections: boolean[][],
|
||||
iterations: number = 100
|
||||
): number[] {
|
||||
const indexes = Array(points.length).fill(0);
|
||||
const pointsPerRegion = Math.ceil(points.length / regions);
|
||||
|
||||
let conv = false;
|
||||
do {
|
||||
// Assign
|
||||
const regionsCount = Array(regions).fill(0);
|
||||
const pointCentDists = Array(points.length)
|
||||
.fill(0)
|
||||
.map((_) => Array(regions).fill(0));
|
||||
points.forEach((point, pi) => {
|
||||
let minDist: number | null = null;
|
||||
let index = 0;
|
||||
centroids.forEach((centroid, ci) => {
|
||||
const d = dist(point, centroid);
|
||||
if (minDist === null || d < minDist) {
|
||||
if (regionsCount[ci] < pointsPerRegion) {
|
||||
minDist = d;
|
||||
index = ci;
|
||||
}
|
||||
}
|
||||
|
||||
pointCentDists[pi][ci] = d;
|
||||
});
|
||||
|
||||
indexes[pi] = index;
|
||||
regionsCount[index]++;
|
||||
});
|
||||
|
||||
// Update
|
||||
const newCentroids = Array(centroids.length)
|
||||
.fill(0)
|
||||
.map((_) => [0, 0]);
|
||||
const centroidsCount = Array(centroids.length).fill(0);
|
||||
points.forEach((point, pi) => {
|
||||
newCentroids[indexes[pi]][0] += point[0];
|
||||
newCentroids[indexes[pi]][1] += point[1];
|
||||
centroidsCount[indexes[pi]]++;
|
||||
});
|
||||
|
||||
conv = true;
|
||||
centroids.forEach((centroid, ci) => {
|
||||
newCentroids[ci][0] = newCentroids[ci][0] / centroidsCount[ci];
|
||||
newCentroids[ci][1] = newCentroids[ci][1] / centroidsCount[ci];
|
||||
|
||||
if (centroid[0] !== newCentroids[ci][0] || centroid[1] !== newCentroids[ci][1]) {
|
||||
conv = false;
|
||||
}
|
||||
});
|
||||
|
||||
centroids = newCentroids;
|
||||
|
||||
console.log('iterations', iterations);
|
||||
console.log('centroids', centroids);
|
||||
|
||||
conv = conv || --iterations === 0;
|
||||
} while (!conv);
|
||||
|
||||
// Refine
|
||||
let maxRefine = 10;
|
||||
do {
|
||||
console.log('Refining');
|
||||
conv = true;
|
||||
points.forEach((_, p1) => {
|
||||
const index = indexes[p1];
|
||||
const hasSameColorNeighbor = connections[p1].some((connection, p2) => connection && index === indexes[p2]);
|
||||
if (!hasSameColorNeighbor) {
|
||||
const centroid = centroids[index];
|
||||
let minDist: number | null = null;
|
||||
let closestNeighbor: number | null = null;
|
||||
connections[p1].forEach((connection, p2) => {
|
||||
if (connection) {
|
||||
const neighbor = points[p2];
|
||||
const d = dist(neighbor, centroid);
|
||||
if (minDist === null || d < minDist) {
|
||||
minDist = d;
|
||||
closestNeighbor = p2;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
indexes[p1] = indexes[closestNeighbor!];
|
||||
indexes[closestNeighbor!] = index;
|
||||
|
||||
conv = false;
|
||||
}
|
||||
});
|
||||
conv = conv || --maxRefine === 0;
|
||||
} while (!conv);
|
||||
|
||||
return indexes;
|
||||
}
|
||||
|
||||
function dist(p1: number[], p2: number[]): number {
|
||||
return (p1[0] - p2[0]) * (p1[0] - p2[0]) + (p1[1] - p2[1]) * (p1[1] - p2[1]);
|
||||
}
|
||||
6
pnpm-lock.yaml
generated
6
pnpm-lock.yaml
generated
|
|
@ -1,4 +1,4 @@
|
|||
lockfileVersion: 5.3
|
||||
lockfileVersion: 5.4
|
||||
|
||||
specifiers:
|
||||
husky: ^5.0.9
|
||||
|
|
@ -11,7 +11,7 @@ devDependencies:
|
|||
husky: 5.2.0
|
||||
lint-staged: 10.5.4
|
||||
prettier: 2.3.2
|
||||
prettier-plugin-organize-imports: 1.1.1_prettier@2.3.2+typescript@4.3.5
|
||||
prettier-plugin-organize-imports: 1.1.1_6oxwvdycj6wwexyeuofwnckqjq
|
||||
typescript: 4.3.5
|
||||
|
||||
packages:
|
||||
|
|
@ -681,7 +681,7 @@ packages:
|
|||
semver-compare: 1.0.0
|
||||
dev: true
|
||||
|
||||
/prettier-plugin-organize-imports/1.1.1_prettier@2.3.2+typescript@4.3.5:
|
||||
/prettier-plugin-organize-imports/1.1.1_6oxwvdycj6wwexyeuofwnckqjq:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-rFA1lnek1FYkMGthm4xBKME41qUKItTovuo24bCGZu/Vu1n3gW71UPLAkIdwewwkZCe29gRVweSOPXvAdckFuw==,
|
||||
|
|
|
|||
944
viewer/pnpm-lock.yaml
generated
944
viewer/pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load diff
|
|
@ -10,19 +10,19 @@ function launchSelfContained(selector = '#app') {
|
|||
|
||||
const emitter = launch(selector);
|
||||
|
||||
let gameState = setup(6, { map: 'Italy', variant: 'original', showMoney: true });
|
||||
let gameState = setup(3, { map: 'Brazil', variant: 'original', showMoney: true, randomizeMap: true }, '3');
|
||||
|
||||
// gameState.map.viewBox = [1465, 860];
|
||||
// gameState.map.viewBox = [1480, 1060];
|
||||
// gameState.map.playerOrderPosition = [1160, 140];
|
||||
// gameState.map.cityCountPosition = [0, 0];
|
||||
// gameState.map.powerPlantMarketPosition = [745, 0];
|
||||
// gameState.map.mapPosition = [-20, 320];
|
||||
// gameState.map.mapPosition = [0, 100];
|
||||
// gameState.map.buttonsPosition = [1305, 0];
|
||||
// gameState.map.playerBoardsPosition = [1105, 200];
|
||||
// gameState.map.roundInfoPosition = [20, 590];
|
||||
// gameState.map.supplyPosition = [0, 720];
|
||||
|
||||
// gameState.map.adjustRatio = [1.1, 1];
|
||||
// gameState.map.adjustRatio = [1, 1];
|
||||
// gameState.map.cities = gameState.map.cities.map(city => ({
|
||||
// ...city,
|
||||
// x: city.x * gameState.map.adjustRatio![0],
|
||||
|
|
@ -35,8 +35,6 @@ function launchSelfContained(selector = '#app') {
|
|||
// y: 600 - city.x
|
||||
// }));
|
||||
|
||||
// gameState.map.cities.forEach(c => console.log(`{ name: ${c.name}, region: ${c.region}, x: ${Math.round(c.x)}, y: ${Math.round(c.y)} },`));
|
||||
|
||||
for (let i = 0; i < gameState.players.length; i++) {
|
||||
gameState.players[i].name = `Player ${i + 1}`;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue