Add continuous integration
This commit is contained in:
parent
7220b4aace
commit
50b57cb24d
59 changed files with 17229 additions and 12421 deletions
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 .
|
||||||
|
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 .
|
||||||
|
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
|
||||||
42
.gitpod.yml
42
.gitpod.yml
|
|
@ -1,30 +1,30 @@
|
||||||
image:
|
image:
|
||||||
file: .gitpod.dockerfile
|
file: .gitpod.dockerfile
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
- init: pnpm install
|
- init: pnpm install
|
||||||
command: cd viewer && pnpm serve
|
command: cd viewer && pnpm serve
|
||||||
|
|
||||||
ports:
|
ports:
|
||||||
- port: 8080
|
- port: 8080
|
||||||
onOpen: open-preview
|
onOpen: open-preview
|
||||||
|
|
||||||
github:
|
github:
|
||||||
prebuilds:
|
prebuilds:
|
||||||
# enable for the master/default branch (defaults to true)
|
# enable for the master/default branch (defaults to true)
|
||||||
master: true
|
master: true
|
||||||
# enable for pull requests coming from this repo (defaults to true)
|
# enable for pull requests coming from this repo (defaults to true)
|
||||||
pullRequests: true
|
pullRequests: true
|
||||||
# enable for pull requests coming from forks (defaults to false)
|
# enable for pull requests coming from forks (defaults to false)
|
||||||
pullRequestsFromForks: true
|
pullRequestsFromForks: true
|
||||||
# add a "Review in Gitpod" button as a comment to pull requests (defaults to true)
|
# add a "Review in Gitpod" button as a comment to pull requests (defaults to true)
|
||||||
addComment: true
|
addComment: true
|
||||||
# add a "Review in Gitpod" button to pull requests (defaults to false)
|
# add a "Review in Gitpod" button to pull requests (defaults to false)
|
||||||
addBadge: false
|
addBadge: false
|
||||||
# add a label once the prebuild is ready to pull requests (defaults to false)
|
# add a label once the prebuild is ready to pull requests (defaults to false)
|
||||||
addLabel: prebuilt-in-gitpod
|
addLabel: prebuilt-in-gitpod
|
||||||
|
|
||||||
vscode:
|
vscode:
|
||||||
extensions:
|
extensions:
|
||||||
- octref.vetur@0.32.0:03mwRhlVpWDul4qBChcVUA==
|
- octref.vetur@0.32.0:03mwRhlVpWDul4qBChcVUA==
|
||||||
- vtrois.gitmoji-vscode@1.0.5:iedq1JRjfM74CfhCoy3gJQ==
|
- vtrois.gitmoji-vscode@1.0.5:iedq1JRjfM74CfhCoy3gJQ==
|
||||||
|
|
|
||||||
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,3 +1,5 @@
|
||||||
{
|
{
|
||||||
"tabWidth": 4
|
"tabWidth": 4,
|
||||||
|
"singleQuote": true,
|
||||||
|
"printWidth": 120
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,8 @@ Mono repo containing the viewer & the engine for Gaia Container
|
||||||
|
|
||||||
Checkout their READMEs:
|
Checkout their READMEs:
|
||||||
|
|
||||||
- [engine](./engine/README.md)
|
- [engine](./engine/README.md)
|
||||||
- [viewer](./viewer/README.md)
|
- [viewer](./viewer/README.md)
|
||||||
|
|
||||||
## Demo
|
## Demo
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,13 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
root: true,
|
root: true,
|
||||||
env: {
|
env: {
|
||||||
node: true
|
node: true,
|
||||||
},
|
},
|
||||||
parserOptions: {
|
parserOptions: {
|
||||||
ecmaVersion: 2020
|
ecmaVersion: 2020,
|
||||||
},
|
},
|
||||||
parser: '@typescript-eslint/parser',
|
parser: '@typescript-eslint/parser',
|
||||||
plugins: [
|
plugins: ['@typescript-eslint'],
|
||||||
'@typescript-eslint',
|
|
||||||
],
|
|
||||||
extends: [
|
extends: [
|
||||||
'eslint:recommended',
|
'eslint:recommended',
|
||||||
'plugin:@typescript-eslint/eslint-recommended',
|
'plugin:@typescript-eslint/eslint-recommended',
|
||||||
|
|
@ -23,15 +21,14 @@ module.exports = {
|
||||||
// '@typescript-eslint/consistent-type-assertions': 'off',
|
// '@typescript-eslint/consistent-type-assertions': 'off',
|
||||||
// '@typescript-eslint/no-explicit-any': 'off',
|
// '@typescript-eslint/no-explicit-any': 'off',
|
||||||
'@typescript-eslint/no-empty-function': 'off',
|
'@typescript-eslint/no-empty-function': 'off',
|
||||||
'@typescript-eslint/no-unused-vars': ["warn", { "argsIgnorePattern": "^_" }],
|
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
|
||||||
'@typescript-eslint/explicit-function-return-type': 'off',
|
'@typescript-eslint/explicit-function-return-type': 'off',
|
||||||
'@typescript-eslint/no-use-before-define': 'off',
|
'@typescript-eslint/no-use-before-define': 'off',
|
||||||
'@typescript-eslint/no-namespace': 'off',
|
'@typescript-eslint/no-namespace': 'off',
|
||||||
'no-inner-declarations': 'off',
|
'no-inner-declarations': 'off',
|
||||||
'no-return-assign': 'off',
|
'no-return-assign': 'off',
|
||||||
// 'no-fallthrough': 'off',
|
// 'no-fallthrough': 'off',
|
||||||
quotes: 'off',
|
|
||||||
'no-empty': 'off',
|
'no-empty': 'off',
|
||||||
'quotes': ['error', 'single']
|
quotes: ['error', 'single'],
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
1
engine/.gitignore
vendored
Normal file
1
engine/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
/dist
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
language: node_js
|
language: node_js
|
||||||
|
|
||||||
node_js:
|
node_js:
|
||||||
- node
|
- node
|
||||||
|
|
|
||||||
12
engine/.vscode/launch.json
vendored
12
engine/.vscode/launch.json
vendored
|
|
@ -14,21 +14,17 @@
|
||||||
"--slow",
|
"--slow",
|
||||||
"5000",
|
"5000",
|
||||||
"--colors",
|
"--colors",
|
||||||
"${workspaceFolder}/src/*.spec.ts",
|
"${workspaceFolder}/src/*.spec.ts"
|
||||||
],
|
],
|
||||||
"internalConsoleOptions": "openOnSessionStart",
|
"internalConsoleOptions": "openOnSessionStart",
|
||||||
"skipFiles": [
|
"skipFiles": ["<node_internals>/**"]
|
||||||
"<node_internals>/**"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "node",
|
"type": "node",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"name": "Launch Program",
|
"name": "Launch Program",
|
||||||
"skipFiles": [
|
"skipFiles": ["<node_internals>/**"],
|
||||||
"<node_internals>/**"
|
|
||||||
],
|
|
||||||
"program": "${workspaceFolder}/index.js"
|
"program": "${workspaceFolder}/index.js"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
2
engine/.vscode/settings.json
vendored
2
engine/.vscode/settings.json
vendored
|
|
@ -1,3 +1,3 @@
|
||||||
{
|
{
|
||||||
"editor.formatOnSave": true
|
"editor.formatOnSave": true
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
export { setup, currentPlayers, move, stripSecret, ended, reconstructState } from './src/engine';
|
export { availableMoves, AvailableMoves } from './src/available-moves';
|
||||||
export type { GameState, Player, PointCard } from './src/gamestate';
|
export { currentPlayers, ended, move, reconstructState, setup, stripSecret } from './src/engine';
|
||||||
export { MoveName, Move, Moves } from './src/move';
|
|
||||||
export { Phase } from './src/gamestate';
|
export { Phase } from './src/gamestate';
|
||||||
|
export type { GameState, Player, PointCard } from './src/gamestate';
|
||||||
export { GameEventName, LogItem } from './src/log';
|
export { GameEventName, LogItem } from './src/log';
|
||||||
export { availableMoves, AvailableMoves } from './src/available-moves';
|
export { Move, MoveName, Moves } from './src/move';
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"prepublishOnly": "npm run test && npm run clean && tsc",
|
"prepublishOnly": "npm run test && npm run clean && tsc",
|
||||||
"build": "npm run clean && tsc",
|
"build": "npm run clean && tsc",
|
||||||
"clean": "del /q dist",
|
"clean": "rm -Rf dist",
|
||||||
"lint": "eslint . --ext .ts",
|
"lint": "eslint . --ext .ts",
|
||||||
"test": "mocha -r ts-node/register src/**/*.spec.ts src/*.spec.ts"
|
"test": "mocha -r ts-node/register src/**/*.spec.ts src/*.spec.ts"
|
||||||
},
|
},
|
||||||
|
|
@ -47,4 +47,4 @@
|
||||||
"dist",
|
"dist",
|
||||||
"tsconfig.json"
|
"tsconfig.json"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
4093
engine/pnpm-lock.yaml
generated
4093
engine/pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load diff
|
|
@ -4,8 +4,14 @@ import { MoveName } from './move';
|
||||||
|
|
||||||
export interface AvailableMoves {
|
export interface AvailableMoves {
|
||||||
[MoveName.DomesticSale]?: ContainerPiece[];
|
[MoveName.DomesticSale]?: ContainerPiece[];
|
||||||
[MoveName.BuyFromFactory]?: Array<{ player: number; piece: ContainerPiece }>;
|
[MoveName.BuyFromFactory]?: Array<{
|
||||||
[MoveName.BuyFromWarehouse]?: Array<{ player: number; piece: ContainerPiece }>;
|
player: number;
|
||||||
|
piece: ContainerPiece;
|
||||||
|
}>;
|
||||||
|
[MoveName.BuyFromWarehouse]?: Array<{
|
||||||
|
player: number;
|
||||||
|
piece: ContainerPiece;
|
||||||
|
}>;
|
||||||
[MoveName.BuyFactory]?: ContainerColor[];
|
[MoveName.BuyFactory]?: ContainerColor[];
|
||||||
[MoveName.BuyWarehouse]?: boolean[];
|
[MoveName.BuyWarehouse]?: boolean[];
|
||||||
[MoveName.GetLoan]?: boolean[];
|
[MoveName.GetLoan]?: boolean[];
|
||||||
|
|
@ -25,37 +31,31 @@ export function availableMoves(G: GameState, player: Player): AvailableMoves {
|
||||||
switch (G.phase) {
|
switch (G.phase) {
|
||||||
case Phase.Bid: {
|
case Phase.Bid: {
|
||||||
const moves = {
|
const moves = {
|
||||||
[MoveName.Bid]: [true]
|
[MoveName.Bid]: [true],
|
||||||
};
|
};
|
||||||
|
|
||||||
if (player.loans.length < 2)
|
if (player.loans.length < 2) moves[MoveName.GetLoan] = [true];
|
||||||
moves[MoveName.GetLoan] = [true];
|
|
||||||
|
|
||||||
|
|
||||||
// Undo
|
// Undo
|
||||||
const lastLog = G.log[G.log.length - 1];
|
const lastLog = G.log[G.log.length - 1];
|
||||||
if (lastLog.type == 'move' && lastLog.player == G.currentPlayer)
|
if (lastLog.type == 'move' && lastLog.player == G.currentPlayer) moves[MoveName.Undo] = [true];
|
||||||
moves[MoveName.Undo] = [true];
|
|
||||||
|
|
||||||
return moves;
|
return moves;
|
||||||
}
|
}
|
||||||
|
|
||||||
case Phase.AcceptDecline: {
|
case Phase.AcceptDecline: {
|
||||||
const moves: AvailableMoves = {
|
const moves: AvailableMoves = {
|
||||||
[MoveName.Accept]: G.highestBidders
|
[MoveName.Accept]: G.highestBidders,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (player.loans.length < 2)
|
if (player.loans.length < 2) moves[MoveName.GetLoan] = [true];
|
||||||
moves[MoveName.GetLoan] = [true];
|
|
||||||
|
|
||||||
const highestBidder = G.players[G.highestBidders[0]];
|
const highestBidder = G.players[G.highestBidders[0]];
|
||||||
if (player.money >= highestBidder.bid + highestBidder.additionalBid)
|
if (player.money >= highestBidder.bid + highestBidder.additionalBid) moves[MoveName.Decline] = [true];
|
||||||
moves[MoveName.Decline] = [true];
|
|
||||||
|
|
||||||
// Undo
|
// Undo
|
||||||
const lastLog = G.log[G.log.length - 1];
|
const lastLog = G.log[G.log.length - 1];
|
||||||
if (lastLog.type == 'move' && lastLog.player == G.currentPlayer)
|
if (lastLog.type == 'move' && lastLog.player == G.currentPlayer) moves[MoveName.Undo] = [true];
|
||||||
moves[MoveName.Undo] = [true];
|
|
||||||
|
|
||||||
return moves;
|
return moves;
|
||||||
}
|
}
|
||||||
|
|
@ -66,32 +66,54 @@ export function availableMoves(G: GameState, player: Player): AvailableMoves {
|
||||||
// DomesticSale
|
// DomesticSale
|
||||||
if (player.actions > 0 && G.round > 1) {
|
if (player.actions > 0 && G.round > 1) {
|
||||||
if (player.containersOnFactoryStore.length > 0) {
|
if (player.containersOnFactoryStore.length > 0) {
|
||||||
moves[MoveName.DomesticSale] = player.containersOnFactoryStore.map(c => c.piece);
|
moves[MoveName.DomesticSale] = player.containersOnFactoryStore.map((c) => c.piece);
|
||||||
} else if (player.containersOnWarehouseStore.length > 0) {
|
} else if (player.containersOnWarehouseStore.length > 0) {
|
||||||
moves[MoveName.DomesticSale] = player.containersOnWarehouseStore.map(c => c.piece);
|
moves[MoveName.DomesticSale] = player.containersOnWarehouseStore.map((c) => c.piece);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// BuyFromFactory
|
// BuyFromFactory
|
||||||
if (player.actions > 0 || player.lastMove?.name === MoveName.BuyFromFactory) {
|
if (player.actions > 0 || player.lastMove?.name === MoveName.BuyFromFactory) {
|
||||||
if (player.containersOnWarehouseStore.length < player.warehouses.length) {
|
if (player.containersOnWarehouseStore.length < player.warehouses.length) {
|
||||||
const containersAvailable: { player: number; container: ContainerOnStore }[] = [];
|
const containersAvailable: {
|
||||||
const playersToBuy: Player[] = player.actions === 0 && player.lastMove?.name === MoveName.BuyFromFactory ?
|
player: number;
|
||||||
[G.players[player.lastMove.data.player]] : G.players.filter(p => p.id !== player.id);
|
container: ContainerOnStore;
|
||||||
playersToBuy.forEach(p => {
|
}[] = [];
|
||||||
containersAvailable.push(...p.containersOnFactoryStore.map(c => ({ player: p.id, container: c })));
|
const playersToBuy: Player[] =
|
||||||
|
player.actions === 0 && player.lastMove?.name === MoveName.BuyFromFactory
|
||||||
|
? [G.players[player.lastMove.data.player]]
|
||||||
|
: G.players.filter((p) => p.id !== player.id);
|
||||||
|
playersToBuy.forEach((p) => {
|
||||||
|
containersAvailable.push(
|
||||||
|
...p.containersOnFactoryStore.map((c) => ({
|
||||||
|
player: p.id,
|
||||||
|
container: c,
|
||||||
|
}))
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
const buyable = containersAvailable.filter(c => c.container.price <= player.money).map(c => ({ player: c.player, piece: c.container.piece }));
|
const buyable = containersAvailable
|
||||||
|
.filter((c) => c.container.price <= player.money)
|
||||||
|
.map((c) => ({
|
||||||
|
player: c.player,
|
||||||
|
piece: c.container.piece,
|
||||||
|
}));
|
||||||
|
|
||||||
if (buyable.length > 0)
|
if (buyable.length > 0) moves[MoveName.BuyFromFactory] = buyable;
|
||||||
moves[MoveName.BuyFromFactory] = buyable;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// BuyFromWarehouse
|
// BuyFromWarehouse
|
||||||
if (player.actions > 0 || player.lastMove?.name === MoveName.Sail || player.lastMove?.name === MoveName.BuyFromWarehouse) {
|
if (
|
||||||
if (player.ship.shipPosition !== ShipPosition.Island && player.ship.shipPosition !== ShipPosition.OpenSea && player.ship.containers.length < 5) {
|
player.actions > 0 ||
|
||||||
|
player.lastMove?.name === MoveName.Sail ||
|
||||||
|
player.lastMove?.name === MoveName.BuyFromWarehouse
|
||||||
|
) {
|
||||||
|
if (
|
||||||
|
player.ship.shipPosition !== ShipPosition.Island &&
|
||||||
|
player.ship.shipPosition !== ShipPosition.OpenSea &&
|
||||||
|
player.ship.containers.length < 5
|
||||||
|
) {
|
||||||
let otherPlayer: Player;
|
let otherPlayer: Player;
|
||||||
switch (player.ship.shipPosition) {
|
switch (player.ship.shipPosition) {
|
||||||
case ShipPosition.PlayerHarbor01:
|
case ShipPosition.PlayerHarbor01:
|
||||||
|
|
@ -131,14 +153,19 @@ export function availableMoves(G: GameState, player: Player): AvailableMoves {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (otherPlayer.containersOnWarehouseStore.length > 0) {
|
if (otherPlayer.containersOnWarehouseStore.length > 0) {
|
||||||
const buyable: { player: number; piece: ContainerPiece }[] = [];
|
const buyable: {
|
||||||
otherPlayer.containersOnWarehouseStore.forEach(c => {
|
player: number;
|
||||||
|
piece: ContainerPiece;
|
||||||
|
}[] = [];
|
||||||
|
otherPlayer.containersOnWarehouseStore.forEach((c) => {
|
||||||
if (c.price <= player.money)
|
if (c.price <= player.money)
|
||||||
buyable.push({ player: otherPlayer.id, piece: c.piece });
|
buyable.push({
|
||||||
|
player: otherPlayer.id,
|
||||||
|
piece: c.piece,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
if (buyable.length > 0)
|
if (buyable.length > 0) moves[MoveName.BuyFromWarehouse] = buyable;
|
||||||
moves[MoveName.BuyFromWarehouse] = buyable;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -146,13 +173,15 @@ export function availableMoves(G: GameState, player: Player): AvailableMoves {
|
||||||
// BuyFactory
|
// BuyFactory
|
||||||
if (player.actions > 0 && player.money >= (player.factories.length + 1) * 3) {
|
if (player.actions > 0 && player.money >= (player.factories.length + 1) * 3) {
|
||||||
const factoriesLeft: ContainerColor[] = [];
|
const factoriesLeft: ContainerColor[] = [];
|
||||||
Object.values(ContainerColor).forEach(color => {
|
Object.values(ContainerColor).forEach((color) => {
|
||||||
if (G.factoriesLeft.filter(f => f.color.toString() === color).length > 0 && player.factories.map(f => f.color).indexOf(color) == -1)
|
if (
|
||||||
|
G.factoriesLeft.filter((f) => f.color.toString() === color).length > 0 &&
|
||||||
|
player.factories.map((f) => f.color).indexOf(color) == -1
|
||||||
|
)
|
||||||
factoriesLeft.push(color);
|
factoriesLeft.push(color);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (factoriesLeft.length > 0)
|
if (factoriesLeft.length > 0) moves[MoveName.BuyFactory] = factoriesLeft;
|
||||||
moves[MoveName.BuyFactory] = factoriesLeft;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// BuyWarehouse
|
// BuyWarehouse
|
||||||
|
|
@ -162,24 +191,30 @@ export function availableMoves(G: GameState, player: Player): AvailableMoves {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetLoan
|
// GetLoan
|
||||||
if (player.loans.length < 2)
|
if (player.loans.length < 2) moves[MoveName.GetLoan] = [true];
|
||||||
moves[MoveName.GetLoan] = [true];
|
|
||||||
|
|
||||||
// PayLoan
|
// PayLoan
|
||||||
if (player.loans.length > 0 && player.money >= 10)
|
if (player.loans.length > 0 && player.money >= 10) moves[MoveName.PayLoan] = [true];
|
||||||
moves[MoveName.PayLoan] = [true];
|
|
||||||
|
|
||||||
// ArrangeFactory
|
// ArrangeFactory
|
||||||
if (player.actions > 0 || player.lastMove?.name === MoveName.Produce || player.lastMove?.name === MoveName.ArrangeFactory) {
|
if (
|
||||||
|
player.actions > 0 ||
|
||||||
|
player.lastMove?.name === MoveName.Produce ||
|
||||||
|
player.lastMove?.name === MoveName.ArrangeFactory
|
||||||
|
) {
|
||||||
if (player.containersOnFactoryStore.length > 0) {
|
if (player.containersOnFactoryStore.length > 0) {
|
||||||
moves[MoveName.ArrangeFactory] = player.containersOnFactoryStore.map(c => c.piece);
|
moves[MoveName.ArrangeFactory] = player.containersOnFactoryStore.map((c) => c.piece);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ArrangeWarehouse
|
// ArrangeWarehouse
|
||||||
if (player.actions > 0 || player.lastMove?.name === MoveName.BuyFromFactory || player.lastMove?.name === MoveName.ArrangeWarehouse) {
|
if (
|
||||||
|
player.actions > 0 ||
|
||||||
|
player.lastMove?.name === MoveName.BuyFromFactory ||
|
||||||
|
player.lastMove?.name === MoveName.ArrangeWarehouse
|
||||||
|
) {
|
||||||
if (player.containersOnWarehouseStore.length > 0) {
|
if (player.containersOnWarehouseStore.length > 0) {
|
||||||
moves[MoveName.ArrangeWarehouse] = player.containersOnWarehouseStore.map(c => c.piece);
|
moves[MoveName.ArrangeWarehouse] = player.containersOnWarehouseStore.map((c) => c.piece);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -187,12 +222,28 @@ export function availableMoves(G: GameState, player: Player): AvailableMoves {
|
||||||
if (player.actions > 0) {
|
if (player.actions > 0) {
|
||||||
const positions: ShipPosition[] = [];
|
const positions: ShipPosition[] = [];
|
||||||
if (player.ship.shipPosition === ShipPosition.OpenSea) {
|
if (player.ship.shipPosition === ShipPosition.OpenSea) {
|
||||||
positions.push(...G.players.filter(p => p !== player).map(p => ShipPosition['PlayerHarbor' + p.id + '1' as keyof ShipPosition]));
|
positions.push(
|
||||||
positions.push(...G.players.filter(p => p !== player).map(p => ShipPosition['PlayerHarbor' + p.id + '2' as keyof ShipPosition]));
|
...G.players
|
||||||
positions.push(...G.players.filter(p => p !== player).map(p => ShipPosition['PlayerHarbor' + p.id + '3' as keyof ShipPosition]));
|
.filter((p) => p !== player)
|
||||||
positions.push(...G.players.filter(p => p !== player).map(p => ShipPosition['PlayerHarbor' + p.id + '4' as keyof ShipPosition]));
|
.map((p) => ShipPosition[('PlayerHarbor' + p.id + '1') as keyof ShipPosition])
|
||||||
|
);
|
||||||
|
positions.push(
|
||||||
|
...G.players
|
||||||
|
.filter((p) => p !== player)
|
||||||
|
.map((p) => ShipPosition[('PlayerHarbor' + p.id + '2') as keyof ShipPosition])
|
||||||
|
);
|
||||||
|
positions.push(
|
||||||
|
...G.players
|
||||||
|
.filter((p) => p !== player)
|
||||||
|
.map((p) => ShipPosition[('PlayerHarbor' + p.id + '3') as keyof ShipPosition])
|
||||||
|
);
|
||||||
|
positions.push(
|
||||||
|
...G.players
|
||||||
|
.filter((p) => p !== player)
|
||||||
|
.map((p) => ShipPosition[('PlayerHarbor' + p.id + '4') as keyof ShipPosition])
|
||||||
|
);
|
||||||
|
|
||||||
remove(positions, pos => G.players.map(p => p.ship.shipPosition).indexOf(pos) != -1);
|
remove(positions, (pos) => G.players.map((p) => p.ship.shipPosition).indexOf(pos) != -1);
|
||||||
|
|
||||||
if (player.ship.containers.length > 0) {
|
if (player.ship.containers.length > 0) {
|
||||||
positions.push(ShipPosition.Island);
|
positions.push(ShipPosition.Island);
|
||||||
|
|
@ -208,18 +259,28 @@ export function availableMoves(G: GameState, player: Player): AvailableMoves {
|
||||||
|
|
||||||
// Produce
|
// Produce
|
||||||
const containersLeft: ContainerColor[] = [];
|
const containersLeft: ContainerColor[] = [];
|
||||||
Object.keys(ContainerColor).forEach(key => {
|
Object.keys(ContainerColor).forEach((key) => {
|
||||||
if (G.containersLeft.filter(f => f.color.toString() === ContainerColor[key]).length > 0)
|
if (G.containersLeft.filter((f) => f.color.toString() === ContainerColor[key]).length > 0)
|
||||||
containersLeft.push(ContainerColor[key]);
|
containersLeft.push(ContainerColor[key]);
|
||||||
});
|
});
|
||||||
|
|
||||||
if ((player.produced.length === 0 && player.money >= 1 && player.actions > 0) || (player.lastMove?.name === MoveName.Produce)) {
|
if (
|
||||||
if (player.containersOnFactoryStore.length < player.factories.length * 2 && player.produced.length < player.factories.length) {
|
(player.produced.length === 0 && player.money >= 1 && player.actions > 0) ||
|
||||||
|
player.lastMove?.name === MoveName.Produce
|
||||||
|
) {
|
||||||
|
if (
|
||||||
|
player.containersOnFactoryStore.length < player.factories.length * 2 &&
|
||||||
|
player.produced.length < player.factories.length
|
||||||
|
) {
|
||||||
const canProduce: ContainerColor[] = [];
|
const canProduce: ContainerColor[] = [];
|
||||||
player.factories.forEach(factory => {
|
player.factories.forEach((factory) => {
|
||||||
if (canProduce.indexOf(factory.color) === -1) {
|
if (canProduce.indexOf(factory.color) === -1) {
|
||||||
const totalFactories = player.factories.filter(factoryColor => factoryColor === factory).length;
|
const totalFactories = player.factories.filter(
|
||||||
const producedContainers = player.produced.filter(producedColor => producedColor === factory.color).length;
|
(factoryColor) => factoryColor === factory
|
||||||
|
).length;
|
||||||
|
const producedContainers = player.produced.filter(
|
||||||
|
(producedColor) => producedColor === factory.color
|
||||||
|
).length;
|
||||||
|
|
||||||
if (totalFactories > producedContainers && containersLeft.indexOf(factory.color) !== -1)
|
if (totalFactories > producedContainers && containersLeft.indexOf(factory.color) !== -1)
|
||||||
canProduce.push(factory.color);
|
canProduce.push(factory.color);
|
||||||
|
|
@ -227,8 +288,7 @@ export function availableMoves(G: GameState, player: Player): AvailableMoves {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (canProduce.length > 0) {
|
if (canProduce.length > 0) {
|
||||||
if (player.lastMove?.name === MoveName.Produce)
|
if (player.lastMove?.name === MoveName.Produce) moves = {};
|
||||||
moves = {};
|
|
||||||
|
|
||||||
moves[MoveName.Produce] = canProduce;
|
moves[MoveName.Produce] = canProduce;
|
||||||
}
|
}
|
||||||
|
|
@ -237,8 +297,7 @@ export function availableMoves(G: GameState, player: Player): AvailableMoves {
|
||||||
|
|
||||||
// Undo
|
// Undo
|
||||||
const lastLog = G.log[G.log.length - 1];
|
const lastLog = G.log[G.log.length - 1];
|
||||||
if (lastLog.type == 'move' && lastLog.player == G.currentPlayer)
|
if (lastLog.type == 'move' && lastLog.player == G.currentPlayer) moves[MoveName.Undo] = [true];
|
||||||
moves[MoveName.Undo] = [true];
|
|
||||||
|
|
||||||
return moves;
|
return moves;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,51 +1,151 @@
|
||||||
import { ContainerColor, PointCard } from "./gamestate";
|
import { ContainerColor, PointCard } from './gamestate';
|
||||||
|
|
||||||
const pointCards: PointCard[] = [
|
const pointCards: PointCard[] = [
|
||||||
{
|
{
|
||||||
containerValues: [
|
containerValues: [
|
||||||
{ containerColor: ContainerColor.White, baseValue: 10, specialValue: 10 },
|
{
|
||||||
{ containerColor: ContainerColor.Orange, baseValue: 5, specialValue: 10 },
|
containerColor: ContainerColor.White,
|
||||||
{ containerColor: ContainerColor.Tan, baseValue: 6, specialValue: 6 },
|
baseValue: 10,
|
||||||
{ containerColor: ContainerColor.Brown, baseValue: 4, specialValue: 4 },
|
specialValue: 10,
|
||||||
{ containerColor: ContainerColor.Black, baseValue: 2, specialValue: 2 }
|
},
|
||||||
]
|
{
|
||||||
|
containerColor: ContainerColor.Orange,
|
||||||
|
baseValue: 5,
|
||||||
|
specialValue: 10,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
containerColor: ContainerColor.Tan,
|
||||||
|
baseValue: 6,
|
||||||
|
specialValue: 6,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
containerColor: ContainerColor.Brown,
|
||||||
|
baseValue: 4,
|
||||||
|
specialValue: 4,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
containerColor: ContainerColor.Black,
|
||||||
|
baseValue: 2,
|
||||||
|
specialValue: 2,
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
containerValues: [
|
containerValues: [
|
||||||
{ containerColor: ContainerColor.Brown, baseValue: 10, specialValue: 10 },
|
{
|
||||||
{ containerColor: ContainerColor.Black, baseValue: 5, specialValue: 10 },
|
containerColor: ContainerColor.Brown,
|
||||||
{ containerColor: ContainerColor.White, baseValue: 6, specialValue: 6 },
|
baseValue: 10,
|
||||||
{ containerColor: ContainerColor.Orange, baseValue: 4, specialValue: 4 },
|
specialValue: 10,
|
||||||
{ containerColor: ContainerColor.Tan, baseValue: 2, specialValue: 2 }
|
},
|
||||||
]
|
{
|
||||||
|
containerColor: ContainerColor.Black,
|
||||||
|
baseValue: 5,
|
||||||
|
specialValue: 10,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
containerColor: ContainerColor.White,
|
||||||
|
baseValue: 6,
|
||||||
|
specialValue: 6,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
containerColor: ContainerColor.Orange,
|
||||||
|
baseValue: 4,
|
||||||
|
specialValue: 4,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
containerColor: ContainerColor.Tan,
|
||||||
|
baseValue: 2,
|
||||||
|
specialValue: 2,
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
containerValues: [
|
containerValues: [
|
||||||
{ containerColor: ContainerColor.Black, baseValue: 10, specialValue: 10 },
|
{
|
||||||
{ containerColor: ContainerColor.White, baseValue: 5, specialValue: 10 },
|
containerColor: ContainerColor.Black,
|
||||||
{ containerColor: ContainerColor.Orange, baseValue: 6, specialValue: 6 },
|
baseValue: 10,
|
||||||
{ containerColor: ContainerColor.Tan, baseValue: 4, specialValue: 4 },
|
specialValue: 10,
|
||||||
{ containerColor: ContainerColor.Brown, baseValue: 2, specialValue: 2 }
|
},
|
||||||
]
|
{
|
||||||
|
containerColor: ContainerColor.White,
|
||||||
|
baseValue: 5,
|
||||||
|
specialValue: 10,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
containerColor: ContainerColor.Orange,
|
||||||
|
baseValue: 6,
|
||||||
|
specialValue: 6,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
containerColor: ContainerColor.Tan,
|
||||||
|
baseValue: 4,
|
||||||
|
specialValue: 4,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
containerColor: ContainerColor.Brown,
|
||||||
|
baseValue: 2,
|
||||||
|
specialValue: 2,
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
containerValues: [
|
containerValues: [
|
||||||
{ containerColor: ContainerColor.Orange, baseValue: 10, specialValue: 10 },
|
{
|
||||||
{ containerColor: ContainerColor.Tan, baseValue: 5, specialValue: 10 },
|
containerColor: ContainerColor.Orange,
|
||||||
{ containerColor: ContainerColor.Brown, baseValue: 6, specialValue: 6 },
|
baseValue: 10,
|
||||||
{ containerColor: ContainerColor.Black, baseValue: 4, specialValue: 4 },
|
specialValue: 10,
|
||||||
{ containerColor: ContainerColor.White, baseValue: 2, specialValue: 2 }
|
},
|
||||||
]
|
{
|
||||||
|
containerColor: ContainerColor.Tan,
|
||||||
|
baseValue: 5,
|
||||||
|
specialValue: 10,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
containerColor: ContainerColor.Brown,
|
||||||
|
baseValue: 6,
|
||||||
|
specialValue: 6,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
containerColor: ContainerColor.Black,
|
||||||
|
baseValue: 4,
|
||||||
|
specialValue: 4,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
containerColor: ContainerColor.White,
|
||||||
|
baseValue: 2,
|
||||||
|
specialValue: 2,
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
containerValues: [
|
containerValues: [
|
||||||
{ containerColor: ContainerColor.Tan, baseValue: 10, specialValue: 10 },
|
{
|
||||||
{ containerColor: ContainerColor.Brown, baseValue: 5, specialValue: 10 },
|
containerColor: ContainerColor.Tan,
|
||||||
{ containerColor: ContainerColor.Black, baseValue: 6, specialValue: 6 },
|
baseValue: 10,
|
||||||
{ containerColor: ContainerColor.White, baseValue: 4, specialValue: 4 },
|
specialValue: 10,
|
||||||
{ containerColor: ContainerColor.Orange, baseValue: 2, specialValue: 2 }
|
},
|
||||||
]
|
{
|
||||||
|
containerColor: ContainerColor.Brown,
|
||||||
|
baseValue: 5,
|
||||||
|
specialValue: 10,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
containerColor: ContainerColor.Black,
|
||||||
|
baseValue: 6,
|
||||||
|
specialValue: 6,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
containerColor: ContainerColor.White,
|
||||||
|
baseValue: 4,
|
||||||
|
specialValue: 4,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
containerColor: ContainerColor.Orange,
|
||||||
|
baseValue: 2,
|
||||||
|
specialValue: 2,
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
export default pointCards;
|
export default pointCards;
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,9 @@
|
||||||
import { expect } from "chai";
|
import { expect } from 'chai';
|
||||||
import { availableMoves } from "./available-moves";
|
import { ended, setup } from './engine';
|
||||||
import { setup, move as execMove, ended } from './engine';
|
|
||||||
import { ContainerColor, ShipPosition } from "./gamestate";
|
|
||||||
import { Move } from './move';
|
|
||||||
|
|
||||||
describe("Engine", () => {
|
describe('Engine', () => {
|
||||||
it("should play full game", () => {
|
it('should play full game', () => {
|
||||||
const G = setup(5, { beginner: false }, "test");
|
const G = setup(5, { beginner: false }, 'test');
|
||||||
|
|
||||||
// G.currentPlayer = 0;
|
// G.currentPlayer = 0;
|
||||||
// G.players[0].actions = 2;
|
// G.players[0].actions = 2;
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,16 @@ import { cloneDeep, groupBy, isEqual } from 'lodash';
|
||||||
import seedrandom from 'seedrandom';
|
import seedrandom from 'seedrandom';
|
||||||
import { availableMoves } from './available-moves';
|
import { availableMoves } from './available-moves';
|
||||||
import pointCards from './cards';
|
import pointCards from './cards';
|
||||||
import { ContainerColor, ContainerPiece, FactoryPiece, GameOptions, GameState, Phase, Player, ShipPosition } from './gamestate';
|
import {
|
||||||
|
ContainerColor,
|
||||||
|
ContainerPiece,
|
||||||
|
FactoryPiece,
|
||||||
|
GameOptions,
|
||||||
|
GameState,
|
||||||
|
Phase,
|
||||||
|
Player,
|
||||||
|
ShipPosition,
|
||||||
|
} from './gamestate';
|
||||||
import { GameEventName, LogItem } from './log';
|
import { GameEventName, LogItem } from './log';
|
||||||
import { Move, MoveName, Moves } from './move';
|
import { Move, MoveName, Moves } from './move';
|
||||||
import { asserts, shuffle } from './utils';
|
import { asserts, shuffle } from './utils';
|
||||||
|
|
@ -22,7 +31,11 @@ export function setup(numPlayers: number, { beginner = true }: GameOptions, seed
|
||||||
pointCard: cards.shift()!,
|
pointCard: cards.shift()!,
|
||||||
factories: [],
|
factories: [],
|
||||||
warehouses: [],
|
warehouses: [],
|
||||||
ship: { piece: { id: 'S' + id }, containers: [], shipPosition: ShipPosition.OpenSea },
|
ship: {
|
||||||
|
piece: { id: 'S' + id },
|
||||||
|
containers: [],
|
||||||
|
shipPosition: ShipPosition.OpenSea,
|
||||||
|
},
|
||||||
containersOnFactoryStore: [],
|
containersOnFactoryStore: [],
|
||||||
containersOnWarehouseStore: [],
|
containersOnWarehouseStore: [],
|
||||||
containersOnIsland: [],
|
containersOnIsland: [],
|
||||||
|
|
@ -38,25 +51,35 @@ export function setup(numPlayers: number, { beginner = true }: GameOptions, seed
|
||||||
showBid: false,
|
showBid: false,
|
||||||
showAdditionalBid: false,
|
showAdditionalBid: false,
|
||||||
finalScore: 0,
|
finalScore: 0,
|
||||||
isAI: false
|
isAI: false,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
id = 0;
|
id = 0;
|
||||||
const totalContainers = players.length * 4;
|
const totalContainers = players.length * 4;
|
||||||
const containersLeft: ContainerPiece[] = [];
|
const containersLeft: ContainerPiece[] = [];
|
||||||
containersLeft.push(...new Array(totalContainers).fill(0).map(_ => ({ id: 'C' + id++, color: ContainerColor.Brown })));
|
containersLeft.push(
|
||||||
containersLeft.push(...new Array(totalContainers).fill(0).map(_ => ({ id: 'C' + id++, color: ContainerColor.White })));
|
...new Array(totalContainers).fill(0).map((_) => ({ id: 'C' + id++, color: ContainerColor.Brown }))
|
||||||
containersLeft.push(...new Array(totalContainers).fill(0).map(_ => ({ id: 'C' + id++, color: ContainerColor.Black })));
|
);
|
||||||
containersLeft.push(...new Array(totalContainers).fill(0).map(_ => ({ id: 'C' + id++, color: ContainerColor.Orange })));
|
containersLeft.push(
|
||||||
containersLeft.push(...new Array(totalContainers).fill(0).map(_ => ({ id: 'C' + id++, color: ContainerColor.Tan })));
|
...new Array(totalContainers).fill(0).map((_) => ({ id: 'C' + id++, color: ContainerColor.White }))
|
||||||
|
);
|
||||||
|
containersLeft.push(
|
||||||
|
...new Array(totalContainers).fill(0).map((_) => ({ id: 'C' + id++, color: ContainerColor.Black }))
|
||||||
|
);
|
||||||
|
containersLeft.push(
|
||||||
|
...new Array(totalContainers).fill(0).map((_) => ({ id: 'C' + id++, color: ContainerColor.Orange }))
|
||||||
|
);
|
||||||
|
containersLeft.push(
|
||||||
|
...new Array(totalContainers).fill(0).map((_) => ({ id: 'C' + id++, color: ContainerColor.Tan }))
|
||||||
|
);
|
||||||
|
|
||||||
id = 0;
|
id = 0;
|
||||||
const factoriesLeft: FactoryPiece[] = [];
|
const factoriesLeft: FactoryPiece[] = [];
|
||||||
factoriesLeft.push(...new Array(5).fill(0).map(_ => ({ id: 'F' + id++, color: ContainerColor.Brown })));
|
factoriesLeft.push(...new Array(5).fill(0).map((_) => ({ id: 'F' + id++, color: ContainerColor.Brown })));
|
||||||
factoriesLeft.push(...new Array(5).fill(0).map(_ => ({ id: 'F' + id++, color: ContainerColor.White })));
|
factoriesLeft.push(...new Array(5).fill(0).map((_) => ({ id: 'F' + id++, color: ContainerColor.White })));
|
||||||
factoriesLeft.push(...new Array(5).fill(0).map(_ => ({ id: 'F' + id++, color: ContainerColor.Black })));
|
factoriesLeft.push(...new Array(5).fill(0).map((_) => ({ id: 'F' + id++, color: ContainerColor.Black })));
|
||||||
factoriesLeft.push(...new Array(5).fill(0).map(_ => ({ id: 'F' + id++, color: ContainerColor.Orange })));
|
factoriesLeft.push(...new Array(5).fill(0).map((_) => ({ id: 'F' + id++, color: ContainerColor.Orange })));
|
||||||
factoriesLeft.push(...new Array(5).fill(0).map(_ => ({ id: 'F' + id++, color: ContainerColor.Tan })));
|
factoriesLeft.push(...new Array(5).fill(0).map((_) => ({ id: 'F' + id++, color: ContainerColor.Tan })));
|
||||||
|
|
||||||
const warehousesLeft = new Array(players.length * 5).fill(0).map((_, i) => ({ id: 'W' + i }));
|
const warehousesLeft = new Array(players.length * 5).fill(0).map((_, i) => ({ id: 'W' + i }));
|
||||||
const loansLeft = new Array(players.length * 2).fill(0).map((_, i) => ({ id: 'L' + i }));
|
const loansLeft = new Array(players.length * 2).fill(0).map((_, i) => ({ id: 'L' + i }));
|
||||||
|
|
@ -77,18 +100,21 @@ export function setup(numPlayers: number, { beginner = true }: GameOptions, seed
|
||||||
log: [],
|
log: [],
|
||||||
hiddenLog: [],
|
hiddenLog: [],
|
||||||
seed,
|
seed,
|
||||||
round: 1
|
round: 1,
|
||||||
} as GameState;
|
} as GameState;
|
||||||
|
|
||||||
const colors = shuffle([ContainerColor.Black, ContainerColor.Orange, ContainerColor.Tan, ContainerColor.White, ContainerColor.Brown], rng() + '');
|
const colors = shuffle(
|
||||||
|
[ContainerColor.Black, ContainerColor.Orange, ContainerColor.Tan, ContainerColor.White, ContainerColor.Brown],
|
||||||
|
rng() + ''
|
||||||
|
);
|
||||||
|
|
||||||
G.players.forEach((player, i) => {
|
G.players.forEach((player, i) => {
|
||||||
const color = colors[i];
|
const color = colors[i];
|
||||||
let index = G.factoriesLeft.findIndex(f => f.color == color);
|
let index = G.factoriesLeft.findIndex((f) => f.color == color);
|
||||||
const factory = G.factoriesLeft.splice(index, 1)[0];
|
const factory = G.factoriesLeft.splice(index, 1)[0];
|
||||||
player.factories.push(factory);
|
player.factories.push(factory);
|
||||||
|
|
||||||
index = G.containersLeft.findIndex(c => c.color == color);
|
index = G.containersLeft.findIndex((c) => c.color == color);
|
||||||
const container = G.containersLeft.splice(index, 1)[0];
|
const container = G.containersLeft.splice(index, 1)[0];
|
||||||
player.containersOnFactoryStore.push({ piece: container, price: 2 });
|
player.containersOnFactoryStore.push({ piece: container, price: 2 });
|
||||||
|
|
||||||
|
|
@ -122,7 +148,7 @@ export function stripSecret(G: GameState, player?: number): GameState {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
log: G.log
|
log: G.log,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -136,17 +162,23 @@ export function move(G: GameState, move: Move, playerNumber: number, fake?: bool
|
||||||
|
|
||||||
assert(G.currentPlayer === playerNumber, 'It is not your turn!');
|
assert(G.currentPlayer === playerNumber, 'It is not your turn!');
|
||||||
assert(available, 'You are not allowed to run the command ' + move.name);
|
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);
|
assert(
|
||||||
assert(move.name != MoveName.Bid || move.extraData.price + player.bid <= player.money, 'Can\'t bid more money than you have!');
|
available.some((x) => isEqual(x, move.data)),
|
||||||
|
'Wrong argument for the command ' + move.name
|
||||||
|
);
|
||||||
|
assert(
|
||||||
|
move.name != MoveName.Bid || move.extraData.price + player.bid <= player.money,
|
||||||
|
"Can't bid more money than you have!"
|
||||||
|
);
|
||||||
|
|
||||||
switch (move.name) {
|
switch (move.name) {
|
||||||
case MoveName.DomesticSale: {
|
case MoveName.DomesticSale: {
|
||||||
asserts<Moves.MoveDomesticSale>(move);
|
asserts<Moves.MoveDomesticSale>(move);
|
||||||
if (player.containersOnFactoryStore.length > 0) {
|
if (player.containersOnFactoryStore.length > 0) {
|
||||||
const aux = player.containersOnFactoryStore.find(x => isEqual(x.piece, move.data))!;
|
const aux = player.containersOnFactoryStore.find((x) => isEqual(x.piece, move.data))!;
|
||||||
player.containersOnFactoryStore.splice(player.containersOnFactoryStore.indexOf(aux), 1);
|
player.containersOnFactoryStore.splice(player.containersOnFactoryStore.indexOf(aux), 1);
|
||||||
} else {
|
} else {
|
||||||
const aux = player.containersOnWarehouseStore.find(x => isEqual(x.piece, move.data))!;
|
const aux = player.containersOnWarehouseStore.find((x) => isEqual(x.piece, move.data))!;
|
||||||
player.containersOnWarehouseStore.splice(player.containersOnWarehouseStore.indexOf(aux), 1);
|
player.containersOnWarehouseStore.splice(player.containersOnWarehouseStore.indexOf(aux), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -155,7 +187,14 @@ export function move(G: GameState, move: Move, playerNumber: number, fake?: bool
|
||||||
player.money += 2;
|
player.money += 2;
|
||||||
player.actions--;
|
player.actions--;
|
||||||
|
|
||||||
G.log.push({ type: 'move', player: playerNumber, move, pretty: `${playerNameHTML(player)} sells a ${containerColorHTML(move.data.color)} container back to the supply for $2` });
|
G.log.push({
|
||||||
|
type: 'move',
|
||||||
|
player: playerNumber,
|
||||||
|
move,
|
||||||
|
pretty: `${playerNameHTML(player)} sells a ${containerColorHTML(
|
||||||
|
move.data.color
|
||||||
|
)} container back to the supply for $2`,
|
||||||
|
});
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -167,7 +206,14 @@ export function move(G: GameState, move: Move, playerNumber: number, fake?: bool
|
||||||
player.money -= player.factories.length * 3;
|
player.money -= player.factories.length * 3;
|
||||||
player.actions--;
|
player.actions--;
|
||||||
|
|
||||||
G.log.push({ type: 'move', player: playerNumber, move, pretty: `${playerNameHTML(player)} buys a ${containerColorHTML(move.data)} factory for $${player.factories.length * 3}` });
|
G.log.push({
|
||||||
|
type: 'move',
|
||||||
|
player: playerNumber,
|
||||||
|
move,
|
||||||
|
pretty: `${playerNameHTML(player)} buys a ${containerColorHTML(move.data)} factory for $${
|
||||||
|
player.factories.length * 3
|
||||||
|
}`,
|
||||||
|
});
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -179,7 +225,12 @@ export function move(G: GameState, move: Move, playerNumber: number, fake?: bool
|
||||||
player.money -= player.warehouses.length + 2;
|
player.money -= player.warehouses.length + 2;
|
||||||
player.actions--;
|
player.actions--;
|
||||||
|
|
||||||
G.log.push({ type: 'move', player: playerNumber, move, pretty: `${playerNameHTML(player)} buys a warehouse for $${player.warehouses.length + 2}` });
|
G.log.push({
|
||||||
|
type: 'move',
|
||||||
|
player: playerNumber,
|
||||||
|
move,
|
||||||
|
pretty: `${playerNameHTML(player)} buys a warehouse for $${player.warehouses.length + 2}`,
|
||||||
|
});
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -187,14 +238,20 @@ export function move(G: GameState, move: Move, playerNumber: number, fake?: bool
|
||||||
case MoveName.BuyFromFactory: {
|
case MoveName.BuyFromFactory: {
|
||||||
asserts<Moves.MoveBuyFromFactory>(move);
|
asserts<Moves.MoveBuyFromFactory>(move);
|
||||||
const otherPlayer = G.players[move.data.player];
|
const otherPlayer = G.players[move.data.player];
|
||||||
const aux = otherPlayer.containersOnFactoryStore.find(x => isEqual(x.piece, move.data.piece))!;
|
const aux = otherPlayer.containersOnFactoryStore.find((x) => isEqual(x.piece, move.data.piece))!;
|
||||||
otherPlayer.containersOnFactoryStore.splice(otherPlayer.containersOnFactoryStore.indexOf(aux), 1);
|
otherPlayer.containersOnFactoryStore.splice(otherPlayer.containersOnFactoryStore.indexOf(aux), 1);
|
||||||
player.containersOnWarehouseStore.push({ piece: move.data.piece, price: move.extraData.price });
|
player.containersOnWarehouseStore.push({
|
||||||
|
piece: move.data.piece,
|
||||||
|
price: move.extraData.price,
|
||||||
|
});
|
||||||
|
|
||||||
player.money -= aux.price;
|
player.money -= aux.price;
|
||||||
otherPlayer.money += aux.price;
|
otherPlayer.money += aux.price;
|
||||||
|
|
||||||
if (player.lastMove?.name !== MoveName.BuyFromFactory || player.lastMove?.data.player !== move.data.player) {
|
if (
|
||||||
|
player.lastMove?.name !== MoveName.BuyFromFactory ||
|
||||||
|
player.lastMove?.data.player !== move.data.player
|
||||||
|
) {
|
||||||
player.actions -= 1;
|
player.actions -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -202,7 +259,11 @@ export function move(G: GameState, move: Move, playerNumber: number, fake?: bool
|
||||||
type: 'move',
|
type: 'move',
|
||||||
player: playerNumber,
|
player: playerNumber,
|
||||||
move,
|
move,
|
||||||
pretty: `${playerNameHTML(player)} buys a ${containerColorHTML(move.data.piece.color)} container from ${playerNameHTML(otherPlayer)} for $${aux.price}, new price is $${move.extraData.price}`
|
pretty: `${playerNameHTML(player)} buys a ${containerColorHTML(
|
||||||
|
move.data.piece.color
|
||||||
|
)} container from ${playerNameHTML(otherPlayer)} for $${aux.price}, new price is $${
|
||||||
|
move.extraData.price
|
||||||
|
}`,
|
||||||
});
|
});
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
@ -211,14 +272,18 @@ export function move(G: GameState, move: Move, playerNumber: number, fake?: bool
|
||||||
case MoveName.BuyFromWarehouse: {
|
case MoveName.BuyFromWarehouse: {
|
||||||
asserts<Moves.MoveBuyFromWarehouse>(move);
|
asserts<Moves.MoveBuyFromWarehouse>(move);
|
||||||
const otherPlayer = G.players[move.data.player];
|
const otherPlayer = G.players[move.data.player];
|
||||||
const aux = otherPlayer.containersOnWarehouseStore.find(x => isEqual(x.piece, move.data.piece))!;
|
const aux = otherPlayer.containersOnWarehouseStore.find((x) => isEqual(x.piece, move.data.piece))!;
|
||||||
otherPlayer.containersOnWarehouseStore.splice(otherPlayer.containersOnWarehouseStore.indexOf(aux), 1);
|
otherPlayer.containersOnWarehouseStore.splice(otherPlayer.containersOnWarehouseStore.indexOf(aux), 1);
|
||||||
player.ship.containers.push(move.data.piece);
|
player.ship.containers.push(move.data.piece);
|
||||||
|
|
||||||
player.money -= aux.price;
|
player.money -= aux.price;
|
||||||
otherPlayer.money += aux.price;
|
otherPlayer.money += aux.price;
|
||||||
|
|
||||||
if ((player.lastMove?.name !== MoveName.BuyFromWarehouse || player.lastMove?.data.player !== move.data.player) && player.lastMove?.name !== MoveName.Sail) {
|
if (
|
||||||
|
(player.lastMove?.name !== MoveName.BuyFromWarehouse ||
|
||||||
|
player.lastMove?.data.player !== move.data.player) &&
|
||||||
|
player.lastMove?.name !== MoveName.Sail
|
||||||
|
) {
|
||||||
player.actions -= 1;
|
player.actions -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -226,7 +291,9 @@ export function move(G: GameState, move: Move, playerNumber: number, fake?: bool
|
||||||
type: 'move',
|
type: 'move',
|
||||||
player: playerNumber,
|
player: playerNumber,
|
||||||
move,
|
move,
|
||||||
pretty: `${playerNameHTML(player)} buys a ${containerColorHTML(move.data.piece.color)} container from ${playerNameHTML(otherPlayer)} for $${aux.price}`
|
pretty: `${playerNameHTML(player)} buys a ${containerColorHTML(
|
||||||
|
move.data.piece.color
|
||||||
|
)} container from ${playerNameHTML(otherPlayer)} for $${aux.price}`,
|
||||||
});
|
});
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
@ -239,9 +306,19 @@ export function move(G: GameState, move: Move, playerNumber: number, fake?: bool
|
||||||
player.money += 10;
|
player.money += 10;
|
||||||
|
|
||||||
if (G.phase == Phase.Bid) {
|
if (G.phase == Phase.Bid) {
|
||||||
G.hiddenLog.push({ type: 'move', player: playerNumber, move, pretty: `${playerNameHTML(player)} takes a loan` });
|
G.hiddenLog.push({
|
||||||
|
type: 'move',
|
||||||
|
player: playerNumber,
|
||||||
|
move,
|
||||||
|
pretty: `${playerNameHTML(player)} takes a loan`,
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
G.log.push({ type: 'move', player: playerNumber, move, pretty: `${playerNameHTML(player)} takes a loan` });
|
G.log.push({
|
||||||
|
type: 'move',
|
||||||
|
player: playerNumber,
|
||||||
|
move,
|
||||||
|
pretty: `${playerNameHTML(player)} takes a loan`,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
@ -254,9 +331,19 @@ export function move(G: GameState, move: Move, playerNumber: number, fake?: bool
|
||||||
player.money -= 10;
|
player.money -= 10;
|
||||||
|
|
||||||
if (G.phase == Phase.Bid) {
|
if (G.phase == Phase.Bid) {
|
||||||
G.hiddenLog.push({ type: 'move', player: playerNumber, move, pretty: `${playerNameHTML(player)} pays a loan` });
|
G.hiddenLog.push({
|
||||||
|
type: 'move',
|
||||||
|
player: playerNumber,
|
||||||
|
move,
|
||||||
|
pretty: `${playerNameHTML(player)} pays a loan`,
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
G.log.push({ type: 'move', player: playerNumber, move, pretty: `${playerNameHTML(player)} pays a loan` });
|
G.log.push({
|
||||||
|
type: 'move',
|
||||||
|
player: playerNumber,
|
||||||
|
move,
|
||||||
|
pretty: `${playerNameHTML(player)} pays a loan`,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
@ -265,7 +352,10 @@ export function move(G: GameState, move: Move, playerNumber: number, fake?: bool
|
||||||
case MoveName.Produce: {
|
case MoveName.Produce: {
|
||||||
asserts<Moves.MoveProduce>(move);
|
asserts<Moves.MoveProduce>(move);
|
||||||
remove(G.containersLeft, move.extraData.piece);
|
remove(G.containersLeft, move.extraData.piece);
|
||||||
player.containersOnFactoryStore.push({ piece: move.extraData.piece, price: move.extraData.price });
|
player.containersOnFactoryStore.push({
|
||||||
|
piece: move.extraData.piece,
|
||||||
|
price: move.extraData.price,
|
||||||
|
});
|
||||||
player.produced.push(move.extraData.piece.color);
|
player.produced.push(move.extraData.piece.color);
|
||||||
if (player.lastMove?.name !== MoveName.Produce) {
|
if (player.lastMove?.name !== MoveName.Produce) {
|
||||||
player.actions -= 1;
|
player.actions -= 1;
|
||||||
|
|
@ -273,7 +363,14 @@ export function move(G: GameState, move: Move, playerNumber: number, fake?: bool
|
||||||
playerBefore(player, G).money += 1;
|
playerBefore(player, G).money += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
G.log.push({ type: 'move', player: playerNumber, move, pretty: `${playerNameHTML(player)} produces a ${containerColorHTML(move.extraData.piece.color)} container, price is $${move.extraData.price}` });
|
G.log.push({
|
||||||
|
type: 'move',
|
||||||
|
player: playerNumber,
|
||||||
|
move,
|
||||||
|
pretty: `${playerNameHTML(player)} produces a ${containerColorHTML(
|
||||||
|
move.extraData.piece.color
|
||||||
|
)} container, price is $${move.extraData.price}`,
|
||||||
|
});
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -290,37 +387,65 @@ export function move(G: GameState, move: Move, playerNumber: number, fake?: bool
|
||||||
player.actions--;
|
player.actions--;
|
||||||
}
|
}
|
||||||
|
|
||||||
G.log.push({ type: 'move', player: playerNumber, move, pretty: `${playerNameHTML(player)} sails to ${prettyShipPosition(G, move.data)}` });
|
G.log.push({
|
||||||
|
type: 'move',
|
||||||
|
player: playerNumber,
|
||||||
|
move,
|
||||||
|
pretty: `${playerNameHTML(player)} sails to ${prettyShipPosition(G, move.data)}`,
|
||||||
|
});
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case MoveName.ArrangeFactory: {
|
case MoveName.ArrangeFactory: {
|
||||||
asserts<Moves.MoveArrangeFactory>(move);
|
asserts<Moves.MoveArrangeFactory>(move);
|
||||||
const aux = player.containersOnFactoryStore.find(x => isEqual(x.piece, move.data))!;
|
const aux = player.containersOnFactoryStore.find((x) => isEqual(x.piece, move.data))!;
|
||||||
player.containersOnFactoryStore.splice(player.containersOnFactoryStore.indexOf(aux), 1);
|
player.containersOnFactoryStore.splice(player.containersOnFactoryStore.indexOf(aux), 1);
|
||||||
player.containersOnFactoryStore.push({ piece: move.data, price: move.extraData.price });
|
player.containersOnFactoryStore.push({
|
||||||
|
piece: move.data,
|
||||||
|
price: move.extraData.price,
|
||||||
|
});
|
||||||
|
|
||||||
if (player.lastMove?.name !== MoveName.Produce && player.lastMove?.name !== MoveName.ArrangeFactory) {
|
if (player.lastMove?.name !== MoveName.Produce && player.lastMove?.name !== MoveName.ArrangeFactory) {
|
||||||
player.actions--;
|
player.actions--;
|
||||||
}
|
}
|
||||||
|
|
||||||
G.log.push({ type: 'move', player: playerNumber, move, pretty: `${playerNameHTML(player)} changes the price of a ${containerColorHTML(move.data.color)} factory container from $${aux.price} to $${move.extraData.price}` });
|
G.log.push({
|
||||||
|
type: 'move',
|
||||||
|
player: playerNumber,
|
||||||
|
move,
|
||||||
|
pretty: `${playerNameHTML(player)} changes the price of a ${containerColorHTML(
|
||||||
|
move.data.color
|
||||||
|
)} factory container from $${aux.price} to $${move.extraData.price}`,
|
||||||
|
});
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case MoveName.ArrangeWarehouse: {
|
case MoveName.ArrangeWarehouse: {
|
||||||
asserts<Moves.MoveArrangeWarehouse>(move);
|
asserts<Moves.MoveArrangeWarehouse>(move);
|
||||||
const aux = player.containersOnWarehouseStore.find(x => isEqual(x.piece, move.data))!;
|
const aux = player.containersOnWarehouseStore.find((x) => isEqual(x.piece, move.data))!;
|
||||||
player.containersOnWarehouseStore.splice(player.containersOnWarehouseStore.indexOf(aux), 1);
|
player.containersOnWarehouseStore.splice(player.containersOnWarehouseStore.indexOf(aux), 1);
|
||||||
player.containersOnWarehouseStore.push({ piece: move.data, price: move.extraData.price });
|
player.containersOnWarehouseStore.push({
|
||||||
|
piece: move.data,
|
||||||
|
price: move.extraData.price,
|
||||||
|
});
|
||||||
|
|
||||||
if (player.lastMove?.name !== MoveName.BuyFromFactory && player.lastMove?.name !== MoveName.ArrangeWarehouse) {
|
if (
|
||||||
|
player.lastMove?.name !== MoveName.BuyFromFactory &&
|
||||||
|
player.lastMove?.name !== MoveName.ArrangeWarehouse
|
||||||
|
) {
|
||||||
player.actions--;
|
player.actions--;
|
||||||
}
|
}
|
||||||
|
|
||||||
G.log.push({ type: 'move', player: playerNumber, move, pretty: `${playerNameHTML(player)} changes the price of a ${containerColorHTML(move.data.color)} warehouse container from $${aux.price} to $${move.extraData.price}` });
|
G.log.push({
|
||||||
|
type: 'move',
|
||||||
|
player: playerNumber,
|
||||||
|
move,
|
||||||
|
pretty: `${playerNameHTML(player)} changes the price of a ${containerColorHTML(
|
||||||
|
move.data.color
|
||||||
|
)} warehouse container from $${aux.price} to $${move.extraData.price}`,
|
||||||
|
});
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -329,31 +454,55 @@ export function move(G: GameState, move: Move, playerNumber: number, fake?: bool
|
||||||
asserts<Moves.MoveBid>(move);
|
asserts<Moves.MoveBid>(move);
|
||||||
|
|
||||||
if (G.highestBidders.length === 0) {
|
if (G.highestBidders.length === 0) {
|
||||||
G.hiddenLog.push({ type: 'move', player: playerNumber, move, pretty: `${playerNameHTML(player)} bids $${move.extraData.price}` });
|
G.hiddenLog.push({
|
||||||
|
type: 'move',
|
||||||
|
player: playerNumber,
|
||||||
|
move,
|
||||||
|
pretty: `${playerNameHTML(player)} bids $${move.extraData.price}`,
|
||||||
|
});
|
||||||
player.bid = move.extraData.price;
|
player.bid = move.extraData.price;
|
||||||
nextPlayer(G);
|
nextPlayer(G);
|
||||||
} else {
|
} else {
|
||||||
G.hiddenLog.push({ type: 'move', player: playerNumber, move, pretty: `${playerNameHTML(player)} bids additional $${move.extraData.price}` });
|
G.hiddenLog.push({
|
||||||
|
type: 'move',
|
||||||
|
player: playerNumber,
|
||||||
|
move,
|
||||||
|
pretty: `${playerNameHTML(player)} bids additional $${move.extraData.price}`,
|
||||||
|
});
|
||||||
player.additionalBid = move.extraData.price;
|
player.additionalBid = move.extraData.price;
|
||||||
do { nextPlayer(G); } while (G.highestBidders.indexOf(G.currentPlayer) === -1 && G.auctioningPlayer !== G.currentPlayer);
|
do {
|
||||||
|
nextPlayer(G);
|
||||||
|
} while (G.highestBidders.indexOf(G.currentPlayer) === -1 && G.auctioningPlayer !== G.currentPlayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (G.auctioningPlayer === G.currentPlayer) {
|
if (G.auctioningPlayer === G.currentPlayer) {
|
||||||
if (G.highestBidders.length === 0) {
|
if (G.highestBidders.length === 0) {
|
||||||
G.players.filter(p => p.id !== G.currentPlayer).forEach(p => { p.showBid = true; });
|
G.players
|
||||||
const highestBid = Math.max(...G.players.map(p => p.bid));
|
.filter((p) => p.id !== G.currentPlayer)
|
||||||
const highestBidders = G.players.filter(p => p.id != G.currentPlayer && p.bid === highestBid).map(p => p.id);
|
.forEach((p) => {
|
||||||
|
p.showBid = true;
|
||||||
|
});
|
||||||
|
const highestBid = Math.max(...G.players.map((p) => p.bid));
|
||||||
|
const highestBidders = G.players
|
||||||
|
.filter((p) => p.id != G.currentPlayer && p.bid === highestBid)
|
||||||
|
.map((p) => p.id);
|
||||||
G.highestBidders = highestBidders;
|
G.highestBidders = highestBidders;
|
||||||
if (highestBidders.length > 1) {
|
if (highestBidders.length > 1) {
|
||||||
while (highestBidders.indexOf(G.currentPlayer) === -1) { nextPlayer(G); }
|
while (highestBidders.indexOf(G.currentPlayer) === -1) {
|
||||||
|
nextPlayer(G);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
G.phase = Phase.AcceptDecline;
|
G.phase = Phase.AcceptDecline;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const highestBid = Math.max(...G.players.map(p => p.bid + p.additionalBid));
|
const highestBid = Math.max(...G.players.map((p) => p.bid + p.additionalBid));
|
||||||
const highestBidders = G.players.filter(p => p.id != G.currentPlayer && p.bid + p.additionalBid === highestBid).map(p => p.id);
|
const highestBidders = G.players
|
||||||
|
.filter((p) => p.id != G.currentPlayer && p.bid + p.additionalBid === highestBid)
|
||||||
|
.map((p) => p.id);
|
||||||
G.highestBidders = highestBidders;
|
G.highestBidders = highestBidders;
|
||||||
G.players.forEach(p => { p.showAdditionalBid = true; });
|
G.players.forEach((p) => {
|
||||||
|
p.showAdditionalBid = true;
|
||||||
|
});
|
||||||
G.phase = Phase.AcceptDecline;
|
G.phase = Phase.AcceptDecline;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -372,15 +521,19 @@ export function move(G: GameState, move: Move, playerNumber: number, fake?: bool
|
||||||
player.ship.containers = [];
|
player.ship.containers = [];
|
||||||
otherPlayer.money -= otherPlayer.bid + otherPlayer.additionalBid;
|
otherPlayer.money -= otherPlayer.bid + otherPlayer.additionalBid;
|
||||||
player.money += (otherPlayer.bid + otherPlayer.additionalBid) * 2;
|
player.money += (otherPlayer.bid + otherPlayer.additionalBid) * 2;
|
||||||
G.players.forEach(p => { p.bid = p.additionalBid = 0; });
|
G.players.forEach((p) => {
|
||||||
G.players.forEach(p => { p.showBid = p.showAdditionalBid = false; });
|
p.bid = p.additionalBid = 0;
|
||||||
|
});
|
||||||
|
G.players.forEach((p) => {
|
||||||
|
p.showBid = p.showAdditionalBid = false;
|
||||||
|
});
|
||||||
G.auctioningPlayer = undefined;
|
G.auctioningPlayer = undefined;
|
||||||
G.highestBidders = [];
|
G.highestBidders = [];
|
||||||
G.phase = Phase.Move;
|
G.phase = Phase.Move;
|
||||||
|
|
||||||
nextPlayer(G);
|
nextPlayer(G);
|
||||||
if (!fake) {
|
if (!fake) {
|
||||||
if ([...new Set(G.containersLeft.map(c => c.color))].length >= 4) {
|
if ([...new Set(G.containersLeft.map((c) => c.color))].length >= 4) {
|
||||||
doUpkeep(G);
|
doUpkeep(G);
|
||||||
} else {
|
} else {
|
||||||
G.phase = Phase.GameEnd;
|
G.phase = Phase.GameEnd;
|
||||||
|
|
@ -389,7 +542,12 @@ export function move(G: GameState, move: Move, playerNumber: number, fake?: bool
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
G.log.push({ type: 'move', player: playerNumber, move, pretty: `${playerNameHTML(player)} accepts ${playerNameHTML(otherPlayer)}'s bid` });
|
G.log.push({
|
||||||
|
type: 'move',
|
||||||
|
player: playerNumber,
|
||||||
|
move,
|
||||||
|
pretty: `${playerNameHTML(player)} accepts ${playerNameHTML(otherPlayer)}'s bid`,
|
||||||
|
});
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -399,15 +557,19 @@ export function move(G: GameState, move: Move, playerNumber: number, fake?: bool
|
||||||
player.ship.containers = [];
|
player.ship.containers = [];
|
||||||
const bid = G.players[G.highestBidders[0]].bid + G.players[G.highestBidders[0]].additionalBid;
|
const bid = G.players[G.highestBidders[0]].bid + G.players[G.highestBidders[0]].additionalBid;
|
||||||
player.money -= bid;
|
player.money -= bid;
|
||||||
G.players.forEach(p => { p.bid = p.additionalBid = 0; });
|
G.players.forEach((p) => {
|
||||||
G.players.forEach(p => { p.showBid = p.showAdditionalBid = false; });
|
p.bid = p.additionalBid = 0;
|
||||||
|
});
|
||||||
|
G.players.forEach((p) => {
|
||||||
|
p.showBid = p.showAdditionalBid = false;
|
||||||
|
});
|
||||||
G.auctioningPlayer = undefined;
|
G.auctioningPlayer = undefined;
|
||||||
G.highestBidders = [];
|
G.highestBidders = [];
|
||||||
G.phase = Phase.Move;
|
G.phase = Phase.Move;
|
||||||
|
|
||||||
nextPlayer(G);
|
nextPlayer(G);
|
||||||
if (!fake) {
|
if (!fake) {
|
||||||
if ([...new Set(G.containersLeft.map(c => c.color))].length >= 4) {
|
if ([...new Set(G.containersLeft.map((c) => c.color))].length >= 4) {
|
||||||
doUpkeep(G);
|
doUpkeep(G);
|
||||||
} else {
|
} else {
|
||||||
G.phase = Phase.GameEnd;
|
G.phase = Phase.GameEnd;
|
||||||
|
|
@ -416,7 +578,12 @@ export function move(G: GameState, move: Move, playerNumber: number, fake?: bool
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
G.log.push({ type: 'move', player: playerNumber, move, pretty: `${playerNameHTML(player)} declines all bids` });
|
G.log.push({
|
||||||
|
type: 'move',
|
||||||
|
player: playerNumber,
|
||||||
|
move,
|
||||||
|
pretty: `${playerNameHTML(player)} declines all bids`,
|
||||||
|
});
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -424,11 +591,16 @@ export function move(G: GameState, move: Move, playerNumber: number, fake?: bool
|
||||||
case MoveName.Pass: {
|
case MoveName.Pass: {
|
||||||
asserts<Moves.MovePass>(move);
|
asserts<Moves.MovePass>(move);
|
||||||
|
|
||||||
G.log.push({ type: 'move', player: playerNumber, move, pretty: `${playerNameHTML(player)} passes` });
|
G.log.push({
|
||||||
|
type: 'move',
|
||||||
|
player: playerNumber,
|
||||||
|
move,
|
||||||
|
pretty: `${playerNameHTML(player)} passes`,
|
||||||
|
});
|
||||||
|
|
||||||
nextPlayer(G);
|
nextPlayer(G);
|
||||||
if (!fake) {
|
if (!fake) {
|
||||||
if ([...new Set(G.containersLeft.map(c => c.color))].length >= 4) {
|
if ([...new Set(G.containersLeft.map((c) => c.color))].length >= 4) {
|
||||||
doUpkeep(G);
|
doUpkeep(G);
|
||||||
} else {
|
} else {
|
||||||
G.phase = Phase.GameEnd;
|
G.phase = Phase.GameEnd;
|
||||||
|
|
@ -455,8 +627,7 @@ export function move(G: GameState, move: Move, playerNumber: number, fake?: bool
|
||||||
|
|
||||||
player.availableMoves = null;
|
player.availableMoves = null;
|
||||||
|
|
||||||
if (move.name != MoveName.GetLoan && move.name != MoveName.PayLoan)
|
if (move.name != MoveName.GetLoan && move.name != MoveName.PayLoan) player.lastMove = move;
|
||||||
player.lastMove = move;
|
|
||||||
|
|
||||||
if (G.currentPlayer !== undefined)
|
if (G.currentPlayer !== undefined)
|
||||||
G.players[G.currentPlayer].availableMoves = availableMoves(G, G.players[G.currentPlayer]);
|
G.players[G.currentPlayer].availableMoves = availableMoves(G, G.players[G.currentPlayer]);
|
||||||
|
|
@ -477,18 +648,31 @@ export function moveAI(G: GameState, playerNumber: number): GameState {
|
||||||
moveName = MoveName.PayLoan;
|
moveName = MoveName.PayLoan;
|
||||||
const dataArr = player.availableMoves![moveName];
|
const dataArr = player.availableMoves![moveName];
|
||||||
data = dataArr[Math.floor(Math.random() * dataArr.length)];
|
data = dataArr[Math.floor(Math.random() * dataArr.length)];
|
||||||
} else if (G.phase == Phase.Move && player.actions > 0 && player.ship.containers.length > 0 && player.lastMove?.name != MoveName.BuyFromWarehouse) {
|
} else if (
|
||||||
|
G.phase == Phase.Move &&
|
||||||
|
player.actions > 0 &&
|
||||||
|
player.ship.containers.length > 0 &&
|
||||||
|
player.lastMove?.name != MoveName.BuyFromWarehouse
|
||||||
|
) {
|
||||||
moveName = MoveName.Sail;
|
moveName = MoveName.Sail;
|
||||||
data = player.ship.shipPosition == ShipPosition.OpenSea ? ShipPosition.Island : ShipPosition.OpenSea;
|
data = player.ship.shipPosition == ShipPosition.OpenSea ? ShipPosition.Island : ShipPosition.OpenSea;
|
||||||
} else {
|
} else {
|
||||||
const moves = Object.keys(player.availableMoves!);
|
const moves = Object.keys(player.availableMoves!);
|
||||||
|
|
||||||
if (player.lastMove?.name == MoveName.Sail && player.ship.containers.length < 5 &&
|
if (
|
||||||
((player.lastMove?.data.startsWith('playerHarbor0') && G.players[0].containersOnWarehouseStore.length > 0) ||
|
player.lastMove?.name == MoveName.Sail &&
|
||||||
(player.lastMove?.data.startsWith('playerHarbor1') && G.players[1].containersOnWarehouseStore.length > 0) ||
|
player.ship.containers.length < 5 &&
|
||||||
(player.lastMove?.data.startsWith('playerHarbor2') && G.players[2].containersOnWarehouseStore.length > 0) ||
|
((player.lastMove?.data.startsWith('playerHarbor0') &&
|
||||||
(player.lastMove?.data.startsWith('playerHarbor3') && G.players[3].containersOnWarehouseStore.length > 0) ||
|
G.players[0].containersOnWarehouseStore.length > 0) ||
|
||||||
(player.lastMove?.data.startsWith('playerHarbor4') && G.players[4].containersOnWarehouseStore.length > 0))) {
|
(player.lastMove?.data.startsWith('playerHarbor1') &&
|
||||||
|
G.players[1].containersOnWarehouseStore.length > 0) ||
|
||||||
|
(player.lastMove?.data.startsWith('playerHarbor2') &&
|
||||||
|
G.players[2].containersOnWarehouseStore.length > 0) ||
|
||||||
|
(player.lastMove?.data.startsWith('playerHarbor3') &&
|
||||||
|
G.players[3].containersOnWarehouseStore.length > 0) ||
|
||||||
|
(player.lastMove?.data.startsWith('playerHarbor4') &&
|
||||||
|
G.players[4].containersOnWarehouseStore.length > 0))
|
||||||
|
) {
|
||||||
moveName = MoveName.BuyFromWarehouse;
|
moveName = MoveName.BuyFromWarehouse;
|
||||||
} else {
|
} else {
|
||||||
moveName = moves[Math.floor(Math.random() * moves.length)];
|
moveName = moves[Math.floor(Math.random() * moves.length)];
|
||||||
|
|
@ -506,33 +690,24 @@ export function moveAI(G: GameState, playerNumber: number): GameState {
|
||||||
moveName = null;
|
moveName = null;
|
||||||
} else if (moveName == MoveName.Sail) {
|
} else if (moveName == MoveName.Sail) {
|
||||||
if (data == ShipPosition.Island) {
|
if (data == ShipPosition.Island) {
|
||||||
if (player.ship.containers.length == 0)
|
if (player.ship.containers.length == 0) moveName = null;
|
||||||
moveName = null;
|
|
||||||
} else if (data.startsWith('playerHarbor0')) {
|
} else if (data.startsWith('playerHarbor0')) {
|
||||||
if (G.players[0].containersOnWarehouseStore.length == 0)
|
if (G.players[0].containersOnWarehouseStore.length == 0) moveName = null;
|
||||||
moveName = null;
|
|
||||||
} else if (data.startsWith('playerHarbor1')) {
|
} else if (data.startsWith('playerHarbor1')) {
|
||||||
if (G.players[1].containersOnWarehouseStore.length == 0)
|
if (G.players[1].containersOnWarehouseStore.length == 0) moveName = null;
|
||||||
moveName = null;
|
|
||||||
} else if (data.startsWith('playerHarbor2')) {
|
} else if (data.startsWith('playerHarbor2')) {
|
||||||
if (G.players[2].containersOnWarehouseStore.length == 0)
|
if (G.players[2].containersOnWarehouseStore.length == 0) moveName = null;
|
||||||
moveName = null;
|
|
||||||
} else if (data.startsWith('playerHarbor3')) {
|
} else if (data.startsWith('playerHarbor3')) {
|
||||||
if (G.players[3].containersOnWarehouseStore.length == 0)
|
if (G.players[3].containersOnWarehouseStore.length == 0) moveName = null;
|
||||||
moveName = null;
|
|
||||||
} else if (data.startsWith('playerHarbor4')) {
|
} else if (data.startsWith('playerHarbor4')) {
|
||||||
if (G.players[4].containersOnWarehouseStore.length == 0)
|
if (G.players[4].containersOnWarehouseStore.length == 0) moveName = null;
|
||||||
moveName = null;
|
|
||||||
} else {
|
} else {
|
||||||
if (player.lastMove?.name == MoveName.Sail)
|
if (player.lastMove?.name == MoveName.Sail) moveName = null;
|
||||||
moveName = null;
|
|
||||||
}
|
}
|
||||||
} else if (moveName == MoveName.ArrangeFactory) {
|
} else if (moveName == MoveName.ArrangeFactory) {
|
||||||
if (player.lastMove?.name != MoveName.Produce)
|
if (player.lastMove?.name != MoveName.Produce) moveName = null;
|
||||||
moveName = null;
|
|
||||||
} else if (moveName == MoveName.ArrangeWarehouse) {
|
} else if (moveName == MoveName.ArrangeWarehouse) {
|
||||||
if (player.lastMove?.name != MoveName.BuyFromFactory)
|
if (player.lastMove?.name != MoveName.BuyFromFactory) moveName = null;
|
||||||
moveName = null;
|
|
||||||
} else if (moveName == MoveName.GetLoan) {
|
} else if (moveName == MoveName.GetLoan) {
|
||||||
moveName = null;
|
moveName = null;
|
||||||
} else if (moveName == MoveName.Produce) {
|
} else if (moveName == MoveName.Produce) {
|
||||||
|
|
@ -548,14 +723,11 @@ export function moveAI(G: GameState, playerNumber: number): GameState {
|
||||||
moveName = null;
|
moveName = null;
|
||||||
}
|
}
|
||||||
} else if (moveName == MoveName.BuyFactory) {
|
} else if (moveName == MoveName.BuyFactory) {
|
||||||
if (player.factories.length == 3 || player.money < 15)
|
if (player.factories.length == 3 || player.money < 15) moveName = null;
|
||||||
moveName = null;
|
|
||||||
} else if (moveName == MoveName.BuyWarehouse) {
|
} else if (moveName == MoveName.BuyWarehouse) {
|
||||||
if (player.warehouses.length == 3 || player.money < 17)
|
if (player.warehouses.length == 3 || player.money < 17) moveName = null;
|
||||||
moveName = null;
|
|
||||||
} else if (moveName == MoveName.DomesticSale) {
|
} else if (moveName == MoveName.DomesticSale) {
|
||||||
if (player.money > 5)
|
if (player.money > 5) moveName = null;
|
||||||
moveName = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -565,32 +737,63 @@ export function moveAI(G: GameState, playerNumber: number): GameState {
|
||||||
let playerMove: Move;
|
let playerMove: Move;
|
||||||
switch (moveName) {
|
switch (moveName) {
|
||||||
case MoveName.BuyFromFactory:
|
case MoveName.BuyFromFactory:
|
||||||
playerMove = { name: moveName, data, extraData: { price: Math.floor(Math.random() * 3) + 2 } };
|
playerMove = {
|
||||||
|
name: moveName,
|
||||||
|
data,
|
||||||
|
extraData: { price: Math.floor(Math.random() * 3) + 2 },
|
||||||
|
};
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MoveName.BuyFactory:
|
case MoveName.BuyFactory:
|
||||||
playerMove = { name: moveName, data, extraData: G.factoriesLeft.find(p => p.color == data) };
|
playerMove = {
|
||||||
|
name: moveName,
|
||||||
|
data,
|
||||||
|
extraData: G.factoriesLeft.find((p) => p.color == data),
|
||||||
|
};
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MoveName.BuyWarehouse:
|
case MoveName.BuyWarehouse:
|
||||||
playerMove = { name: moveName, data, extraData: G.warehousesLeft[0] };
|
playerMove = {
|
||||||
|
name: moveName,
|
||||||
|
data,
|
||||||
|
extraData: G.warehousesLeft[0],
|
||||||
|
};
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MoveName.Produce:
|
case MoveName.Produce:
|
||||||
playerMove = { name: moveName, data, extraData: { piece: G.containersLeft.find(p => p.color == data), price: Math.floor(Math.random() * 3) + 1 } };
|
playerMove = {
|
||||||
|
name: moveName,
|
||||||
|
data,
|
||||||
|
extraData: {
|
||||||
|
piece: G.containersLeft.find((p) => p.color == data),
|
||||||
|
price: Math.floor(Math.random() * 3) + 1,
|
||||||
|
},
|
||||||
|
};
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MoveName.ArrangeFactory:
|
case MoveName.ArrangeFactory:
|
||||||
playerMove = { name: moveName, data, extraData: { price: Math.floor(Math.random() * 3) + 1 } };
|
playerMove = {
|
||||||
|
name: moveName,
|
||||||
|
data,
|
||||||
|
extraData: { price: Math.floor(Math.random() * 3) + 1 },
|
||||||
|
};
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MoveName.ArrangeWarehouse:
|
case MoveName.ArrangeWarehouse:
|
||||||
playerMove = { name: moveName, data, extraData: { price: Math.floor(Math.random() * 3) + 2 } };
|
playerMove = {
|
||||||
|
name: moveName,
|
||||||
|
data,
|
||||||
|
extraData: { price: Math.floor(Math.random() * 3) + 2 },
|
||||||
|
};
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MoveName.Bid: {
|
case MoveName.Bid: {
|
||||||
const bid = Math.floor(Math.random() * (player.money - player.bid));
|
const bid = Math.floor(Math.random() * (player.money - player.bid));
|
||||||
playerMove = { name: moveName, data, extraData: { price: bid > 10 ? Math.ceil(bid / 2) : bid } };
|
playerMove = {
|
||||||
|
name: moveName,
|
||||||
|
data,
|
||||||
|
extraData: { price: bid > 10 ? Math.ceil(bid / 2) : bid },
|
||||||
|
};
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -607,14 +810,14 @@ export function ended(G: GameState): boolean {
|
||||||
}
|
}
|
||||||
|
|
||||||
function calculateEndScore(G: GameState) {
|
function calculateEndScore(G: GameState) {
|
||||||
G.players.forEach(player => {
|
G.players.forEach((player) => {
|
||||||
player.finalScoreBreakdown = [];
|
player.finalScoreBreakdown = [];
|
||||||
player.finalScoreBreakdown.push('$' + player.money);
|
player.finalScoreBreakdown.push('$' + player.money);
|
||||||
|
|
||||||
if (player.containersOnIsland.length > 0) {
|
if (player.containersOnIsland.length > 0) {
|
||||||
const hasOneOfEach = [...new Set(player.containersOnIsland.map(c => c.color))].length == 5;
|
const hasOneOfEach = [...new Set(player.containersOnIsland.map((c) => c.color))].length == 5;
|
||||||
|
|
||||||
const grouped = groupBy(player.containersOnIsland, piece => piece.color);
|
const grouped = groupBy(player.containersOnIsland, (piece) => piece.color);
|
||||||
const most = Object.keys(grouped).reduce((a, b) => {
|
const most = Object.keys(grouped).reduce((a, b) => {
|
||||||
if (grouped[a].length == grouped[b].length) {
|
if (grouped[a].length == grouped[b].length) {
|
||||||
if (a == player.pointCard!.containerValues[1].containerColor) {
|
if (a == player.pointCard!.containerValues[1].containerColor) {
|
||||||
|
|
@ -622,8 +825,12 @@ function calculateEndScore(G: GameState) {
|
||||||
} else if (b == player.pointCard!.containerValues[1].containerColor) {
|
} else if (b == player.pointCard!.containerValues[1].containerColor) {
|
||||||
return b;
|
return b;
|
||||||
} else {
|
} else {
|
||||||
const aValue = player.pointCard!.containerValues.find(cv => cv.containerColor == a)!.baseValue;
|
const aValue = player.pointCard!.containerValues.find(
|
||||||
const bValue = player.pointCard!.containerValues.find(cv => cv.containerColor == b)!.baseValue;
|
(cv) => cv.containerColor == a
|
||||||
|
)!.baseValue;
|
||||||
|
const bValue = player.pointCard!.containerValues.find(
|
||||||
|
(cv) => cv.containerColor == b
|
||||||
|
)!.baseValue;
|
||||||
return aValue > bValue ? b : a;
|
return aValue > bValue ? b : a;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -631,18 +838,29 @@ function calculateEndScore(G: GameState) {
|
||||||
return grouped[a].length > grouped[b].length ? a : b;
|
return grouped[a].length > grouped[b].length ? a : b;
|
||||||
});
|
});
|
||||||
|
|
||||||
const points = cloneDeep(player.pointCard!.containerValues).sort((a, b) => a.containerColor.localeCompare(b.containerColor)).map(cv => {
|
const points = cloneDeep(player.pointCard!.containerValues)
|
||||||
if (cv.containerColor == most) {
|
.sort((a, b) => a.containerColor.localeCompare(b.containerColor))
|
||||||
player.finalScoreBreakdown!.push('$' + (hasOneOfEach ? cv.specialValue : cv.baseValue) + ' x -');
|
.map((cv) => {
|
||||||
return 0;
|
if (cv.containerColor == most) {
|
||||||
} else if (grouped[cv.containerColor]) {
|
player.finalScoreBreakdown!.push(
|
||||||
player.finalScoreBreakdown!.push('$' + (hasOneOfEach ? cv.specialValue : cv.baseValue) + ' x ' + grouped[cv.containerColor].length);
|
'$' + (hasOneOfEach ? cv.specialValue : cv.baseValue) + ' x -'
|
||||||
return grouped[cv.containerColor].length * (hasOneOfEach ? cv.specialValue : cv.baseValue);
|
);
|
||||||
} else {
|
return 0;
|
||||||
player.finalScoreBreakdown!.push('$' + (hasOneOfEach ? cv.specialValue : cv.baseValue) + ' x 0');
|
} else if (grouped[cv.containerColor]) {
|
||||||
return 0;
|
player.finalScoreBreakdown!.push(
|
||||||
}
|
'$' +
|
||||||
});
|
(hasOneOfEach ? cv.specialValue : cv.baseValue) +
|
||||||
|
' x ' +
|
||||||
|
grouped[cv.containerColor].length
|
||||||
|
);
|
||||||
|
return grouped[cv.containerColor].length * (hasOneOfEach ? cv.specialValue : cv.baseValue);
|
||||||
|
} else {
|
||||||
|
player.finalScoreBreakdown!.push(
|
||||||
|
'$' + (hasOneOfEach ? cv.specialValue : cv.baseValue) + ' x 0'
|
||||||
|
);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
player.money += points.reduce((a, b) => a + b, 0);
|
player.money += points.reduce((a, b) => a + b, 0);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -663,7 +881,7 @@ function calculateEndScore(G: GameState) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function scores(G: GameState): number[] {
|
export function scores(G: GameState): number[] {
|
||||||
return G.players.map(_ => 0);
|
return G.players.map((_) => 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function reconstructState(initialState: GameState, log: LogItem[]): GameState {
|
export function reconstructState(initialState: GameState, log: LogItem[]): GameState {
|
||||||
|
|
@ -707,37 +925,103 @@ function doUpkeep(G: GameState) {
|
||||||
interest.push('money');
|
interest.push('money');
|
||||||
} else if (player.containersOnIsland.length > 0) {
|
} else if (player.containersOnIsland.length > 0) {
|
||||||
const container = removeRandom(player.containersOnIsland);
|
const container = removeRandom(player.containersOnIsland);
|
||||||
G.log.push({ type: 'event', event: { name: GameEventName.Upkeep, interest: `The bank seizes a ${containerColorHTML(container.color)} container from ${playerNameHTML(player)}'s island` } });
|
G.log.push({
|
||||||
|
type: 'event',
|
||||||
|
event: {
|
||||||
|
name: GameEventName.Upkeep,
|
||||||
|
interest: `The bank seizes a ${containerColorHTML(container.color)} container from ${playerNameHTML(
|
||||||
|
player
|
||||||
|
)}'s island`,
|
||||||
|
},
|
||||||
|
});
|
||||||
} else if (player.containersOnWarehouseStore.length + player.containersOnFactoryStore.length > 0) {
|
} else if (player.containersOnWarehouseStore.length + player.containersOnFactoryStore.length > 0) {
|
||||||
if (player.containersOnWarehouseStore.length >= 2) {
|
if (player.containersOnWarehouseStore.length >= 2) {
|
||||||
const c1 = removeRandom(player.containersOnWarehouseStore);
|
const c1 = removeRandom(player.containersOnWarehouseStore);
|
||||||
const c2 = removeRandom(player.containersOnWarehouseStore);
|
const c2 = removeRandom(player.containersOnWarehouseStore);
|
||||||
G.log.push({ type: 'event', event: { name: GameEventName.Upkeep, interest: `The bank seizes a ${containerColorHTML(c1.color)} container and a ${containerColorHTML(c2.color)} container from ${playerNameHTML(player)}'s warehouses` } });
|
G.log.push({
|
||||||
|
type: 'event',
|
||||||
|
event: {
|
||||||
|
name: GameEventName.Upkeep,
|
||||||
|
interest: `The bank seizes a ${containerColorHTML(
|
||||||
|
c1.color
|
||||||
|
)} container and a ${containerColorHTML(c2.color)} container from ${playerNameHTML(
|
||||||
|
player
|
||||||
|
)}'s warehouses`,
|
||||||
|
},
|
||||||
|
});
|
||||||
} else if (player.containersOnWarehouseStore.length == 1) {
|
} else if (player.containersOnWarehouseStore.length == 1) {
|
||||||
const c1 = removeRandom(player.containersOnWarehouseStore);
|
const c1 = removeRandom(player.containersOnWarehouseStore);
|
||||||
if (player.containersOnFactoryStore.length >= 1) {
|
if (player.containersOnFactoryStore.length >= 1) {
|
||||||
const c2 = removeRandom(player.containersOnFactoryStore);
|
const c2 = removeRandom(player.containersOnFactoryStore);
|
||||||
G.log.push({ type: 'event', event: { name: GameEventName.Upkeep, interest: `The bank seizes a ${containerColorHTML(c1.color)} container from ${playerNameHTML(player)}'s warehouses and a ${c2.color} container from ${playerNameHTML(player)}'s factory` } });
|
G.log.push({
|
||||||
|
type: 'event',
|
||||||
|
event: {
|
||||||
|
name: GameEventName.Upkeep,
|
||||||
|
interest: `The bank seizes a ${containerColorHTML(
|
||||||
|
c1.color
|
||||||
|
)} container from ${playerNameHTML(player)}'s warehouses and a ${
|
||||||
|
c2.color
|
||||||
|
} container from ${playerNameHTML(player)}'s factory`,
|
||||||
|
},
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
G.log.push({ type: 'event', event: { name: GameEventName.Upkeep, interest: `The bank seizes a ${containerColorHTML(c1.color)} container from ${playerNameHTML(player)}'s warehouses` } });
|
G.log.push({
|
||||||
|
type: 'event',
|
||||||
|
event: {
|
||||||
|
name: GameEventName.Upkeep,
|
||||||
|
interest: `The bank seizes a ${containerColorHTML(
|
||||||
|
c1.color
|
||||||
|
)} container from ${playerNameHTML(player)}'s warehouses`,
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const c1 = removeRandom(player.containersOnFactoryStore);
|
const c1 = removeRandom(player.containersOnFactoryStore);
|
||||||
if (player.containersOnFactoryStore.length >= 1) {
|
if (player.containersOnFactoryStore.length >= 1) {
|
||||||
const c2 = removeRandom(player.containersOnFactoryStore);
|
const c2 = removeRandom(player.containersOnFactoryStore);
|
||||||
G.log.push({ type: 'event', event: { name: GameEventName.Upkeep, interest: `The bank seizes a ${containerColorHTML(c1.color)} container and a ${containerColorHTML(c2.color)} container from ${playerNameHTML(player)}'s factory` } });
|
G.log.push({
|
||||||
|
type: 'event',
|
||||||
|
event: {
|
||||||
|
name: GameEventName.Upkeep,
|
||||||
|
interest: `The bank seizes a ${containerColorHTML(
|
||||||
|
c1.color
|
||||||
|
)} container and a ${containerColorHTML(c2.color)} container from ${playerNameHTML(
|
||||||
|
player
|
||||||
|
)}'s factory`,
|
||||||
|
},
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
G.log.push({ type: 'event', event: { name: GameEventName.Upkeep, interest: `The bank seizes a ${containerColorHTML(c1.color)} container from ${playerNameHTML(player)}'s factory` } });
|
G.log.push({
|
||||||
|
type: 'event',
|
||||||
|
event: {
|
||||||
|
name: GameEventName.Upkeep,
|
||||||
|
interest: `The bank seizes a ${containerColorHTML(
|
||||||
|
c1.color
|
||||||
|
)} container from ${playerNameHTML(player)}'s factory`,
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (player.warehouses.length > 2) {
|
} else if (player.warehouses.length > 2) {
|
||||||
player.warehouses.pop();
|
player.warehouses.pop();
|
||||||
player.loans.pop();
|
player.loans.pop();
|
||||||
G.log.push({ type: 'event', event: { name: GameEventName.Upkeep, interest: `The bank seizes a warehouse from ${playerNameHTML(player)}` } });
|
G.log.push({
|
||||||
|
type: 'event',
|
||||||
|
event: {
|
||||||
|
name: GameEventName.Upkeep,
|
||||||
|
interest: `The bank seizes a warehouse from ${playerNameHTML(player)}`,
|
||||||
|
},
|
||||||
|
});
|
||||||
} else if (player.factories.length > 2) {
|
} else if (player.factories.length > 2) {
|
||||||
player.factories.pop();
|
player.factories.pop();
|
||||||
player.loans.pop();
|
player.loans.pop();
|
||||||
G.log.push({ type: 'event', event: { name: GameEventName.Upkeep, interest: `The bank seizes a factory from ${playerNameHTML(player)}` } });
|
G.log.push({
|
||||||
|
type: 'event',
|
||||||
|
event: {
|
||||||
|
name: GameEventName.Upkeep,
|
||||||
|
interest: `The bank seizes a factory from ${playerNameHTML(player)}`,
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -750,7 +1034,7 @@ function doUpkeep(G: GameState) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function remove(array, value) {
|
function remove(array, value) {
|
||||||
const aux = array.find(x => isEqual(x, value));
|
const aux = array.find((x) => isEqual(x, value));
|
||||||
return array.splice(array.indexOf(aux), 1);
|
return array.splice(array.indexOf(aux), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -782,7 +1066,9 @@ function prettyShipPosition(G: GameState, data: ShipPosition): string {
|
||||||
}
|
}
|
||||||
|
|
||||||
function playerNameHTML(player) {
|
function playerNameHTML(player) {
|
||||||
return `<span style="background-color: ${playerColors[player.id]}; font-weight: bold; padding: 0 3px;">${player.name}</span>`;
|
return `<span style="background-color: ${playerColors[player.id]}; font-weight: bold; padding: 0 3px;">${
|
||||||
|
player.name
|
||||||
|
}</span>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function containerColorHTML(containerColor: ContainerColor) {
|
function containerColorHTML(containerColor: ContainerColor) {
|
||||||
|
|
@ -795,4 +1081,4 @@ function containerColorHTML(containerColor: ContainerColor) {
|
||||||
case ContainerColor.Black:
|
case ContainerColor.Black:
|
||||||
return '<span style="background-color: #2F4F4F; font-weight: bold; border: 1px solid black; padding: 0 3px;">darkslategray</span>';
|
return '<span style="background-color: #2F4F4F; font-weight: bold; border: 1px solid black; padding: 0 3px;">darkslategray</span>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ export enum ContainerColor {
|
||||||
Brown = 'brown',
|
Brown = 'brown',
|
||||||
White = 'white',
|
White = 'white',
|
||||||
Black = 'darkslategray',
|
Black = 'darkslategray',
|
||||||
Tan = 'tan'
|
Tan = 'tan',
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ContainerValue {
|
export interface ContainerValue {
|
||||||
|
|
@ -51,7 +51,7 @@ export enum ShipPosition {
|
||||||
PlayerHarbor42 = 'playerHarbor42',
|
PlayerHarbor42 = 'playerHarbor42',
|
||||||
PlayerHarbor43 = 'playerHarbor43',
|
PlayerHarbor43 = 'playerHarbor43',
|
||||||
PlayerHarbor44 = 'playerHarbor44',
|
PlayerHarbor44 = 'playerHarbor44',
|
||||||
Island = 'island'
|
Island = 'island',
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Ship {
|
export interface Ship {
|
||||||
|
|
@ -90,7 +90,7 @@ export enum Phase {
|
||||||
Bid = 'bid',
|
Bid = 'bid',
|
||||||
AcceptDecline = 'acceptDecline',
|
AcceptDecline = 'acceptDecline',
|
||||||
Setup = 'setup',
|
Setup = 'setup',
|
||||||
GameEnd = 'gameEnd'
|
GameEnd = 'gameEnd',
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ContainerPiece {
|
export interface ContainerPiece {
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import { Move } from './move';
|
||||||
export enum GameEventName {
|
export enum GameEventName {
|
||||||
GameStart = 'Game Start!',
|
GameStart = 'Game Start!',
|
||||||
GameEnd = 'Game End!',
|
GameEnd = 'Game End!',
|
||||||
Upkeep = 'Upkeep'
|
Upkeep = 'Upkeep',
|
||||||
}
|
}
|
||||||
|
|
||||||
export declare namespace GameEvents {
|
export declare namespace GameEvents {
|
||||||
|
|
@ -32,13 +32,13 @@ export type LogPhase = {
|
||||||
export type LogEvent = {
|
export type LogEvent = {
|
||||||
type: 'event';
|
type: 'event';
|
||||||
event: GameEvent;
|
event: GameEvent;
|
||||||
}
|
};
|
||||||
|
|
||||||
export type LogMove = {
|
export type LogMove = {
|
||||||
type: 'move';
|
type: 'move';
|
||||||
player: number;
|
player: number;
|
||||||
move: Move;
|
move: Move;
|
||||||
pretty: string;
|
pretty: string;
|
||||||
}
|
};
|
||||||
|
|
||||||
export type LogItem = LogPhase | LogEvent | LogMove;
|
export type LogItem = LogPhase | LogEvent | LogMove;
|
||||||
|
|
|
||||||
|
|
@ -96,13 +96,22 @@ export declare namespace Moves {
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Move =
|
export type Move =
|
||||||
Moves.MoveBuyFromFactory | Moves.MoveBuyFromWarehouse |
|
| Moves.MoveBuyFromFactory
|
||||||
Moves.MoveBuyFactory | Moves.MoveBuyWarehouse |
|
| Moves.MoveBuyFromWarehouse
|
||||||
Moves.MoveGetLoan | Moves.MovePayLoan |
|
| Moves.MoveBuyFactory
|
||||||
Moves.MoveProduce | Moves.MoveSail |
|
| Moves.MoveBuyWarehouse
|
||||||
Moves.MoveArrangeFactory | Moves.MoveArrangeWarehouse |
|
| Moves.MoveGetLoan
|
||||||
Moves.MoveBid | Moves.MoveAccept | Moves.MoveDecline |
|
| Moves.MovePayLoan
|
||||||
Moves.MovePass | Moves.MoveUndo | Moves.MoveDomesticSale;
|
| Moves.MoveProduce
|
||||||
|
| Moves.MoveSail
|
||||||
|
| Moves.MoveArrangeFactory
|
||||||
|
| Moves.MoveArrangeWarehouse
|
||||||
|
| Moves.MoveBid
|
||||||
|
| Moves.MoveAccept
|
||||||
|
| Moves.MoveDecline
|
||||||
|
| Moves.MovePass
|
||||||
|
| Moves.MoveUndo
|
||||||
|
| Moves.MoveDomesticSale;
|
||||||
|
|
||||||
export enum MoveName {
|
export enum MoveName {
|
||||||
DomesticSale = 'domesticSale',
|
DomesticSale = 'domesticSale',
|
||||||
|
|
@ -120,5 +129,5 @@ export enum MoveName {
|
||||||
Accept = 'accept',
|
Accept = 'accept',
|
||||||
Decline = 'decline',
|
Decline = 'decline',
|
||||||
Pass = 'pass',
|
Pass = 'pass',
|
||||||
Undo = 'undo'
|
Undo = 'undo',
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
import { expect } from "chai";
|
import { expect } from 'chai';
|
||||||
import { shuffle } from './utils';
|
import { shuffle } from './utils';
|
||||||
|
|
||||||
describe("utils", () => {
|
describe('utils', () => {
|
||||||
describe("shuffle", () => {
|
describe('shuffle', () => {
|
||||||
it("should shuffle the same way based on the seed", () => {
|
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], '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], "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]);
|
expect(shuffle([1, 2, 3, 4], 'a')).to.have.ordered.members([4, 2, 3, 1]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
import seedrandom from "seedrandom";
|
import seedrandom from 'seedrandom';
|
||||||
|
|
||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
export function asserts<T>(move: any): asserts move is T {
|
export function asserts<T>(move: any): asserts move is T {}
|
||||||
}
|
|
||||||
|
|
||||||
/* eslint-enable */
|
/* eslint-enable */
|
||||||
|
|
||||||
|
|
@ -20,5 +19,5 @@ export function shuffle<T>(array: T[], seed: string) {
|
||||||
reverse.set(n, i);
|
reverse.set(n, i);
|
||||||
});
|
});
|
||||||
|
|
||||||
return [...reverse.keys()].sort().map(n => array[reverse.get(n)!]);
|
return [...reverse.keys()].sort().map((n) => array[reverse.get(n)!]);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,22 +5,12 @@
|
||||||
"module": "commonjs",
|
"module": "commonjs",
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"strictNullChecks": true,
|
"strictNullChecks": true,
|
||||||
"declaration": true, /* Generates corresponding '.d.ts' file. */
|
"declaration": true /* Generates corresponding '.d.ts' file. */,
|
||||||
"sourceMap": false, /* Generates corresponding '.map' file. */
|
"sourceMap": false /* Generates corresponding '.map' file. */,
|
||||||
// "outFile": "./", /* Concatenate and emit output to single file. */
|
// "outFile": "./", /* Concatenate and emit output to single file. */
|
||||||
"outDir": "./dist", /* Redirect output structure to the directory. */
|
"outDir": "./dist" /* Redirect output structure to the directory. */
|
||||||
},
|
},
|
||||||
"types": [
|
"types": ["node"],
|
||||||
"node"
|
"include": ["src/**/*.ts", "index.ts", "wrapper.ts"],
|
||||||
],
|
"exclude": ["node_modules", "dist", "**/*.spec.ts"]
|
||||||
"include": [
|
}
|
||||||
"src/**/*.ts",
|
|
||||||
"index.ts",
|
|
||||||
"wrapper.ts"
|
|
||||||
],
|
|
||||||
"exclude": [
|
|
||||||
"node_modules",
|
|
||||||
"dist",
|
|
||||||
"**/*.spec.ts"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
import type { GameState } from './index';
|
import type { GameState } from './index';
|
||||||
import { Move } from './src/move';
|
|
||||||
import * as engine from './src/engine';
|
import * as engine from './src/engine';
|
||||||
import { asserts } from './src/utils';
|
|
||||||
import type { LogMove } from './src/log';
|
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> {
|
export async function init(nbPlayers: number, expansions: string[], options: {}, seed?: string): Promise<GameState> {
|
||||||
return engine.setup(nbPlayers, options, seed);
|
return engine.setup(nbPlayers, options, seed);
|
||||||
|
|
@ -20,7 +20,7 @@ export async function move(G: GameState, move: Move, player: number) {
|
||||||
return G;
|
return G;
|
||||||
}
|
}
|
||||||
|
|
||||||
export { ended, scores } from './src/engine';
|
export { ended, scores, stripSecret } from './src/engine';
|
||||||
|
|
||||||
export function rankings(G: GameState) {
|
export function rankings(G: GameState) {
|
||||||
const sortedPlayers = G.players
|
const sortedPlayers = G.players
|
||||||
|
|
@ -30,9 +30,10 @@ export function rankings(G: GameState) {
|
||||||
} else {
|
} else {
|
||||||
return p1.money - p2.money;
|
return p1.money - p2.money;
|
||||||
}
|
}
|
||||||
}).map(pl => pl.id);
|
})
|
||||||
|
.map((pl) => pl.id);
|
||||||
|
|
||||||
return G.players.map(pl => sortedPlayers.indexOf(pl.id) + 1);
|
return G.players.map((pl) => sortedPlayers.indexOf(pl.id) + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function replay(G: GameState) {
|
export function replay(G: GameState) {
|
||||||
|
|
@ -46,7 +47,7 @@ export function replay(G: GameState) {
|
||||||
G.players[i].name = oldPlayers[i].name;
|
G.players[i].name = oldPlayers[i].name;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const move of oldG.log.filter(event => event.type === 'move')) {
|
for (const move of oldG.log.filter((event) => event.type === 'move')) {
|
||||||
asserts<LogMove>(move);
|
asserts<LogMove>(move);
|
||||||
|
|
||||||
G = engine.move(G, move.move, move.player);
|
G = engine.move(G, move.move, move.player);
|
||||||
|
|
@ -69,15 +70,13 @@ export function currentPlayer(G: GameState) {
|
||||||
return G.currentPlayer;
|
return G.currentPlayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
export { stripSecret } from './src/engine';
|
|
||||||
|
|
||||||
export function messages(G: GameState) {
|
export function messages(G: GameState) {
|
||||||
const messages = (G as any).messages || [];
|
const messages = (G as any).messages || [];
|
||||||
delete (G as any).messages;
|
delete (G as any).messages;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
messages,
|
messages,
|
||||||
data: G
|
data: G,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -89,8 +88,11 @@ export function logSlice(G: GameState, options?: { player?: number; start?: numb
|
||||||
const stripped = engine.stripSecret(G, options?.player);
|
const stripped = engine.stripSecret(G, options?.player);
|
||||||
return {
|
return {
|
||||||
log: stripped.log.slice(options?.start, options?.end),
|
log: stripped.log.slice(options?.start, options?.end),
|
||||||
availableMoves: options?.end === undefined ?
|
availableMoves:
|
||||||
stripped.players.map(pl => pl.availableMoves) :
|
options?.end === undefined
|
||||||
engine.stripSecret(replay({ ...G, log: G.log.slice(0, options!.end) }), options!.player).players.map(pl => pl.availableMoves)
|
? stripped.players.map((pl) => pl.availableMoves)
|
||||||
|
: engine
|
||||||
|
.stripSecret(replay({ ...G, log: G.log.slice(0, options!.end) }), options!.player)
|
||||||
|
.players.map((pl) => pl.availableMoves),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
34
package.json
34
package.json
|
|
@ -1,19 +1,19 @@
|
||||||
{
|
{
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lint-staged": "lint-staged",
|
"lint-staged": "lint-staged",
|
||||||
"postinstall": "husky install",
|
"postinstall": "husky install",
|
||||||
"prettier": "prettier --plugin-search-dir=. --write .",
|
"prettier": "prettier --plugin-search-dir=. --write .",
|
||||||
"prettier-check": "prettier --plugin-search-dir=. --check ."
|
"prettier-check": "prettier --plugin-search-dir=. --check ."
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"husky": "^5.0.9",
|
"husky": "^5.0.9",
|
||||||
"lint-staged": "^10.5.4",
|
"lint-staged": "^10.5.4",
|
||||||
"prettier": "^2.2.1",
|
"prettier": "^2.2.1",
|
||||||
"prettier-plugin-organize-imports": "^1.1.1",
|
"prettier-plugin-organize-imports": "^1.1.1",
|
||||||
"typescript": "^4.1.5"
|
"typescript": "^4.1.5"
|
||||||
},
|
},
|
||||||
"lint-staged": {
|
"lint-staged": {
|
||||||
"*.{css,scss,graphql,html,json,js,jsx,md,mdx,ts,tsx,vue,yaml,yml}": "prettier --plugin-search-dir=. --write"
|
"*.{css,scss,graphql,html,json,js,jsx,md,mdx,ts,tsx,vue,yaml,yml}": "prettier --plugin-search-dir=. --write"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
1622
pnpm-lock.yaml
generated
1622
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load diff
|
|
@ -1,3 +1,3 @@
|
||||||
packages:
|
packages:
|
||||||
- "viewer"
|
- 'viewer'
|
||||||
- "engine"
|
- 'engine'
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,26 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
extends: ["eslint:recommended", "plugin:vue/recommended"],
|
extends: ['eslint:recommended', 'plugin:vue/recommended'],
|
||||||
rules: {
|
rules: {
|
||||||
"vue/no-unused-vars": "error",
|
'vue/no-unused-vars': 'error',
|
||||||
"vue/html-indent": ["error", 4, { alignAttributesVertically: false }],
|
'vue/html-indent': ['error', 4, { alignAttributesVertically: false }],
|
||||||
"vue/max-attributes-per-line": 0,
|
'vue/max-attributes-per-line': 0,
|
||||||
"vue/html-closing-bracket-newline": [
|
'vue/html-closing-bracket-newline': [
|
||||||
"error",
|
'error',
|
||||||
{
|
{
|
||||||
singleline: "never",
|
singleline: 'never',
|
||||||
multiline: "never",
|
multiline: 'never',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
"vue/attribute-hyphenation": ["error", "never"],
|
'vue/attribute-hyphenation': ['error', 'never'],
|
||||||
"vue/singleline-html-element-content-newline": "off",
|
'vue/singleline-html-element-content-newline': 'off',
|
||||||
"no-case-declarations": "off",
|
'no-case-declarations': 'off',
|
||||||
"no-unused-vars": "off",
|
'no-unused-vars': 'off',
|
||||||
quotes: ["error", "single"],
|
quotes: ['error', 'single'],
|
||||||
},
|
},
|
||||||
env: {
|
env: {
|
||||||
node: true,
|
node: true,
|
||||||
},
|
},
|
||||||
parserOptions: {
|
parserOptions: {
|
||||||
parser: "@typescript-eslint/parser",
|
parser: '@typescript-eslint/parser',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
<template>
|
<template></template>
|
||||||
|
|
||||||
</template>
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import {Vue, Component, Prop, Watch} from "vue-property-decorator";
|
import {Vue, Component, Prop, Watch} from "vue-property-decorator";
|
||||||
|
|
||||||
|
|
@ -8,5 +6,4 @@ import {Vue, Component, Prop, Watch} from "vue-property-decorator";
|
||||||
export default class $0 extends Vue {
|
export default class $0 extends Vue {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -1,29 +1,35 @@
|
||||||
# container-viewer
|
# container-viewer
|
||||||
|
|
||||||
## Project setup
|
## Project setup
|
||||||
|
|
||||||
```
|
```
|
||||||
yarn install
|
yarn install
|
||||||
```
|
```
|
||||||
|
|
||||||
### Compiles and hot-reloads for development
|
### Compiles and hot-reloads for development
|
||||||
|
|
||||||
```
|
```
|
||||||
yarn serve
|
yarn serve
|
||||||
```
|
```
|
||||||
|
|
||||||
### Compiles and minifies for production
|
### Compiles and minifies for production
|
||||||
|
|
||||||
```
|
```
|
||||||
yarn build
|
yarn build
|
||||||
```
|
```
|
||||||
|
|
||||||
### Run your unit tests
|
### Run your unit tests
|
||||||
|
|
||||||
```
|
```
|
||||||
yarn test:unit
|
yarn test:unit
|
||||||
```
|
```
|
||||||
|
|
||||||
### Lints and fixes files
|
### Lints and fixes files
|
||||||
|
|
||||||
```
|
```
|
||||||
yarn lint
|
yarn lint
|
||||||
```
|
```
|
||||||
|
|
||||||
### Customize configuration
|
### Customize configuration
|
||||||
|
|
||||||
See [Configuration Reference](https://cli.vuejs.org/config/).
|
See [Configuration Reference](https://cli.vuejs.org/config/).
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
presets: [
|
presets: ['@vue/cli-plugin-babel/preset'],
|
||||||
'@vue/cli-plugin-babel/preset'
|
};
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
|
||||||
21674
viewer/pnpm-lock.yaml
generated
21674
viewer/pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load diff
|
|
@ -1,17 +1,20 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8" />
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||||
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
|
||||||
<!-- <link rel="icon" href="<%= BASE_URL %>favicon.ico">-->
|
<!-- <link rel="icon" href="<%= BASE_URL %>favicon.ico">-->
|
||||||
<title><%= htmlWebpackPlugin.options.title %></title>
|
<title><%= htmlWebpackPlugin.options.title %></title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<noscript>
|
<noscript>
|
||||||
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
|
<strong
|
||||||
</noscript>
|
>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript
|
||||||
<div id="app"></div>
|
enabled. Please enable it to continue.</strong
|
||||||
<!-- built files will be auto injected -->
|
>
|
||||||
</body>
|
</noscript>
|
||||||
|
<div id="app"></div>
|
||||||
|
<!-- built files will be auto injected -->
|
||||||
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
|
|
@ -12,4 +12,4 @@ import { Vue, Component } from 'vue-property-decorator';
|
||||||
@Component
|
@Component
|
||||||
export default class LogButton extends Vue {
|
export default class LogButton extends Vue {
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -14,4 +14,4 @@ export default class UndoButton extends Vue {
|
||||||
@Prop()
|
@Prop()
|
||||||
enabled!: boolean;
|
enabled!: boolean;
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,6 @@ export default class Calculator extends Vue {
|
||||||
this.value = 0;
|
this.value = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
.calculator {
|
.calculator {
|
||||||
|
|
@ -60,7 +59,7 @@ export default class Calculator extends Vue {
|
||||||
}
|
}
|
||||||
|
|
||||||
.visor {
|
.visor {
|
||||||
font-family: "system-ui";
|
font-family: 'system-ui';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
||||||
|
|
@ -153,7 +153,6 @@ export default class DropZone extends Vue {
|
||||||
return this.ui.helpOn && this.canDrop;
|
return this.ui.helpOn && this.canDrop;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
g.placeholder {
|
g.placeholder {
|
||||||
|
|
@ -173,4 +172,4 @@ g.placeholder {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,11 @@
|
||||||
{{ getStatusMessage() }}
|
{{ getStatusMessage() }}
|
||||||
</div>
|
</div>
|
||||||
<audio id="piece-drop" preload="none">
|
<audio id="piece-drop" preload="none">
|
||||||
<source src="../audio/piece-drop.mp3" type="audio/mpeg">
|
<source src="../audio/piece-drop.mp3" type="audio/mpeg" />
|
||||||
</audio>
|
</audio>
|
||||||
<audio id="notification" preload="none">
|
<audio id="notification" preload="none">
|
||||||
<source src="../audio/notification.mp3" type="audio/mpeg">
|
<source src="../audio/notification.mp3" type="audio/mpeg" />
|
||||||
<source src="../audio/notification.ogg" type="audio/ogg">
|
<source src="../audio/notification.ogg" type="audio/ogg" />
|
||||||
</audio>
|
</audio>
|
||||||
<svg id="scene" viewBox="0 0 1250 650" height="650">
|
<svg id="scene" viewBox="0 0 1250 650" height="650">
|
||||||
<rect width="100%" height="100%" x="0" y="0" fill="lightblue" />
|
<rect width="100%" height="100%" x="0" y="0" fill="lightblue" />
|
||||||
|
|
@ -21,27 +21,60 @@
|
||||||
<SoundButton transform="translate(1200, 15)" :isOn="soundOn" @click="toggleSound()" />
|
<SoundButton transform="translate(1200, 15)" :isOn="soundOn" @click="toggleSound()" />
|
||||||
<HelpButton transform="translate(1200, 55)" :isOn="ui.helpOn" @click="toggleHelp()" />
|
<HelpButton transform="translate(1200, 55)" :isOn="ui.helpOn" @click="toggleHelp()" />
|
||||||
|
|
||||||
<DropZone transform="translate(5, 5)" :width="600" :height="90" :enabled="true" :accepts="'container'" :data="{ type: 'supply' }" />
|
<DropZone
|
||||||
|
transform="translate(5, 5)"
|
||||||
|
:width="600"
|
||||||
|
:height="90"
|
||||||
|
:enabled="true"
|
||||||
|
:accepts="'container'"
|
||||||
|
:data="{ type: 'supply' }"
|
||||||
|
/>
|
||||||
|
|
||||||
<template v-if="G">
|
<template v-if="G">
|
||||||
<template v-for="(p, i) in G.players">
|
<template v-for="(p, i) in G.players">
|
||||||
<PlayerBoard :key="'B' + i"
|
<PlayerBoard
|
||||||
|
:key="'B' + i"
|
||||||
:player="p"
|
:player="p"
|
||||||
:color="playerColors[i]"
|
:color="playerColors[i]"
|
||||||
:transform="`translate(${250 * i}, 100)`"
|
:transform="`translate(${250 * i}, 100)`"
|
||||||
:owner="i"
|
:owner="i"
|
||||||
:isCurrentPlayer="isCurrentPlayer(i)"
|
:isCurrentPlayer="isCurrentPlayer(i)"
|
||||||
:ended="gameEnded(G)"
|
:ended="gameEnded(G)"
|
||||||
@pieceDrop="onPieceDrop" />
|
@pieceDrop="onPieceDrop"
|
||||||
<rect :key="'I' + i" width="390" height="41" x="860" :y="430 + i * 44" fill="none" stroke-width="3" :stroke="playerColors[i]" />
|
/>
|
||||||
|
<rect
|
||||||
|
:key="'I' + i"
|
||||||
|
width="390"
|
||||||
|
height="41"
|
||||||
|
x="860"
|
||||||
|
:y="430 + i * 44"
|
||||||
|
fill="none"
|
||||||
|
stroke-width="3"
|
||||||
|
:stroke="playerColors[i]"
|
||||||
|
/>
|
||||||
</template>
|
</template>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<DropZone :transform="`translate(280, 425)`" :width="400" :height="225" :enabled="true" :accepts="'ship'" :data="{ type: 'openSea' }" />
|
<DropZone
|
||||||
<DropZone :transform="`translate(770, 425)`" :width="480" :height="225" :enabled="true" :accepts="'ship'" :data="{ type: 'islandHarbor' }" />
|
:transform="`translate(280, 425)`"
|
||||||
|
:width="400"
|
||||||
|
:height="225"
|
||||||
|
:enabled="true"
|
||||||
|
:accepts="'ship'"
|
||||||
|
:data="{ type: 'openSea' }"
|
||||||
|
/>
|
||||||
|
<DropZone
|
||||||
|
:transform="`translate(770, 425)`"
|
||||||
|
:width="480"
|
||||||
|
:height="225"
|
||||||
|
:enabled="true"
|
||||||
|
:accepts="'ship'"
|
||||||
|
:data="{ type: 'islandHarbor' }"
|
||||||
|
/>
|
||||||
|
|
||||||
<template v-for="ship in ships">
|
<template v-for="ship in ships">
|
||||||
<Ship :key="ship.id"
|
<Ship
|
||||||
|
:key="ship.id"
|
||||||
:pieceId="ship.id"
|
:pieceId="ship.id"
|
||||||
:targetState="{ x: ship.x, y: ship.y, rotate: ship.rotate }"
|
:targetState="{ x: ship.x, y: ship.y, rotate: ship.rotate }"
|
||||||
:canDrag="canDragShip(ship)"
|
:canDrag="canDragShip(ship)"
|
||||||
|
|
@ -49,43 +82,63 @@
|
||||||
:owner="ship.owner"
|
:owner="ship.owner"
|
||||||
:ownerName="G.players[ship.owner].name"
|
:ownerName="G.players[ship.owner].name"
|
||||||
:position="ship.position"
|
:position="ship.position"
|
||||||
:color="ship.color" />
|
:color="ship.color"
|
||||||
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template v-for="container in containers">
|
<template v-for="container in containers">
|
||||||
<Container :key="container.id"
|
<Container
|
||||||
|
:key="container.id"
|
||||||
:pieceId="container.id"
|
:pieceId="container.id"
|
||||||
:targetState="{ x: container.x, y: container.y, rotate: container.rotate }"
|
:targetState="{
|
||||||
|
x: container.x,
|
||||||
|
y: container.y,
|
||||||
|
rotate: container.rotate,
|
||||||
|
}"
|
||||||
:canDrag="canDragContainer(container)"
|
:canDrag="canDragContainer(container)"
|
||||||
:color="container.color"
|
:color="container.color"
|
||||||
:owner="container.owner"
|
:owner="container.owner"
|
||||||
:state="container.state" />
|
:state="container.state"
|
||||||
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template v-for="factory in factories">
|
<template v-for="factory in factories">
|
||||||
<Factory :key="factory.id"
|
<Factory
|
||||||
|
:key="factory.id"
|
||||||
:pieceId="factory.id"
|
:pieceId="factory.id"
|
||||||
:targetState="{ x: factory.x, y: factory.y}"
|
:targetState="{ x: factory.x, y: factory.y }"
|
||||||
:color="factory.color"
|
:color="factory.color"
|
||||||
:canDrag="canDragFactory(factory)" />
|
:canDrag="canDragFactory(factory)"
|
||||||
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template v-for="warehouse in warehouses">
|
<template v-for="warehouse in warehouses">
|
||||||
<Warehouse :key="warehouse.id"
|
<Warehouse
|
||||||
|
:key="warehouse.id"
|
||||||
:pieceId="warehouse.id"
|
:pieceId="warehouse.id"
|
||||||
:targetState="{ x: warehouse.x, y: warehouse.y}"
|
:targetState="{ x: warehouse.x, y: warehouse.y }"
|
||||||
:canDrag="canDragWarehouse(warehouse)" />
|
:canDrag="canDragWarehouse(warehouse)"
|
||||||
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<DropZone :transform="`translate(1045, 5)`" :width="50" :height="90" :enabled="true" :accepts="'loan'" :data="{ type: 'payLoan' }" />
|
<DropZone
|
||||||
|
:transform="`translate(1045, 5)`"
|
||||||
|
:width="50"
|
||||||
|
:height="90"
|
||||||
|
:enabled="true"
|
||||||
|
:accepts="'loan'"
|
||||||
|
:data="{ type: 'payLoan' }"
|
||||||
|
/>
|
||||||
|
|
||||||
<template v-for="loanCard in loanCards">
|
<template v-for="loanCard in loanCards">
|
||||||
<LoanCard :key="loanCard.id"
|
<LoanCard
|
||||||
|
:key="loanCard.id"
|
||||||
:targetState="{ x: loanCard.x, y: loanCard.y }"
|
:targetState="{ x: loanCard.x, y: loanCard.y }"
|
||||||
:owner="loanCard.owner"
|
:owner="loanCard.owner"
|
||||||
:player="player"
|
:player="player"
|
||||||
:canDrag="canDragLoan(loanCard)"
|
:canDrag="canDragLoan(loanCard)"
|
||||||
@fastClick="loan($event)" />
|
@fastClick="loan($event)"
|
||||||
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template v-if="G">
|
<template v-if="G">
|
||||||
|
|
@ -97,53 +150,282 @@
|
||||||
<Calculator v-if="G.phase == 'bid'" transform="translate(140, 430)" @bid="bid($event)" />
|
<Calculator v-if="G.phase == 'bid'" transform="translate(140, 430)" @bid="bid($event)" />
|
||||||
<template v-if="player == G.auctioningPlayer">
|
<template v-if="player == G.auctioningPlayer">
|
||||||
<template v-for="(bidder, i) in G.highestBidders">
|
<template v-for="(bidder, i) in G.highestBidders">
|
||||||
<Button :key="bidder" :transform="`translate(140, ${450 + 40 * i})`" :width="130" :text="'Accept ' + getName(bidder)" @click="accept(bidder)" />
|
<Button
|
||||||
|
:key="bidder"
|
||||||
|
:transform="`translate(140, ${450 + 40 * i})`"
|
||||||
|
:width="130"
|
||||||
|
:text="'Accept ' + getName(bidder)"
|
||||||
|
@click="accept(bidder)"
|
||||||
|
/>
|
||||||
</template>
|
</template>
|
||||||
<Button :transform="`translate(140, ${450 + 40 * G.highestBidders.length})`" :width="130" :text="'Decline'" :enabled="canDecline()" @click="decline()" />
|
<Button
|
||||||
|
:transform="`translate(140, ${450 + 40 * G.highestBidders.length})`"
|
||||||
|
:width="130"
|
||||||
|
:text="'Decline'"
|
||||||
|
:enabled="canDecline()"
|
||||||
|
@click="decline()"
|
||||||
|
/>
|
||||||
</template>
|
</template>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template v-if="G && gameEnded(G)">
|
<template v-if="G && gameEnded(G)">
|
||||||
<Button :transform="`translate(140, 580)`" :width="130" :text="'Final Score'" @click="endScoreVisible = true" />
|
<Button
|
||||||
|
:transform="`translate(140, 580)`"
|
||||||
|
:width="130"
|
||||||
|
:text="'Final Score'"
|
||||||
|
@click="endScoreVisible = true"
|
||||||
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template v-if="ui.helpOn">
|
<template v-if="ui.helpOn">
|
||||||
<template v-if="ui.dragged == null">
|
<template v-if="ui.dragged == null">
|
||||||
<rect v-if="canBuyFactory('orange')" x="8" y="8" width="114" height="24" fill="none" stroke="blue" stroke-width="2px" rx="2px" />
|
<rect
|
||||||
<rect v-if="canBuyFactory('brown')" x="128" y="8" width="114" height="24" fill="none" stroke="blue" stroke-width="2px" rx="2px" />
|
v-if="canBuyFactory('orange')"
|
||||||
<rect v-if="canBuyFactory('white')" x="248" y="8" width="114" height="24" fill="none" stroke="blue" stroke-width="2px" rx="2px" />
|
x="8"
|
||||||
<rect v-if="canBuyFactory('darkslategray')" x="368" y="8" width="114" height="24" fill="none" stroke="blue" stroke-width="2px" rx="2px" />
|
y="8"
|
||||||
<rect v-if="canBuyFactory('tan')" x="488" y="8" width="114" height="24" fill="none" stroke="blue" stroke-width="2px" rx="2px" />
|
width="114"
|
||||||
|
height="24"
|
||||||
|
fill="none"
|
||||||
|
stroke="blue"
|
||||||
|
stroke-width="2px"
|
||||||
|
rx="2px"
|
||||||
|
/>
|
||||||
|
<rect
|
||||||
|
v-if="canBuyFactory('brown')"
|
||||||
|
x="128"
|
||||||
|
y="8"
|
||||||
|
width="114"
|
||||||
|
height="24"
|
||||||
|
fill="none"
|
||||||
|
stroke="blue"
|
||||||
|
stroke-width="2px"
|
||||||
|
rx="2px"
|
||||||
|
/>
|
||||||
|
<rect
|
||||||
|
v-if="canBuyFactory('white')"
|
||||||
|
x="248"
|
||||||
|
y="8"
|
||||||
|
width="114"
|
||||||
|
height="24"
|
||||||
|
fill="none"
|
||||||
|
stroke="blue"
|
||||||
|
stroke-width="2px"
|
||||||
|
rx="2px"
|
||||||
|
/>
|
||||||
|
<rect
|
||||||
|
v-if="canBuyFactory('darkslategray')"
|
||||||
|
x="368"
|
||||||
|
y="8"
|
||||||
|
width="114"
|
||||||
|
height="24"
|
||||||
|
fill="none"
|
||||||
|
stroke="blue"
|
||||||
|
stroke-width="2px"
|
||||||
|
rx="2px"
|
||||||
|
/>
|
||||||
|
<rect
|
||||||
|
v-if="canBuyFactory('tan')"
|
||||||
|
x="488"
|
||||||
|
y="8"
|
||||||
|
width="114"
|
||||||
|
height="24"
|
||||||
|
fill="none"
|
||||||
|
stroke="blue"
|
||||||
|
stroke-width="2px"
|
||||||
|
rx="2px"
|
||||||
|
/>
|
||||||
|
|
||||||
<rect v-if="canBuyWarehouse()" x="615" y="10" width="424" height="72" fill="none" stroke="blue" stroke-width="2px" rx="2px" />
|
<rect
|
||||||
|
v-if="canBuyWarehouse()"
|
||||||
|
x="615"
|
||||||
|
y="10"
|
||||||
|
width="424"
|
||||||
|
height="72"
|
||||||
|
fill="none"
|
||||||
|
stroke="blue"
|
||||||
|
stroke-width="2px"
|
||||||
|
rx="2px"
|
||||||
|
/>
|
||||||
|
|
||||||
<rect v-if="canProduce('orange')" x="6" y="36" width="116" height="54" fill="none" stroke="blue" stroke-width="2px" rx="2px" />
|
<rect
|
||||||
<rect v-if="canProduce('brown')" x="126" y="36" width="116" height="54" fill="none" stroke="blue" stroke-width="2px" rx="2px" />
|
v-if="canProduce('orange')"
|
||||||
<rect v-if="canProduce('white')" x="246" y="36" width="116" height="54" fill="none" stroke="blue" stroke-width="2px" rx="2px" />
|
x="6"
|
||||||
<rect v-if="canProduce('darkslategray')" x="366" y="36" width="116" height="54" fill="none" stroke="blue" stroke-width="2px" rx="2px" />
|
y="36"
|
||||||
<rect v-if="canProduce('tan')" x="486" y="36" width="116" height="54" fill="none" stroke="blue" stroke-width="2px" rx="2px" />
|
width="116"
|
||||||
|
height="54"
|
||||||
|
fill="none"
|
||||||
|
stroke="blue"
|
||||||
|
stroke-width="2px"
|
||||||
|
rx="2px"
|
||||||
|
/>
|
||||||
|
<rect
|
||||||
|
v-if="canProduce('brown')"
|
||||||
|
x="126"
|
||||||
|
y="36"
|
||||||
|
width="116"
|
||||||
|
height="54"
|
||||||
|
fill="none"
|
||||||
|
stroke="blue"
|
||||||
|
stroke-width="2px"
|
||||||
|
rx="2px"
|
||||||
|
/>
|
||||||
|
<rect
|
||||||
|
v-if="canProduce('white')"
|
||||||
|
x="246"
|
||||||
|
y="36"
|
||||||
|
width="116"
|
||||||
|
height="54"
|
||||||
|
fill="none"
|
||||||
|
stroke="blue"
|
||||||
|
stroke-width="2px"
|
||||||
|
rx="2px"
|
||||||
|
/>
|
||||||
|
<rect
|
||||||
|
v-if="canProduce('darkslategray')"
|
||||||
|
x="366"
|
||||||
|
y="36"
|
||||||
|
width="116"
|
||||||
|
height="54"
|
||||||
|
fill="none"
|
||||||
|
stroke="blue"
|
||||||
|
stroke-width="2px"
|
||||||
|
rx="2px"
|
||||||
|
/>
|
||||||
|
<rect
|
||||||
|
v-if="canProduce('tan')"
|
||||||
|
x="486"
|
||||||
|
y="36"
|
||||||
|
width="116"
|
||||||
|
height="54"
|
||||||
|
fill="none"
|
||||||
|
stroke="blue"
|
||||||
|
stroke-width="2px"
|
||||||
|
rx="2px"
|
||||||
|
/>
|
||||||
|
|
||||||
<rect v-if="canGetLoan()" x="1045" y="5" width="50" height="90" fill="none" stroke="blue" stroke-width="2px" rx="2px" />
|
<rect
|
||||||
|
v-if="canGetLoan()"
|
||||||
|
x="1045"
|
||||||
|
y="5"
|
||||||
|
width="50"
|
||||||
|
height="90"
|
||||||
|
fill="none"
|
||||||
|
stroke="blue"
|
||||||
|
stroke-width="2px"
|
||||||
|
rx="2px"
|
||||||
|
/>
|
||||||
|
|
||||||
<rect v-if="canPass()" x="1104" y="4" width="82" height="28" fill="none" stroke="blue" stroke-width="2px" rx="2px" />
|
<rect
|
||||||
|
v-if="canPass()"
|
||||||
|
x="1104"
|
||||||
|
y="4"
|
||||||
|
width="82"
|
||||||
|
height="28"
|
||||||
|
fill="none"
|
||||||
|
stroke="blue"
|
||||||
|
stroke-width="2px"
|
||||||
|
rx="2px"
|
||||||
|
/>
|
||||||
|
|
||||||
<rect v-if="canUndo()" x="1104" y="35" width="82" height="28" fill="none" stroke="blue" stroke-width="2px" rx="2px" />
|
<rect
|
||||||
|
v-if="canUndo()"
|
||||||
|
x="1104"
|
||||||
|
y="35"
|
||||||
|
width="82"
|
||||||
|
height="28"
|
||||||
|
fill="none"
|
||||||
|
stroke="blue"
|
||||||
|
stroke-width="2px"
|
||||||
|
rx="2px"
|
||||||
|
/>
|
||||||
|
|
||||||
<rect v-if="canPayLoan()" :x="200 + player * 250" y="123" width="47" height="77" fill="none" stroke="blue" stroke-width="2px" rx="2px" />
|
<rect
|
||||||
|
v-if="canPayLoan()"
|
||||||
|
:x="200 + player * 250"
|
||||||
|
y="123"
|
||||||
|
width="47"
|
||||||
|
height="77"
|
||||||
|
fill="none"
|
||||||
|
stroke="blue"
|
||||||
|
stroke-width="2px"
|
||||||
|
rx="2px"
|
||||||
|
/>
|
||||||
|
|
||||||
<g v-if="canSail()">
|
<g v-if="canSail()">
|
||||||
<rect v-if="!ships[player].rotate" :x="ships[player].x - 5" :y="ships[player].y - 5" width="40" height="90" fill="none" stroke="blue" stroke-width="2px" rx="2px" />
|
<rect
|
||||||
<rect v-else :x="ships[player].x - 30" :y="ships[player].y + 20" width="90" height="40" fill="none" stroke="blue" stroke-width="2px" rx="2px" />
|
v-if="!ships[player].rotate"
|
||||||
|
:x="ships[player].x - 5"
|
||||||
|
:y="ships[player].y - 5"
|
||||||
|
width="40"
|
||||||
|
height="90"
|
||||||
|
fill="none"
|
||||||
|
stroke="blue"
|
||||||
|
stroke-width="2px"
|
||||||
|
rx="2px"
|
||||||
|
/>
|
||||||
|
<rect
|
||||||
|
v-else
|
||||||
|
:x="ships[player].x - 30"
|
||||||
|
:y="ships[player].y + 20"
|
||||||
|
width="90"
|
||||||
|
height="40"
|
||||||
|
fill="none"
|
||||||
|
stroke="blue"
|
||||||
|
stroke-width="2px"
|
||||||
|
rx="2px"
|
||||||
|
/>
|
||||||
</g>
|
</g>
|
||||||
|
|
||||||
<rect v-if="canArrangeFactory()" :x="6 + player * 250" y="158" width="188" height="44" fill="none" stroke="blue" stroke-width="2px" rx="2px" />
|
<rect
|
||||||
|
v-if="canArrangeFactory()"
|
||||||
|
:x="6 + player * 250"
|
||||||
|
y="158"
|
||||||
|
width="188"
|
||||||
|
height="44"
|
||||||
|
fill="none"
|
||||||
|
stroke="blue"
|
||||||
|
stroke-width="2px"
|
||||||
|
rx="2px"
|
||||||
|
/>
|
||||||
|
|
||||||
<rect v-if="canArrangeWarehouse()" :x="6 + player * 250" y="248" width="236" height="44" fill="none" stroke="blue" stroke-width="2px" rx="2px" />
|
<rect
|
||||||
|
v-if="canArrangeWarehouse()"
|
||||||
|
:x="6 + player * 250"
|
||||||
|
y="248"
|
||||||
|
width="236"
|
||||||
|
height="44"
|
||||||
|
fill="none"
|
||||||
|
stroke="blue"
|
||||||
|
stroke-width="2px"
|
||||||
|
rx="2px"
|
||||||
|
/>
|
||||||
|
|
||||||
<template v-if="G">
|
<template v-if="G">
|
||||||
<template v-for="(p, i) in G.players">
|
<template v-for="(p, i) in G.players">
|
||||||
<rect v-if="canBuyFromPlayerFactory(p)" :key="'PHF' + i" :x="6 + i * 250" y="158" width="188" height="44" fill="none" stroke="blue" stroke-width="2px" rx="2px" />
|
<rect
|
||||||
<rect v-if="canBuyFromPlayerWarehouse(p)" :key="'PHW' + i" :x="6 + i * 250" y="248" width="236" height="44" fill="none" stroke="blue" stroke-width="2px" rx="2px" />
|
v-if="canBuyFromPlayerFactory(p)"
|
||||||
|
:key="'PHF' + i"
|
||||||
|
:x="6 + i * 250"
|
||||||
|
y="158"
|
||||||
|
width="188"
|
||||||
|
height="44"
|
||||||
|
fill="none"
|
||||||
|
stroke="blue"
|
||||||
|
stroke-width="2px"
|
||||||
|
rx="2px"
|
||||||
|
/>
|
||||||
|
<rect
|
||||||
|
v-if="canBuyFromPlayerWarehouse(p)"
|
||||||
|
:key="'PHW' + i"
|
||||||
|
:x="6 + i * 250"
|
||||||
|
y="248"
|
||||||
|
width="236"
|
||||||
|
height="44"
|
||||||
|
fill="none"
|
||||||
|
stroke="blue"
|
||||||
|
stroke-width="2px"
|
||||||
|
rx="2px"
|
||||||
|
/>
|
||||||
</template>
|
</template>
|
||||||
</template>
|
</template>
|
||||||
</template>
|
</template>
|
||||||
|
|
@ -170,15 +452,34 @@
|
||||||
<table class="final-score-table">
|
<table class="final-score-table">
|
||||||
<tr>
|
<tr>
|
||||||
<th>Player</th>
|
<th>Player</th>
|
||||||
<th v-for="player in G.players" :key="'FS' + player.id">{{ player.name }}</th>
|
<th v-for="player in G.players" :key="'FS' + player.id">
|
||||||
|
{{ player.name }}
|
||||||
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
<tr v-for="(cat, i) in ['Money', 'Brown', 'Dark Green', 'Orange', 'Tan', 'White', 'Containers in Warehouse', 'Containers in Ship', 'Loans']" :key="'FC_' + cat">
|
<tr
|
||||||
|
v-for="(cat, i) in [
|
||||||
|
'Money',
|
||||||
|
'Brown',
|
||||||
|
'Dark Green',
|
||||||
|
'Orange',
|
||||||
|
'Tan',
|
||||||
|
'White',
|
||||||
|
'Containers in Warehouse',
|
||||||
|
'Containers in Ship',
|
||||||
|
'Loans',
|
||||||
|
]"
|
||||||
|
:key="'FC_' + cat"
|
||||||
|
>
|
||||||
<td>{{ cat }}</td>
|
<td>{{ cat }}</td>
|
||||||
<td v-for="player in G.players" :key="'FS' + player.id + i">{{ player.finalScoreBreakdown ? player.finalScoreBreakdown[i] : '0' }}</td>
|
<td v-for="player in G.players" :key="'FS' + player.id + i">
|
||||||
|
{{ player.finalScoreBreakdown ? player.finalScoreBreakdown[i] : '0' }}
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Final Score</td>
|
<td>Final Score</td>
|
||||||
<td v-for="player in G.players" :key="'FS' + player.id + 'money'">{{ player.money > 0 ? '$' + player.money : '-$' + Math.abs(player.money) }}</td>
|
<td v-for="player in G.players" :key="'FS' + player.id + 'money'">
|
||||||
|
{{ player.money > 0 ? '$' + player.money : '-$' + Math.abs(player.money) }}
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -877,7 +1178,6 @@ export default class Game extends Vue {
|
||||||
return logReversed;
|
return logReversed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
.game {
|
.game {
|
||||||
|
|
@ -915,7 +1215,7 @@ html {
|
||||||
}
|
}
|
||||||
|
|
||||||
text {
|
text {
|
||||||
font-family: "Arial";
|
font-family: 'Arial';
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
dominant-baseline: central;
|
dominant-baseline: central;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
<template>
|
<template>
|
||||||
<g class="player-board">
|
<g class="player-board">
|
||||||
<rect width="250" height="20" x="0" y="0" :fill="color" />
|
<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>
|
<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="250" height="180" x="0" y="20" fill="gray" />
|
||||||
|
|
||||||
|
|
@ -9,12 +11,43 @@
|
||||||
<rect width="20" height="80" x="62" 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="124" y="200" fill="gray" />
|
||||||
<rect width="20" height="80" x="186" 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
|
||||||
<DropZone :transform="`translate(82, 200)`" :width="42" :height="80" :accepts="'ship'" :data="{ type: 'playerHarbor' + owner + '2', owner: owner }" />
|
:transform="`translate(20, 200)`"
|
||||||
<DropZone :transform="`translate(144, 200)`" :width="42" :height="80" :accepts="'ship'" :data="{ type: 'playerHarbor' + owner + '3', owner: owner }" />
|
:width="42"
|
||||||
<DropZone :transform="`translate(206, 200)`" :width="43" :height="80" :accepts="'ship'" :data="{ type: 'playerHarbor' + owner + '4', owner: owner }" />
|
: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' }" />
|
<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" />
|
<circle r="14" cx="28" cy="40" fill="none" stroke="lightgray" />
|
||||||
<text text-anchor="middle" x="28" y="40" fill="lightgray">-</text>
|
<text text-anchor="middle" x="28" y="40" fill="lightgray">-</text>
|
||||||
|
|
@ -24,48 +57,135 @@
|
||||||
<text text-anchor="middle" x="124" y="40" fill="lightgray">9</text>
|
<text text-anchor="middle" x="124" y="40" fill="lightgray">9</text>
|
||||||
<circle r="14" cx="172" cy="40" fill="none" stroke="lightgray" />
|
<circle r="14" cx="172" cy="40" fill="none" stroke="lightgray" />
|
||||||
<text text-anchor="middle" x="171" y="40" fill="lightgray">12</text>
|
<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' }" />
|
<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" />
|
<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>
|
<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 }" />
|
<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" />
|
<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>
|
<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 }" />
|
<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" />
|
<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>
|
<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 }" />
|
<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" />
|
<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>
|
<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 }" />
|
<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>
|
<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>
|
<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>
|
<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>
|
<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>
|
<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>
|
<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>
|
<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>
|
<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>
|
<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>
|
<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' }" />
|
<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" />
|
<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>
|
<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 }" />
|
<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" />
|
<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>
|
<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 }" />
|
<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" />
|
<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>
|
<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 }" />
|
<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" />
|
<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>
|
<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 }" />
|
<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" />
|
<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>
|
<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 }" />
|
<DropZone
|
||||||
|
:transform="`translate(200, 150)`"
|
||||||
|
:width="40"
|
||||||
|
:height="40"
|
||||||
|
:enabled="isCurrentPlayer"
|
||||||
|
:accepts="'container'"
|
||||||
|
:data="{ type: 'warehouseStore', price: 6 }"
|
||||||
|
/>
|
||||||
</g>
|
</g>
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
|
@ -119,5 +239,4 @@ export default class PlayerBoard extends Vue {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
</script>
|
||||||
</script>
|
|
||||||
|
|
|
||||||
|
|
@ -5,15 +5,50 @@
|
||||||
</g>
|
</g>
|
||||||
<g v-else>
|
<g v-else>
|
||||||
<rect width="100" height="160" fill="silver" stroke="white" stroke-width="2" rx="2" />
|
<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" />
|
<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>
|
<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" />
|
<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>
|
<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" />
|
<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>
|
<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" />
|
<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>
|
<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" />
|
<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>
|
<text x="70" y="140" text-anchor="middle">2</text>
|
||||||
</g>
|
</g>
|
||||||
</g>
|
</g>
|
||||||
|
|
@ -29,7 +64,6 @@ export default class PointCard extends Vue {
|
||||||
|
|
||||||
turned = false;
|
turned = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
.point-card {
|
.point-card {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,9 @@
|
||||||
<template>
|
<template>
|
||||||
<g :id="elId" :class="['piece', { dragging, canDrag }]" :transform="`translate(${currentX}, ${currentY}) rotate(${rotate}, 10, 5)`">
|
<g
|
||||||
|
:id="elId"
|
||||||
|
:class="['piece', { dragging, canDrag }]"
|
||||||
|
:transform="`translate(${currentX}, ${currentY}) rotate(${rotate}, 10, 5)`"
|
||||||
|
>
|
||||||
<filter id="my-filter">
|
<filter id="my-filter">
|
||||||
<feComponentTransfer>
|
<feComponentTransfer>
|
||||||
<feFuncR type="linear" slope="0.5" />
|
<feFuncR type="linear" slope="0.5" />
|
||||||
|
|
@ -33,5 +37,4 @@ export default class Container extends Mixins(Piece) {
|
||||||
@Prop()
|
@Prop()
|
||||||
state?: ContainerState;
|
state?: ContainerState;
|
||||||
}
|
}
|
||||||
|
</script>
|
||||||
</script>
|
|
||||||
|
|
|
||||||
|
|
@ -103,5 +103,4 @@ export default class Draggable extends Vue {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -19,5 +19,4 @@ export default class Factory extends Mixins(Piece) {
|
||||||
@Prop()
|
@Prop()
|
||||||
color?: string;
|
color?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,6 @@ export default class LoanCard extends Mixins(Piece) {
|
||||||
@Prop()
|
@Prop()
|
||||||
player?: number;
|
player?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
.loan {
|
.loan {
|
||||||
|
|
|
||||||
|
|
@ -124,5 +124,4 @@ export default class Piece extends Draggable {
|
||||||
return this.dragging ? 'dragged' : (this.transitioning || this.moving ? 'moving' : undefined);
|
return this.dragging ? 'dragged' : (this.transitioning || this.moving ? 'moving' : undefined);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,18 @@
|
||||||
<template>
|
<template>
|
||||||
<g :id="elId" :class="['piece', { dragging, canDrag }]" :transform="`translate(${currentX}, ${currentY}) rotate(${rotate}, 15, 40)`">
|
<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" />
|
<path d="M15 0 L30 10 L30 80 L0 80 L0 10Z" :fill="color" stroke="black" />
|
||||||
<template v-for="(container, i) in containers">
|
<template v-for="(container, i) in containers">
|
||||||
<Container :key="container.id"
|
<Container
|
||||||
|
:key="container.id"
|
||||||
:pieceId="container.id"
|
:pieceId="container.id"
|
||||||
:targetState="{ x: 5, y: 15 + 12 * i, rotate: 0 }"
|
:targetState="{ x: 5, y: 15 + 12 * i, rotate: 0 }"
|
||||||
:canDrag="false"
|
:canDrag="false"
|
||||||
:color="container.color" />
|
:color="container.color"
|
||||||
|
/>
|
||||||
</template>
|
</template>
|
||||||
<DropZone :width="30" :height="80" :enabled="player == owner" :accepts="'container'" :data="{ type: 'ship' }" />
|
<DropZone :width="30" :height="80" :enabled="player == owner" :accepts="'container'" :data="{ type: 'ship' }" />
|
||||||
<title>{{ ownerName }}'s Ship</title>
|
<title>{{ ownerName }}'s Ship</title>
|
||||||
|
|
@ -48,5 +54,4 @@ export default class Ship extends Mixins(Piece) {
|
||||||
@Prop()
|
@Prop()
|
||||||
position!: ShipPosition;
|
position!: ShipPosition;
|
||||||
}
|
}
|
||||||
|
</script>
|
||||||
</script>
|
|
||||||
|
|
|
||||||
|
|
@ -16,5 +16,4 @@ import Piece from './Piece.vue';
|
||||||
})
|
})
|
||||||
export default class Warehouse extends Mixins(Piece) {
|
export default class Warehouse extends Mixins(Piece) {
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -4,27 +4,31 @@ import Vue from 'vue';
|
||||||
import Game from './components/Game.vue';
|
import Game from './components/Game.vue';
|
||||||
|
|
||||||
function launch(selector: string) {
|
function launch(selector: string) {
|
||||||
let params: { state: null | GameState; player?: number; emitter: EventEmitter } = { state: null, emitter: new EventEmitter() };
|
let params: {
|
||||||
|
state: null | GameState;
|
||||||
|
player?: number;
|
||||||
|
emitter: EventEmitter;
|
||||||
|
} = { state: null, emitter: new EventEmitter() };
|
||||||
|
|
||||||
const app = new Vue({
|
const app = new Vue({
|
||||||
render: (h) => h(Game, { props: params }, [])
|
render: (h) => h(Game, { props: params }, []),
|
||||||
}).$mount(selector);
|
}).$mount(selector);
|
||||||
|
|
||||||
const item: EventEmitter = new EventEmitter();
|
const item: EventEmitter = new EventEmitter();
|
||||||
|
|
||||||
params.emitter.on('move', (move: Move) => item.emit('move', move));
|
params.emitter.on('move', (move: Move) => item.emit('move', move));
|
||||||
|
|
||||||
item.addListener('state', data => {
|
item.addListener('state', (data) => {
|
||||||
params.state = data;
|
params.state = data;
|
||||||
app.$forceUpdate();
|
app.$forceUpdate();
|
||||||
app.$nextTick().then(() => item.emit('ready'));
|
app.$nextTick().then(() => item.emit('ready'));
|
||||||
});
|
});
|
||||||
item.addListener('state:updated', () => item.emit('fetchState'));
|
item.addListener('state:updated', () => item.emit('fetchState'));
|
||||||
item.addListener('player', data => {
|
item.addListener('player', (data) => {
|
||||||
params.player = data.index;
|
params.player = data.index;
|
||||||
app.$forceUpdate();
|
app.$forceUpdate();
|
||||||
});
|
});
|
||||||
item.addListener('gamelog', _ => item.emit('fetchState'));
|
item.addListener('gamelog', (_) => item.emit('fetchState'));
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,7 @@ function launchSelfContained(selector = '#app') {
|
||||||
const playerIndex = 1;
|
const playerIndex = 1;
|
||||||
|
|
||||||
for (const player of gameState.players) {
|
for (const player of gameState.players) {
|
||||||
if (player.id != playerIndex)
|
if (player.id != playerIndex) player.isAI = true;
|
||||||
player.isAI = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
emitter.on('move', async (move: Move) => {
|
emitter.on('move', async (move: Move) => {
|
||||||
|
|
@ -29,8 +28,11 @@ function launchSelfContained(selector = '#app') {
|
||||||
emitter.emit('state', cloneDeep(strip ? stripSecret(gameState, playerIndex) : gameState));
|
emitter.emit('state', cloneDeep(strip ? stripSecret(gameState, playerIndex) : gameState));
|
||||||
|
|
||||||
let delay = 800;
|
let delay = 800;
|
||||||
while (gameState.players.some(pl => pl.isAI && pl.availableMoves)) {
|
while (gameState.players.some((pl) => pl.isAI && pl.availableMoves)) {
|
||||||
gameState = moveAI(gameState, gameState.players.findIndex(pl => pl.isAI && pl.availableMoves));
|
gameState = moveAI(
|
||||||
|
gameState,
|
||||||
|
gameState.players.findIndex((pl) => pl.isAI && pl.availableMoves)
|
||||||
|
);
|
||||||
let newState = cloneDeep(strip ? stripSecret(gameState, playerIndex) : gameState);
|
let newState = cloneDeep(strip ? stripSecret(gameState, playerIndex) : gameState);
|
||||||
setTimeout(() => emitter.emit('state', newState), delay);
|
setTimeout(() => emitter.emit('state', newState), delay);
|
||||||
delay += 800;
|
delay += 800;
|
||||||
|
|
@ -39,14 +41,19 @@ function launchSelfContained(selector = '#app') {
|
||||||
console.log('available moves', gameState.players[playerIndex].availableMoves);
|
console.log('available moves', gameState.players[playerIndex].availableMoves);
|
||||||
});
|
});
|
||||||
|
|
||||||
emitter.on('fetchSate', () => emitter.emit('state', cloneDeep(strip ? stripSecret(gameState, playerIndex) : gameState)));
|
emitter.on('fetchSate', () =>
|
||||||
|
emitter.emit('state', cloneDeep(strip ? stripSecret(gameState, playerIndex) : gameState))
|
||||||
|
);
|
||||||
|
|
||||||
emitter.emit('player', { index: playerIndex });
|
emitter.emit('player', { index: playerIndex });
|
||||||
emitter.emit('state', cloneDeep(strip ? stripSecret(gameState, playerIndex) : gameState));
|
emitter.emit('state', cloneDeep(strip ? stripSecret(gameState, playerIndex) : gameState));
|
||||||
|
|
||||||
let delay = 800;
|
let delay = 800;
|
||||||
while (gameState.players.some(pl => pl.isAI && pl.availableMoves)) {
|
while (gameState.players.some((pl) => pl.isAI && pl.availableMoves)) {
|
||||||
gameState = moveAI(gameState, gameState.players.findIndex(pl => pl.isAI && pl.availableMoves));
|
gameState = moveAI(
|
||||||
|
gameState,
|
||||||
|
gameState.players.findIndex((pl) => pl.isAI && pl.availableMoves)
|
||||||
|
);
|
||||||
let newState = cloneDeep(strip ? stripSecret(gameState, playerIndex) : gameState);
|
let newState = cloneDeep(strip ? stripSecret(gameState, playerIndex) : gameState);
|
||||||
setTimeout(() => emitter.emit('state', newState), delay);
|
setTimeout(() => emitter.emit('state', newState), delay);
|
||||||
delay += 800;
|
delay += 800;
|
||||||
|
|
|
||||||
18
viewer/src/shims-tsx.d.ts
vendored
18
viewer/src/shims-tsx.d.ts
vendored
|
|
@ -1,13 +1,13 @@
|
||||||
import Vue, { VNode } from 'vue'
|
import Vue, { VNode } from 'vue';
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
namespace JSX {
|
namespace JSX {
|
||||||
// tslint:disable no-empty-interface
|
// tslint:disable no-empty-interface
|
||||||
interface Element extends VNode {}
|
interface Element extends VNode {}
|
||||||
// tslint:disable no-empty-interface
|
// tslint:disable no-empty-interface
|
||||||
interface ElementClass extends Vue {}
|
interface ElementClass extends Vue {}
|
||||||
interface IntrinsicElements {
|
interface IntrinsicElements {
|
||||||
[elem: string]: any;
|
[elem: string]: any;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
4
viewer/src/shims-vue.d.ts
vendored
4
viewer/src/shims-vue.d.ts
vendored
|
|
@ -1,4 +1,4 @@
|
||||||
declare module '*.vue' {
|
declare module '*.vue' {
|
||||||
import Vue from 'vue'
|
import Vue from 'vue';
|
||||||
export default Vue
|
export default Vue;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ export enum PieceType {
|
||||||
Factory = 'factory',
|
Factory = 'factory',
|
||||||
Container = 'container',
|
Container = 'container',
|
||||||
Ship = 'ship',
|
Ship = 'ship',
|
||||||
Loan = 'loan'
|
Loan = 'loan',
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum DropZoneType {
|
export enum DropZoneType {
|
||||||
|
|
@ -56,7 +56,7 @@ export enum DropZoneType {
|
||||||
IslandHarbor = 'islandHarbor',
|
IslandHarbor = 'islandHarbor',
|
||||||
GetLoan = 'getLoan',
|
GetLoan = 'getLoan',
|
||||||
PayLoan = 'payLoan',
|
PayLoan = 'payLoan',
|
||||||
Supply = 'supply'
|
Supply = 'supply',
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum ContainerState {
|
export enum ContainerState {
|
||||||
|
|
@ -64,5 +64,5 @@ export enum ContainerState {
|
||||||
OnFactoryStore = 'onFactoryStore',
|
OnFactoryStore = 'onFactoryStore',
|
||||||
OnWarehouseStore = 'onWarehouseStore',
|
OnWarehouseStore = 'onWarehouseStore',
|
||||||
OnShip = 'onShip',
|
OnShip = 'onShip',
|
||||||
OnIsland = 'onIsland'
|
OnIsland = 'onIsland',
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
import launch from './launch';
|
import launch from './launch';
|
||||||
|
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
(window as any).container = { launch };
|
(window as any).container = { launch };
|
||||||
}
|
}
|
||||||
|
|
||||||
export default launch;
|
export default launch;
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
import { expect } from 'chai'
|
import HelloWorld from '@/components/HelloWorld.vue';
|
||||||
import { shallowMount } from '@vue/test-utils'
|
import { shallowMount } from '@vue/test-utils';
|
||||||
import HelloWorld from '@/components/HelloWorld.vue'
|
import { expect } from 'chai';
|
||||||
|
|
||||||
describe('HelloWorld.vue', () => {
|
describe('HelloWorld.vue', () => {
|
||||||
it('renders props.msg when passed', () => {
|
it('renders props.msg when passed', () => {
|
||||||
const msg = 'new message'
|
const msg = 'new message';
|
||||||
const wrapper = shallowMount(HelloWorld, {
|
const wrapper = shallowMount(HelloWorld, {
|
||||||
propsData: { msg }
|
propsData: { msg },
|
||||||
})
|
});
|
||||||
expect(wrapper.text()).to.include(msg)
|
expect(wrapper.text()).to.include(msg);
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,29 +1,29 @@
|
||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "esnext",
|
"target": "esnext",
|
||||||
"module": "esnext",
|
"module": "esnext",
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"jsx": "preserve",
|
"jsx": "preserve",
|
||||||
"importHelpers": true,
|
"importHelpers": true,
|
||||||
"moduleResolution": "node",
|
"moduleResolution": "node",
|
||||||
"experimentalDecorators": true,
|
"experimentalDecorators": true,
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"allowSyntheticDefaultImports": true,
|
"allowSyntheticDefaultImports": true,
|
||||||
"noImplicitAny": false,
|
"noImplicitAny": false,
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
"baseUrl": ".",
|
"baseUrl": ".",
|
||||||
"types": ["webpack-env", "mocha", "chai"],
|
"types": ["webpack-env", "mocha", "chai"],
|
||||||
"paths": {
|
"paths": {
|
||||||
"@/*": ["viewer/src/*"]
|
"@/*": ["viewer/src/*"]
|
||||||
|
},
|
||||||
|
"lib": ["esnext", "dom", "dom.iterable", "scripthost"]
|
||||||
},
|
},
|
||||||
"lib": ["esnext", "dom", "dom.iterable", "scripthost"]
|
"include": [
|
||||||
},
|
"viewer/src/**/*.ts",
|
||||||
"include": [
|
"viewer/src/**/*.tsx",
|
||||||
"viewer/src/**/*.ts",
|
"viewer/src/**/*.vue",
|
||||||
"viewer/src/**/*.tsx",
|
"viewer/tests/**/*.ts",
|
||||||
"viewer/src/**/*.vue",
|
"viewer/tests/**/*.tsx"
|
||||||
"viewer/tests/**/*.ts",
|
],
|
||||||
"viewer/tests/**/*.tsx"
|
"exclude": ["node_modules"]
|
||||||
],
|
|
||||||
"exclude": ["node_modules"]
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue