Initial
This commit is contained in:
commit
ed72398736
91 changed files with 20908 additions and 0 deletions
5
.editorconfig
Normal file
5
.editorconfig
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
[*.{js,jsx,ts,tsx,vue}]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
40
.github/workflows/engine-publish.yml
vendored
Normal file
40
.github/workflows/engine-publish.yml
vendored
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
name: Engine - Version and Release
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
newversion:
|
||||
description: 'Semantic Version Bump Type (major minor patch)'
|
||||
default: patch
|
||||
|
||||
env:
|
||||
node_version: 14
|
||||
|
||||
defaults:
|
||||
run:
|
||||
working-directory: engine
|
||||
|
||||
jobs:
|
||||
version_and_release:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Use Node.js ${{ env.node_version }}
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: ${{ env.node_version }}
|
||||
# setting a registry enables the NODE_AUTH_TOKEN env variable where we can set an npm token. REQUIRED
|
||||
registry-url: 'https://registry.npmjs.org'
|
||||
- uses: pnpm/action-setup@v1.2.1
|
||||
with:
|
||||
version: 5.17.1
|
||||
- run: pnpm install
|
||||
- run: git config --global user.name github-actions
|
||||
- run: git config --global user.email bot@github.com
|
||||
- run: yarn config set version-git-message "Engine v%s"
|
||||
- run: yarn version --${{ github.event.inputs.newversion }}
|
||||
- run: sed -i 's:container-engine:@boardgamers/container-engine:' package.json
|
||||
- run: pnpm publish --access public --no-git-checks .
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
- run: git push --follow-tags
|
||||
30
.github/workflows/engine-test.yml
vendored
Normal file
30
.github/workflows/engine-test.yml
vendored
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
name: Engine - Test
|
||||
on:
|
||||
push:
|
||||
paths:
|
||||
- '.github/workflows/engine-test.yml'
|
||||
- 'engine/**'
|
||||
pull_request:
|
||||
paths:
|
||||
- '.github/workflows/engine-test.yml'
|
||||
- 'engine/**'
|
||||
|
||||
defaults:
|
||||
run:
|
||||
working-directory: engine
|
||||
|
||||
jobs:
|
||||
lint_and_test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: '12'
|
||||
- uses: pnpm/action-setup@v1.2.1
|
||||
with:
|
||||
version: 5.17.1
|
||||
- run: pnpm install
|
||||
- run: pnpm build
|
||||
- run: pnpm lint
|
||||
- run: pnpm test
|
||||
14
.github/workflows/prettier.yml
vendored
Normal file
14
.github/workflows/prettier.yml
vendored
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
name: All
|
||||
on: [pull_request, push]
|
||||
|
||||
jobs:
|
||||
prettier:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-node@v1
|
||||
- uses: pnpm/action-setup@v1.2.1
|
||||
with:
|
||||
version: 5.17.1
|
||||
- run: pnpm install
|
||||
- run: pnpm run prettier-check
|
||||
40
.github/workflows/viewer-publish.yml
vendored
Normal file
40
.github/workflows/viewer-publish.yml
vendored
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
name: Viewer - Version and Release
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
newversion:
|
||||
description: 'Semantic Version Bump Type (major minor patch)'
|
||||
default: patch
|
||||
|
||||
env:
|
||||
node_version: 14
|
||||
|
||||
defaults:
|
||||
run:
|
||||
working-directory: viewer
|
||||
|
||||
jobs:
|
||||
version_and_release:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Use Node.js ${{ env.node_version }}
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: ${{ env.node_version }}
|
||||
# setting a registry enables the NODE_AUTH_TOKEN env variable where we can set an npm token. REQUIRED
|
||||
registry-url: 'https://registry.npmjs.org'
|
||||
- uses: pnpm/action-setup@v1.2.1
|
||||
with:
|
||||
version: 5.17.1
|
||||
- run: pnpm install
|
||||
- run: git config --global user.name github-actions
|
||||
- run: git config --global user.email bot@github.com
|
||||
- run: yarn config set version-git-message "Viewer v%s"
|
||||
- run: yarn version --${{ github.event.inputs.newversion }}
|
||||
- run: sed -i 's:"container-viewer":"@boardgamers/container-viewer":' package.json
|
||||
- run: pnpm publish --access public --no-git-checks .
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
- run: git push --follow-tags
|
||||
32
.github/workflows/viewer-test.yml
vendored
Normal file
32
.github/workflows/viewer-test.yml
vendored
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
name: Viewer - Test
|
||||
on:
|
||||
push:
|
||||
paths:
|
||||
- '.github/workflows/viewer-test.yml'
|
||||
- 'viewer/**'
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
paths:
|
||||
- '.github/workflows/viewer-test.yml'
|
||||
- 'viewer/**'
|
||||
|
||||
defaults:
|
||||
run:
|
||||
working-directory: viewer
|
||||
|
||||
jobs:
|
||||
test_and_build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: '14'
|
||||
- uses: pnpm/action-setup@v1.2.1
|
||||
with:
|
||||
version: 5.17.1
|
||||
- run: pnpm install
|
||||
# - run: pnpm lint
|
||||
# - run: pnpm test
|
||||
- run: pnpm build
|
||||
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
node_modules
|
||||
3
.gitpod.dockerfile
Normal file
3
.gitpod.dockerfile
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
FROM gitpod/workspace-full
|
||||
|
||||
RUN npm install -g pnpm
|
||||
30
.gitpod.yml
Normal file
30
.gitpod.yml
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
image:
|
||||
file: .gitpod.dockerfile
|
||||
|
||||
tasks:
|
||||
- init: pnpm install
|
||||
command: cd viewer && pnpm serve
|
||||
|
||||
ports:
|
||||
- port: 8080
|
||||
onOpen: open-preview
|
||||
|
||||
github:
|
||||
prebuilds:
|
||||
# enable for the master/default branch (defaults to true)
|
||||
master: true
|
||||
# enable for pull requests coming from this repo (defaults to true)
|
||||
pullRequests: true
|
||||
# enable for pull requests coming from forks (defaults to false)
|
||||
pullRequestsFromForks: true
|
||||
# add a "Review in Gitpod" button as a comment to pull requests (defaults to true)
|
||||
addComment: true
|
||||
# add a "Review in Gitpod" button to pull requests (defaults to false)
|
||||
addBadge: false
|
||||
# add a label once the prebuild is ready to pull requests (defaults to false)
|
||||
addLabel: prebuilt-in-gitpod
|
||||
|
||||
vscode:
|
||||
extensions:
|
||||
- octref.vetur@0.32.0:03mwRhlVpWDul4qBChcVUA==
|
||||
- vtrois.gitmoji-vscode@1.0.5:iedq1JRjfM74CfhCoy3gJQ==
|
||||
1
.husky/.gitignore
vendored
Normal file
1
.husky/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
_
|
||||
4
.husky/pre-commit
Normal file
4
.husky/pre-commit
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#!/bin/sh
|
||||
. "$(dirname "$0")/_/husky.sh"
|
||||
|
||||
pnpm run lint-staged
|
||||
1
.npmrc
Normal file
1
.npmrc
Normal file
|
|
@ -0,0 +1 @@
|
|||
shared-workspace-lockfile = false
|
||||
5
.prettierrc
Normal file
5
.prettierrc
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"tabWidth": 4,
|
||||
"singleQuote": true,
|
||||
"printWidth": 120
|
||||
}
|
||||
29
README.md
Normal file
29
README.md
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
# Container
|
||||
|
||||
[](https://gitpod.io/#https://github.com/boardgamers/container)
|
||||
|
||||
Mono repo containing the viewer & the engine for Gaia Container
|
||||
|
||||
Checkout their READMEs:
|
||||
|
||||
- [engine](./engine/README.md)
|
||||
- [viewer](./viewer/README.md)
|
||||
|
||||
## Demo
|
||||
|
||||
Check out [boardgamers.space](https://www.boardgamers.space)! Reach out to us if you want to contribute.
|
||||
|
||||
## Install
|
||||
|
||||
Do `pnpm install` in the main folder
|
||||
|
||||
## Test locally
|
||||
|
||||
After the installation step, you can run the viewer with:
|
||||
|
||||
```
|
||||
cd viewer
|
||||
npm run serve
|
||||
```
|
||||
|
||||
It will use the engine in its sibling folder
|
||||
34
engine/.eslintrc.js
Normal file
34
engine/.eslintrc.js
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
module.exports = {
|
||||
root: true,
|
||||
env: {
|
||||
node: true,
|
||||
},
|
||||
parserOptions: {
|
||||
ecmaVersion: 2020,
|
||||
},
|
||||
parser: '@typescript-eslint/parser',
|
||||
plugins: ['@typescript-eslint'],
|
||||
extends: [
|
||||
'eslint:recommended',
|
||||
'plugin:@typescript-eslint/eslint-recommended',
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
],
|
||||
rules: {
|
||||
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
|
||||
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
|
||||
semi: ['error', 'always'],
|
||||
'@typescript-eslint/no-non-null-assertion': 'off',
|
||||
// '@typescript-eslint/consistent-type-assertions': 'off',
|
||||
// '@typescript-eslint/no-explicit-any': 'off',
|
||||
'@typescript-eslint/no-empty-function': 'off',
|
||||
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
|
||||
'@typescript-eslint/explicit-function-return-type': 'off',
|
||||
'@typescript-eslint/no-use-before-define': 'off',
|
||||
'@typescript-eslint/no-namespace': 'off',
|
||||
'no-inner-declarations': 'off',
|
||||
'no-return-assign': 'off',
|
||||
// 'no-fallthrough': 'off',
|
||||
'no-empty': 'off',
|
||||
quotes: 'off',
|
||||
},
|
||||
};
|
||||
1
engine/.gitignore
vendored
Normal file
1
engine/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
/dist
|
||||
6
engine/.pnpm-debug.log
Normal file
6
engine/.pnpm-debug.log
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"0 debug pnpm:scope": {
|
||||
"selected": 1,
|
||||
"workspacePrefix": "C:\\Users\\LucasAndradeMello\\Desktop\\Pessoal\\bg\\powergrid\\powergrid"
|
||||
}
|
||||
}
|
||||
4
engine/.travis.yml
Normal file
4
engine/.travis.yml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
language: node_js
|
||||
|
||||
node_js:
|
||||
- node
|
||||
30
engine/.vscode/launch.json
vendored
Normal file
30
engine/.vscode/launch.json
vendored
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"name": "Mocha Tests",
|
||||
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
|
||||
"args": [
|
||||
"--require",
|
||||
"ts-node/register",
|
||||
"--reporter",
|
||||
"dot",
|
||||
"--slow",
|
||||
"5000",
|
||||
"--colors",
|
||||
"${workspaceFolder}/src/*.spec.ts"
|
||||
],
|
||||
"internalConsoleOptions": "openOnSessionStart",
|
||||
"skipFiles": ["<node_internals>/**"]
|
||||
},
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"name": "Launch Program",
|
||||
"skipFiles": ["<node_internals>/**"],
|
||||
"program": "${workspaceFolder}/index.js"
|
||||
}
|
||||
]
|
||||
}
|
||||
3
engine/.vscode/settings.json
vendored
Normal file
3
engine/.vscode/settings.json
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"editor.formatOnSave": true
|
||||
}
|
||||
21
engine/LICENSE
Normal file
21
engine/LICENSE
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2018 donkeytech
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
31
engine/README.md
Normal file
31
engine/README.md
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
# container-engine
|
||||
|
||||
Typescript engine for Container.
|
||||
|
||||
## Setup
|
||||
|
||||
### Requirements
|
||||
|
||||
Recent version of node / pnpm.
|
||||
|
||||
### Dependencies
|
||||
|
||||
In the project's folder:
|
||||
|
||||
```
|
||||
pnpm
|
||||
```
|
||||
|
||||
### Build
|
||||
|
||||
To compile Typescript into javascript:
|
||||
|
||||
```
|
||||
pnpm build
|
||||
```
|
||||
|
||||
### Test
|
||||
|
||||
```
|
||||
pnpm test
|
||||
```
|
||||
6
engine/index.ts
Normal file
6
engine/index.ts
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
export { availableMoves, AvailableMoves } from './src/available-moves';
|
||||
export { currentPlayers, ended, move, reconstructState, setup, stripSecret } from './src/engine';
|
||||
export { Phase } from './src/gamestate';
|
||||
export type { GameState, Player, PointCard } from './src/gamestate';
|
||||
export { GameEventName, LogItem } from './src/log';
|
||||
export { Move, MoveName, Moves } from './src/move';
|
||||
50
engine/package.json
Normal file
50
engine/package.json
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
{
|
||||
"name": "container-engine",
|
||||
"version": "1.0.8",
|
||||
"description": "An engine for Container",
|
||||
"main": "dist/index.js",
|
||||
"types": "index.ts",
|
||||
"source": "index.ts",
|
||||
"repository": "git@github.com:LucasAMello/container-engine.git",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"author": "LucasAMello",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"prepublishOnly": "npm run test && npm run clean && tsc",
|
||||
"build": "npm run clean && tsc",
|
||||
"clean": "rm -Rf dist",
|
||||
"lint": "eslint . --ext .ts",
|
||||
"test": "mocha -r ts-node/register src/**/*.spec.ts src/*.spec.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/lodash": "^4.14.149",
|
||||
"@types/seedrandom": "^2.4.27",
|
||||
"lodash": "^4.17.15",
|
||||
"seedrandom": "^3.0.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/chai": "^4.1.2",
|
||||
"@types/mocha": "^2.2.48",
|
||||
"@types/node": "^13.11.0",
|
||||
"@typescript-eslint/eslint-plugin": "^2.31.0",
|
||||
"@typescript-eslint/parser": "^2.31.0",
|
||||
"chai": "^4.1.2",
|
||||
"eslint": "^6.8.0",
|
||||
"eslint-plugin-import": "^2.20.2",
|
||||
"eslint-plugin-node": "^11.1.0",
|
||||
"eslint-plugin-promise": "^4.2.1",
|
||||
"eslint-plugin-standard": "^4.0.1",
|
||||
"mocha": "^5.0.4",
|
||||
"ts-node": "^10.0.0",
|
||||
"typescript": "^4.3.5"
|
||||
},
|
||||
"files": [
|
||||
"index.ts",
|
||||
"wrapper.ts",
|
||||
"src",
|
||||
"dist",
|
||||
"tsconfig.json"
|
||||
]
|
||||
}
|
||||
2361
engine/pnpm-lock.yaml
generated
Normal file
2361
engine/pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load diff
275
engine/src/available-moves.ts
Normal file
275
engine/src/available-moves.ts
Normal file
|
|
@ -0,0 +1,275 @@
|
|||
import { range } from 'lodash';
|
||||
import { GameState, Phase, Player, PowerPlantType, ResourceType } from './gamestate';
|
||||
import { MoveName } from './move';
|
||||
import prices from './prices';
|
||||
|
||||
export interface AvailableMoves {
|
||||
[MoveName.ChoosePowerPlant]?: number[];
|
||||
[MoveName.Bid]?: number[];
|
||||
[MoveName.DiscardPowerPlant]?: number[];
|
||||
[MoveName.DiscardResources]?: ResourceType[];
|
||||
[MoveName.BuyResource]?: {
|
||||
resource: ResourceType;
|
||||
price: number;
|
||||
}[];
|
||||
[MoveName.Build]?: string[];
|
||||
[MoveName.UsePowerPlant]?: {
|
||||
powerPlant: number;
|
||||
resourcesSpent: ResourceType[];
|
||||
citiesPowered: number;
|
||||
}[];
|
||||
[MoveName.Pass]?: boolean[];
|
||||
[MoveName.Undo]?: boolean[];
|
||||
}
|
||||
|
||||
export function availableMoves(G: GameState, player: Player): AvailableMoves {
|
||||
const moves = {
|
||||
[MoveName.Undo]: [true]
|
||||
};
|
||||
|
||||
switch (G.phase) {
|
||||
case Phase.Auction: {
|
||||
if (player.powerPlants.length > 4 || (G.players.length > 2 && player.powerPlants.length > 3)) {
|
||||
moves[MoveName.DiscardPowerPlant] = player.powerPlants;
|
||||
} else {
|
||||
const toDiscard: ResourceType[] = []
|
||||
if (player.coalCapacity < player.coalLeft) {
|
||||
toDiscard.push(ResourceType.Coal);
|
||||
}
|
||||
|
||||
if (player.oilCapacity < player.oilLeft) {
|
||||
toDiscard.push(ResourceType.Oil);
|
||||
}
|
||||
|
||||
if (player.garbageCapacity < player.garbageLeft) {
|
||||
toDiscard.push(ResourceType.Garbage);
|
||||
}
|
||||
|
||||
if (player.uraniumCapacity < player.uraniumLeft) {
|
||||
toDiscard.push(ResourceType.Uranium);
|
||||
}
|
||||
|
||||
if (toDiscard.length > 0) {
|
||||
moves[MoveName.DiscardResources] = toDiscard;
|
||||
} else {
|
||||
if (G.chosenPowerPlant == null) {
|
||||
moves[MoveName.ChoosePowerPlant] = G.actualMarket;
|
||||
} else {
|
||||
moves[MoveName.Bid] = range(G.currentBid, player.money + 1);
|
||||
|
||||
if (G.currentBid != null) {
|
||||
moves[MoveName.Pass] = [true];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case Phase.Resources: {
|
||||
const toBuy: { resource: ResourceType; price: number; }[] = [];
|
||||
|
||||
if (G.coalMarket > 0) {
|
||||
const price = prices[ResourceType.Coal][prices[ResourceType.Coal].length - G.coalMarket];
|
||||
if (player.money >= price) {
|
||||
toBuy.push({ resource: ResourceType.Coal, price });
|
||||
}
|
||||
}
|
||||
|
||||
if (G.oilMarket > 0) {
|
||||
const price = prices[ResourceType.Oil][prices[ResourceType.Oil].length - G.oilMarket];
|
||||
if (player.money >= price) {
|
||||
toBuy.push({ resource: ResourceType.Oil, price });
|
||||
}
|
||||
}
|
||||
|
||||
if (G.garbageMarket > 0) {
|
||||
const price = prices[ResourceType.Garbage][prices[ResourceType.Garbage].length - G.garbageMarket];
|
||||
if (player.money >= price) {
|
||||
toBuy.push({ resource: ResourceType.Garbage, price });
|
||||
}
|
||||
}
|
||||
|
||||
if (G.uraniumMarket > 0) {
|
||||
const price = prices[ResourceType.Uranium][prices[ResourceType.Uranium].length - G.uraniumMarket];
|
||||
if (player.money >= price) {
|
||||
toBuy.push({ resource: ResourceType.Uranium, price });
|
||||
}
|
||||
}
|
||||
|
||||
if (toBuy.length > 0) {
|
||||
moves[MoveName.BuyResource] = toBuy;
|
||||
}
|
||||
|
||||
moves[MoveName.Pass] = [true];
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case Phase.Building: {
|
||||
let toBuild = player.cities.length == 0 ?
|
||||
G.map.cities.map(c => ({ name: c.name, price: 10 })) :
|
||||
dijkstra(G, player);
|
||||
|
||||
toBuild = toBuild.filter(c => c.price <= player.money);
|
||||
|
||||
if (toBuild.length > 0) {
|
||||
moves[MoveName.Build] = toBuild;
|
||||
}
|
||||
|
||||
moves[MoveName.Pass] = [true];
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case Phase.Bureaucracy: {
|
||||
const toUse: { powerPlant: number; resourcesSpent: ResourceType[]; citiesPowered: number; }[] = [];
|
||||
|
||||
player.powerPlants.forEach(powerPlant => {
|
||||
if (!player.powerPlantsUsed.includes(powerPlant.number)) {
|
||||
switch (powerPlant.type) {
|
||||
case PowerPlantType.Coal: {
|
||||
if (player.coalLeft >= powerPlant.cost) {
|
||||
toUse.push({
|
||||
powerPlant: powerPlant.number,
|
||||
resourcesSpent: new Array(powerPlant.cost).fill(ResourceType.Coal),
|
||||
citiesPowered: powerPlant.citiesPowered
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
case PowerPlantType.Oil: {
|
||||
if (player.oilLeft >= powerPlant.cost) {
|
||||
toUse.push({
|
||||
powerPlant: powerPlant.number,
|
||||
resourcesSpent: new Array(powerPlant.cost).fill(ResourceType.Oil),
|
||||
citiesPowered: powerPlant.citiesPowered
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
case PowerPlantType.Garbage: {
|
||||
if (player.garbageLeft >= powerPlant.cost) {
|
||||
toUse.push({
|
||||
powerPlant: powerPlant.number,
|
||||
resourcesSpent: new Array(powerPlant.cost).fill(ResourceType.Garbage),
|
||||
citiesPowered: powerPlant.citiesPowered
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
case PowerPlantType.Uranium: {
|
||||
if (player.uraniumLeft >= powerPlant.cost) {
|
||||
toUse.push({
|
||||
powerPlant: powerPlant.number,
|
||||
resourcesSpent: new Array(powerPlant.cost).fill(ResourceType.Uranium),
|
||||
citiesPowered: powerPlant.citiesPowered
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
case PowerPlantType.Wind:
|
||||
case PowerPlantType.Nuclear:
|
||||
toUse.push({
|
||||
powerPlant: powerPlant.number,
|
||||
resourcesSpent: [],
|
||||
citiesPowered: powerPlant.citiesPowered
|
||||
});
|
||||
|
||||
break;
|
||||
|
||||
case PowerPlantType.Hybrid: {
|
||||
if (player.coalLeft + player.oilLeft >= powerPlant.cost) {
|
||||
let resourcesSpentArr: ResourceType[][];
|
||||
if (powerPlant.cost == 1) {
|
||||
resourcesSpentArr = [[ResourceType.Coal], [ResourceType.Oil]];
|
||||
} else if (powerPlant.cost == 2) {
|
||||
resourcesSpentArr = [
|
||||
[ResourceType.Coal, ResourceType.Coal],
|
||||
[ResourceType.Coal, ResourceType.Oil],
|
||||
[ResourceType.Oil, ResourceType.Oil]
|
||||
];
|
||||
} else {
|
||||
resourcesSpentArr = [
|
||||
[ResourceType.Coal, ResourceType.Coal, ResourceType.Coal],
|
||||
[ResourceType.Coal, ResourceType.Coal, ResourceType.Oil],
|
||||
[ResourceType.Coal, ResourceType.Oil, ResourceType.Oil],
|
||||
[ResourceType.Oil, ResourceType.Oil, ResourceType.Oil]
|
||||
];
|
||||
}
|
||||
|
||||
resourcesSpentArr.forEach(resourcesSpent => {
|
||||
if (resourcesSpent.filter(r => r == ResourceType.Coal).length <= player.coalLeft &&
|
||||
resourcesSpent.filter(r => r == ResourceType.Oil).length <= player.oilLeft) {
|
||||
toUse.push({
|
||||
powerPlant: powerPlant.number,
|
||||
resourcesSpent: resourcesSpent,
|
||||
citiesPowered: powerPlant.citiesPowered
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (toUse.length > 0) {
|
||||
moves[MoveName.UsePowerPlant] = toUse;
|
||||
}
|
||||
|
||||
moves[MoveName.Pass] = [true];
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return moves;
|
||||
}
|
||||
|
||||
function dijkstra(G: GameState, player: Player): { name: string; price: number; }[] {
|
||||
const nodes = G.map.cities.map(c => ({ name: c.name, price: 0, visited: false }));
|
||||
|
||||
let currentNode = nodes.find(n => n.name == player.cities[0].name)!;
|
||||
currentNode.price = 0;
|
||||
|
||||
while (true) {
|
||||
const currentConnections = G.map.connections.filter(c => c.to == currentNode.name || c.from == currentNode.name);
|
||||
currentConnections.forEach(connection => {
|
||||
const otherNode = nodes.find(n => connection.to == currentNode.name ? n.name == connection.from : n.name == connection.to)!;
|
||||
const price = player.cities.find(c => c.name == otherNode.name) ? 0 : currentNode.price + connection.cost;
|
||||
if (!otherNode.visited || otherNode.price > price) {
|
||||
otherNode.price = price;
|
||||
}
|
||||
});
|
||||
|
||||
currentNode.visited = true;
|
||||
|
||||
if (!nodes.some(n => !n.visited)) {
|
||||
break;
|
||||
}
|
||||
|
||||
currentNode = nodes.reduce((a, b) => {
|
||||
if (a.visited) {
|
||||
return b;
|
||||
}
|
||||
|
||||
if (b.visited) {
|
||||
return a;
|
||||
}
|
||||
|
||||
if (a.price <= b.price) {
|
||||
return a;
|
||||
}
|
||||
|
||||
return b;
|
||||
});
|
||||
|
||||
if (currentNode.price > player.money) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return nodes;
|
||||
}
|
||||
219
engine/src/engine.spec.ts
Normal file
219
engine/src/engine.spec.ts
Normal file
|
|
@ -0,0 +1,219 @@
|
|||
import { expect } from 'chai';
|
||||
import { ended, setup } from './engine';
|
||||
|
||||
describe('Engine', () => {
|
||||
it('should setup a game correctly', () => {
|
||||
const G = setup(5, { fastBid: false }, 'test');
|
||||
|
||||
// expect(G.factoriesLeft[0].id).to.equal('F1');
|
||||
// expect(G.factoriesLeft).to.have.length(20);
|
||||
// expect(G.players[0].factories[0].id).to.equal('F5');
|
||||
// expect(G.players[1].factories[0].id).to.equal('F15');
|
||||
// expect(G.players[2].factories[0].id).to.equal('F10');
|
||||
// expect(G.players[3].factories[0].id).to.equal('F20');
|
||||
// expect(G.players[4].factories[0].id).to.equal('F0');
|
||||
});
|
||||
|
||||
it('should play full game', () => {
|
||||
const G = setup(5, { fastBid: false }, 'test');
|
||||
|
||||
// G.currentPlayers = [0];
|
||||
// G.players[0].actions = 2;
|
||||
// G.players[0].availableMoves = availableMoves(G, G.players[0]);
|
||||
// G.players[0].factories[0] = ContainerColor.Brown;
|
||||
// G.players[1].factories[0] = ContainerColor.Orange;
|
||||
// G.players[2].factories[0] = ContainerColor.Black;
|
||||
// G.players[3].factories[0] = ContainerColor.Tan;
|
||||
// G.players[4].factories[0] = ContainerColor.White;
|
||||
// G.players[0].containersOnFactoryStore[0] = { containerColor: ContainerColor.Brown, price: 2 };
|
||||
// G.players[1].containersOnFactoryStore[0] = { containerColor: ContainerColor.Orange, price: 2 };
|
||||
// G.players[2].containersOnFactoryStore[0] = { containerColor: ContainerColor.Black, price: 2 };
|
||||
// G.players[3].containersOnFactoryStore[0] = { containerColor: ContainerColor.Tan, price: 2 };
|
||||
// G.players[4].containersOnFactoryStore[0] = { containerColor: ContainerColor.White, price: 2 };
|
||||
|
||||
// G = execMove(G, { name: "buyFactory", data: ContainerColor.Orange } as Move, 0);
|
||||
// G = execMove(G, { name: "buyWarehouse", data: true } as Move, 0);
|
||||
// G = execMove(G, { name: "pass", data: true } as Move, 0);
|
||||
|
||||
// G = execMove(G, { name: "buyFactory", data: ContainerColor.Tan } as Move, 1);
|
||||
// G = execMove(G, { name: "produce", data: ContainerColor.Orange, extraData: { price: 2 } } as Move, 1);
|
||||
// G = execMove(G, { name: "produce", data: ContainerColor.Tan, extraData: { price: 2 } } as Move, 1);
|
||||
// G = execMove(G, { name: "pass", data: true } as Move, 1);
|
||||
|
||||
// G = execMove(G, { name: "buyWarehouse", data: true } as Move, 2);
|
||||
// G = execMove(G, { name: "buyFromFactory", data: { player: 1, container: { containerColor: ContainerColor.Orange, price: 2 } }, extraData: { price: 4 } } as Move, 2);
|
||||
// G = execMove(G, { name: "buyFromFactory", data: { player: 1, container: { containerColor: ContainerColor.Orange, price: 2 } }, extraData: { price: 4 } } as Move, 2);
|
||||
// G = execMove(G, { name: "pass", data: true } as Move, 2);
|
||||
|
||||
// G = execMove(G, { name: "buyFactory", data: ContainerColor.Black } as Move, 3);
|
||||
// G = execMove(G, { name: "produce", data: ContainerColor.Black, extraData: { price: 3 } } as Move, 3);
|
||||
// G = execMove(G, { name: "produce", data: ContainerColor.Tan, extraData: { price: 2 } } as Move, 3);
|
||||
// G = execMove(G, { name: "pass", data: true } as Move, 3);
|
||||
|
||||
// G = execMove(G, { name: "buyWarehouse", data: true } as Move, 4);
|
||||
// G = execMove(G, { name: "sail", data: ShipPosition.Player2 } as Move, 4);
|
||||
// G = execMove(G, { name: "buyFromWarehouse", data: { player: 2, container: { containerColor: ContainerColor.Orange, price: 4 } } } as Move, 4);
|
||||
// G = execMove(G, { name: "buyFromWarehouse", data: { player: 2, container: { containerColor: ContainerColor.Orange, price: 4 } } } as Move, 4);
|
||||
// G = execMove(G, { name: "pass", data: true } as Move, 4);
|
||||
|
||||
// G = execMove(G, { name: "produce", data: ContainerColor.Orange, extraData: { price: 3 } } as Move, 0);
|
||||
// G = execMove(G, { name: "produce", data: ContainerColor.Brown, extraData: { price: 2 } } as Move, 0);
|
||||
// G = execMove(G, { name: "buyFromFactory", data: { player: 2, container: { containerColor: ContainerColor.Black, price: 2 } }, extraData: { price: 3 } } as Move, 0);
|
||||
// G = execMove(G, { name: "pass", data: true } as Move, 0);
|
||||
|
||||
// G = execMove(G, { name: "buyFactory", data: ContainerColor.White } as Move, 1);
|
||||
// G = execMove(G, { name: "produce", data: ContainerColor.Orange, extraData: { price: 2 } } as Move, 1);
|
||||
// G = execMove(G, { name: "produce", data: ContainerColor.Tan, extraData: { price: 2 } } as Move, 1);
|
||||
// G = execMove(G, { name: "produce", data: ContainerColor.White, extraData: { price: 3 } } as Move, 1);
|
||||
// G = execMove(G, { name: "pass", data: true } as Move, 1);
|
||||
|
||||
// G = execMove(G, { name: "buyFactory", data: ContainerColor.Brown } as Move, 2);
|
||||
// G = execMove(G, { name: "buyFromFactory", data: { player: 1, container: { containerColor: ContainerColor.Tan, price: 2 } }, extraData: { price: 3 } } as Move, 2);
|
||||
// G = execMove(G, { name: "buyFromFactory", data: { player: 1, container: { containerColor: ContainerColor.Tan, price: 2 } }, extraData: { price: 3 } } as Move, 2);
|
||||
// G = execMove(G, { name: "pass", data: true } as Move, 2);
|
||||
|
||||
// G = execMove(G, { name: "buyFactory", data: ContainerColor.Brown } as Move, 3);
|
||||
// G = execMove(G, { name: "produce", data: ContainerColor.Tan, extraData: { price: 2 } } as Move, 3);
|
||||
// G = execMove(G, { name: "produce", data: ContainerColor.Black, extraData: { price: 3 } } as Move, 3);
|
||||
// G = execMove(G, { name: "produce", data: ContainerColor.Brown, extraData: { price: 2 } } as Move, 3);
|
||||
// G = execMove(G, { name: "pass", data: true } as Move, 3);
|
||||
|
||||
// G = execMove(G, { name: "buyWarehouse", data: true } as Move, 4);
|
||||
// G = execMove(G, { name: "sail", data: ShipPosition.OpenSea } as Move, 4);
|
||||
// G = execMove(G, { name: "pass", data: true } as Move, 4);
|
||||
|
||||
// G = execMove(G, { name: "buyFromFactory", data: { player: 3, container: { containerColor: ContainerColor.Tan, price: 2 } }, extraData: { price: 4 } } as Move, 0);
|
||||
// G = execMove(G, { name: "sail", data: ShipPosition.Player2 } as Move, 0);
|
||||
// G = execMove(G, { name: "buyFromWarehouse", data: { player: 2, container: { containerColor: ContainerColor.Tan, price: 3 } } } as Move, 0);
|
||||
// G = execMove(G, { name: "buyFromWarehouse", data: { player: 2, container: { containerColor: ContainerColor.Tan, price: 3 } } } as Move, 0);
|
||||
// G = execMove(G, { name: "pass", data: true } as Move, 0);
|
||||
|
||||
// G = execMove(G, { name: "produce", data: ContainerColor.Tan, extraData: { price: 3 } } as Move, 1);
|
||||
// G = execMove(G, { name: "produce", data: ContainerColor.Orange, extraData: { price: 3 } } as Move, 1);
|
||||
// G = execMove(G, { name: "produce", data: ContainerColor.White, extraData: { price: 3 } } as Move, 1);
|
||||
// G = execMove(G, { name: "arrangeFactory", data: { containerColor: ContainerColor.White, price: 3 }, extraData: { price: 2 } } as Move, 1);
|
||||
// G = execMove(G, { name: "arrangeFactory", data: { containerColor: ContainerColor.White, price: 3 }, extraData: { price: 2 } } as Move, 1);
|
||||
// G = execMove(G, { name: "arrangeFactory", data: { containerColor: ContainerColor.Orange, price: 3 }, extraData: { price: 2 } } as Move, 1);
|
||||
// G = execMove(G, { name: "arrangeFactory", data: { containerColor: ContainerColor.Tan, price: 3 }, extraData: { price: 2 } } as Move, 1);
|
||||
// G = execMove(G, { name: "sail", data: ShipPosition.Player0 } as Move, 1);
|
||||
// G = execMove(G, { name: "buyFromWarehouse", data: { player: 0, container: { containerColor: ContainerColor.Black, price: 3 } } } as Move, 1);
|
||||
// G = execMove(G, { name: "buyFromWarehouse", data: { player: 0, container: { containerColor: ContainerColor.Tan, price: 4 } } } as Move, 1);
|
||||
// G = execMove(G, { name: "pass", data: true } as Move, 1);
|
||||
|
||||
// G = execMove(G, { name: "buyWarehouse", data: true } as Move, 2);
|
||||
// G = execMove(G, { name: "buyFromFactory", data: { player: 1, container: { containerColor: ContainerColor.White, price: 2 } }, extraData: { price: 3 } } as Move, 2);
|
||||
// G = execMove(G, { name: "buyFromFactory", data: { player: 1, container: { containerColor: ContainerColor.White, price: 2 } }, extraData: { price: 3 } } as Move, 2);
|
||||
// G = execMove(G, { name: "buyFromFactory", data: { player: 1, container: { containerColor: ContainerColor.Orange, price: 2 } }, extraData: { price: 4 } } as Move, 2);
|
||||
// G = execMove(G, { name: "pass", data: true } as Move, 2);
|
||||
|
||||
// G = execMove(G, { name: "buyWarehouse", data: true } as Move, 3);
|
||||
// G = execMove(G, { name: "produce", data: ContainerColor.Brown, extraData: { price: 1 } } as Move, 3);
|
||||
// G = execMove(G, { name: "arrangeFactory", data: { containerColor: ContainerColor.Brown, price: 2 }, extraData: { price: 1 } } as Move, 3);
|
||||
// G = execMove(G, { name: "arrangeFactory", data: { containerColor: ContainerColor.Black, price: 3 }, extraData: { price: 2 } } as Move, 3);
|
||||
// G = execMove(G, { name: "arrangeFactory", data: { containerColor: ContainerColor.Black, price: 3 }, extraData: { price: 2 } } as Move, 3);
|
||||
// G = execMove(G, { name: "pass", data: true } as Move, 3);
|
||||
|
||||
// G = execMove(G, { name: "buyFromFactory", data: { player: 3, container: { containerColor: ContainerColor.Brown, price: 1 } }, extraData: { price: 4 } } as Move, 4);
|
||||
// G = execMove(G, { name: "buyFromFactory", data: { player: 3, container: { containerColor: ContainerColor.Brown, price: 1 } }, extraData: { price: 4 } } as Move, 4);
|
||||
// G = execMove(G, { name: "sail", data: ShipPosition.Island } as Move, 4);
|
||||
// G = execMove(G, { name: "bid", data: true, extraData: { price: 1 } } as Move, 0);
|
||||
// G = execMove(G, { name: "bid", data: true, extraData: { price: 5 } } as Move, 1);
|
||||
// G = execMove(G, { name: "bid", data: true, extraData: { price: 4 } } as Move, 2);
|
||||
// G = execMove(G, { name: "bid", data: true, extraData: { price: 2 } } as Move, 3);
|
||||
// G = execMove(G, { name: "accept", data: 1 } as Move, 4);
|
||||
|
||||
// G = execMove(G, { name: "buyFromWarehouse", data: { player: 2, container: { containerColor: ContainerColor.White, price: 3 } } } as Move, 0);
|
||||
// G = execMove(G, { name: "buyFromWarehouse", data: { player: 2, container: { containerColor: ContainerColor.White, price: 3 } } } as Move, 0);
|
||||
// G = execMove(G, { name: "sail", data: ShipPosition.OpenSea } as Move, 0);
|
||||
// G = execMove(G, { name: "pass", data: true } as Move, 0);
|
||||
|
||||
// G = execMove(G, { name: "produce", data: ContainerColor.Orange, extraData: { price: 2 } } as Move, 1);
|
||||
// G = execMove(G, { name: "produce", data: ContainerColor.Tan, extraData: { price: 2 } } as Move, 1);
|
||||
// G = execMove(G, { name: "produce", data: ContainerColor.White, extraData: { price: 2 } } as Move, 1);
|
||||
// G = execMove(G, { name: "sail", data: ShipPosition.OpenSea } as Move, 1);
|
||||
// G = execMove(G, { name: "pass", data: true } as Move, 1);
|
||||
|
||||
// G = execMove(G, { name: "sail", data: ShipPosition.Player4 } as Move, 2);
|
||||
// G = execMove(G, { name: "buyFromWarehouse", data: { player: 4, container: { containerColor: ContainerColor.Brown, price: 4 } } } as Move, 2);
|
||||
// G = execMove(G, { name: "buyFromWarehouse", data: { player: 4, container: { containerColor: ContainerColor.Brown, price: 4 } } } as Move, 2);
|
||||
// G = execMove(G, { name: "buyFromFactory", data: { player: 3, container: { containerColor: ContainerColor.Black, price: 2 } }, extraData: { price: 3 } } as Move, 2);
|
||||
// G = execMove(G, { name: "buyFromFactory", data: { player: 3, container: { containerColor: ContainerColor.Black, price: 2 } }, extraData: { price: 3 } } as Move, 2);
|
||||
// G = execMove(G, { name: "arrangeWarehouse", data: { containerColor: ContainerColor.Orange, price: 4 }, extraData: { price: 3 } } as Move, 2);
|
||||
// G = execMove(G, { name: "pass", data: true } as Move, 2);
|
||||
|
||||
// G = execMove(G, { name: "sail", data: ShipPosition.Player2 } as Move, 3);
|
||||
// G = execMove(G, { name: "getLoan", data: true } as Move, 3);
|
||||
// G = execMove(G, { name: "buyFromWarehouse", data: { player: 2, container: { containerColor: ContainerColor.Black, price: 3 } } } as Move, 3);
|
||||
// G = execMove(G, { name: "buyFromWarehouse", data: { player: 2, container: { containerColor: ContainerColor.Black, price: 3 } } } as Move, 3);
|
||||
// G = execMove(G, { name: "buyFromWarehouse", data: { player: 2, container: { containerColor: ContainerColor.Orange, price: 3 } } } as Move, 3);
|
||||
// G = execMove(G, { name: "sail", data: ShipPosition.OpenSea } as Move, 3);
|
||||
// G = execMove(G, { name: "pass", data: true } as Move, 3);
|
||||
|
||||
// G = execMove(G, { name: "buyFromFactory", data: { player: 1, container: { containerColor: ContainerColor.White, price: 2 } }, extraData: { price: 4 } } as Move, 4);
|
||||
// G = execMove(G, { name: "buyFromFactory", data: { player: 1, container: { containerColor: ContainerColor.Orange, price: 2 } }, extraData: { price: 3 } } as Move, 4);
|
||||
// G = execMove(G, { name: "buyFromFactory", data: { player: 1, container: { containerColor: ContainerColor.Tan, price: 2 } }, extraData: { price: 3 } } as Move, 4);
|
||||
// G = execMove(G, { name: "sail", data: ShipPosition.OpenSea } as Move, 4);
|
||||
// G = execMove(G, { name: "pass", data: true } as Move, 4);
|
||||
|
||||
// G = execMove(G, { name: "sail", data: ShipPosition.Island } as Move, 0);
|
||||
// G = execMove(G, { name: "getLoan", data: true } as Move, 1);
|
||||
// G = execMove(G, { name: "bid", data: true, extraData: { price: 11 } } as Move, 1);
|
||||
// G = execMove(G, { name: "getLoan", data: true } as Move, 2);
|
||||
// G = execMove(G, { name: "bid", data: true, extraData: { price: 8 } } as Move, 2);
|
||||
// G = execMove(G, { name: "bid", data: true, extraData: { price: 7 } } as Move, 3);
|
||||
// G = execMove(G, { name: "bid", data: true, extraData: { price: 9 } } as Move, 4);
|
||||
// G = execMove(G, { name: "accept", data: 1 } as Move, 0);
|
||||
|
||||
// G = execMove(G, { name: "getLoan", data: true } as Move, 1);
|
||||
// G = execMove(G, { name: "sail", data: ShipPosition.Player4 } as Move, 1);
|
||||
// G = execMove(G, { name: "buyFromWarehouse", data: { player: 4, container: { containerColor: ContainerColor.Tan, price: 3 } } } as Move, 1);
|
||||
// G = execMove(G, { name: "buyFromWarehouse", data: { player: 4, container: { containerColor: ContainerColor.Orange, price: 3 } } } as Move, 1);
|
||||
// G = execMove(G, { name: "buyFromWarehouse", data: { player: 4, container: { containerColor: ContainerColor.White, price: 4 } } } as Move, 1);
|
||||
// G = execMove(G, { name: "sail", data: ShipPosition.OpenSea } as Move, 1);
|
||||
// G = execMove(G, { name: "pass", data: true } as Move, 1);
|
||||
|
||||
// G = execMove(G, { name: "payLoan", data: true } as Move, 2);
|
||||
// G = execMove(G, { name: "buyFromFactory", data: { player: 0, container: { containerColor: ContainerColor.Brown, price: 2 } }, extraData: { price: 3 } } as Move, 2);
|
||||
// G = execMove(G, { name: "buyFromFactory", data: { player: 0, container: { containerColor: ContainerColor.Brown, price: 2 } }, extraData: { price: 3 } } as Move, 2);
|
||||
// G = execMove(G, { name: "buyFromFactory", data: { player: 3, container: { containerColor: ContainerColor.Tan, price: 2 } }, extraData: { price: 4 } } as Move, 2);
|
||||
// G = execMove(G, { name: "pass", data: true } as Move, 2);
|
||||
|
||||
// G = execMove(G, { name: "sail", data: ShipPosition.Player2 } as Move, 3);
|
||||
// G = execMove(G, { name: "buyFromWarehouse", data: { player: 2, container: { containerColor: ContainerColor.Brown, price: 3 } } } as Move, 3);
|
||||
// G = execMove(G, { name: "buyFromWarehouse", data: { player: 2, container: { containerColor: ContainerColor.Tan, price: 4 } } } as Move, 3);
|
||||
// G = execMove(G, { name: "produce", data: ContainerColor.Brown, extraData: { price: 2 } } as Move, 3);
|
||||
// G = execMove(G, { name: "produce", data: ContainerColor.Black, extraData: { price: 3 } } as Move, 3);
|
||||
// G = execMove(G, { name: "produce", data: ContainerColor.Tan, extraData: { price: 2 } } as Move, 3);
|
||||
// G = execMove(G, { name: "pass", data: true } as Move, 3);
|
||||
|
||||
// G = execMove(G, { name: "buyFromFactory", data: { player: 3, container: { containerColor: ContainerColor.Tan, price: 2 } }, extraData: { price: 4 } } as Move, 4);
|
||||
// G = execMove(G, { name: "buyFromFactory", data: { player: 3, container: { containerColor: ContainerColor.Tan, price: 2 } }, extraData: { price: 4 } } as Move, 4);
|
||||
// G = execMove(G, { name: "buyFromFactory", data: { player: 3, container: { containerColor: ContainerColor.Brown, price: 2 } }, extraData: { price: 2 } } as Move, 4);
|
||||
// G = execMove(G, { name: "sail", data: ShipPosition.Player2 } as Move, 4);
|
||||
// G = execMove(G, { name: "buyFromWarehouse", data: { player: 2, container: { containerColor: ContainerColor.Brown, price: 3 } } } as Move, 4);
|
||||
// G = execMove(G, { name: "pass", data: true } as Move, 4);
|
||||
|
||||
// G = execMove(G, { name: "buyWarehouse", data: true } as Move, 0);
|
||||
// G = execMove(G, { name: "buyFromFactory", data: { player: 1, container: { containerColor: ContainerColor.Tan, price: 2 } }, extraData: { price: 3 } } as Move, 0);
|
||||
// G = execMove(G, { name: "buyFromFactory", data: { player: 1, container: { containerColor: ContainerColor.Orange, price: 2 } }, extraData: { price: 4 } } as Move, 0);
|
||||
// G = execMove(G, { name: "pass", data: true } as Move, 0);
|
||||
|
||||
// G = execMove(G, { name: "produce", data: ContainerColor.Orange, extraData: { price: 3 } } as Move, 1);
|
||||
// G = execMove(G, { name: "produce", data: ContainerColor.White, extraData: { price: 3 } } as Move, 1);
|
||||
// G = execMove(G, { name: "produce", data: ContainerColor.Tan, extraData: { price: 3 } } as Move, 1);
|
||||
// G = execMove(G, { name: "sail", data: ShipPosition.Island } as Move, 1);
|
||||
// G = execMove(G, { name: "bid", data: true, extraData: { price: 12 } } as Move, 2);
|
||||
// G = execMove(G, { name: "bid", data: true, extraData: { price: 5 } } as Move, 3);
|
||||
// G = execMove(G, { name: "bid", data: true, extraData: { price: 20 } } as Move, 4);
|
||||
// G = execMove(G, { name: "bid", data: true, extraData: { price: 7 } } as Move, 0);
|
||||
// G = execMove(G, { name: "accept", data: 4 } as Move, 1);
|
||||
|
||||
// G = execMove(G, { name: "pass", data: true } as Move, 0);
|
||||
// G = execMove(G, { name: "pass", data: true } as Move, 1);
|
||||
// G = execMove(G, { name: "pass", data: true } as Move, 2);
|
||||
// G = execMove(G, { name: "pass", data: true } as Move, 3);
|
||||
// G = execMove(G, { name: "pass", data: true } as Move, 4);
|
||||
|
||||
expect(ended(G)).to.be.false;
|
||||
});
|
||||
});
|
||||
477
engine/src/engine.ts
Normal file
477
engine/src/engine.ts
Normal file
|
|
@ -0,0 +1,477 @@
|
|||
import assert from 'assert';
|
||||
import { cloneDeep, isEqual, range } from 'lodash';
|
||||
import seedrandom from 'seedrandom';
|
||||
import { availableMoves } from './available-moves';
|
||||
import powerPlants from './powerPlants';
|
||||
import map from './map';
|
||||
import { GameOptions, GameState, Phase, Player, ResourceType } from './gamestate';
|
||||
import { GameEventName, LogItem } from './log';
|
||||
import { Move, MoveName, Moves } from './move';
|
||||
import { asserts, shuffle } from './utils';
|
||||
|
||||
const playerColors = ['dodgerblue', 'red', 'yellow', 'limegreen', 'mediumorchid'];
|
||||
|
||||
export function setup(numPlayers: number, { fastBid = false }: GameOptions, seed?: string): GameState {
|
||||
seed = seed ?? Math.random().toString();
|
||||
const rng = seedrandom(seed);
|
||||
|
||||
let powerPlantsDeck = cloneDeep(powerPlants);
|
||||
powerPlantsDeck = powerPlantsDeck.slice(8);
|
||||
const powerPlant13 = powerPlantsDeck.splice(2, 1)[0];
|
||||
powerPlantsDeck = shuffle(powerPlantsDeck, rng() + '');
|
||||
if (numPlayers == 2 || numPlayers == 3) {
|
||||
powerPlantsDeck = powerPlantsDeck.slice(8);
|
||||
} else if (numPlayers == 4) {
|
||||
powerPlantsDeck = powerPlantsDeck.slice(4);
|
||||
}
|
||||
|
||||
powerPlantsDeck.unshift(powerPlant13);
|
||||
|
||||
const players: Player[] = range(numPlayers).map((id) => ({
|
||||
id,
|
||||
powerPlants: [],
|
||||
coalCapacity: 0, coalLeft: 0,
|
||||
oilCapacity: 0, oilLeft: 0,
|
||||
garbageCapacity: 0, garbageLeft: 0,
|
||||
uraniumCapacity: 0, uraniumLeft: 0,
|
||||
money: 50,
|
||||
housesLeft: 22,
|
||||
cities: [],
|
||||
powerPlantsUsed: [],
|
||||
availableMoves: null,
|
||||
lastMove: null,
|
||||
isDropped: false,
|
||||
isAI: false,
|
||||
bid: 0,
|
||||
passed: false,
|
||||
skipAuction: false,
|
||||
citiesPowered: 0
|
||||
}));
|
||||
|
||||
const playerOrder = shuffle(range(numPlayers), rng() + '');
|
||||
const startingPlayer = playerOrder[0];
|
||||
|
||||
const G: GameState = {
|
||||
map,
|
||||
players,
|
||||
playerOrder,
|
||||
currentPlayers: [startingPlayer],
|
||||
powerPlantsDeck,
|
||||
coalSupply: 0,
|
||||
oilSupply: 6,
|
||||
garbageSupply: 18,
|
||||
uraniumSupply: 10,
|
||||
coalMarket: 24,
|
||||
oilMarket: 18,
|
||||
garbageMarket: 6,
|
||||
uraniumMarket: 2,
|
||||
actualMarket: [3, 4, 5, 6],
|
||||
futureMarket: [7, 8, 9, 10],
|
||||
chosenPowerPlant: 0,
|
||||
currentBid: 0,
|
||||
highestBidders: [],
|
||||
auctioningPlayer: undefined,
|
||||
step: 1,
|
||||
phase: Phase.Auction,
|
||||
options: { fastBid },
|
||||
log: [],
|
||||
hiddenLog: [],
|
||||
seed,
|
||||
round: 1,
|
||||
auctionSkips: 0
|
||||
} as GameState;
|
||||
|
||||
G.log.push({ type: 'event', event: { name: GameEventName.GameStart } });
|
||||
|
||||
G.players[startingPlayer].availableMoves = availableMoves(G, G.players[startingPlayer]);
|
||||
|
||||
return G;
|
||||
}
|
||||
|
||||
export function stripSecret(G: GameState, player?: number): GameState {
|
||||
return {
|
||||
...G,
|
||||
seed: 'secret',
|
||||
hiddenLog: [],
|
||||
players: G.players.map((pl, i) => {
|
||||
if (player === i) {
|
||||
return pl;
|
||||
} else {
|
||||
return {
|
||||
...pl,
|
||||
availableMoves: pl.availableMoves ? {} : null,
|
||||
money: ended(G) ? pl.money : 0
|
||||
};
|
||||
}
|
||||
}),
|
||||
log: G.log,
|
||||
};
|
||||
}
|
||||
|
||||
export function currentPlayers(G: GameState): number[] {
|
||||
return G.currentPlayers;
|
||||
}
|
||||
|
||||
export function move(G: GameState, move: Move, playerNumber: number, fake?: boolean): GameState {
|
||||
const player = G.players[playerNumber];
|
||||
const available = player.availableMoves?.[move.name];
|
||||
|
||||
assert(G.currentPlayers.includes(playerNumber), 'It is not your turn!');
|
||||
assert(available, 'You are not allowed to run the command ' + move.name);
|
||||
assert(
|
||||
available.some((x) => isEqual(x, move.data)),
|
||||
'Wrong argument for the command ' + move.name
|
||||
);
|
||||
|
||||
switch (move.name) {
|
||||
case MoveName.ChoosePowerPlant: {
|
||||
asserts<Moves.MoveChoosePowerPlant>(move);
|
||||
|
||||
G.chosenPowerPlant = move.data.powerPlant;
|
||||
G.currentBid = player.bid = move.data.startingPrice;
|
||||
|
||||
G.log.push({
|
||||
type: 'move',
|
||||
player: playerNumber,
|
||||
move,
|
||||
simple: `${player.name} chooses power plant ${move.data.powerPlant} to initiate an auction`,
|
||||
pretty: `${playerNameHTML(player)} chooses power plant ${move.data.powerPlant} to initiate an auction`,
|
||||
});
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case MoveName.Bid: {
|
||||
asserts<Moves.MoveBid>(move);
|
||||
|
||||
G.currentBid = player.bid = move.data.price;
|
||||
|
||||
G.log.push({
|
||||
type: 'move',
|
||||
player: playerNumber,
|
||||
move,
|
||||
simple: `${player.name} bids $${move.data.price}`,
|
||||
pretty: `${playerNameHTML(player)} bids ${move.data.price}`,
|
||||
});
|
||||
|
||||
nextPlayerAuction(G);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case MoveName.Pass: {
|
||||
asserts<Moves.MovePass>(move);
|
||||
|
||||
switch (G.phase) {
|
||||
case Phase.Auction: {
|
||||
if (G.chosenPowerPlant == 0) {
|
||||
player.skipAuction = true;
|
||||
G.auctionSkips++;
|
||||
|
||||
if (G.players.some(p => !p.skipAuction)) {
|
||||
nextPlayerAuction(G);
|
||||
} else {
|
||||
if (G.auctionSkips == G.players.length) {
|
||||
G.actualMarket.shift();
|
||||
addPowerPlant(G);
|
||||
}
|
||||
|
||||
G.phase = Phase.Resources;
|
||||
G.currentPlayers = [G.playerOrder[G.players.length - 1]];
|
||||
}
|
||||
} else {
|
||||
player.passed = true;
|
||||
|
||||
const notPassed = G.players.filter(p => !p.passed && !p.skipAuction);
|
||||
if (notPassed.length == 1) {
|
||||
const winningPlayer = notPassed[0];
|
||||
winningPlayer.powerPlants.push(powerPlants.find(p => p.number == G.chosenPowerPlant)!);
|
||||
winningPlayer.money -= winningPlayer.bid;
|
||||
winningPlayer.skipAuction = true;
|
||||
|
||||
if (winningPlayer.powerPlants.length > 4 || (G.players.length > 2 && winningPlayer.powerPlants.length > 3)) {
|
||||
G.currentPlayers = [winningPlayer.id];
|
||||
} else {
|
||||
if (G.players.some(p => !p.skipAuction)) {
|
||||
nextPlayerAuction(G);
|
||||
|
||||
G.chosenPowerPlant = G.currentBid = 0;
|
||||
G.players.forEach(p => { p.bid = 0; p.passed = false; });
|
||||
} else {
|
||||
G.phase = Phase.Resources;
|
||||
G.currentPlayers = [G.playerOrder[G.players.length - 1]];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
nextPlayerAuction(G);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case Phase.Resources: {
|
||||
break;
|
||||
}
|
||||
|
||||
case Phase.Building: {
|
||||
break;
|
||||
}
|
||||
|
||||
case Phase.Bureaucracy: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
G.log.push({
|
||||
type: 'move',
|
||||
player: playerNumber,
|
||||
move,
|
||||
simple: `${player.name} passes`,
|
||||
pretty: `${playerNameHTML(player)} passes`,
|
||||
});
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case MoveName.DiscardPowerPlant: {
|
||||
asserts<Moves.MoveDiscardPowerPlant>(move);
|
||||
|
||||
player.powerPlants = player.powerPlants.filter(p => p.number != move.data.powerPlant);
|
||||
|
||||
if (player.coalCapacity >= player.coalLeft &&
|
||||
player.oilCapacity >= player.oilLeft &&
|
||||
player.garbageCapacity >= player.garbageLeft &&
|
||||
player.uraniumCapacity >= player.uraniumLeft) {
|
||||
if (G.players.some(p => !p.skipAuction)) {
|
||||
nextPlayerAuction(G);
|
||||
|
||||
G.chosenPowerPlant = G.currentBid = 0;
|
||||
G.players.forEach(p => { p.bid = 0; p.passed = false; });
|
||||
} else {
|
||||
G.phase = Phase.Resources;
|
||||
G.currentPlayers = [G.playerOrder[G.players.length - 1]];
|
||||
}
|
||||
}
|
||||
|
||||
G.log.push({
|
||||
type: 'move',
|
||||
player: playerNumber,
|
||||
move,
|
||||
simple: `${player.name} discards power plant ${move.data.powerPlant}`,
|
||||
pretty: `${playerNameHTML(player)} discards power plant ${move.data.powerPlant}`,
|
||||
});
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case MoveName.DiscardResources: {
|
||||
asserts<Moves.MoveDiscardResources>(move);
|
||||
|
||||
let discardedCoal = 0;
|
||||
let discardedOil = 0;
|
||||
move.data.resourcesDiscarded.forEach(resource => {
|
||||
switch (resource) {
|
||||
case ResourceType.Coal:
|
||||
player.coalLeft--;
|
||||
G.coalSupply++;
|
||||
discardedCoal++;
|
||||
break;
|
||||
|
||||
case ResourceType.Oil:
|
||||
player.oilLeft--;
|
||||
G.oilSupply++;
|
||||
discardedOil++;
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
if (G.players.some(p => !p.skipAuction)) {
|
||||
nextPlayerAuction(G);
|
||||
|
||||
G.chosenPowerPlant = G.currentBid = 0;
|
||||
G.players.forEach(p => { p.bid = 0; p.passed = false; });
|
||||
} else {
|
||||
G.phase = Phase.Resources;
|
||||
G.currentPlayers = [G.playerOrder[G.players.length - 1]];
|
||||
}
|
||||
|
||||
let discardedStr = '';
|
||||
if (discardedOil == 0) {
|
||||
discardedStr = `${discardedCoal} coal`;
|
||||
} else {
|
||||
if (discardedCoal == 0) {
|
||||
discardedStr = `${discardedOil} oil`;
|
||||
} else {
|
||||
discardedStr = `${discardedCoal} coal and ${discardedOil} oil`;
|
||||
}
|
||||
}
|
||||
|
||||
G.log.push({
|
||||
type: 'move',
|
||||
player: playerNumber,
|
||||
move,
|
||||
simple: `${player.name} discards resources: ${discardedStr}`,
|
||||
pretty: `${playerNameHTML(player)} discards resources: ${discardedStr}`,
|
||||
});
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case MoveName.BuyResource: {
|
||||
asserts<Moves.MoveBuyResource>(move);
|
||||
switch (move.data.resource) {
|
||||
case ResourceType.Coal:
|
||||
player.coalLeft++;
|
||||
G.coalMarket--;
|
||||
break;
|
||||
|
||||
case ResourceType.Oil:
|
||||
player.oilLeft++;
|
||||
G.oilMarket--;
|
||||
break;
|
||||
|
||||
case ResourceType.Garbage:
|
||||
player.garbageLeft++;
|
||||
G.garbageMarket--;
|
||||
break;
|
||||
|
||||
case ResourceType.Uranium:
|
||||
player.uraniumLeft++;
|
||||
G.uraniumMarket--;
|
||||
break;
|
||||
}
|
||||
|
||||
player.money -= move.data.price;
|
||||
|
||||
G.log.push({
|
||||
type: 'move',
|
||||
player: playerNumber,
|
||||
move,
|
||||
simple: `${player.name} buys ${move.data.resource} for ${move.data.price}`,
|
||||
pretty: `${playerNameHTML(player)} buys ${move.data.resource} for ${move.data.price}`,
|
||||
});
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case MoveName.Build: {
|
||||
asserts<Moves.MoveBuild>(move);
|
||||
break;
|
||||
}
|
||||
|
||||
case MoveName.UsePowerPlant: {
|
||||
asserts<Moves.MoveUsePowerPlant>(move);
|
||||
break;
|
||||
}
|
||||
|
||||
case MoveName.Undo: {
|
||||
asserts<Moves.MoveUndo>(move);
|
||||
|
||||
const lastLog = G.log[G.log.length - 1];
|
||||
if (lastLog.type == 'move' && G.currentPlayers.includes(lastLog.player) && !fake) {
|
||||
G.log.pop();
|
||||
G = reconstructState(getBaseState(G), G.log);
|
||||
}
|
||||
|
||||
return G;
|
||||
}
|
||||
}
|
||||
|
||||
player.availableMoves = null;
|
||||
player.lastMove = move;
|
||||
|
||||
G.currentPlayers.forEach((p) => (G.players[p].availableMoves = availableMoves(G, G.players[p])));
|
||||
|
||||
return G;
|
||||
}
|
||||
|
||||
export function moveAI(G: GameState, playerNumber: number): GameState {
|
||||
return move(G, { name: MoveName.Pass, data: true }, playerNumber);
|
||||
}
|
||||
|
||||
export function ended(G: GameState): boolean {
|
||||
return G.phase == Phase.GameEnd;
|
||||
}
|
||||
|
||||
export function scores(G: GameState): number[] {
|
||||
return ended(G) ? G.players.map((p) => p.citiesPowered) : G.players.map((_) => 0);
|
||||
}
|
||||
|
||||
export function reconstructState(initialState: GameState, log: LogItem[]): GameState {
|
||||
const G = cloneDeep(initialState);
|
||||
|
||||
for (const item of log) {
|
||||
switch (item.type) {
|
||||
case 'event': {
|
||||
break;
|
||||
}
|
||||
|
||||
case 'phase': {
|
||||
break;
|
||||
}
|
||||
|
||||
case 'move': {
|
||||
move(G, item.move, item.player);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return G;
|
||||
}
|
||||
|
||||
export function nextPlayer(G: GameState) {
|
||||
const index = G.playerOrder.indexOf(G.currentPlayers[0]);
|
||||
G.currentPlayers = [G.playerOrder[(index + 1) % G.players.length]];
|
||||
|
||||
if (G.players[G.currentPlayers[0]].isDropped && G.players.some((p) => !p.isDropped)) nextPlayer(G);
|
||||
}
|
||||
|
||||
export function nextPlayerReverse(G: GameState) {
|
||||
const index = G.playerOrder.indexOf(G.currentPlayers[0]);
|
||||
G.currentPlayers = [G.playerOrder[(index - 1 + G.players.length) % G.players.length]];
|
||||
|
||||
if (G.players[G.currentPlayers[0]].isDropped && G.players.some((p) => !p.isDropped)) nextPlayerReverse(G);
|
||||
}
|
||||
|
||||
export function nextPlayerAuction(G: GameState) {
|
||||
const index = G.playerOrder.indexOf(G.currentPlayers[0]);
|
||||
G.currentPlayers = [G.playerOrder[(index + 1) % G.players.length]];
|
||||
|
||||
if (G.players[G.currentPlayers[0]].isDropped && G.players.some((p) => !p.isDropped)) {
|
||||
G.players[G.currentPlayers[0]].skipAuction = true;
|
||||
nextPlayerAuction(G);
|
||||
}
|
||||
|
||||
if (G.players[G.currentPlayers[0]].skipAuction && G.players.some((p) => !p.skipAuction)) {
|
||||
nextPlayerAuction(G);
|
||||
}
|
||||
}
|
||||
|
||||
function addPowerPlant(G: GameState) {
|
||||
const powerPlant = G.powerPlantsDeck.shift()!;
|
||||
const market = [...G.actualMarket, ...G.futureMarket, powerPlant.number];
|
||||
market.sort();
|
||||
if (G.step == 3) {
|
||||
G.actualMarket = market;
|
||||
} else {
|
||||
G.actualMarket = market.slice(0, 4);
|
||||
G.futureMarket = market.slice(4);
|
||||
}
|
||||
}
|
||||
|
||||
function getBaseState(G: GameState): GameState {
|
||||
const baseState = setup(G.players.length, G.options, G.seed);
|
||||
baseState.players.forEach((player, i) => {
|
||||
player.name = G.players[i].name;
|
||||
player.isAI = G.players[i].isAI;
|
||||
});
|
||||
|
||||
return baseState;
|
||||
}
|
||||
|
||||
function playerNameHTML(player) {
|
||||
return `<span style="background-color: ${playerColors[player.id]}; font-weight: bold; padding: 0 3px;">${player.name
|
||||
}</span>`;
|
||||
}
|
||||
140
engine/src/gamestate.ts
Normal file
140
engine/src/gamestate.ts
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
import { AvailableMoves } from './available-moves';
|
||||
import { LogItem } from './log';
|
||||
import { Move } from './move';
|
||||
|
||||
export interface GameOptions {
|
||||
fastBid?: boolean;
|
||||
}
|
||||
|
||||
export interface City {
|
||||
name: string;
|
||||
area: string;
|
||||
x: number;
|
||||
y: number;
|
||||
}
|
||||
|
||||
export interface Connection {
|
||||
from: string;
|
||||
to: string;
|
||||
cost: number;
|
||||
}
|
||||
|
||||
export interface Map {
|
||||
name: string;
|
||||
cities: City[];
|
||||
connections: Connection[];
|
||||
}
|
||||
|
||||
export enum ResourceType {
|
||||
Coal,
|
||||
Oil,
|
||||
Garbage,
|
||||
Uranium
|
||||
}
|
||||
|
||||
export enum PowerPlantType {
|
||||
Coal,
|
||||
Oil,
|
||||
Garbage,
|
||||
Uranium,
|
||||
Hybrid,
|
||||
Wind,
|
||||
Nuclear
|
||||
}
|
||||
|
||||
export interface PowerPlant {
|
||||
number: number;
|
||||
type: PowerPlantType;
|
||||
cost: number;
|
||||
citiesPowered: number;
|
||||
}
|
||||
|
||||
export interface CityPosition {
|
||||
name: string;
|
||||
position: number;
|
||||
}
|
||||
|
||||
export interface Player {
|
||||
id: number;
|
||||
name?: string;
|
||||
powerPlants: PowerPlant[];
|
||||
coalCapacity: number;
|
||||
coalLeft: number;
|
||||
oilCapacity: number;
|
||||
oilLeft: number;
|
||||
garbageCapacity: number;
|
||||
garbageLeft: number;
|
||||
uraniumCapacity: number;
|
||||
uraniumLeft: number;
|
||||
money: number;
|
||||
housesLeft: number;
|
||||
cities: CityPosition[];
|
||||
powerPlantsUsed: number[];
|
||||
availableMoves: AvailableMoves | null;
|
||||
lastMove: Move | null;
|
||||
isDropped: boolean;
|
||||
bid: number;
|
||||
isAI: boolean;
|
||||
passed: boolean;
|
||||
skipAuction: boolean;
|
||||
citiesPowered: number;
|
||||
}
|
||||
|
||||
export enum Phase {
|
||||
Order,
|
||||
Auction,
|
||||
Resources,
|
||||
Building,
|
||||
Bureaucracy,
|
||||
GameEnd
|
||||
}
|
||||
|
||||
// export interface HousePiece {
|
||||
// id: `H${number}`;
|
||||
// }
|
||||
|
||||
// export interface CoalPiece {
|
||||
// id: `C${number}`;
|
||||
// }
|
||||
|
||||
// export interface OilPiece {
|
||||
// id: `O${number}`;
|
||||
// }
|
||||
|
||||
// export interface GarbagePiece {
|
||||
// id: `G${number}`;
|
||||
// }
|
||||
|
||||
// export interface UraniumPiece {
|
||||
// id: `U${number}`;
|
||||
// }
|
||||
|
||||
export interface GameState {
|
||||
map: Map;
|
||||
players: Player[];
|
||||
playerOrder: number[];
|
||||
currentPlayers: number[];
|
||||
powerPlantsDeck: PowerPlant[];
|
||||
coalSupply: number;
|
||||
oilSupply: number;
|
||||
garbageSupply: number;
|
||||
uraniumSupply: number;
|
||||
coalMarket: number;
|
||||
oilMarket: number;
|
||||
garbageMarket: number;
|
||||
uraniumMarket: number;
|
||||
actualMarket: number[];
|
||||
futureMarket: number[];
|
||||
chosenPowerPlant: number;
|
||||
currentBid: number;
|
||||
auctioningPlayer: number | undefined;
|
||||
highestBidders: number[];
|
||||
step: number;
|
||||
phase: Phase;
|
||||
options: GameOptions;
|
||||
log: LogItem[];
|
||||
hiddenLog: LogItem[];
|
||||
seed: string;
|
||||
round: number;
|
||||
auctionSkips: number;
|
||||
}
|
||||
45
engine/src/log.ts
Normal file
45
engine/src/log.ts
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
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;
|
||||
};
|
||||
|
||||
export type LogEvent = {
|
||||
type: 'event';
|
||||
event: GameEvent;
|
||||
};
|
||||
|
||||
export type LogMove = {
|
||||
type: 'move';
|
||||
player: number;
|
||||
move: Move;
|
||||
simple: string;
|
||||
pretty: string;
|
||||
};
|
||||
|
||||
export type LogItem = LogPhase | LogEvent | LogMove;
|
||||
140
engine/src/map.ts
Normal file
140
engine/src/map.ts
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
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: 13409 },
|
||||
{ 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 },
|
||||
],
|
||||
connections: [
|
||||
{ from: 'Seattle', to: 'Portland', cost: 3 },
|
||||
{ from: 'Seattle', to: 'Boise', cost: 12 },
|
||||
{ from: 'Seattle', to: 'Billings', cost: 9 },
|
||||
{ from: 'Portland', to: 'Boise', cost: 13 },
|
||||
{ from: 'Portland', to: 'San Francisco', cost: 24 },
|
||||
{ from: 'Boise', to: 'Billings', cost: 12 },
|
||||
{ from: 'Boise', to: 'Cheyenne', cost: 24 },
|
||||
{ from: 'Boise', to: 'San Francisco', cost: 23 },
|
||||
{ from: 'Boise', to: 'Saltlake City', cost: 8 },
|
||||
{ from: 'Billings', to: 'Cheyenne', cost: 9 },
|
||||
{ from: 'Billings', to: 'Fargo', cost: 17 },
|
||||
{ from: 'Billings', to: 'Minneapolis', cost: 18 },
|
||||
{ from: 'Cheyenne', to: 'Denver', cost: 0 },
|
||||
{ from: 'Cheyenne', to: 'Omaha', cost: 14 },
|
||||
{ from: 'Cheyenne', to: 'Minneapolis', cost: 18 },
|
||||
{ from: 'Denver', to: 'Saltlake City', cost: 21 },
|
||||
{ from: 'Denver', to: 'Santa Fe', cost: 13 },
|
||||
{ from: 'Denver', to: 'Kansas City', cost: 16 },
|
||||
{ from: 'Omaha', to: 'Kansas City', cost: 5 },
|
||||
{ from: 'Omaha', to: 'Minneapolis', cost: 8 },
|
||||
{ from: 'Omaha', to: 'Chicago', cost: 13 },
|
||||
{ from: 'San Francisco', to: 'Los Angeles', cost: 9 },
|
||||
{ from: 'San Francisco', to: 'Las Vegas', cost: 14 },
|
||||
{ from: 'San Francisco', to: 'Saltlake City', cost: 27 },
|
||||
{ from: 'Los Angeles', to: 'San Diego', cost: 3 },
|
||||
{ from: 'Los Angeles', to: 'Las Vegas', cost: 9 },
|
||||
{ from: 'San Diego', to: 'Las Vegas', cost: 9 },
|
||||
{ from: 'San Diego', to: 'Phoenix', cost: 14 },
|
||||
{ from: 'Las Vegas', to: 'Saltlake City', cost: 18 },
|
||||
{ from: 'Las Vegas', to: 'Phoenix', cost: 15 },
|
||||
{ from: 'Las Vegas', to: 'Santa Fe', cost: 27 },
|
||||
{ from: 'Saltlake City', to: 'Santa Fe', cost: 28 },
|
||||
{ from: 'Phoenix', to: 'Santa Fe', cost: 18 },
|
||||
{ from: 'Santa Fe', to: 'Kansas City', cost: 16 },
|
||||
{ from: 'Santa Fe', to: 'Oklahoma City', cost: 15 },
|
||||
{ from: 'Santa Fe', to: 'Dallas', cost: 16 },
|
||||
{ from: 'Santa Fe', to: 'Houston', cost: 21 },
|
||||
{ from: 'Kansas City', to: 'Oklahoma City', cost: 8 },
|
||||
{ from: 'Kansas City', to: 'Menphis', cost: 12 },
|
||||
{ from: 'Kansas City', to: 'Chicago', cost: 8 },
|
||||
{ from: 'Kansas City', to: 'St. Louis', cost: 6 },
|
||||
{ from: 'Oklahoma City', to: 'Dallas', cost: 3 },
|
||||
{ from: 'Oklahoma City', to: 'Menphis', cost: 14 },
|
||||
{ from: 'Dallas', to: 'Houston', cost: 5 },
|
||||
{ from: 'Dallas', to: 'Menphis', cost: 12 },
|
||||
{ from: 'Dallas', to: 'New Orleans', cost: 12 },
|
||||
{ from: 'Houston', to: 'New Orleans', cost: 8 },
|
||||
{ from: 'Menphis', to: 'Birmingham', cost: 6 },
|
||||
{ from: 'Menphis', to: 'New Orleans', cost: 7 },
|
||||
{ from: 'Menphis', to: 'St. Louis', cost: 7 },
|
||||
{ from: 'Birmingham', to: 'New Orleans', cost: 11 },
|
||||
{ from: 'Birmingham', to: 'Atlanta', cost: 3 },
|
||||
{ from: 'Birmingham', to: 'Jacksonvile', cost: 9 },
|
||||
{ from: 'New Orleans', to: 'Jacksonvile', cost: 16 },
|
||||
{ from: 'Fargo', to: 'Duluth', cost: 6 },
|
||||
{ from: 'Fargo', to: 'Minneapolis', cost: 6 },
|
||||
{ from: 'Duluth', to: 'Minneapolis', cost: 5 },
|
||||
{ from: 'Duluth', to: 'Chicago', cost: 12 },
|
||||
{ from: 'Duluth', to: 'Detroit', cost: 15 },
|
||||
{ from: 'Minneapolis', to: 'Chicago', cost: 8 },
|
||||
{ from: 'Chicago', to: 'St. Louis', cost: 10 },
|
||||
{ from: 'Chicago', to: 'Cincinnati', cost: 7 },
|
||||
{ from: 'Chicago', to: 'Detroit', cost: 7 },
|
||||
{ from: 'St. Louis', to: 'Cincinnati', cost: 12 },
|
||||
{ from: 'St. Louis', to: 'Atlanta', cost: 12 },
|
||||
{ from: 'Cincinnati', to: 'Knoxvile', cost: 6 },
|
||||
{ from: 'Cincinnati', to: 'Detroit', cost: 4 },
|
||||
{ from: 'Cincinnati', to: 'Pittsburgh', cost: 7 },
|
||||
{ from: 'Cincinnati', to: 'Raleigh', cost: 15 },
|
||||
{ from: 'Knoxvile', to: 'Atlanta', cost: 5 },
|
||||
{ from: 'Detroit', to: 'Buffalo', cost: 7 },
|
||||
{ from: 'Detroit', to: 'Pittsburgh', cost: 6 },
|
||||
{ from: 'Buffalo', to: 'Pittsburgh', cost: 7 },
|
||||
{ from: 'Buffalo', to: 'New York', cost: 8 },
|
||||
{ from: 'Pittsburgh', to: 'Washington', cost: 6 },
|
||||
{ from: 'Pittsburgh', to: 'Raleigh', cost: 7 },
|
||||
{ from: 'Boston', to: 'New York', cost: 3 },
|
||||
{ from: 'New York', to: 'Philadelphia', cost: 0 },
|
||||
{ from: 'Philadelphia', to: 'Washington', cost: 3 },
|
||||
{ from: 'Washington', to: 'Horecin', cost: 5 },
|
||||
{ from: 'Horecin', to: 'Raleigh', cost: 3 },
|
||||
{ from: 'Raleigh', to: 'Atlanta', cost: 7 },
|
||||
{ from: 'Raleigh', to: 'Savannah', cost: 7 },
|
||||
{ from: 'Atlanta', to: 'Savannah', cost: 7 },
|
||||
{ from: 'Savannah', to: 'Jacksonvile', cost: 0 },
|
||||
{ from: 'Jacksonvile', to: 'Tampa', cost: 4 },
|
||||
{ from: 'Tampa', to: 'Miami', cost: 4 }
|
||||
]
|
||||
};
|
||||
|
||||
export default map;
|
||||
90
engine/src/move.ts
Normal file
90
engine/src/move.ts
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
import { ResourceType } from './gamestate';
|
||||
|
||||
export declare namespace Moves {
|
||||
export interface MoveChoosePowerPlant {
|
||||
name: MoveName.ChoosePowerPlant;
|
||||
data: {
|
||||
powerPlant: number;
|
||||
startingPrice: number;
|
||||
};
|
||||
}
|
||||
|
||||
export interface MoveBid {
|
||||
name: MoveName.Bid;
|
||||
data: {
|
||||
price: number;
|
||||
};
|
||||
}
|
||||
|
||||
export interface MoveDiscardPowerPlant {
|
||||
name: MoveName.DiscardPowerPlant;
|
||||
data: {
|
||||
powerPlant: number;
|
||||
};
|
||||
}
|
||||
|
||||
export interface MoveDiscardResources {
|
||||
name: MoveName.DiscardResources;
|
||||
data: {
|
||||
resourcesDiscarded: ResourceType[];
|
||||
};
|
||||
}
|
||||
|
||||
export interface MoveBuyResource {
|
||||
name: MoveName.BuyResource;
|
||||
data: {
|
||||
resource: ResourceType;
|
||||
price: number;
|
||||
};
|
||||
}
|
||||
|
||||
export interface MoveBuild {
|
||||
name: MoveName.Build;
|
||||
data: {
|
||||
city: string;
|
||||
price: number;
|
||||
};
|
||||
}
|
||||
|
||||
export interface MoveUsePowerPlant {
|
||||
name: MoveName.UsePowerPlant;
|
||||
data: {
|
||||
powerPlant: number;
|
||||
resourcesSpent: ResourceType[];
|
||||
citiesPowered: number;
|
||||
};
|
||||
}
|
||||
|
||||
export interface MovePass {
|
||||
name: MoveName.Pass;
|
||||
data: true;
|
||||
}
|
||||
|
||||
export interface MoveUndo {
|
||||
name: MoveName.Undo;
|
||||
data: true;
|
||||
}
|
||||
}
|
||||
|
||||
export type Move =
|
||||
| Moves.MoveChoosePowerPlant
|
||||
| Moves.MoveBid
|
||||
| Moves.MoveDiscardPowerPlant
|
||||
| Moves.MoveDiscardResources
|
||||
| Moves.MoveBuyResource
|
||||
| Moves.MoveBuild
|
||||
| Moves.MoveUsePowerPlant
|
||||
| Moves.MovePass
|
||||
| Moves.MoveUndo;
|
||||
|
||||
export enum MoveName {
|
||||
ChoosePowerPlant,
|
||||
Bid,
|
||||
DiscardPowerPlant,
|
||||
DiscardResources,
|
||||
BuyResource,
|
||||
Build,
|
||||
UsePowerPlant,
|
||||
Pass,
|
||||
Undo
|
||||
}
|
||||
48
engine/src/powerPlants.ts
Normal file
48
engine/src/powerPlants.ts
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
import { PowerPlant, PowerPlantType } from './gamestate';
|
||||
|
||||
const powerPlants: PowerPlant[] = [
|
||||
{ number: 3, type: PowerPlantType.Oil, cost: 2, citiesPowered: 1 },
|
||||
{ number: 4, type: PowerPlantType.Coal, cost: 2, citiesPowered: 1 },
|
||||
{ number: 5, type: PowerPlantType.Hybrid, cost: 2, citiesPowered: 1 },
|
||||
{ number: 6, type: PowerPlantType.Garbage, cost: 1, citiesPowered: 1 },
|
||||
{ number: 7, type: PowerPlantType.Oil, cost: 3, citiesPowered: 2 },
|
||||
{ number: 8, type: PowerPlantType.Coal, cost: 3, citiesPowered: 2 },
|
||||
{ number: 9, type: PowerPlantType.Oil, cost: 1, citiesPowered: 1 },
|
||||
{ number: 10, type: PowerPlantType.Coal, cost: 2, citiesPowered: 2 },
|
||||
{ number: 11, type: PowerPlantType.Uranium, cost: 1, citiesPowered: 2 },
|
||||
{ number: 12, type: PowerPlantType.Hybrid, cost: 2, citiesPowered: 2 },
|
||||
{ number: 13, type: PowerPlantType.Wind, cost: 0, citiesPowered: 1 },
|
||||
{ number: 14, type: PowerPlantType.Garbage, cost: 2, citiesPowered: 2 },
|
||||
{ number: 15, type: PowerPlantType.Coal, cost: 2, citiesPowered: 3 },
|
||||
{ number: 16, type: PowerPlantType.Oil, cost: 2, citiesPowered: 3 },
|
||||
{ number: 17, type: PowerPlantType.Uranium, cost: 1, citiesPowered: 2 },
|
||||
{ number: 18, type: PowerPlantType.Wind, cost: 0, citiesPowered: 2 },
|
||||
{ number: 19, type: PowerPlantType.Garbage, cost: 2, citiesPowered: 3 },
|
||||
{ number: 20, type: PowerPlantType.Coal, cost: 3, citiesPowered: 5 },
|
||||
{ number: 21, type: PowerPlantType.Garbage, cost: 2, citiesPowered: 4 },
|
||||
{ number: 22, type: PowerPlantType.Wind, cost: 0, citiesPowered: 2 },
|
||||
{ number: 23, type: PowerPlantType.Uranium, cost: 1, citiesPowered: 3 },
|
||||
{ number: 24, type: PowerPlantType.Garbage, cost: 2, citiesPowered: 4 },
|
||||
{ number: 25, type: PowerPlantType.Coal, cost: 2, citiesPowered: 5 },
|
||||
{ number: 26, type: PowerPlantType.Oil, cost: 2, citiesPowered: 5 },
|
||||
{ number: 27, type: PowerPlantType.Wind, cost: 0, citiesPowered: 3 },
|
||||
{ number: 28, type: PowerPlantType.Uranium, cost: 1, citiesPowered: 4 },
|
||||
{ number: 29, type: PowerPlantType.Hybrid, cost: 1, citiesPowered: 4 },
|
||||
{ number: 30, type: PowerPlantType.Garbage, cost: 3, citiesPowered: 6 },
|
||||
{ number: 31, type: PowerPlantType.Coal, cost: 3, citiesPowered: 6 },
|
||||
{ number: 32, type: PowerPlantType.Oil, cost: 3, citiesPowered: 6 },
|
||||
{ number: 33, type: PowerPlantType.Wind, cost: 0, citiesPowered: 4 },
|
||||
{ number: 34, type: PowerPlantType.Uranium, cost: 1, citiesPowered: 5 },
|
||||
{ number: 35, type: PowerPlantType.Oil, cost: 1, citiesPowered: 5 },
|
||||
{ number: 36, type: PowerPlantType.Coal, cost: 3, citiesPowered: 7 },
|
||||
{ number: 37, type: PowerPlantType.Wind, cost: 0, citiesPowered: 4 },
|
||||
{ number: 38, type: PowerPlantType.Garbage, cost: 3, citiesPowered: 7 },
|
||||
{ number: 39, type: PowerPlantType.Uranium, cost: 1, citiesPowered: 6 },
|
||||
{ number: 40, type: PowerPlantType.Oil, cost: 2, citiesPowered: 6 },
|
||||
{ number: 42, type: PowerPlantType.Coal, cost: 2, citiesPowered: 6 },
|
||||
{ number: 44, type: PowerPlantType.Wind, cost: 0, citiesPowered: 5 },
|
||||
{ number: 46, type: PowerPlantType.Hybrid, cost: 3, citiesPowered: 7 },
|
||||
{ number: 50, type: PowerPlantType.Nuclear, cost: 0, citiesPowered: 6 },
|
||||
];
|
||||
|
||||
export default powerPlants;
|
||||
10
engine/src/prices.ts
Normal file
10
engine/src/prices.ts
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import { ResourceType } from "./gamestate";
|
||||
|
||||
const prices = {
|
||||
[ResourceType.Coal]: [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8],
|
||||
[ResourceType.Oil]: [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8],
|
||||
[ResourceType.Garbage]: [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8],
|
||||
[ResourceType.Uranium]: [1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16],
|
||||
};
|
||||
|
||||
export default prices;
|
||||
13
engine/src/utils.spec.ts
Normal file
13
engine/src/utils.spec.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import { expect } from 'chai';
|
||||
import { shuffle } from './utils';
|
||||
|
||||
describe('utils', () => {
|
||||
describe('shuffle', () => {
|
||||
it('should shuffle the same way based on the seed', () => {
|
||||
expect(shuffle([1, 2, 3, 4], 'a')).to.have.ordered.members([4, 2, 3, 1]);
|
||||
expect(shuffle([1, 2, 3, 4], 'b')).to.have.ordered.members([3, 1, 2, 4]);
|
||||
expect(shuffle([1, 2, 3, 4], 'b')).to.have.ordered.members([3, 1, 2, 4]);
|
||||
expect(shuffle([1, 2, 3, 4], 'a')).to.have.ordered.members([4, 2, 3, 1]);
|
||||
});
|
||||
});
|
||||
});
|
||||
23
engine/src/utils.ts
Normal file
23
engine/src/utils.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import seedrandom from 'seedrandom';
|
||||
|
||||
/* eslint-disable */
|
||||
export function asserts<T>(move: any): asserts move is T {}
|
||||
|
||||
/* eslint-enable */
|
||||
|
||||
export function shuffle<T>(array: T[], seed: string) {
|
||||
const rng = seedrandom.alea(seed);
|
||||
const reverse = new Map<number, number>();
|
||||
|
||||
array.forEach((item, i) => {
|
||||
let n = rng.int32();
|
||||
|
||||
while (reverse.has(n)) {
|
||||
n = rng.int32();
|
||||
}
|
||||
|
||||
reverse.set(n, i);
|
||||
});
|
||||
|
||||
return [...reverse.keys()].sort().map((n) => array[reverse.get(n)!]);
|
||||
}
|
||||
16
engine/tsconfig.json
Normal file
16
engine/tsconfig.json
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
/* Basic Options */
|
||||
"target": "es2018",
|
||||
"module": "commonjs",
|
||||
"esModuleInterop": true,
|
||||
"strictNullChecks": true,
|
||||
"declaration": true /* Generates corresponding '.d.ts' file. */,
|
||||
"sourceMap": false /* Generates corresponding '.map' file. */,
|
||||
// "outFile": "./", /* Concatenate and emit output to single file. */
|
||||
"outDir": "./dist" /* Redirect output structure to the directory. */
|
||||
},
|
||||
"types": ["node"],
|
||||
"include": ["src/**/*.ts", "index.ts", "wrapper.ts"],
|
||||
"exclude": ["node_modules", "dist", "**/*.spec.ts"]
|
||||
}
|
||||
99
engine/wrapper.ts
Normal file
99
engine/wrapper.ts
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
import { cloneDeep } from 'lodash';
|
||||
import type { GameState } from './index';
|
||||
import * as engine from './src/engine';
|
||||
import type { LogMove } from './src/log';
|
||||
import { Move } from './src/move';
|
||||
import { asserts } from './src/utils';
|
||||
|
||||
export async function init(nbPlayers: number, expansions: string[], options: {}, seed?: string): Promise<GameState> {
|
||||
return engine.setup(nbPlayers, options, seed);
|
||||
}
|
||||
|
||||
export function setPlayerMetaData(G: GameState, player: number, metaData: { name: string }) {
|
||||
G.players[player].name = metaData.name;
|
||||
|
||||
return G;
|
||||
}
|
||||
|
||||
export async function move(G: GameState, move: Move, player: number) {
|
||||
G = engine.move(G, move, player);
|
||||
|
||||
return G;
|
||||
}
|
||||
|
||||
export { ended, scores, stripSecret } from './src/engine';
|
||||
|
||||
export function rankings(G: GameState) {
|
||||
const sortedPlayers = cloneDeep(G.players)
|
||||
.sort((p1, p2) => {
|
||||
if (p1.money == p2.money) {
|
||||
return p1.containersOnIsland.length - p2.containersOnIsland.length;
|
||||
} else {
|
||||
return p1.money - p2.money;
|
||||
}
|
||||
})
|
||||
.map((pl) => pl.id)
|
||||
.reverse();
|
||||
|
||||
return G.players.map((pl) => sortedPlayers.indexOf(pl.id) + 1);
|
||||
}
|
||||
|
||||
export function replay(G: GameState) {
|
||||
const oldPlayers = G.players;
|
||||
|
||||
const oldG = G;
|
||||
|
||||
G = engine.setup(G.players.length, G.options, G.seed);
|
||||
|
||||
for (let i = 0; i < oldPlayers.length && i < G.players.length; i++) {
|
||||
G.players[i].name = oldPlayers[i].name;
|
||||
}
|
||||
|
||||
for (const move of oldG.log.filter((event) => event.type === 'move')) {
|
||||
asserts<LogMove>(move);
|
||||
|
||||
G = engine.move(G, move.move, move.player);
|
||||
}
|
||||
|
||||
return G;
|
||||
}
|
||||
|
||||
export function round(G: GameState) {
|
||||
return G.round;
|
||||
}
|
||||
|
||||
export async function dropPlayer(G: GameState, player: number) {
|
||||
G.players[player].isDropped = true;
|
||||
|
||||
engine.nextPlayer(G);
|
||||
|
||||
return G;
|
||||
}
|
||||
|
||||
export function currentPlayer(G: GameState) {
|
||||
return G.currentPlayers;
|
||||
}
|
||||
|
||||
export function messages(G: GameState) {
|
||||
return {
|
||||
messages: [],
|
||||
data: G,
|
||||
};
|
||||
}
|
||||
|
||||
export function logLength(G: GameState, _player?: number) {
|
||||
return G.log.length;
|
||||
}
|
||||
|
||||
export function logSlice(G: GameState, options?: { player?: number; start?: number; end?: number }) {
|
||||
const stripped = engine.stripSecret(G, options?.player);
|
||||
return {
|
||||
log: stripped.log.slice(options?.start, options?.end),
|
||||
availableMoves:
|
||||
options?.end === undefined
|
||||
? stripped.players.map((pl) => pl.availableMoves)
|
||||
: engine
|
||||
.stripSecret(replay({ ...G, log: G.log.slice(0, options!.end) }), options!.player)
|
||||
.players.map((pl) => pl.availableMoves),
|
||||
};
|
||||
}
|
||||
19
package.json
Normal file
19
package.json
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"lint-staged": "lint-staged",
|
||||
"postinstall": "husky install",
|
||||
"prettier": "prettier --plugin-search-dir=. --write .",
|
||||
"prettier-check": "prettier --plugin-search-dir=. --check ."
|
||||
},
|
||||
"devDependencies": {
|
||||
"husky": "^5.0.9",
|
||||
"lint-staged": "^10.5.4",
|
||||
"prettier": "^2.2.1",
|
||||
"prettier-plugin-organize-imports": "^1.1.1",
|
||||
"typescript": "^4.1.5"
|
||||
},
|
||||
"lint-staged": {
|
||||
"*.{css,scss,graphql,html,json,js,jsx,md,mdx,ts,tsx,vue,yaml,yml}": "prettier --plugin-search-dir=. --write"
|
||||
}
|
||||
}
|
||||
951
pnpm-lock.yaml
generated
Normal file
951
pnpm-lock.yaml
generated
Normal file
|
|
@ -0,0 +1,951 @@
|
|||
lockfileVersion: 5.3
|
||||
|
||||
specifiers:
|
||||
husky: ^5.0.9
|
||||
lint-staged: ^10.5.4
|
||||
prettier: ^2.2.1
|
||||
prettier-plugin-organize-imports: ^1.1.1
|
||||
typescript: ^4.1.5
|
||||
|
||||
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
|
||||
typescript: 4.3.5
|
||||
|
||||
packages:
|
||||
/@babel/code-frame/7.14.5:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-9pzDqyc6OLDaqe+zbACgFkb6fKMNG6CObKpnYXChRsvYGyEdc7CA2BaqeOM+vOtCS5ndmJicPJhKAwYRI6UfFw==,
|
||||
}
|
||||
engines: { node: '>=6.9.0' }
|
||||
dependencies:
|
||||
'@babel/highlight': 7.14.5
|
||||
dev: true
|
||||
|
||||
/@babel/helper-validator-identifier/7.14.5:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-5lsetuxCLilmVGyiLEfoHBRX8UCFD+1m2x3Rj97WrW3V7H3u4RWRXA4evMjImCsin2J2YT0QaVDGf+z8ondbAg==,
|
||||
}
|
||||
engines: { node: '>=6.9.0' }
|
||||
dev: true
|
||||
|
||||
/@babel/highlight/7.14.5:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-qf9u2WFWVV0MppaL877j2dBtQIDgmidgjGk5VIMw3OadXvYaXn66U1BFlH2t4+t3i+8PhedppRv+i40ABzd+gg==,
|
||||
}
|
||||
engines: { node: '>=6.9.0' }
|
||||
dependencies:
|
||||
'@babel/helper-validator-identifier': 7.14.5
|
||||
chalk: 2.4.2
|
||||
js-tokens: 4.0.0
|
||||
dev: true
|
||||
|
||||
/@types/parse-json/4.0.0:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-//oorEZjL6sbPcKUaCdIGlIUeH26mgzimjBB77G6XRgnDl/L5wOnpyBGRe/Mmf5CVW3PwEBE1NjiMZ/ssFh4wA==,
|
||||
}
|
||||
dev: true
|
||||
|
||||
/aggregate-error/3.1.0:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-4I7Td01quW/RpocfNayFdFVk1qSuoh0E7JrbRJ16nH01HhKFQ88INq9Sd+nd72zqRySlr9BmDA8xlEJ6vJMrYA==,
|
||||
}
|
||||
engines: { node: '>=8' }
|
||||
dependencies:
|
||||
clean-stack: 2.2.0
|
||||
indent-string: 4.0.0
|
||||
dev: true
|
||||
|
||||
/ansi-colors/4.1.1:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA==,
|
||||
}
|
||||
engines: { node: '>=6' }
|
||||
dev: true
|
||||
|
||||
/ansi-escapes/4.3.2:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-gKXj5ALrKWQLsYG9jlTRmR/xKluxHV+Z9QEwNIgCfM1/uwPMCuzVVnh5mwTd+OuBZcwSIMbqssNWRm1lE51QaQ==,
|
||||
}
|
||||
engines: { node: '>=8' }
|
||||
dependencies:
|
||||
type-fest: 0.21.3
|
||||
dev: true
|
||||
|
||||
/ansi-regex/5.0.0:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==,
|
||||
}
|
||||
engines: { node: '>=8' }
|
||||
dev: true
|
||||
|
||||
/ansi-styles/3.2.1:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==,
|
||||
}
|
||||
engines: { node: '>=4' }
|
||||
dependencies:
|
||||
color-convert: 1.9.3
|
||||
dev: true
|
||||
|
||||
/ansi-styles/4.3.0:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==,
|
||||
}
|
||||
engines: { node: '>=8' }
|
||||
dependencies:
|
||||
color-convert: 2.0.1
|
||||
dev: true
|
||||
|
||||
/astral-regex/2.0.0:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-Z7tMw1ytTXt5jqMcOP+OQteU1VuNK9Y02uuJtKQ1Sv69jXQKKg5cibLwGJow8yzZP+eAc18EmLGPal0bp36rvQ==,
|
||||
}
|
||||
engines: { node: '>=8' }
|
||||
dev: true
|
||||
|
||||
/braces/3.0.2:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==,
|
||||
}
|
||||
engines: { node: '>=8' }
|
||||
dependencies:
|
||||
fill-range: 7.0.1
|
||||
dev: true
|
||||
|
||||
/callsites/3.1.0:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==,
|
||||
}
|
||||
engines: { node: '>=6' }
|
||||
dev: true
|
||||
|
||||
/chalk/2.4.2:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==,
|
||||
}
|
||||
engines: { node: '>=4' }
|
||||
dependencies:
|
||||
ansi-styles: 3.2.1
|
||||
escape-string-regexp: 1.0.5
|
||||
supports-color: 5.5.0
|
||||
dev: true
|
||||
|
||||
/chalk/4.1.1:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-diHzdDKxcU+bAsUboHLPEDQiw0qEe0qd7SYUn3HgcFlWgbDcfLGswOHYeGrHKzG9z6UYf01d9VFMfZxPM1xZSg==,
|
||||
}
|
||||
engines: { node: '>=10' }
|
||||
dependencies:
|
||||
ansi-styles: 4.3.0
|
||||
supports-color: 7.2.0
|
||||
dev: true
|
||||
|
||||
/clean-stack/2.2.0:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-4diC9HaTE+KRAMWhDhrGOECgWZxoevMc5TlkObMqNSsVU62PYzXZ/SMTjzyGAFF1YusgxGcSWTEXBhp0CPwQ1A==,
|
||||
}
|
||||
engines: { node: '>=6' }
|
||||
dev: true
|
||||
|
||||
/cli-cursor/3.1.0:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-I/zHAwsKf9FqGoXM4WWRACob9+SNukZTd94DWF57E4toouRulbCxcUh6RKUEOQlYTHJnzkPMySvPNaaSLNfLZw==,
|
||||
}
|
||||
engines: { node: '>=8' }
|
||||
dependencies:
|
||||
restore-cursor: 3.1.0
|
||||
dev: true
|
||||
|
||||
/cli-truncate/2.1.0:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-n8fOixwDD6b/ObinzTrp1ZKFzbgvKZvuz/TvejnLn1aQfC6r52XEx85FmuC+3HI+JM7coBRXUvNqEU2PHVrHpg==,
|
||||
}
|
||||
engines: { node: '>=8' }
|
||||
dependencies:
|
||||
slice-ansi: 3.0.0
|
||||
string-width: 4.2.2
|
||||
dev: true
|
||||
|
||||
/color-convert/1.9.3:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==,
|
||||
}
|
||||
dependencies:
|
||||
color-name: 1.1.3
|
||||
dev: true
|
||||
|
||||
/color-convert/2.0.1:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==,
|
||||
}
|
||||
engines: { node: '>=7.0.0' }
|
||||
dependencies:
|
||||
color-name: 1.1.4
|
||||
dev: true
|
||||
|
||||
/color-name/1.1.3:
|
||||
resolution: { integrity: sha1-p9BVi9icQveV3UIyj3QIMcpTvCU= }
|
||||
dev: true
|
||||
|
||||
/color-name/1.1.4:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==,
|
||||
}
|
||||
dev: true
|
||||
|
||||
/colorette/1.2.2:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-MKGMzyfeuutC/ZJ1cba9NqcNpfeqMUcYmyF1ZFY6/Cn7CNSAKx6a+s48sqLqyAiZuaP2TcqMhoo+dlwFnVxT9w==,
|
||||
}
|
||||
dev: true
|
||||
|
||||
/commander/6.2.1:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-U7VdrJFnJgo4xjrHpTzu0yrHPGImdsmD95ZlgYSEajAn2JKzDhDTPG9kBTefmObL2w/ngeZnilk+OV9CG3d7UA==,
|
||||
}
|
||||
engines: { node: '>= 6' }
|
||||
dev: true
|
||||
|
||||
/cosmiconfig/7.0.0:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-pondGvTuVYDk++upghXJabWzL6Kxu6f26ljFw64Swq9v6sQPUL3EUlVDV56diOjpCayKihL6hVe8exIACU4XcA==,
|
||||
}
|
||||
engines: { node: '>=10' }
|
||||
dependencies:
|
||||
'@types/parse-json': 4.0.0
|
||||
import-fresh: 3.3.0
|
||||
parse-json: 5.2.0
|
||||
path-type: 4.0.0
|
||||
yaml: 1.10.2
|
||||
dev: true
|
||||
|
||||
/cross-spawn/7.0.3:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==,
|
||||
}
|
||||
engines: { node: '>= 8' }
|
||||
dependencies:
|
||||
path-key: 3.1.1
|
||||
shebang-command: 2.0.0
|
||||
which: 2.0.2
|
||||
dev: true
|
||||
|
||||
/debug/4.3.1:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==,
|
||||
}
|
||||
engines: { node: '>=6.0' }
|
||||
peerDependencies:
|
||||
supports-color: '*'
|
||||
peerDependenciesMeta:
|
||||
supports-color:
|
||||
optional: true
|
||||
dependencies:
|
||||
ms: 2.1.2
|
||||
dev: true
|
||||
|
||||
/dedent/0.7.0:
|
||||
resolution: { integrity: sha1-JJXduvbrh0q7Dhvp3yLS5aVEMmw= }
|
||||
dev: true
|
||||
|
||||
/emoji-regex/8.0.0:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==,
|
||||
}
|
||||
dev: true
|
||||
|
||||
/end-of-stream/1.4.4:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==,
|
||||
}
|
||||
dependencies:
|
||||
once: 1.4.0
|
||||
dev: true
|
||||
|
||||
/enquirer/2.3.6:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-yjNnPr315/FjS4zIsUxYguYUPP2e1NK4d7E7ZOLiyYCcbFBiTMyID+2wvm2w6+pZ/odMA7cRkjhsPbltwBOrLg==,
|
||||
}
|
||||
engines: { node: '>=8.6' }
|
||||
dependencies:
|
||||
ansi-colors: 4.1.1
|
||||
dev: true
|
||||
|
||||
/error-ex/1.3.2:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-7dFHNmqeFSEt2ZBsCriorKnn3Z2pj+fd9kmI6QoWw4//DL+icEBfc0U7qJCisqrTsKTjw4fNFy2pW9OqStD84g==,
|
||||
}
|
||||
dependencies:
|
||||
is-arrayish: 0.2.1
|
||||
dev: true
|
||||
|
||||
/escape-string-regexp/1.0.5:
|
||||
resolution: { integrity: sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ= }
|
||||
engines: { node: '>=0.8.0' }
|
||||
dev: true
|
||||
|
||||
/execa/4.1.0:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-j5W0//W7f8UxAn8hXVnwG8tLwdiUy4FJLcSupCg6maBYZDpyBvTApK7KyuI4bKj8KOh1r2YH+6ucuYtJv1bTZA==,
|
||||
}
|
||||
engines: { node: '>=10' }
|
||||
dependencies:
|
||||
cross-spawn: 7.0.3
|
||||
get-stream: 5.2.0
|
||||
human-signals: 1.1.1
|
||||
is-stream: 2.0.0
|
||||
merge-stream: 2.0.0
|
||||
npm-run-path: 4.0.1
|
||||
onetime: 5.1.2
|
||||
signal-exit: 3.0.3
|
||||
strip-final-newline: 2.0.0
|
||||
dev: true
|
||||
|
||||
/fill-range/7.0.1:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==,
|
||||
}
|
||||
engines: { node: '>=8' }
|
||||
dependencies:
|
||||
to-regex-range: 5.0.1
|
||||
dev: true
|
||||
|
||||
/get-own-enumerable-property-symbols/3.0.2:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-I0UBV/XOz1XkIJHEUDMZAbzCThU/H8DxmSfmdGcKPnVhu2VfFqr34jr9777IyaTYvxjedWhqVIilEDsCdP5G6g==,
|
||||
}
|
||||
dev: true
|
||||
|
||||
/get-stream/5.2.0:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-nBF+F1rAZVCu/p7rjzgA+Yb4lfYXrpl7a6VmJrU8wF9I1CKvP/QwPNZHnOlwbTkY6dvtFIzFMSyQXbLoTQPRpA==,
|
||||
}
|
||||
engines: { node: '>=8' }
|
||||
dependencies:
|
||||
pump: 3.0.0
|
||||
dev: true
|
||||
|
||||
/has-flag/3.0.0:
|
||||
resolution: { integrity: sha1-tdRU3CGZriJWmfNGfloH87lVuv0= }
|
||||
engines: { node: '>=4' }
|
||||
dev: true
|
||||
|
||||
/has-flag/4.0.0:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==,
|
||||
}
|
||||
engines: { node: '>=8' }
|
||||
dev: true
|
||||
|
||||
/human-signals/1.1.1:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-SEQu7vl8KjNL2eoGBLF3+wAjpsNfA9XMlXAYj/3EdaNfAlxKthD1xjEQfGOUhllCGGJVNY34bRr6lPINhNjyZw==,
|
||||
}
|
||||
engines: { node: '>=8.12.0' }
|
||||
dev: true
|
||||
|
||||
/husky/5.2.0:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-AM8T/auHXRBxlrfPVLKP6jt49GCM2Zz47m8G3FOMsLmTv8Dj/fKVWE0Rh2d4Qrvmy131xEsdQnb3OXRib67PGg==,
|
||||
}
|
||||
engines: { node: '>= 10' }
|
||||
hasBin: true
|
||||
dev: true
|
||||
|
||||
/import-fresh/3.3.0:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-veYYhQa+D1QBKznvhUHxb8faxlrwUnxseDAbAp457E0wLNio2bOSKnjYDhMj+YiAq61xrMGhQk9iXVk5FzgQMw==,
|
||||
}
|
||||
engines: { node: '>=6' }
|
||||
dependencies:
|
||||
parent-module: 1.0.1
|
||||
resolve-from: 4.0.0
|
||||
dev: true
|
||||
|
||||
/indent-string/4.0.0:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-EdDDZu4A2OyIK7Lr/2zG+w5jmbuk1DVBnEwREQvBzspBJkCEbRa8GxU1lghYcaGJCnRWibjDXlq779X1/y5xwg==,
|
||||
}
|
||||
engines: { node: '>=8' }
|
||||
dev: true
|
||||
|
||||
/is-arrayish/0.2.1:
|
||||
resolution: { integrity: sha1-d8mYQFJ6qOyxqLppe4BkWnqSap0= }
|
||||
dev: true
|
||||
|
||||
/is-fullwidth-code-point/3.0.0:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==,
|
||||
}
|
||||
engines: { node: '>=8' }
|
||||
dev: true
|
||||
|
||||
/is-number/7.0.0:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==,
|
||||
}
|
||||
engines: { node: '>=0.12.0' }
|
||||
dev: true
|
||||
|
||||
/is-obj/1.0.1:
|
||||
resolution: { integrity: sha1-PkcprB9f3gJc19g6iW2rn09n2w8= }
|
||||
engines: { node: '>=0.10.0' }
|
||||
dev: true
|
||||
|
||||
/is-regexp/1.0.0:
|
||||
resolution: { integrity: sha1-/S2INUXEa6xaYz57mgnof6LLUGk= }
|
||||
engines: { node: '>=0.10.0' }
|
||||
dev: true
|
||||
|
||||
/is-stream/2.0.0:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-XCoy+WlUr7d1+Z8GgSuXmpuUFC9fOhRXglJMx+dwLKTkL44Cjd4W1Z5P+BQZpr+cR93aGP4S/s7Ftw6Nd/kiEw==,
|
||||
}
|
||||
engines: { node: '>=8' }
|
||||
dev: true
|
||||
|
||||
/is-unicode-supported/0.1.0:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw==,
|
||||
}
|
||||
engines: { node: '>=10' }
|
||||
dev: true
|
||||
|
||||
/isexe/2.0.0:
|
||||
resolution: { integrity: sha1-6PvzdNxVb/iUehDcsFctYz8s+hA= }
|
||||
dev: true
|
||||
|
||||
/js-tokens/4.0.0:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==,
|
||||
}
|
||||
dev: true
|
||||
|
||||
/json-parse-even-better-errors/2.3.1:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w==,
|
||||
}
|
||||
dev: true
|
||||
|
||||
/lines-and-columns/1.1.6:
|
||||
resolution: { integrity: sha1-HADHQ7QzzQpOgHWPe2SldEDZ/wA= }
|
||||
dev: true
|
||||
|
||||
/lint-staged/10.5.4:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-EechC3DdFic/TdOPgj/RB3FicqE6932LTHCUm0Y2fsD9KGlLB+RwJl2q1IYBIvEsKzDOgn0D4gll+YxG5RsrKg==,
|
||||
}
|
||||
hasBin: true
|
||||
dependencies:
|
||||
chalk: 4.1.1
|
||||
cli-truncate: 2.1.0
|
||||
commander: 6.2.1
|
||||
cosmiconfig: 7.0.0
|
||||
debug: 4.3.1
|
||||
dedent: 0.7.0
|
||||
enquirer: 2.3.6
|
||||
execa: 4.1.0
|
||||
listr2: 3.10.0_enquirer@2.3.6
|
||||
log-symbols: 4.1.0
|
||||
micromatch: 4.0.4
|
||||
normalize-path: 3.0.0
|
||||
please-upgrade-node: 3.2.0
|
||||
string-argv: 0.3.1
|
||||
stringify-object: 3.3.0
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
dev: true
|
||||
|
||||
/listr2/3.10.0_enquirer@2.3.6:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-eP40ZHihu70sSmqFNbNy2NL1YwImmlMmPh9WO5sLmPDleurMHt3n+SwEWNu2kzKScexZnkyFtc1VI0z/TGlmpw==,
|
||||
}
|
||||
engines: { node: '>=10.0.0' }
|
||||
peerDependencies:
|
||||
enquirer: '>= 2.3.0 < 3'
|
||||
dependencies:
|
||||
cli-truncate: 2.1.0
|
||||
colorette: 1.2.2
|
||||
enquirer: 2.3.6
|
||||
log-update: 4.0.0
|
||||
p-map: 4.0.0
|
||||
rxjs: 6.6.7
|
||||
through: 2.3.8
|
||||
wrap-ansi: 7.0.0
|
||||
dev: true
|
||||
|
||||
/log-symbols/4.1.0:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-8XPvpAA8uyhfteu8pIvQxpJZ7SYYdpUivZpGy6sFsBuKRY/7rQGavedeB8aK+Zkyq6upMFVL/9AW6vOYzfRyLg==,
|
||||
}
|
||||
engines: { node: '>=10' }
|
||||
dependencies:
|
||||
chalk: 4.1.1
|
||||
is-unicode-supported: 0.1.0
|
||||
dev: true
|
||||
|
||||
/log-update/4.0.0:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-9fkkDevMefjg0mmzWFBW8YkFP91OrizzkW3diF7CpG+S2EYdy4+TVfGwz1zeF8x7hCx1ovSPTOE9Ngib74qqUg==,
|
||||
}
|
||||
engines: { node: '>=10' }
|
||||
dependencies:
|
||||
ansi-escapes: 4.3.2
|
||||
cli-cursor: 3.1.0
|
||||
slice-ansi: 4.0.0
|
||||
wrap-ansi: 6.2.0
|
||||
dev: true
|
||||
|
||||
/merge-stream/2.0.0:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==,
|
||||
}
|
||||
dev: true
|
||||
|
||||
/micromatch/4.0.4:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-pRmzw/XUcwXGpD9aI9q/0XOwLNygjETJ8y0ao0wdqprrzDa4YnxLcz7fQRZr8voh8V10kGhABbNcHVk5wHgWwg==,
|
||||
}
|
||||
engines: { node: '>=8.6' }
|
||||
dependencies:
|
||||
braces: 3.0.2
|
||||
picomatch: 2.3.0
|
||||
dev: true
|
||||
|
||||
/mimic-fn/2.1.0:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==,
|
||||
}
|
||||
engines: { node: '>=6' }
|
||||
dev: true
|
||||
|
||||
/ms/2.1.2:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==,
|
||||
}
|
||||
dev: true
|
||||
|
||||
/normalize-path/3.0.0:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==,
|
||||
}
|
||||
engines: { node: '>=0.10.0' }
|
||||
dev: true
|
||||
|
||||
/npm-run-path/4.0.1:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==,
|
||||
}
|
||||
engines: { node: '>=8' }
|
||||
dependencies:
|
||||
path-key: 3.1.1
|
||||
dev: true
|
||||
|
||||
/once/1.4.0:
|
||||
resolution: { integrity: sha1-WDsap3WWHUsROsF9nFC6753Xa9E= }
|
||||
dependencies:
|
||||
wrappy: 1.0.2
|
||||
dev: true
|
||||
|
||||
/onetime/5.1.2:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg==,
|
||||
}
|
||||
engines: { node: '>=6' }
|
||||
dependencies:
|
||||
mimic-fn: 2.1.0
|
||||
dev: true
|
||||
|
||||
/p-map/4.0.0:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-/bjOqmgETBYB5BoEeGVea8dmvHb2m9GLy1E9W43yeyfP6QQCZGFNa+XRceJEuDB6zqr+gKpIAmlLebMpykw/MQ==,
|
||||
}
|
||||
engines: { node: '>=10' }
|
||||
dependencies:
|
||||
aggregate-error: 3.1.0
|
||||
dev: true
|
||||
|
||||
/parent-module/1.0.1:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==,
|
||||
}
|
||||
engines: { node: '>=6' }
|
||||
dependencies:
|
||||
callsites: 3.1.0
|
||||
dev: true
|
||||
|
||||
/parse-json/5.2.0:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-ayCKvm/phCGxOkYRSCM82iDwct8/EonSEgCSxWxD7ve6jHggsFl4fZVQBPRNgQoKiuV/odhFrGzQXZwbifC8Rg==,
|
||||
}
|
||||
engines: { node: '>=8' }
|
||||
dependencies:
|
||||
'@babel/code-frame': 7.14.5
|
||||
error-ex: 1.3.2
|
||||
json-parse-even-better-errors: 2.3.1
|
||||
lines-and-columns: 1.1.6
|
||||
dev: true
|
||||
|
||||
/path-key/3.1.1:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==,
|
||||
}
|
||||
engines: { node: '>=8' }
|
||||
dev: true
|
||||
|
||||
/path-type/4.0.0:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==,
|
||||
}
|
||||
engines: { node: '>=8' }
|
||||
dev: true
|
||||
|
||||
/picomatch/2.3.0:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-lY1Q/PiJGC2zOv/z391WOTD+Z02bCgsFfvxoXXf6h7kv9o+WmsmzYqrAwY63sNgOxE4xEdq0WyUnXfKeBrSvYw==,
|
||||
}
|
||||
engines: { node: '>=8.6' }
|
||||
dev: true
|
||||
|
||||
/please-upgrade-node/3.2.0:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-gQR3WpIgNIKwBMVLkpMUeR3e1/E1y42bqDQZfql+kDeXd8COYfM8PQA4X6y7a8u9Ua9FHmsrrmirW2vHs45hWg==,
|
||||
}
|
||||
dependencies:
|
||||
semver-compare: 1.0.0
|
||||
dev: true
|
||||
|
||||
/prettier-plugin-organize-imports/1.1.1_prettier@2.3.2+typescript@4.3.5:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-rFA1lnek1FYkMGthm4xBKME41qUKItTovuo24bCGZu/Vu1n3gW71UPLAkIdwewwkZCe29gRVweSOPXvAdckFuw==,
|
||||
}
|
||||
peerDependencies:
|
||||
prettier: '>=1.10'
|
||||
typescript: '>=2.8.2'
|
||||
dependencies:
|
||||
prettier: 2.3.2
|
||||
typescript: 4.3.5
|
||||
dev: true
|
||||
|
||||
/prettier/2.3.2:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-lnJzDfJ66zkMy58OL5/NY5zp70S7Nz6KqcKkXYzn2tMVrNxvbqaBpg7H3qHaLxCJ5lNMsGuM8+ohS7cZrthdLQ==,
|
||||
}
|
||||
engines: { node: '>=10.13.0' }
|
||||
hasBin: true
|
||||
dev: true
|
||||
|
||||
/pump/3.0.0:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==,
|
||||
}
|
||||
dependencies:
|
||||
end-of-stream: 1.4.4
|
||||
once: 1.4.0
|
||||
dev: true
|
||||
|
||||
/resolve-from/4.0.0:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==,
|
||||
}
|
||||
engines: { node: '>=4' }
|
||||
dev: true
|
||||
|
||||
/restore-cursor/3.1.0:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-l+sSefzHpj5qimhFSE5a8nufZYAM3sBSVMAPtYkmC+4EH2anSGaEMXSD0izRQbu9nfyQ9y5JrVmp7E8oZrUjvA==,
|
||||
}
|
||||
engines: { node: '>=8' }
|
||||
dependencies:
|
||||
onetime: 5.1.2
|
||||
signal-exit: 3.0.3
|
||||
dev: true
|
||||
|
||||
/rxjs/6.6.7:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-hTdwr+7yYNIT5n4AMYp85KA6yw2Va0FLa3Rguvbpa4W3I5xynaBZo41cM3XM+4Q6fRMj3sBYIR1VAmZMXYJvRQ==,
|
||||
}
|
||||
engines: { npm: '>=2.0.0' }
|
||||
dependencies:
|
||||
tslib: 1.14.1
|
||||
dev: true
|
||||
|
||||
/semver-compare/1.0.0:
|
||||
resolution: { integrity: sha1-De4hahyUGrN+nvsXiPavxf9VN/w= }
|
||||
dev: true
|
||||
|
||||
/shebang-command/2.0.0:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==,
|
||||
}
|
||||
engines: { node: '>=8' }
|
||||
dependencies:
|
||||
shebang-regex: 3.0.0
|
||||
dev: true
|
||||
|
||||
/shebang-regex/3.0.0:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==,
|
||||
}
|
||||
engines: { node: '>=8' }
|
||||
dev: true
|
||||
|
||||
/signal-exit/3.0.3:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA==,
|
||||
}
|
||||
dev: true
|
||||
|
||||
/slice-ansi/3.0.0:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-pSyv7bSTC7ig9Dcgbw9AuRNUb5k5V6oDudjZoMBSr13qpLBG7tB+zgCkARjq7xIUgdz5P1Qe8u+rSGdouOOIyQ==,
|
||||
}
|
||||
engines: { node: '>=8' }
|
||||
dependencies:
|
||||
ansi-styles: 4.3.0
|
||||
astral-regex: 2.0.0
|
||||
is-fullwidth-code-point: 3.0.0
|
||||
dev: true
|
||||
|
||||
/slice-ansi/4.0.0:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-qMCMfhY040cVHT43K9BFygqYbUPFZKHOg7K73mtTWJRb8pyP3fzf4Ixd5SzdEJQ6MRUg/WBnOLxghZtKKurENQ==,
|
||||
}
|
||||
engines: { node: '>=10' }
|
||||
dependencies:
|
||||
ansi-styles: 4.3.0
|
||||
astral-regex: 2.0.0
|
||||
is-fullwidth-code-point: 3.0.0
|
||||
dev: true
|
||||
|
||||
/string-argv/0.3.1:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-a1uQGz7IyVy9YwhqjZIZu1c8JO8dNIe20xBmSS6qu9kv++k3JGzCVmprbNN5Kn+BgzD5E7YYwg1CcjuJMRNsvg==,
|
||||
}
|
||||
engines: { node: '>=0.6.19' }
|
||||
dev: true
|
||||
|
||||
/string-width/4.2.2:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-XBJbT3N4JhVumXE0eoLU9DCjcaF92KLNqTmFCnG1pf8duUxFGwtP6AD6nkjw9a3IdiRtL3E2w3JDiE/xi3vOeA==,
|
||||
}
|
||||
engines: { node: '>=8' }
|
||||
dependencies:
|
||||
emoji-regex: 8.0.0
|
||||
is-fullwidth-code-point: 3.0.0
|
||||
strip-ansi: 6.0.0
|
||||
dev: true
|
||||
|
||||
/stringify-object/3.3.0:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-rHqiFh1elqCQ9WPLIC8I0Q/g/wj5J1eMkyoiD6eoQApWHP0FtlK7rqnhmabL5VUY9JQCcqwwvlOaSuutekgyrw==,
|
||||
}
|
||||
engines: { node: '>=4' }
|
||||
dependencies:
|
||||
get-own-enumerable-property-symbols: 3.0.2
|
||||
is-obj: 1.0.1
|
||||
is-regexp: 1.0.0
|
||||
dev: true
|
||||
|
||||
/strip-ansi/6.0.0:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w==,
|
||||
}
|
||||
engines: { node: '>=8' }
|
||||
dependencies:
|
||||
ansi-regex: 5.0.0
|
||||
dev: true
|
||||
|
||||
/strip-final-newline/2.0.0:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==,
|
||||
}
|
||||
engines: { node: '>=6' }
|
||||
dev: true
|
||||
|
||||
/supports-color/5.5.0:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==,
|
||||
}
|
||||
engines: { node: '>=4' }
|
||||
dependencies:
|
||||
has-flag: 3.0.0
|
||||
dev: true
|
||||
|
||||
/supports-color/7.2.0:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==,
|
||||
}
|
||||
engines: { node: '>=8' }
|
||||
dependencies:
|
||||
has-flag: 4.0.0
|
||||
dev: true
|
||||
|
||||
/through/2.3.8:
|
||||
resolution: { integrity: sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU= }
|
||||
dev: true
|
||||
|
||||
/to-regex-range/5.0.1:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==,
|
||||
}
|
||||
engines: { node: '>=8.0' }
|
||||
dependencies:
|
||||
is-number: 7.0.0
|
||||
dev: true
|
||||
|
||||
/tslib/1.14.1:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==,
|
||||
}
|
||||
dev: true
|
||||
|
||||
/type-fest/0.21.3:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w==,
|
||||
}
|
||||
engines: { node: '>=10' }
|
||||
dev: true
|
||||
|
||||
/typescript/4.3.5:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-DqQgihaQ9cUrskJo9kIyW/+g0Vxsk8cDtZ52a3NGh0YNTfpUSArXSohyUGnvbPazEPLu398C0UxmKSOrPumUzA==,
|
||||
}
|
||||
engines: { node: '>=4.2.0' }
|
||||
hasBin: true
|
||||
dev: true
|
||||
|
||||
/which/2.0.2:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==,
|
||||
}
|
||||
engines: { node: '>= 8' }
|
||||
hasBin: true
|
||||
dependencies:
|
||||
isexe: 2.0.0
|
||||
dev: true
|
||||
|
||||
/wrap-ansi/6.2.0:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==,
|
||||
}
|
||||
engines: { node: '>=8' }
|
||||
dependencies:
|
||||
ansi-styles: 4.3.0
|
||||
string-width: 4.2.2
|
||||
strip-ansi: 6.0.0
|
||||
dev: true
|
||||
|
||||
/wrap-ansi/7.0.0:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==,
|
||||
}
|
||||
engines: { node: '>=10' }
|
||||
dependencies:
|
||||
ansi-styles: 4.3.0
|
||||
string-width: 4.2.2
|
||||
strip-ansi: 6.0.0
|
||||
dev: true
|
||||
|
||||
/wrappy/1.0.2:
|
||||
resolution: { integrity: sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8= }
|
||||
dev: true
|
||||
|
||||
/yaml/1.10.2:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-r3vXyErRCYJ7wg28yvBY5VSoAF8ZvlcW9/BwUzEtUsjvX/DKs24dIkuwjtuprwJJHsbyUbLApepYTR1BN4uHrg==,
|
||||
}
|
||||
engines: { node: '>= 6' }
|
||||
dev: true
|
||||
3
pnpm-workspace.yaml
Normal file
3
pnpm-workspace.yaml
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
packages:
|
||||
- 'viewer'
|
||||
- 'engine'
|
||||
3
viewer/.browserslistrc
Normal file
3
viewer/.browserslistrc
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
> 1%
|
||||
last 2 versions
|
||||
not dead
|
||||
26
viewer/.eslintrc.js
Normal file
26
viewer/.eslintrc.js
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
module.exports = {
|
||||
extends: ['eslint:recommended', 'plugin:vue/recommended'],
|
||||
rules: {
|
||||
'vue/no-unused-vars': 'error',
|
||||
'vue/html-indent': ['error', 4, { alignAttributesVertically: false }],
|
||||
'vue/max-attributes-per-line': 0,
|
||||
'vue/html-closing-bracket-newline': [
|
||||
'error',
|
||||
{
|
||||
singleline: 'never',
|
||||
multiline: 'never',
|
||||
},
|
||||
],
|
||||
'vue/attribute-hyphenation': ['error', 'never'],
|
||||
'vue/singleline-html-element-content-newline': 'off',
|
||||
'no-case-declarations': 'off',
|
||||
'no-unused-vars': 'off',
|
||||
quotes: ['error', 'single'],
|
||||
},
|
||||
env: {
|
||||
node: true,
|
||||
},
|
||||
parserOptions: {
|
||||
parser: '@typescript-eslint/parser',
|
||||
},
|
||||
};
|
||||
21
viewer/.gitignore
vendored
Normal file
21
viewer/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
.DS_Store
|
||||
node_modules
|
||||
/dist
|
||||
|
||||
# local env files
|
||||
.env.local
|
||||
.env.*.local
|
||||
|
||||
# Log files
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
|
||||
# Editor directories and files
|
||||
.idea
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
16
viewer/.vscode/launch.json
vendored
Normal file
16
viewer/.vscode/launch.json
vendored
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "chrome",
|
||||
"request": "launch",
|
||||
"name": "vuejs: chrome",
|
||||
"url": "http://localhost:8080",
|
||||
"webRoot": "${workspaceFolder}/src",
|
||||
"breakOnLoad": true,
|
||||
"sourceMapPathOverrides": {
|
||||
"webpack:///src/*": "${webRoot}/*"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
16
viewer/.vscode/settings.json
vendored
Normal file
16
viewer/.vscode/settings.json
vendored
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"editor.tabSize": 4,
|
||||
"editor.acceptSuggestionOnCommitCharacter": false,
|
||||
"editor.formatOnSave": true,
|
||||
"editor.suggestSelection": "first",
|
||||
"editor.codeActionsOnSave": {
|
||||
"source.fixAll": true,
|
||||
"source.organizeImports": true
|
||||
},
|
||||
"vetur.format.options.tabSize": 4,
|
||||
"vetur.format.defaultFormatter.js": "vscode-typescript",
|
||||
"prettier.tabWidth": 4,
|
||||
"files.trimTrailingWhitespace": true,
|
||||
"vetur.format.defaultFormatter.html": "none",
|
||||
"eslint.validate": ["javascript", "typescript", "vue"]
|
||||
}
|
||||
9
viewer/.vscode/vetur/snippets/vue-class-component.vue
vendored
Normal file
9
viewer/.vscode/vetur/snippets/vue-class-component.vue
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<template></template>
|
||||
<script lang="ts">
|
||||
import {Vue, Component, Prop, Watch} from "vue-property-decorator";
|
||||
|
||||
@Component
|
||||
export default class $0 extends Vue {
|
||||
|
||||
}
|
||||
</script>
|
||||
35
viewer/README.md
Normal file
35
viewer/README.md
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
# container-viewer
|
||||
|
||||
## Project setup
|
||||
|
||||
```
|
||||
yarn install
|
||||
```
|
||||
|
||||
### Compiles and hot-reloads for development
|
||||
|
||||
```
|
||||
yarn serve
|
||||
```
|
||||
|
||||
### Compiles and minifies for production
|
||||
|
||||
```
|
||||
yarn build
|
||||
```
|
||||
|
||||
### Run your unit tests
|
||||
|
||||
```
|
||||
yarn test:unit
|
||||
```
|
||||
|
||||
### Lints and fixes files
|
||||
|
||||
```
|
||||
yarn lint
|
||||
```
|
||||
|
||||
### Customize configuration
|
||||
|
||||
See [Configuration Reference](https://cli.vuejs.org/config/).
|
||||
3
viewer/babel.config.js
Normal file
3
viewer/babel.config.js
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
presets: ['@vue/cli-plugin-babel/preset'],
|
||||
};
|
||||
50
viewer/package.json
Normal file
50
viewer/package.json
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
{
|
||||
"name": "container-viewer",
|
||||
"version": "1.1.3",
|
||||
"scripts": {
|
||||
"serve": "vue-cli-service serve",
|
||||
"build": "vue-cli-service build",
|
||||
"test:unit": "vue-cli-service test:unit",
|
||||
"package": "vue-cli-service build --target lib --name container-viewer src/wrapper.ts",
|
||||
"prepublishOnly": "npm run package"
|
||||
},
|
||||
"dependencies": {
|
||||
"container-engine": "workspace:../engine",
|
||||
"core-js": "^3.6.5",
|
||||
"lodash": "^4.17.19",
|
||||
"regenerator-runtime": "^0.13.7",
|
||||
"tslib": "^2.2.0",
|
||||
"vue": "^2.6.11",
|
||||
"vue-class-component": "^7.2.3",
|
||||
"vue-property-decorator": "^8.4.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/assert": "^1.4.7",
|
||||
"@types/chai": "^4.2.11",
|
||||
"@types/events": "^3.0.0",
|
||||
"@types/lodash": "^4.14.154",
|
||||
"@types/mocha": "^5.2.4",
|
||||
"@typescript-eslint/parser": "^4.26.1",
|
||||
"@vue/cli-plugin-babel": "~4.4.0",
|
||||
"@vue/cli-plugin-typescript": "~4.4.0",
|
||||
"@vue/cli-plugin-unit-mocha": "~4.4.0",
|
||||
"@vue/cli-service": "~4.4.0",
|
||||
"@vue/test-utils": "^1.0.3",
|
||||
"chai": "^4.1.2",
|
||||
"eslint": "^7.28.0",
|
||||
"eslint-plugin-vue": "^7.11.0",
|
||||
"sass": "^1.26.5",
|
||||
"sass-loader": "^8.0.2",
|
||||
"typescript": "^4.3.5",
|
||||
"vue-template-compiler": "^2.6.11"
|
||||
},
|
||||
"files": [
|
||||
"src",
|
||||
"dist/container-viewer.umd.min.js",
|
||||
"dist/container-viewer.css",
|
||||
"dist/img",
|
||||
"dist/media",
|
||||
"tsconfig.json",
|
||||
"public/audio"
|
||||
]
|
||||
}
|
||||
12309
viewer/pnpm-lock.yaml
generated
Normal file
12309
viewer/pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load diff
20
viewer/public/index.html
Normal file
20
viewer/public/index.html
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
|
||||
<!-- <link rel="icon" href="<%= BASE_URL %>favicon.ico">-->
|
||||
<title><%= htmlWebpackPlugin.options.title %></title>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>
|
||||
<strong
|
||||
>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript
|
||||
enabled. Please enable it to continue.</strong
|
||||
>
|
||||
</noscript>
|
||||
<div id="app"></div>
|
||||
<!-- built files will be auto injected -->
|
||||
</body>
|
||||
</html>
|
||||
BIN
viewer/src/audio/notification.mp3
Normal file
BIN
viewer/src/audio/notification.mp3
Normal file
Binary file not shown.
BIN
viewer/src/audio/notification.ogg
Normal file
BIN
viewer/src/audio/notification.ogg
Normal file
Binary file not shown.
BIN
viewer/src/audio/piece-drop.mp3
Normal file
BIN
viewer/src/audio/piece-drop.mp3
Normal file
Binary file not shown.
65
viewer/src/components/Calculator.vue
Normal file
65
viewer/src/components/Calculator.vue
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
<template>
|
||||
<g class="calculator">
|
||||
<rect width="130" height="210" rx="2" />
|
||||
<rect x="10" y="10" width="110" height="30" fill="yellowgreen" rx="2" />
|
||||
<text class="visor" x="110" y="25" fill="black" text-anchor="end">{{ value }}</text>
|
||||
<rect class="button" x="10" y="50" width="30" height="30" fill="gray" rx="2" @click="add(7)" />
|
||||
<text x="25" y="65" fill="white" stroke="white" text-anchor="middle">7</text>
|
||||
<rect class="button" x="50" y="50" width="30" height="30" fill="gray" rx="2" @click="add(8)" />
|
||||
<text x="65" y="65" fill="white" stroke="white" text-anchor="middle">8</text>
|
||||
<rect class="button" x="90" y="50" width="30" height="30" fill="gray" rx="2" @click="add(9)" />
|
||||
<text x="105" y="65" fill="white" stroke="white" text-anchor="middle">9</text>
|
||||
<rect class="button" x="10" y="90" width="30" height="30" fill="gray" rx="2" @click="add(4)" />
|
||||
<text x="25" y="105" fill="white" stroke="white" text-anchor="middle">4</text>
|
||||
<rect class="button" x="50" y="90" width="30" height="30" fill="gray" rx="2" @click="add(5)" />
|
||||
<text x="65" y="105" fill="white" stroke="white" text-anchor="middle">5</text>
|
||||
<rect class="button" x="90" y="90" width="30" height="30" fill="gray" rx="2" @click="add(6)" />
|
||||
<text x="105" y="105" fill="white" stroke="white" text-anchor="middle">6</text>
|
||||
<rect class="button" x="10" y="130" width="30" height="30" fill="gray" rx="2" @click="add(1)" />
|
||||
<text x="25" y="145" fill="white" stroke="white" text-anchor="middle">1</text>
|
||||
<rect class="button" x="50" y="130" width="30" height="30" fill="gray" rx="2" @click="add(2)" />
|
||||
<text x="65" y="145" fill="white" stroke="white" text-anchor="middle">2</text>
|
||||
<rect class="button" x="90" y="130" width="30" height="30" fill="gray" rx="2" @click="add(3)" />
|
||||
<text x="105" y="145" fill="white" stroke="white" text-anchor="middle">3</text>
|
||||
<rect class="button" x="10" y="170" width="30" height="30" fill="gray" rx="2" @click="add(0)" />
|
||||
<text x="25" y="185" fill="white" stroke="white" text-anchor="middle">0</text>
|
||||
<rect class="button" x="50" y="170" width="30" height="30" fill="orange" rx="2" @click="del()" />
|
||||
<text x="65" y="185" fill="white" text-anchor="middle">Del</text>
|
||||
<rect class="button" x="90" y="170" width="30" height="30" fill="orange" rx="2" @click="bid()" />
|
||||
<text x="105" y="185" fill="white" text-anchor="middle">Bid</text>
|
||||
</g>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
import { Vue, Component } from 'vue-property-decorator';
|
||||
|
||||
@Component
|
||||
export default class Calculator extends Vue {
|
||||
value: number = 0;
|
||||
|
||||
add(number) {
|
||||
this.value = Math.min(999, this.value * 10 + number);
|
||||
}
|
||||
|
||||
del() {
|
||||
this.value = Math.floor(this.value / 10);
|
||||
}
|
||||
|
||||
bid() {
|
||||
this.$emit('bid', this.value);
|
||||
this.value = 0;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<style lang="scss">
|
||||
.calculator {
|
||||
fill: #333;
|
||||
|
||||
.button {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.visor {
|
||||
font-family: 'system-ui';
|
||||
}
|
||||
}
|
||||
</style>
|
||||
186
viewer/src/components/DropZone.vue
Normal file
186
viewer/src/components/DropZone.vue
Normal file
|
|
@ -0,0 +1,186 @@
|
|||
<template>
|
||||
<g :class="['placeholder', { showDrop }]">
|
||||
<rect :width="width" :height="height" fill="black" />
|
||||
<title v-if="data && data.type == 'playerHarbor'">Harbor</title>
|
||||
<title v-else-if="data && data.type == 'factoryStore'">Factory Store</title>
|
||||
<title v-else-if="data && data.type == 'warehouseStore'">Harbor Store</title>
|
||||
<title v-else-if="data && data.type == 'factory'">Factory Slot</title>
|
||||
<title v-else-if="data && data.type == 'warehouse'">Warehouse Slot</title>
|
||||
<title v-else-if="data && data.type == 'supply'">Supply</title>
|
||||
<title v-else-if="data && data.type == 'openSea'">Open Sea</title>
|
||||
<title v-else-if="data && data.type == 'islandHarbor'">Island Harbor</title>
|
||||
</g>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
import { Vue, Component, Prop, Watch, Inject, InjectReactive } from 'vue-property-decorator';
|
||||
import { ContainerState, DropZoneType, PieceType, UIData, Preferences } from '../types/ui-data';
|
||||
import { EventEmitter, Listener } from 'events';
|
||||
import Piece from './pieces/Piece.vue';
|
||||
import { Ship, Container, LoanCard } from './pieces';
|
||||
import { ShipPosition } from 'container-engine/src/gamestate';
|
||||
import { MoveName } from 'container-engine';
|
||||
|
||||
@Component
|
||||
export default class DropZone extends Vue {
|
||||
@Inject()
|
||||
readonly ui!: UIData;
|
||||
|
||||
@InjectReactive()
|
||||
readonly preferences!: Preferences;
|
||||
|
||||
@InjectReactive()
|
||||
readonly player!: number;
|
||||
|
||||
@Inject()
|
||||
readonly communicator!: EventEmitter;
|
||||
|
||||
@Prop({ default: true })
|
||||
enabled!: boolean;
|
||||
|
||||
@Prop()
|
||||
width!: number;
|
||||
|
||||
@Prop()
|
||||
height!: number;
|
||||
|
||||
@Prop()
|
||||
accepts?: string;
|
||||
|
||||
@Prop()
|
||||
data?: any;
|
||||
|
||||
@Prop()
|
||||
availableMoves?: any;
|
||||
|
||||
listener?: Listener;
|
||||
overlapping = false;
|
||||
|
||||
updateOverlapping(piece: Piece) {
|
||||
if (!this.enabled) {
|
||||
this.overlapping = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.ui.dragged) {
|
||||
if (this.overlapping) {
|
||||
if (this.accepts?.indexOf(piece.pieceType) != -1) {
|
||||
this.communicator.emit('pieceDrop', piece, this.data);
|
||||
}
|
||||
}
|
||||
|
||||
this.overlapping = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.canDrop) {
|
||||
this.overlapping = false;
|
||||
return;
|
||||
}
|
||||
|
||||
const rect1 = this.$el.getBoundingClientRect();
|
||||
const rect2 = this.ui.dragged!.$el.getBoundingClientRect();
|
||||
|
||||
this.overlapping =
|
||||
rect1.bottom >= rect2.top &&
|
||||
rect1.right >= rect2.left &&
|
||||
rect1.top <= rect2.bottom &&
|
||||
rect1.left <= rect2.right;
|
||||
}
|
||||
|
||||
@Watch('enabled', { immediate: true })
|
||||
onEnabledChanged() {
|
||||
if (!this.listener) {
|
||||
this.listener = (piece) => this.updateOverlapping(piece);
|
||||
this.$on('hook:beforeDestroy', () => this.communicator.off('draggedPosChanged', this.listener!));
|
||||
}
|
||||
|
||||
if (this.enabled) {
|
||||
if (this.communicator.listenerCount('draggedPosChanged') + 1 > this.communicator.getMaxListeners()) {
|
||||
this.communicator.setMaxListeners(this.communicator.getMaxListeners() + 10);
|
||||
}
|
||||
|
||||
this.communicator.on('draggedPosChanged', this.listener!);
|
||||
} else {
|
||||
this.communicator.off('draggedPosChanged', this.listener!);
|
||||
}
|
||||
}
|
||||
|
||||
get canDrop() {
|
||||
if (!this.enabled || !this.ui.dragged || this.accepts?.indexOf(this.ui.dragged.pieceType) == -1) return false;
|
||||
|
||||
if (this.ui.dragged.pieceType == PieceType.Loan) {
|
||||
const loan = this.ui.dragged as LoanCard;
|
||||
if (loan.owner == this.player) {
|
||||
if (this.data.type == DropZoneType.GetLoan) return false;
|
||||
} else {
|
||||
if (this.data.type == DropZoneType.PayLoan) return false;
|
||||
}
|
||||
} else if (this.ui.dragged.pieceType == PieceType.Ship) {
|
||||
const ship = this.ui.dragged as Ship;
|
||||
if (ship.position == ShipPosition.OpenSea) {
|
||||
if (this.data.type == DropZoneType.OpenSea) return false;
|
||||
|
||||
if (this.data.type == DropZoneType.IslandHarbor && ship.containers?.length == 0) return false;
|
||||
|
||||
if (this.data.owner == this.player) return false;
|
||||
} else {
|
||||
if (this.data.type != DropZoneType.OpenSea) return false;
|
||||
}
|
||||
} else if (this.ui.dragged.pieceType == PieceType.Container) {
|
||||
const container = this.ui.dragged as Container;
|
||||
if (container.state == ContainerState.OnBoard) {
|
||||
if (this.data.type != DropZoneType.FactoryStore) return false;
|
||||
} else if (container.state == ContainerState.OnFactoryStore) {
|
||||
if (container.owner == this.player) {
|
||||
if (this.data.type == DropZoneType.Supply) {
|
||||
if (!this.availableMoves[MoveName.DomesticSale]?.find((c) => c.id === container.pieceId)) {
|
||||
return false;
|
||||
}
|
||||
} else if (this.data.type != DropZoneType.FactoryStore) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (this.data.type != DropZoneType.WarehouseStore) return false;
|
||||
}
|
||||
} else if (container.state == ContainerState.OnWarehouseStore) {
|
||||
if (container.owner == this.player) {
|
||||
if (this.data.type == DropZoneType.Supply) {
|
||||
if (!this.availableMoves[MoveName.DomesticSale]?.find((c) => c.id === container.pieceId)) {
|
||||
return false;
|
||||
}
|
||||
} else if (this.data.type != DropZoneType.WarehouseStore) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (this.data.type != DropZoneType.Ship) return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
get showDrop() {
|
||||
return !this.preferences.disableHelp && this.canDrop;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<style lang="scss">
|
||||
g.placeholder {
|
||||
rect {
|
||||
stroke: none;
|
||||
fill: transparent;
|
||||
}
|
||||
|
||||
&.showDrop {
|
||||
rect {
|
||||
stroke: blue;
|
||||
stroke-width: 2px;
|
||||
}
|
||||
}
|
||||
|
||||
&.canClick {
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
1676
viewer/src/components/Game.vue
Normal file
1676
viewer/src/components/Game.vue
Normal file
File diff suppressed because it is too large
Load diff
242
viewer/src/components/PlayerBoard.vue
Normal file
242
viewer/src/components/PlayerBoard.vue
Normal file
|
|
@ -0,0 +1,242 @@
|
|||
<template>
|
||||
<g class="player-board">
|
||||
<rect width="250" height="20" x="0" y="0" :fill="color" />
|
||||
<text x="5" y="10" font-weight="600" fill="black" :text-decoration="isCurrentPlayer ? 'underline' : ''">{{
|
||||
getPlayerName()
|
||||
}}</text>
|
||||
|
||||
<rect width="250" height="180" x="0" y="20" fill="gray" />
|
||||
|
||||
<rect width="20" height="80" x="0" y="200" fill="gray" />
|
||||
<rect width="20" height="80" x="62" y="200" fill="gray" />
|
||||
<rect width="20" height="80" x="124" y="200" fill="gray" />
|
||||
<rect width="20" height="80" x="186" y="200" fill="gray" />
|
||||
<DropZone
|
||||
:transform="`translate(20, 200)`"
|
||||
:width="42"
|
||||
:height="80"
|
||||
:accepts="'ship'"
|
||||
:data="{ type: 'playerHarbor' + owner + '1', owner: owner }"
|
||||
/>
|
||||
<DropZone
|
||||
:transform="`translate(82, 200)`"
|
||||
:width="42"
|
||||
:height="80"
|
||||
:accepts="'ship'"
|
||||
:data="{ type: 'playerHarbor' + owner + '2', owner: owner }"
|
||||
/>
|
||||
<DropZone
|
||||
:transform="`translate(144, 200)`"
|
||||
:width="42"
|
||||
:height="80"
|
||||
:accepts="'ship'"
|
||||
:data="{ type: 'playerHarbor' + owner + '3', owner: owner }"
|
||||
/>
|
||||
<DropZone
|
||||
:transform="`translate(206, 200)`"
|
||||
:width="43"
|
||||
:height="80"
|
||||
:accepts="'ship'"
|
||||
:data="{ type: 'playerHarbor' + owner + '4', owner: owner }"
|
||||
/>
|
||||
|
||||
<DropZone
|
||||
:transform="`translate(200, 23)`"
|
||||
:width="47"
|
||||
:height="77"
|
||||
:enabled="isCurrentPlayer"
|
||||
:accepts="'loan'"
|
||||
:data="{ type: 'getLoan' }"
|
||||
/>
|
||||
|
||||
<circle r="14" cx="28" cy="40" fill="none" stroke="lightgray" />
|
||||
<text text-anchor="middle" x="28" y="40" fill="lightgray">-</text>
|
||||
<circle r="14" cx="76" cy="40" fill="none" stroke="lightgray" />
|
||||
<text text-anchor="middle" x="76" y="40" fill="lightgray">6</text>
|
||||
<circle r="14" cx="124" cy="40" fill="none" stroke="lightgray" />
|
||||
<text text-anchor="middle" x="124" y="40" fill="lightgray">9</text>
|
||||
<circle r="14" cx="172" cy="40" fill="none" stroke="lightgray" />
|
||||
<text text-anchor="middle" x="171" y="40" fill="lightgray">12</text>
|
||||
<DropZone
|
||||
:transform="`translate(13, 25)`"
|
||||
:width="174"
|
||||
:height="30"
|
||||
:enabled="isCurrentPlayer"
|
||||
:accepts="'factory'"
|
||||
:data="{ type: 'factory' }"
|
||||
/>
|
||||
|
||||
<rect x="8" y="60" width="40" height="40" fill="none" stroke="lightgray" />
|
||||
<text text-anchor="middle" x="28" y="90" fill="lightgray">1</text>
|
||||
<DropZone
|
||||
:transform="`translate(8, 60)`"
|
||||
:width="40"
|
||||
:height="40"
|
||||
:enabled="isCurrentPlayer"
|
||||
:accepts="'container'"
|
||||
:data="{ type: 'factoryStore', price: 1 }"
|
||||
/>
|
||||
<rect x="56" y="60" width="40" height="40" fill="none" stroke="lightgray" />
|
||||
<text text-anchor="middle" x="76" y="90" fill="lightgray">2</text>
|
||||
<DropZone
|
||||
:transform="`translate(56, 60)`"
|
||||
:width="40"
|
||||
:height="40"
|
||||
:enabled="isCurrentPlayer"
|
||||
:accepts="'container'"
|
||||
:data="{ type: 'factoryStore', price: 2 }"
|
||||
/>
|
||||
<rect x="104" y="60" width="40" height="40" fill="none" stroke="lightgray" />
|
||||
<text text-anchor="middle" x="124" y="90" fill="lightgray">3</text>
|
||||
<DropZone
|
||||
:transform="`translate(104, 60)`"
|
||||
:width="40"
|
||||
:height="40"
|
||||
:enabled="isCurrentPlayer"
|
||||
:accepts="'container'"
|
||||
:data="{ type: 'factoryStore', price: 3 }"
|
||||
/>
|
||||
<rect x="152" y="60" width="40" height="40" fill="none" stroke="lightgray" />
|
||||
<text text-anchor="middle" x="172" y="90" fill="lightgray">4</text>
|
||||
<DropZone
|
||||
:transform="`translate(152, 60)`"
|
||||
:width="40"
|
||||
:height="40"
|
||||
:enabled="isCurrentPlayer"
|
||||
:accepts="'container'"
|
||||
:data="{ type: 'factoryStore', price: 4 }"
|
||||
/>
|
||||
|
||||
<g transform="translate(8, 105)"
|
||||
><path d="M20 0 L40 13 L40 40 L0 40 L0 13Z" fill="none" stroke="lightgray"
|
||||
/></g>
|
||||
<text text-anchor="middle" x="28" y="128" fill="lightgray">-</text>
|
||||
<g transform="translate(56, 105)"
|
||||
><path d="M20 0 L40 13 L40 40 L0 40 L0 13Z" fill="none" stroke="lightgray"
|
||||
/></g>
|
||||
<text text-anchor="middle" x="76" y="128" fill="lightgray">4</text>
|
||||
<g transform="translate(104, 105)"
|
||||
><path d="M20 0 L40 13 L40 40 L0 40 L0 13Z" fill="none" stroke="lightgray"
|
||||
/></g>
|
||||
<text text-anchor="middle" x="124" y="128" fill="lightgray">5</text>
|
||||
<g transform="translate(152, 105)"
|
||||
><path d="M20 0 L40 13 L40 40 L0 40 L0 13Z" fill="none" stroke="lightgray"
|
||||
/></g>
|
||||
<text text-anchor="middle" x="172" y="128" fill="lightgray">6</text>
|
||||
<g transform="translate(200, 105)"
|
||||
><path d="M20 0 L40 13 L40 40 L0 40 L0 13Z" fill="none" stroke="lightgray"
|
||||
/></g>
|
||||
<text text-anchor="middle" x="220" y="128" fill="lightgray">7</text>
|
||||
<DropZone
|
||||
:transform="`translate(7, 104)`"
|
||||
:width="234"
|
||||
:height="42"
|
||||
:enabled="isCurrentPlayer"
|
||||
:accepts="'warehouse'"
|
||||
:data="{ type: 'warehouse' }"
|
||||
/>
|
||||
|
||||
<rect x="8" y="150" width="40" height="40" fill="none" stroke="lightgray" />
|
||||
<text text-anchor="middle" x="28" y="180" fill="lightgray">2</text>
|
||||
<DropZone
|
||||
:transform="`translate(8, 150)`"
|
||||
:width="40"
|
||||
:height="40"
|
||||
:enabled="isCurrentPlayer"
|
||||
:accepts="'container'"
|
||||
:data="{ type: 'warehouseStore', price: 2 }"
|
||||
/>
|
||||
<rect x="56" y="150" width="40" height="40" fill="none" stroke="lightgray" />
|
||||
<text text-anchor="middle" x="76" y="180" fill="lightgray">3</text>
|
||||
<DropZone
|
||||
:transform="`translate(56, 150)`"
|
||||
:width="40"
|
||||
:height="40"
|
||||
:enabled="isCurrentPlayer"
|
||||
:accepts="'container'"
|
||||
:data="{ type: 'warehouseStore', price: 3 }"
|
||||
/>
|
||||
<rect x="104" y="150" width="40" height="40" fill="none" stroke="lightgray" />
|
||||
<text text-anchor="middle" x="124" y="180" fill="lightgray">4</text>
|
||||
<DropZone
|
||||
:transform="`translate(104, 150)`"
|
||||
:width="40"
|
||||
:height="40"
|
||||
:enabled="isCurrentPlayer"
|
||||
:accepts="'container'"
|
||||
:data="{ type: 'warehouseStore', price: 4 }"
|
||||
/>
|
||||
<rect x="152" y="150" width="40" height="40" fill="none" stroke="lightgray" />
|
||||
<text text-anchor="middle" x="172" y="180" fill="lightgray">5</text>
|
||||
<DropZone
|
||||
:transform="`translate(152, 150)`"
|
||||
:width="40"
|
||||
:height="40"
|
||||
:enabled="isCurrentPlayer"
|
||||
:accepts="'container'"
|
||||
:data="{ type: 'warehouseStore', price: 5 }"
|
||||
/>
|
||||
<rect x="200" y="150" width="40" height="40" fill="none" stroke="lightgray" />
|
||||
<text text-anchor="middle" x="220" y="180" fill="lightgray">6</text>
|
||||
<DropZone
|
||||
:transform="`translate(200, 150)`"
|
||||
:width="40"
|
||||
:height="40"
|
||||
:enabled="isCurrentPlayer"
|
||||
:accepts="'container'"
|
||||
:data="{ type: 'warehouseStore', price: 6 }"
|
||||
/>
|
||||
</g>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
import { Player } from 'container-engine';
|
||||
import { Vue, Component, Prop } from 'vue-property-decorator';
|
||||
import DropZone from './DropZone.vue';
|
||||
|
||||
@Component({
|
||||
components: {
|
||||
DropZone,
|
||||
}
|
||||
})
|
||||
export default class PlayerBoard extends Vue {
|
||||
@Prop()
|
||||
color?: string;
|
||||
|
||||
@Prop()
|
||||
player!: Player;
|
||||
|
||||
@Prop()
|
||||
isCurrentPlayer?: boolean;
|
||||
|
||||
@Prop()
|
||||
owner?: number;
|
||||
|
||||
@Prop()
|
||||
ended?: boolean;
|
||||
|
||||
onPieceDrop(e) {
|
||||
this.$emit('pieceDrop', e);
|
||||
}
|
||||
|
||||
getPlayerName() {
|
||||
let name = '';
|
||||
if (this.isCurrentPlayer) {
|
||||
name += '• ';
|
||||
}
|
||||
|
||||
name += this.player.name;
|
||||
|
||||
if (this.player.showBid) {
|
||||
if (this.player.showAdditionalBid) {
|
||||
name += ' (Bid: $' + (this.player.bid + this.player.additionalBid) + ')';
|
||||
} else {
|
||||
name += ' (Bid: $' + this.player.bid + ')';
|
||||
}
|
||||
} else if (this.ended) {
|
||||
name += ' (Score: $' + (this.player.money) + ')';
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
72
viewer/src/components/PointCard.vue
Normal file
72
viewer/src/components/PointCard.vue
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
<template>
|
||||
<g class="point-card" @click="turned = !turned">
|
||||
<g v-if="turned">
|
||||
<rect width="100" height="160" fill="dimgray" stroke="white" stroke-width="2" rx="2" />
|
||||
</g>
|
||||
<g v-else>
|
||||
<rect width="100" height="160" fill="silver" stroke="white" stroke-width="2" rx="2" />
|
||||
<rect
|
||||
x="20"
|
||||
y="15"
|
||||
width="20"
|
||||
height="10"
|
||||
:fill="pointCard.containerValues[0].containerColor"
|
||||
stroke="black"
|
||||
/>
|
||||
<text x="70" y="20" text-anchor="middle">10</text>
|
||||
<rect
|
||||
x="20"
|
||||
y="45"
|
||||
width="20"
|
||||
height="10"
|
||||
:fill="pointCard.containerValues[1].containerColor"
|
||||
stroke="black"
|
||||
/>
|
||||
<text x="70" y="50" text-anchor="middle">5/10</text>
|
||||
<rect
|
||||
x="20"
|
||||
y="75"
|
||||
width="20"
|
||||
height="10"
|
||||
:fill="pointCard.containerValues[2].containerColor"
|
||||
stroke="black"
|
||||
/>
|
||||
<text x="70" y="80" text-anchor="middle">6</text>
|
||||
<rect
|
||||
x="20"
|
||||
y="105"
|
||||
width="20"
|
||||
height="10"
|
||||
:fill="pointCard.containerValues[3].containerColor"
|
||||
stroke="black"
|
||||
/>
|
||||
<text x="70" y="110" text-anchor="middle">4</text>
|
||||
<rect
|
||||
x="20"
|
||||
y="135"
|
||||
width="20"
|
||||
height="10"
|
||||
:fill="pointCard.containerValues[4].containerColor"
|
||||
stroke="black"
|
||||
/>
|
||||
<text x="70" y="140" text-anchor="middle">2</text>
|
||||
</g>
|
||||
</g>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
import { Vue, Component, Prop } from 'vue-property-decorator';
|
||||
import type { PointCard as PointCardInfo } from 'container-engine'
|
||||
|
||||
@Component
|
||||
export default class PointCard extends Vue {
|
||||
@Prop()
|
||||
pointCard?: PointCardInfo;
|
||||
|
||||
turned = false;
|
||||
}
|
||||
</script>
|
||||
<style lang="scss">
|
||||
.point-card {
|
||||
cursor: pointer;
|
||||
}
|
||||
</style>
|
||||
26
viewer/src/components/buttons/Button.vue
Normal file
26
viewer/src/components/buttons/Button.vue
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
<template>
|
||||
<g :class="['button', { enabled }]" @click="enabled && $emit('click')">
|
||||
<rect :width="width" height="30" fill="gainsboro" stroke="black" rx="2" />
|
||||
<text text-anchor="middle" fill="black" :x="width / 2" y="16">{{ getText() }}</text>
|
||||
<title>{{ text }}</title>
|
||||
</g>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
import { Vue, Component, Prop } from 'vue-property-decorator';
|
||||
|
||||
@Component
|
||||
export default class Button extends Vue {
|
||||
@Prop()
|
||||
text?: string;
|
||||
|
||||
@Prop()
|
||||
width?: number;
|
||||
|
||||
@Prop({ default: true })
|
||||
enabled!: boolean;
|
||||
|
||||
getText() {
|
||||
return this.text!.length > 15 ? this.text?.substring(0, 12).concat('...') : this.text;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
18
viewer/src/components/buttons/HelpButton.vue
Normal file
18
viewer/src/components/buttons/HelpButton.vue
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<template>
|
||||
<g class="button enabled" @click="$emit('click')">
|
||||
<circle cx="15" cy="15" r="15" fill="gainsboro" stroke="black" stroke-width="2px" />
|
||||
<image x="5" y="5" width="20" height="20" href="../../icons/help.svg" />
|
||||
<line v-if="!isOn" x1="5" y1="25" x2="25" y2="5" stroke="black" stroke-width="3px" stroke-linecap="round" />
|
||||
<title v-if="isOn">Help off</title>
|
||||
<title v-else>Help on</title>
|
||||
</g>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
import { Vue, Component, Prop } from 'vue-property-decorator';
|
||||
|
||||
@Component
|
||||
export default class HelpButton extends Vue {
|
||||
@Prop()
|
||||
isOn?: boolean;
|
||||
}
|
||||
</script>
|
||||
15
viewer/src/components/buttons/LogButton.vue
Normal file
15
viewer/src/components/buttons/LogButton.vue
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
<template>
|
||||
<g class="button enabled" @click="$emit('click')">
|
||||
<rect width="80" height="26" fill="gainsboro" stroke="black" rx="2" />
|
||||
<image x="11" y="5" width="16" height="16" href="../../icons/log.svg" />
|
||||
<text text-anchor="middle" fill="black" x="47" y="13">Log</text>
|
||||
<title>Show log</title>
|
||||
</g>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
import { Vue, Component } from 'vue-property-decorator';
|
||||
|
||||
@Component
|
||||
export default class LogButton extends Vue {
|
||||
}
|
||||
</script>
|
||||
17
viewer/src/components/buttons/PassButton.vue
Normal file
17
viewer/src/components/buttons/PassButton.vue
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<template>
|
||||
<g :class="['button', { enabled }]" @click="enabled && $emit('click')">
|
||||
<rect width="80" height="26" fill="gainsboro" stroke="black" rx="2" />
|
||||
<image x="15" y="8" width="10" height="10" href="../../icons/pass.svg" />
|
||||
<text text-anchor="middle" fill="black" x="47" y="13">Pass</text>
|
||||
<title>Pass turn</title>
|
||||
</g>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
import { Vue, Component, Prop } from 'vue-property-decorator';
|
||||
|
||||
@Component
|
||||
export default class PassButton extends Vue {
|
||||
@Prop()
|
||||
enabled!: boolean;
|
||||
}
|
||||
</script>
|
||||
18
viewer/src/components/buttons/SoundButton.vue
Normal file
18
viewer/src/components/buttons/SoundButton.vue
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<template>
|
||||
<g class="button enabled" @click="$emit('click')">
|
||||
<circle cx="15" cy="15" r="15" fill="gainsboro" stroke="black" stroke-width="2px" />
|
||||
<image v-if="isOn" x="5" y="5" width="20" height="20" href="../../icons/sound-on.svg" />
|
||||
<image v-else x="5" y="5" width="20" height="20" href="../../icons/sound-off.svg" />
|
||||
<title v-if="isOn">Sound off</title>
|
||||
<title v-else>Sound on</title>
|
||||
</g>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
import { Vue, Component, Prop } from 'vue-property-decorator';
|
||||
|
||||
@Component
|
||||
export default class SoundButton extends Vue {
|
||||
@Prop()
|
||||
isOn?: boolean;
|
||||
}
|
||||
</script>
|
||||
17
viewer/src/components/buttons/UndoButton.vue
Normal file
17
viewer/src/components/buttons/UndoButton.vue
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<template>
|
||||
<g :class="['button', { enabled }]" @click="enabled && $emit('click')">
|
||||
<rect width="80" height="26" fill="gainsboro" stroke="black" rx="2" />
|
||||
<image x="11" y="4" width="16" height="16" href="../../icons/undo.svg" />
|
||||
<text text-anchor="middle" fill="black" x="47" y="13">Undo</text>
|
||||
<title>Undo last move</title>
|
||||
</g>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
import { Vue, Component, Prop } from 'vue-property-decorator';
|
||||
|
||||
@Component
|
||||
export default class UndoButton extends Vue {
|
||||
@Prop()
|
||||
enabled!: boolean;
|
||||
}
|
||||
</script>
|
||||
8
viewer/src/components/buttons/index.js
Normal file
8
viewer/src/components/buttons/index.js
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import Button from './Button.vue';
|
||||
import HelpButton from './HelpButton.vue';
|
||||
import LogButton from './LogButton.vue';
|
||||
import PassButton from './PassButton.vue';
|
||||
import SoundButton from './SoundButton.vue';
|
||||
import UndoButton from './UndoButton.vue';
|
||||
|
||||
export { Button, HelpButton, LogButton, PassButton, SoundButton, UndoButton };
|
||||
32
viewer/src/components/pieces/Container.vue
Normal file
32
viewer/src/components/pieces/Container.vue
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<template>
|
||||
<g
|
||||
:id="elId"
|
||||
:class="['piece', { dragging, canDrag }]"
|
||||
:transform="`translate(${currentX}, ${currentY}) rotate(${rotate}, 10, 5)`"
|
||||
>
|
||||
<rect width="20" height="10" :fill="color" stroke="black" />
|
||||
|
||||
<title>Container</title>
|
||||
</g>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
import { ContainerState, PieceType } from '@/types/ui-data';
|
||||
import { Component, Mixins, Prop } from 'vue-property-decorator';
|
||||
import Piece from './Piece.vue';
|
||||
|
||||
@Component({
|
||||
created(this: Container) {
|
||||
this.pieceType = PieceType.Container;
|
||||
}
|
||||
})
|
||||
export default class Container extends Mixins(Piece) {
|
||||
@Prop()
|
||||
color?: string;
|
||||
|
||||
@Prop()
|
||||
owner?: number;
|
||||
|
||||
@Prop()
|
||||
state?: ContainerState;
|
||||
}
|
||||
</script>
|
||||
106
viewer/src/components/pieces/Draggable.vue
Normal file
106
viewer/src/components/pieces/Draggable.vue
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
<script lang="ts">
|
||||
import { Vue, Component, Prop } from 'vue-property-decorator';
|
||||
|
||||
@Component({
|
||||
mounted(this: Draggable) {
|
||||
this.$nextTick(() => {
|
||||
const endDrag = () => this.endDrag();
|
||||
const drag = (event: MouseEvent | TouchEvent) => this.drag(event);
|
||||
|
||||
this.htmlElement.addEventListener('mousedown', event => this.startDrag(event));
|
||||
this.htmlElement.addEventListener('touchstart', event => this.startDrag(event));
|
||||
|
||||
this.svgElement.addEventListener('touchmove', drag);
|
||||
this.svgElement.addEventListener('touchend', endDrag);
|
||||
this.svgElement.addEventListener('touchleave', endDrag);
|
||||
this.svgElement.addEventListener('touchcancel', endDrag);
|
||||
|
||||
this.$on('hook:beforeDestroy', () => this.svgElement.removeEventListener('touchmove', drag));
|
||||
this.$on('hook:beforeDestroy', () => this.svgElement.removeEventListener('touchend', endDrag));
|
||||
this.$on('hook:beforeDestroy', () => this.svgElement.removeEventListener('touchleave', endDrag));
|
||||
this.$on('hook:beforeDestroy', () => this.svgElement.removeEventListener('touchcancel', endDrag));
|
||||
|
||||
this.svgElement.addEventListener('mouseleave', endDrag);
|
||||
this.svgElement.addEventListener('mouseup', endDrag);
|
||||
this.svgElement.addEventListener('mousemove', drag);
|
||||
|
||||
this.$on('hook:beforeDestroy', () => this.svgElement.removeEventListener('mouseleave', endDrag));
|
||||
this.$on('hook:beforeDestroy', () => this.svgElement.removeEventListener('mouseup', endDrag));
|
||||
this.$on('hook:beforeDestroy', () => this.svgElement.removeEventListener('mousemove', drag));
|
||||
});
|
||||
}
|
||||
})
|
||||
export default class Draggable extends Vue {
|
||||
@Prop()
|
||||
canDrag!: boolean;
|
||||
|
||||
dragging = false;
|
||||
_offset = { x: 0, y: 0 };
|
||||
_transform?: SVGTransform;
|
||||
_dragStart?: number;
|
||||
|
||||
get svgElement() {
|
||||
return document.querySelector('#scene') as SVGSVGElement;
|
||||
}
|
||||
|
||||
get htmlElement() {
|
||||
return this.$el as SVGGElement;
|
||||
}
|
||||
|
||||
startDrag(evt: MouseEvent | TouchEvent) {
|
||||
if (!this.canDrag)
|
||||
return;
|
||||
|
||||
this.dragging = true;
|
||||
|
||||
this._offset = this.getMousePosition(evt);
|
||||
// Get all the transforms currently on this element
|
||||
const transforms: SVGTransformList = this.htmlElement.transform.baseVal;
|
||||
// Ensure the first transform is a translate transform
|
||||
if (transforms.numberOfItems === 0 || transforms.getItem(0).type !== SVGTransform.SVG_TRANSFORM_TRANSLATE) {
|
||||
// Create an transform that translates by (0, 0)
|
||||
const translate = this.svgElement.createSVGTransform();
|
||||
translate.setTranslate(0, 0);
|
||||
// Add the translation to the front of the transforms list
|
||||
this.htmlElement.transform.baseVal.insertItemBefore(translate, 0);
|
||||
}
|
||||
|
||||
// Get initial translation amount
|
||||
this._transform = transforms.getItem(0);
|
||||
this._offset.x -= this._transform.matrix.e;
|
||||
this._offset.y -= this._transform.matrix.f;
|
||||
this._dragStart = Date.now();
|
||||
}
|
||||
|
||||
drag(evt: MouseEvent | TouchEvent) {
|
||||
if (!this.dragging) {
|
||||
return;
|
||||
}
|
||||
|
||||
evt.preventDefault();
|
||||
const coord = this.getMousePosition(evt);
|
||||
this._transform!.setTranslate(coord.x - this._offset.x, coord.y - this._offset.y);
|
||||
|
||||
this.$emit('draggedTo', { x: coord.x - this._offset.x, y: coord.y - this._offset.y });
|
||||
}
|
||||
|
||||
endDrag() {
|
||||
this.dragging = false;
|
||||
if (Date.now() - this._dragStart! < 100) {
|
||||
this.$nextTick(() => { this.$emit('fastClick', this); });
|
||||
}
|
||||
}
|
||||
|
||||
getMousePosition(evt: MouseEvent | TouchEvent) {
|
||||
if ((evt as TouchEvent).touches) {
|
||||
evt = (evt as TouchEvent).touches[0] as any;
|
||||
}
|
||||
|
||||
const CTM = this.svgElement.getScreenCTM()!;
|
||||
return {
|
||||
x: ((evt as any).clientX - CTM.e) / CTM.a,
|
||||
y: ((evt as any).clientY - CTM.f) / CTM.d
|
||||
};
|
||||
}
|
||||
}
|
||||
</script>
|
||||
22
viewer/src/components/pieces/Factory.vue
Normal file
22
viewer/src/components/pieces/Factory.vue
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<template>
|
||||
<g :id="elId" :class="['piece', { dragging, canDrag }]" :transform="`translate(${currentX}, ${currentY})`">
|
||||
<circle r="10" :fill="color" stroke="black" />
|
||||
|
||||
<title>Factory</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: Factory) {
|
||||
this.pieceType = PieceType.Factory;
|
||||
}
|
||||
})
|
||||
export default class Factory extends Mixins(Piece) {
|
||||
@Prop()
|
||||
color?: string;
|
||||
}
|
||||
</script>
|
||||
47
viewer/src/components/pieces/LoanCard.vue
Normal file
47
viewer/src/components/pieces/LoanCard.vue
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
<template>
|
||||
<g :id="elId" :class="['loan', { dragging, canDrag }]" :transform="`translate(${currentX}, ${currentY})`">
|
||||
<rect width="30" height="60" fill="royalblue" stroke="white" stroke-width="2" rx="2" />
|
||||
<g transform="translate(33, -10) rotate(280, 15, 30)">
|
||||
<text text-anchor="middle" fill="white">Loan</text>
|
||||
</g>
|
||||
<title v-if="owner == -1">Get Loan</title>
|
||||
<title v-else-if="owner == player">Pay Loan</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: LoanCard) {
|
||||
this.pieceType = PieceType.Loan;
|
||||
}
|
||||
})
|
||||
export default class LoanCard extends Mixins(Piece) {
|
||||
@Prop()
|
||||
owner?: number;
|
||||
|
||||
@Prop()
|
||||
player?: number;
|
||||
}
|
||||
</script>
|
||||
<style lang="scss">
|
||||
.loan {
|
||||
&:not(.dragging) {
|
||||
transition-property: transform;
|
||||
transition-duration: 0.8s;
|
||||
transition-timing-function: ease-in-out;
|
||||
}
|
||||
|
||||
&.canDrag {
|
||||
cursor: pointer;
|
||||
|
||||
rect {
|
||||
&:hover {
|
||||
stroke: white;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
127
viewer/src/components/pieces/Piece.vue
Normal file
127
viewer/src/components/pieces/Piece.vue
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
<script lang="ts">
|
||||
import { Component, Inject, Prop, Watch } from 'vue-property-decorator';
|
||||
import Draggable from './Draggable.vue';
|
||||
import { EventEmitter } from 'events';
|
||||
import { PieceType, UIData } from '@/types/ui-data';
|
||||
|
||||
@Component({
|
||||
created(this: Piece) {
|
||||
this.$on('draggedTo', (coords: { x: number, y: number }) => {
|
||||
[this.currentX, this.currentY] = [coords.x, coords.y];
|
||||
|
||||
this.$nextTick(() => {
|
||||
this.communicator.emit('draggedPosChanged', this);
|
||||
});
|
||||
});
|
||||
},
|
||||
mounted(this: Piece) {
|
||||
this.mounted = true;
|
||||
},
|
||||
beforeDestroy(this: Piece) {
|
||||
this.onTransitionEnd();
|
||||
}
|
||||
})
|
||||
export default class Piece extends Draggable {
|
||||
@Prop({ default: () => ({ x: 20, y: 20, rotate: 0 }) })
|
||||
targetState!: {
|
||||
x: number,
|
||||
y: number,
|
||||
rotate: number
|
||||
};
|
||||
|
||||
@Prop()
|
||||
pieceId!: string;
|
||||
|
||||
@Inject()
|
||||
readonly communicator!: EventEmitter;
|
||||
|
||||
@Inject()
|
||||
readonly ui!: UIData;
|
||||
|
||||
public pieceType!: PieceType;
|
||||
|
||||
currentX = 0;
|
||||
currentY = 0;
|
||||
rotate = 0;
|
||||
mounted = false;
|
||||
transitioning = false;
|
||||
transitionCount = 0;
|
||||
|
||||
moving = false;
|
||||
|
||||
startTransitioning() {
|
||||
if (this.transitioning) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.ui.waitingAnimations += 1;
|
||||
this.transitioning = true;
|
||||
this.transitionCount += 1;
|
||||
|
||||
const count = this.transitionCount;
|
||||
|
||||
// Safeguard to make sure even if we don't catch the transition end event, we stop the transition
|
||||
setTimeout(() => {
|
||||
if (count === this.transitionCount) {
|
||||
this.onTransitionEnd();
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
@Watch('dragging')
|
||||
@Watch('targetState', { immediate: true })
|
||||
onTargetChanged(newVal: boolean, oldVal: boolean) {
|
||||
if (this.dragging) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.targetState.x === this.currentX && this.targetState.y === this.currentY) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.transitioning && this.mounted) {
|
||||
if (!(oldVal && !newVal)) {
|
||||
this.startTransitioning();
|
||||
} else {
|
||||
this.moving = true;
|
||||
setTimeout(() => this.moving = false, 800);
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.mounted) {
|
||||
this.currentX = this.targetState.x;
|
||||
this.currentY = this.targetState.y;
|
||||
this.rotate = this.targetState.rotate;
|
||||
} else {
|
||||
// Make sure the animation plays by waiting until the class "dragging" is removed for sure from the element
|
||||
setTimeout(() => {
|
||||
this.currentX = this.targetState.x;
|
||||
this.currentY = this.targetState.y;
|
||||
this.rotate = this.targetState.rotate;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Watch('dragging')
|
||||
onDraggingChanged() {
|
||||
if (this.dragging) {
|
||||
this.ui.dragged = this;
|
||||
} else {
|
||||
this.ui.dragged = null;
|
||||
this.communicator.emit('draggedPosChanged', this);
|
||||
}
|
||||
}
|
||||
|
||||
onTransitionEnd() {
|
||||
// console.log("on transition end", this.transitioning);
|
||||
if (this.transitioning) {
|
||||
this.transitioning = false;
|
||||
this.ui.waitingAnimations = Math.max(this.ui.waitingAnimations - 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
get elId() {
|
||||
return this.dragging ? 'dragged' : (this.transitioning || this.moving ? 'moving' : undefined);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
57
viewer/src/components/pieces/Ship.vue
Normal file
57
viewer/src/components/pieces/Ship.vue
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
<template>
|
||||
<g
|
||||
:id="elId"
|
||||
:class="['piece', { dragging, canDrag }]"
|
||||
:transform="`translate(${currentX}, ${currentY}) rotate(${rotate}, 15, 40)`"
|
||||
>
|
||||
<path d="M15 0 L30 10 L30 80 L0 80 L0 10Z" :fill="color" stroke="black" />
|
||||
<template v-for="(container, i) in containers">
|
||||
<Container
|
||||
:key="container.id"
|
||||
:pieceId="container.id"
|
||||
:targetState="{ x: 5, y: 15 + 12 * i, rotate: 0 }"
|
||||
:canDrag="false"
|
||||
:color="container.color"
|
||||
/>
|
||||
</template>
|
||||
<DropZone :width="30" :height="80" :enabled="player == owner" :accepts="'container'" :data="{ type: 'ship' }" />
|
||||
<title>{{ ownerName }}'s Ship</title>
|
||||
</g>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
import { PieceType } from '@/types/ui-data';
|
||||
import { ContainerPiece, ShipPosition } from 'container-engine/src/gamestate';
|
||||
import { Component, InjectReactive, Mixins, Prop } from 'vue-property-decorator';
|
||||
import Piece from './Piece.vue';
|
||||
import Container from './Container.vue';
|
||||
import DropZone from '../DropZone.vue';
|
||||
|
||||
@Component({
|
||||
created(this: Ship) {
|
||||
this.pieceType = PieceType.Ship;
|
||||
},
|
||||
components: {
|
||||
Container,
|
||||
DropZone
|
||||
}
|
||||
})
|
||||
export default class Ship extends Mixins(Piece) {
|
||||
@InjectReactive()
|
||||
readonly player!: number;
|
||||
|
||||
@Prop()
|
||||
color?: string;
|
||||
|
||||
@Prop()
|
||||
containers?: ContainerPiece[];
|
||||
|
||||
@Prop()
|
||||
owner?: number;
|
||||
|
||||
@Prop()
|
||||
ownerName?: string;
|
||||
|
||||
@Prop()
|
||||
position!: ShipPosition;
|
||||
}
|
||||
</script>
|
||||
19
viewer/src/components/pieces/Warehouse.vue
Normal file
19
viewer/src/components/pieces/Warehouse.vue
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<template>
|
||||
<g :id="elId" :class="['piece', { dragging, canDrag }]" :transform="`translate(${currentX}, ${currentY})`">
|
||||
<path d="M15 0 L30 10 L30 30 L0 30 L0 10Z" fill="dimgray" stroke="black" />
|
||||
<title>Warehouse</title>
|
||||
</g>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
import { PieceType } from '@/types/ui-data';
|
||||
import { Component, Mixins } from 'vue-property-decorator';
|
||||
import Piece from './Piece.vue';
|
||||
|
||||
@Component({
|
||||
created(this: Warehouse) {
|
||||
this.pieceType = PieceType.Warehouse;
|
||||
}
|
||||
})
|
||||
export default class Warehouse extends Mixins(Piece) {
|
||||
}
|
||||
</script>
|
||||
8
viewer/src/components/pieces/index.js
Normal file
8
viewer/src/components/pieces/index.js
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import Container from './Container.vue';
|
||||
import Factory from './Factory.vue';
|
||||
import LoanCard from './LoanCard.vue';
|
||||
import Piece from './Piece.vue';
|
||||
import Ship from './Ship.vue';
|
||||
import Warehouse from './Warehouse.vue';
|
||||
|
||||
export { Container, Factory, LoanCard, Piece, Ship, Warehouse };
|
||||
1
viewer/src/icons/help.svg
Normal file
1
viewer/src/icons/help.svg
Normal file
|
|
@ -0,0 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M14.601 21.5c0 1.38-1.116 2.5-2.499 2.5-1.378 0-2.499-1.12-2.499-2.5s1.121-2.5 2.499-2.5c1.383 0 2.499 1.119 2.499 2.5zm-2.42-21.5c-4.029 0-7.06 2.693-7.06 8h3.955c0-2.304.906-4.189 3.024-4.189 1.247 0 2.57.828 2.684 2.411.123 1.666-.767 2.511-1.892 3.582-2.924 2.78-2.816 4.049-2.816 7.196h3.943c0-1.452-.157-2.508 1.838-4.659 1.331-1.436 2.986-3.222 3.021-5.943.047-3.963-2.751-6.398-6.697-6.398z"/></svg>
|
||||
|
After Width: | Height: | Size: 499 B |
1
viewer/src/icons/log.svg
Normal file
1
viewer/src/icons/log.svg
Normal file
|
|
@ -0,0 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M24 12c0 6.627-5.373 12-12 12s-12-5.373-12-12h2c0 5.514 4.486 10 10 10s10-4.486 10-10-4.486-10-10-10c-2.777 0-5.287 1.141-7.099 2.977l2.061 2.061-6.962 1.354 1.305-7.013 2.179 2.18c2.172-2.196 5.182-3.559 8.516-3.559 6.627 0 12 5.373 12 12zm-13-6v8h7v-2h-5v-6h-2z"/></svg>
|
||||
|
After Width: | Height: | Size: 364 B |
3
viewer/src/icons/pass.svg
Normal file
3
viewer/src/icons/pass.svg
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
<svg width="40" height="40" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M0 0 L20 20 L0 40 Z M20 0 L40 20 L20 40 Z" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 130 B |
3
viewer/src/icons/sound-off.svg
Normal file
3
viewer/src/icons/sound-off.svg
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
|
||||
<path d="M5 17h-5v-10h5v10zm2-10v10l9 5v-20l-9 5zm15.324 4.993l1.646-1.659-1.324-1.324-1.651 1.67-1.665-1.648-1.316 1.318 1.67 1.657-1.65 1.669 1.318 1.317 1.658-1.672 1.666 1.653 1.324-1.325-1.676-1.656z"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 302 B |
3
viewer/src/icons/sound-on.svg
Normal file
3
viewer/src/icons/sound-on.svg
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
|
||||
<path d="M5 17h-5v-10h5v10zm2-10v10l9 5v-20l-9 5zm17 4h-5v2h5v-2zm-1.584-6.232l-4.332 2.5 1 1.732 4.332-2.5-1-1.732zm1 12.732l-4.332-2.5-1 1.732 4.332 2.5 1-1.732z"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 261 B |
3
viewer/src/icons/undo.svg
Normal file
3
viewer/src/icons/undo.svg
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
<svg width="497.25px" height="497.25px" viewBox="0 0 497.25 497.25" xmlns="http://www.w3.org/2000/svg">
|
||||
<path fill="black" d="M248.625,89.25 V0 l-127.5,127.5 l127.5,127.5 V140.25 c84.15,0,153,68.85,153,153 c0,84.15-68.85,153-153,153 c-84.15,0-153-68.85-153-153 h-51 c0,112.2,91.8,204,204,204 s204-91.8,204-204 S360.825,89.25,248.625,89.25z"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 354 B |
51
viewer/src/launch.ts
Normal file
51
viewer/src/launch.ts
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
import type { GameState, Move } from 'container-engine';
|
||||
import { EventEmitter } from 'events';
|
||||
import Vue from 'vue';
|
||||
import Game from './components/Game.vue';
|
||||
import type { Preferences } from './types/ui-data';
|
||||
|
||||
function launch(selector: string) {
|
||||
let params: {
|
||||
state: null | GameState;
|
||||
player?: number;
|
||||
emitter: EventEmitter;
|
||||
preferences: Preferences;
|
||||
} = {
|
||||
state: null,
|
||||
emitter: new EventEmitter(),
|
||||
preferences: {
|
||||
sound: true,
|
||||
disableHelp: false,
|
||||
},
|
||||
};
|
||||
|
||||
const app = new Vue({
|
||||
render: (h) => h(Game, { props: params }, []),
|
||||
}).$mount(selector);
|
||||
|
||||
const item: EventEmitter = new EventEmitter();
|
||||
|
||||
params.emitter.on('move', (move: Move) => item.emit('move', move));
|
||||
params.emitter.on('addLog', (data: string[]) => item.emit('addLog', data));
|
||||
params.emitter.on('replaceLog', (data: string[]) => item.emit('replaceLog', data));
|
||||
|
||||
item.addListener('state', (data) => {
|
||||
params.state = data;
|
||||
app.$forceUpdate();
|
||||
app.$nextTick().then(() => item.emit('ready'));
|
||||
});
|
||||
item.addListener('state:updated', () => item.emit('fetchState'));
|
||||
item.addListener('player', (data) => {
|
||||
params.player = data.index;
|
||||
app.$forceUpdate();
|
||||
});
|
||||
item.addListener('preferences', (data) => {
|
||||
params.preferences = { ...params.preferences, ...data };
|
||||
app.$forceUpdate();
|
||||
});
|
||||
item.addListener('gamelog', (_) => item.emit('fetchState'));
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
export default launch;
|
||||
3
viewer/src/main.ts
Normal file
3
viewer/src/main.ts
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
import launchSelfContained from './self-contained';
|
||||
|
||||
launchSelfContained();
|
||||
65
viewer/src/self-contained.ts
Normal file
65
viewer/src/self-contained.ts
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
import { move as execMove, Move, setup, stripSecret } from 'container-engine';
|
||||
import { moveAI } from 'container-engine/src/engine';
|
||||
import { cloneDeep } from 'lodash';
|
||||
import launch from './launch';
|
||||
|
||||
function launchSelfContained(selector = '#app') {
|
||||
const strip = false;
|
||||
|
||||
const emitter = launch(selector);
|
||||
|
||||
let gameState = setup(5, {});
|
||||
|
||||
for (let i = 0; i < gameState.players.length; i++) {
|
||||
gameState.players[i].name = `Player ${i + 1}`;
|
||||
}
|
||||
|
||||
const playerIndex = 1;
|
||||
|
||||
for (const player of gameState.players) {
|
||||
if (player.id != playerIndex) player.isAI = true;
|
||||
}
|
||||
|
||||
emitter.on('move', async (move: Move) => {
|
||||
console.log('move received', move);
|
||||
gameState = execMove(gameState, move, playerIndex);
|
||||
console.log('new game state', gameState);
|
||||
|
||||
emitter.emit('state', cloneDeep(strip ? stripSecret(gameState, playerIndex) : gameState));
|
||||
|
||||
let delay = 800;
|
||||
while (gameState.players.some((pl) => pl.isAI && pl.availableMoves)) {
|
||||
gameState = moveAI(
|
||||
gameState,
|
||||
gameState.players.findIndex((pl) => pl.isAI && pl.availableMoves)
|
||||
);
|
||||
let newState = cloneDeep(strip ? stripSecret(gameState, playerIndex) : gameState);
|
||||
setTimeout(() => emitter.emit('state', newState), delay);
|
||||
delay += 800;
|
||||
}
|
||||
|
||||
console.log('available moves', gameState.players[playerIndex].availableMoves);
|
||||
});
|
||||
|
||||
emitter.on('fetchSate', () =>
|
||||
emitter.emit('state', cloneDeep(strip ? stripSecret(gameState, playerIndex) : gameState))
|
||||
);
|
||||
|
||||
emitter.emit('player', { index: playerIndex });
|
||||
emitter.emit('state', cloneDeep(strip ? stripSecret(gameState, playerIndex) : gameState));
|
||||
|
||||
let delay = 800;
|
||||
while (gameState.players.some((pl) => pl.isAI && pl.availableMoves)) {
|
||||
gameState = moveAI(
|
||||
gameState,
|
||||
gameState.players.findIndex((pl) => pl.isAI && pl.availableMoves)
|
||||
);
|
||||
let newState = cloneDeep(strip ? stripSecret(gameState, playerIndex) : gameState);
|
||||
setTimeout(() => emitter.emit('state', newState), delay);
|
||||
delay += 800;
|
||||
}
|
||||
|
||||
console.log('available moves', gameState.players[playerIndex].availableMoves);
|
||||
}
|
||||
|
||||
export default launchSelfContained;
|
||||
13
viewer/src/shims-tsx.d.ts
vendored
Normal file
13
viewer/src/shims-tsx.d.ts
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import Vue, { VNode } from 'vue';
|
||||
|
||||
declare global {
|
||||
namespace JSX {
|
||||
// tslint:disable no-empty-interface
|
||||
interface Element extends VNode {}
|
||||
// tslint:disable no-empty-interface
|
||||
interface ElementClass extends Vue {}
|
||||
interface IntrinsicElements {
|
||||
[elem: string]: any;
|
||||
}
|
||||
}
|
||||
}
|
||||
4
viewer/src/shims-vue.d.ts
vendored
Normal file
4
viewer/src/shims-vue.d.ts
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
declare module '*.vue' {
|
||||
import Vue from 'vue';
|
||||
export default Vue;
|
||||
}
|
||||
72
viewer/src/types/ui-data.ts
Normal file
72
viewer/src/types/ui-data.ts
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
import { ContainerPiece, ShipPosition } from 'container-engine/src/gamestate';
|
||||
import PieceComponent from '../components/pieces/Piece.vue';
|
||||
|
||||
export interface UIData {
|
||||
dragged?: PieceComponent | null;
|
||||
waitingAnimations: number;
|
||||
}
|
||||
|
||||
export type Preferences = {
|
||||
sound: boolean;
|
||||
disableHelp: boolean;
|
||||
};
|
||||
|
||||
export interface Piece {
|
||||
id: string;
|
||||
x: number;
|
||||
y: number;
|
||||
owner?: number;
|
||||
color?: string;
|
||||
rotate?: number;
|
||||
state?: string;
|
||||
}
|
||||
|
||||
export interface ShipType extends Piece {
|
||||
containers: ContainerPiece[];
|
||||
position: ShipPosition;
|
||||
}
|
||||
|
||||
export enum PieceType {
|
||||
Warehouse = 'warehouse',
|
||||
Factory = 'factory',
|
||||
Container = 'container',
|
||||
Ship = 'ship',
|
||||
Loan = 'loan',
|
||||
}
|
||||
|
||||
export enum DropZoneType {
|
||||
Ship = 'ship',
|
||||
PlayerHarbor11 = 'playerHarbor11',
|
||||
PlayerHarbor12 = 'playerHarbor12',
|
||||
PlayerHarbor13 = 'playerHarbor13',
|
||||
PlayerHarbor14 = 'playerHarbor14',
|
||||
PlayerHarbor21 = 'playerHarbor21',
|
||||
PlayerHarbor22 = 'playerHarbor22',
|
||||
PlayerHarbor23 = 'playerHarbor23',
|
||||
PlayerHarbor24 = 'playerHarbor24',
|
||||
PlayerHarbor31 = 'playerHarbor31',
|
||||
PlayerHarbor32 = 'playerHarbor32',
|
||||
PlayerHarbor33 = 'playerHarbor33',
|
||||
PlayerHarbor34 = 'playerHarbor34',
|
||||
PlayerHarbor41 = 'playerHarbor41',
|
||||
PlayerHarbor42 = 'playerHarbor42',
|
||||
PlayerHarbor43 = 'playerHarbor43',
|
||||
PlayerHarbor44 = 'playerHarbor44',
|
||||
Factory = 'factory',
|
||||
FactoryStore = 'factoryStore',
|
||||
Warehouse = 'warehouse',
|
||||
WarehouseStore = 'warehouseStore',
|
||||
OpenSea = 'openSea',
|
||||
IslandHarbor = 'islandHarbor',
|
||||
GetLoan = 'getLoan',
|
||||
PayLoan = 'payLoan',
|
||||
Supply = 'supply',
|
||||
}
|
||||
|
||||
export enum ContainerState {
|
||||
OnBoard = 'onBoard',
|
||||
OnFactoryStore = 'onFactoryStore',
|
||||
OnWarehouseStore = 'onWarehouseStore',
|
||||
OnShip = 'onShip',
|
||||
OnIsland = 'onIsland',
|
||||
}
|
||||
8
viewer/src/wrapper.ts
Normal file
8
viewer/src/wrapper.ts
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
// Import vue component
|
||||
import launch from './launch';
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
(window as any).container = { launch };
|
||||
}
|
||||
|
||||
export default launch;
|
||||
13
viewer/tests/unit/example.spec.ts
Normal file
13
viewer/tests/unit/example.spec.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import HelloWorld from '@/components/HelloWorld.vue';
|
||||
import { shallowMount } from '@vue/test-utils';
|
||||
import { expect } from 'chai';
|
||||
|
||||
describe('HelloWorld.vue', () => {
|
||||
it('renders props.msg when passed', () => {
|
||||
const msg = 'new message';
|
||||
const wrapper = shallowMount(HelloWorld, {
|
||||
propsData: { msg },
|
||||
});
|
||||
expect(wrapper.text()).to.include(msg);
|
||||
});
|
||||
});
|
||||
23
viewer/tsconfig.json
Normal file
23
viewer/tsconfig.json
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "esnext",
|
||||
"module": "esnext",
|
||||
"strict": true,
|
||||
"jsx": "preserve",
|
||||
"importHelpers": true,
|
||||
"moduleResolution": "node",
|
||||
"experimentalDecorators": true,
|
||||
"esModuleInterop": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"noImplicitAny": false,
|
||||
"sourceMap": true,
|
||||
"baseUrl": ".",
|
||||
"types": ["webpack-env", "mocha", "chai"],
|
||||
"paths": {
|
||||
"@/*": ["src/*"]
|
||||
},
|
||||
"lib": ["esnext", "dom", "dom.iterable", "scripthost"]
|
||||
},
|
||||
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue", "tests/**/*.ts", "tests/**/*.tsx"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
6
viewer/vue.config.js
Normal file
6
viewer/vue.config.js
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
module.exports = {
|
||||
devServer: {
|
||||
// For gitpod, it needs to be disabled
|
||||
disableHostCheck: true,
|
||||
},
|
||||
};
|
||||
Loading…
Add table
Reference in a new issue