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