1
0

Working on stuff

This commit is contained in:
James Ketr 2025-10-09 16:21:47 -07:00
parent 570d9024ab
commit e68e49bf82
4 changed files with 221 additions and 197 deletions

View File

@ -347,6 +347,7 @@ interface ResourceCount {
sheep: number;
wheat: number;
stone: number;
desert: number;
}
type Received = Record<PlayerColor | "robber", ResourceCount>;
@ -360,13 +361,21 @@ const distributeResources = (game: Game, roll: number): void => {
if (staticData.pips?.[pipIndex] && staticData.pips[pipIndex].roll === roll) {
/* TODO: Fix so it isn't hard coded to "wheat" and instead is the correct resource given
* the resource distribution in shuffeled */
matchedTiles.push({ type: "wheat", robber: game.robber === pos, index: pos });
matchedTiles.push({
type: "wheat",
robber: game.robber === pos,
index: pos,
corners: [],
pip: 0,
roads: [],
asset: 0,
});
}
});
const receives: Received = {} as Received;
PLAYER_COLORS.forEach((color) => {
receives[color] = { wood: 0, brick: 0, sheep: 0, wheat: 0, stone: 0 };
receives[color] = { wood: 0, brick: 0, sheep: 0, wheat: 0, stone: 0, desert: 0 };
});
/* Find which corners are on each tile */
@ -4649,7 +4658,6 @@ router.ws("/ws/:id", async (ws, req) => {
case "mostDeveloped":
case "mostPorts":
case "longestRoad":
case "tiles":
case "pipOrder":
case "signature":
case "borderOrder":
@ -4657,6 +4665,9 @@ router.ws("/ws/:id", async (ws, req) => {
case "activities":
batchedUpdate[field] = game[field];
break;
case "tiles":
batchedUpdate.tiles = staticData.tiles;
break;
case "rules":
batchedUpdate[field] = game.rules ? game.rules : {};
break;
@ -5296,7 +5307,7 @@ const resetGame = (game: any) => {
shuffleArray(game.developmentCards);
/* Reset all player data, and add in any missing colors */
["R", "B", "W", "O"].forEach((color) => {
PLAYER_COLORS.forEach((color) => {
if (color in game.players) {
clearPlayer(game.players[color]);
} else {
@ -5379,15 +5390,9 @@ const createGame = async (id: any) => {
pipOrder: [],
borderOrder: [],
tileOrder: [],
tiles: [],
pips: [],
step: 0 /* used for the suffix # in game backups */,
};
["pips", "borders", "tiles"].forEach((field) => {
(game as any)[field] = (staticData as any)[field];
});
setBeginnerGame(game);
resetGame(game);
@ -5457,16 +5462,13 @@ const shuffleBoard = (game: any): void => {
game.pipOrder = [];
game.animationSeeds = [];
for (let i = 0, p = 0; i < sequence.length; i++) {
const target = sequence[i];
if (typeof target !== "number") {
continue;
}
const target: number = sequence[i]!;
/* If the target tile is the desert (18), then set the
* pip value to the robber (18) otherwise set
* the target pip value to the currently incremeneting
* pip value. */
const tileIdx = typeof game.tileOrder?.[target] === "number" ? game.tileOrder[target] : undefined;
const tileType = typeof tileIdx === "number" && game.tiles?.[tileIdx] ? game.tiles[tileIdx].type : undefined;
const tileIdx = game.tileOrder[target];
const tileType = staticData.tiles[tileIdx]?.type;
if (!game.pipOrder) game.pipOrder = [];
if (tileType === "desert") {
game.robber = target;

View File

@ -1,7 +1,7 @@
import { MAX_ROADS, MAX_CITIES, MAX_SETTLEMENTS } from "./constants";
import type { Player } from "./types";
import type { Player, PlayerColor } from "./types";
export const newPlayer = (color: string): Player => {
export const newPlayer = (color: PlayerColor): Player => {
return {
roads: MAX_ROADS,
cities: MAX_CITIES,
@ -24,7 +24,15 @@ export const newPlayer = (color: string): Player => {
turnStart: 0,
ports: 0,
developmentCards: 0,
} as Player;
orderRoll: 0,
position: "",
orderStatus: "none",
tied: false,
mustDiscard: 0,
live: true,
turnNotice: "",
longestRoad: 0,
};
};
export default newPlayer;

View File

@ -118,8 +118,8 @@ export interface Offer {
[key: string]: any;
}
type ResourceType = "wood" | "brick" | "sheep" | "wheat" | "stone";
export const RESOURCE_TYPES = ["wood", "brick", "sheep", "wheat", "stone"] as ResourceType[];
export type ResourceType = "wood" | "brick" | "sheep" | "wheat" | "stone" | "desert";
export const RESOURCE_TYPES = ["wood", "brick", "sheep", "wheat", "stone", "desert"] as ResourceType[];
export interface Tile {
robber: boolean;
@ -127,6 +127,10 @@ export interface Tile {
type: ResourceType;
resource?: ResourceKey | null;
roll?: number | null;
corners: number[];
pip: number;
roads: number[];
asset: number;
}
export interface Game {
@ -145,7 +149,6 @@ export interface Game {
pipOrder: number[];
tileOrder: number[];
resources?: number;
tiles: Tile[];
pips?: any[];
dice?: number[];
chat?: any[];

View File

@ -1,5 +1,7 @@
"use strict";
import { Tile } from "../routes/games/types";
/* Board Tiles:
* 0 1 2
* 3 4 5 6
@ -20,54 +22,59 @@
* r5 \ / r3
* \/
* c4
*/
*/
/* |
* 0 1 2 |
* 1| 3| 5|
* \. / \ / \ / \ 3
* \. 0/ 1\ 3/ 4\ 6/ 7\
* \./ \ / \ / \
* 0| 2| 4| |6
* 17 2| 0 5| 1 8| 2 |9 4
* 8| 10| 12| |14
* / \ / \ / \ / \
* 10/ 11\ 13/ 14\ 16/ 17\ 19/ 20\
* / \ / \ / \ / \
* 7| 9| 11| 13| |15
* 16 12| 3 15| 4 18| 5 21| 6 |22
* 17| 19| 21| 23| |25 5
* / \ / \ / \ / \ / \ ,/
* 23/ 24\ 26/ 27\ 29/ 30\ 32/ 33\ 35/ 36\ ,/
* / \ / \ / \ / \ / \ ,/
* 16| 18| 20| 22| 24| |26
* 15 25| 7 28| 8 31| 9 34| 10 37| 11 |38 6
* 27| 29| 31| 33| 35| |37
* /' \ / \ / \ / \ / \ /
* /' 39\ 40/ 41\ 43/ 44\ 46/ 47\ 49/ 50\ /53
* /' \ / \ / \ / \ / \ / 7
* 28| 30| 32| 34| |36
* 14 42| 12 45| 13 48| 14 51| 15 |52
* 38| 40| 42| 44| |46
* \ / \ / \ / \ /
* 54\ 55/ 56\ 58/ 59\ 61/ 62\ /65
* \ / \ / \ / \ / 8
* 39| 41| 43| |45
* 13 57| 16 60| 17 63| 18 |64
* 47| 49| 51| |53
* \ / \ / \ / `\
* 66\ 67/ 68\ 69/ 70\ /71 `\
* \ / \ / \ / `\
* 48| 50| 52| 9
* |
* 12 | 11 10
*/
const Tile = (corners: number[], roads: number[]) => {
* 0 1 2 |
* 1| 3| 5|
* \. / \ / \ / \ 3
* \. 0/ 1\ 3/ 4\ 6/ 7\
* \./ \ / \ / \
* 0| 2| 4| |6
* 17 2| 0 5| 1 8| 2 |9 4
* 8| 10| 12| |14
* / \ / \ / \ / \
* 10/ 11\ 13/ 14\ 16/ 17\ 19/ 20\
* / \ / \ / \ / \
* 7| 9| 11| 13| |15
* 16 12| 3 15| 4 18| 5 21| 6 |22
* 17| 19| 21| 23| |25 5
* / \ / \ / \ / \ / \ ,/
* 23/ 24\ 26/ 27\ 29/ 30\ 32/ 33\ 35/ 36\ ,/
* / \ / \ / \ / \ / \ ,/
* 16| 18| 20| 22| 24| |26
* 15 25| 7 28| 8 31| 9 34| 10 37| 11 |38 6
* 27| 29| 31| 33| 35| |37
* /' \ / \ / \ / \ / \ /
* /' 39\ 40/ 41\ 43/ 44\ 46/ 47\ 49/ 50\ /53
* /' \ / \ / \ / \ / \ / 7
* 28| 30| 32| 34| |36
* 14 42| 12 45| 13 48| 14 51| 15 |52
* 38| 40| 42| 44| |46
* \ / \ / \ / \ /
* 54\ 55/ 56\ 58/ 59\ 61/ 62\ /65
* \ / \ / \ / \ / 8
* 39| 41| 43| |45
* 13 57| 16 60| 17 63| 18 |64
* 47| 49| 51| |53
* \ / \ / \ / `\
* 66\ 67/ 68\ 69/ 70\ /71 `\
* \ / \ / \ / `\
* 48| 50| 52| 9
* |
* 12 | 11 10
*/
const newTile = (corners: number[], roads: number[]): Tile => {
return {
corners: corners, /* 6 */
robber: false,
index: -1,
type: "desert",
resource: null,
roll: null,
corners: corners /* 6 */,
pip: -1,
roads: roads,
asset: -1
asset: -1,
};
};
@ -76,44 +83,44 @@ const Tile = (corners: number[], roads: number[]) => {
const Corner = (roads: number[], banks: number[]) => {
return {
roads: roads, /* max of 3 */
banks: banks, /* max of 2 */
data: undefined
roads: roads /* max of 3 */,
banks: banks /* max of 2 */,
data: undefined,
};
};
const Road = (corners: number[]) => {
return {
corners: corners, /* 2 */
data: undefined
}
corners: corners /* 2 */,
data: undefined,
};
};
const layout = {
tiles: [
Tile([ 0, 1, 2, 10, 9, 8], [ 0, 1, 5, 13, 11, 2]),
Tile([ 2, 3, 4, 12, 11, 10], [ 3, 4, 8, 16, 14, 5]),
Tile([ 4, 5, 6, 14, 13, 12], [ 6, 7, 9, 19, 17, 8]),
newTile([0, 1, 2, 10, 9, 8], [0, 1, 5, 13, 11, 2]),
newTile([2, 3, 4, 12, 11, 10], [3, 4, 8, 16, 14, 5]),
newTile([4, 5, 6, 14, 13, 12], [6, 7, 9, 19, 17, 8]),
Tile([ 7, 8, 9, 19, 18, 17], [ 10, 11, 15, 26, 24, 12]),
Tile([ 9, 10, 11, 21, 20, 19], [ 13, 14, 18, 29, 27, 15]),
Tile([ 11, 12, 13, 23, 22, 21], [ 16, 17, 21, 32, 30, 18]),
Tile([ 13, 14, 15, 25, 24, 23], [ 19, 20, 22, 35, 33, 21]),
newTile([7, 8, 9, 19, 18, 17], [10, 11, 15, 26, 24, 12]),
newTile([9, 10, 11, 21, 20, 19], [13, 14, 18, 29, 27, 15]),
newTile([11, 12, 13, 23, 22, 21], [16, 17, 21, 32, 30, 18]),
newTile([13, 14, 15, 25, 24, 23], [19, 20, 22, 35, 33, 21]),
Tile([ 16, 17, 18, 29, 28, 27], [ 23, 24, 28, 40, 39, 25]),
Tile([ 18, 19, 20, 31, 30, 29], [ 26, 27, 31, 43, 41, 28]),
Tile([ 20, 21, 22, 33, 32, 31], [ 29, 30, 34, 46, 44, 31]),
Tile([ 22, 23, 24, 35, 34, 33], [ 32, 33, 37, 49, 47, 34]),
Tile([ 24, 25, 26, 37, 36, 35], [ 35, 36, 38, 53, 50, 37]),
newTile([16, 17, 18, 29, 28, 27], [23, 24, 28, 40, 39, 25]),
newTile([18, 19, 20, 31, 30, 29], [26, 27, 31, 43, 41, 28]),
newTile([20, 21, 22, 33, 32, 31], [29, 30, 34, 46, 44, 31]),
newTile([22, 23, 24, 35, 34, 33], [32, 33, 37, 49, 47, 34]),
newTile([24, 25, 26, 37, 36, 35], [35, 36, 38, 53, 50, 37]),
Tile([ 28, 29, 30, 40, 39, 38], [ 40, 41, 45, 55, 54, 42]),
Tile([ 30, 31, 32, 42, 41, 40], [ 43, 44, 48, 58, 56, 45]),
Tile([ 32, 33, 34, 44, 43, 42], [ 46, 47, 51, 61, 59, 48]),
Tile([ 34, 35, 36, 46, 45, 44], [ 49, 50, 52, 65, 62, 51]),
newTile([28, 29, 30, 40, 39, 38], [40, 41, 45, 55, 54, 42]),
newTile([30, 31, 32, 42, 41, 40], [43, 44, 48, 58, 56, 45]),
newTile([32, 33, 34, 44, 43, 42], [46, 47, 51, 61, 59, 48]),
newTile([34, 35, 36, 46, 45, 44], [49, 50, 52, 65, 62, 51]),
Tile([ 39, 40, 41, 49, 48, 47], [ 55, 56, 60, 67, 66, 57]),
Tile([ 41, 42, 43, 51, 50, 49], [ 58, 59, 63, 69, 68, 60]),
Tile([ 43, 44, 45, 53, 52, 51], [ 61, 62, 64, 71, 70, 63])
newTile([39, 40, 41, 49, 48, 47], [55, 56, 60, 67, 66, 57]),
newTile([41, 42, 43, 51, 50, 49], [58, 59, 63, 69, 68, 60]),
newTile([43, 44, 45, 53, 52, 51], [61, 62, 64, 71, 70, 63]),
],
roads: [
/* 0 */
@ -140,7 +147,7 @@ const layout = {
Road([14, 13]),
/* 20 */
Road([14, 15]),
Road([13,23 ]),
Road([13, 23]),
Road([15, 25]),
Road([17, 16]),
Road([17, 18]),
@ -154,113 +161,117 @@ const layout = {
Road([20, 31]),
Road([23, 22]),
Road([23, 24]),
Road([22,33]),
Road([25,24]),
Road([25,26]),
Road([22, 33]),
Road([25, 24]),
Road([25, 26]),
Road([24, 35]),
Road([26,37]),
Road([27,28]),
Road([26, 37]),
Road([27, 28]),
/* 40 */
Road([29,28]),
Road([29,30]),
Road([28,38]),
Road([31,30]),
Road([31,32]),
Road([30,40]),
Road([33,32]),
Road([33,34]),
Road([32,42]),
Road([35,34]),
Road([29, 28]),
Road([29, 30]),
Road([28, 38]),
Road([31, 30]),
Road([31, 32]),
Road([30, 40]),
Road([33, 32]),
Road([33, 34]),
Road([32, 42]),
Road([35, 34]),
/* 50 */
Road([35,36]),
Road([34,44]),
Road([36,46]),
Road([37,36]),
Road([38,39]),
Road([40,39]),
Road([40,41]),
Road([39,47]),
Road([41,42]),
Road([42,43]),
Road([35, 36]),
Road([34, 44]),
Road([36, 46]),
Road([37, 36]),
Road([38, 39]),
Road([40, 39]),
Road([40, 41]),
Road([39, 47]),
Road([41, 42]),
Road([42, 43]),
/* 60 */
Road([41,49]),
Road([44,43]),
Road([44,45]),
Road([43,51]),
Road([45,53]),
Road([46,45]),
Road([47,48]),
Road([49,48]),
Road([49,50]),
Road([51,50]),
Road([41, 49]),
Road([44, 43]),
Road([44, 45]),
Road([43, 51]),
Road([45, 53]),
Road([46, 45]),
Road([47, 48]),
Road([49, 48]),
Road([49, 50]),
Road([51, 50]),
/* 70 */
Road([51,52]),
Road([53,52]),
Road([51, 52]),
Road([53, 52]),
],
corners: [
/* 0 */
/* 0 */ Corner([2, 0],[0]),
/* 1 */ Corner([0, 1],[0]),
/* 2 */ Corner([1,3,5],[1]),
/* 3 */ Corner([3,4],[1,2]),
/* 4 */ Corner([8,4,6],[2]),
/* 5 */ Corner([6,7],[3]),
/* 6 */ Corner([7,9],[3]),
/* 7 */ Corner([12,10],[16,17]),
/* 8 */ Corner([2,10,11],[17]),
/* 9 */ Corner([11,13,15],[]),
/* 0 */ Corner([2, 0], [0]),
/* 1 */ Corner([0, 1], [0]),
/* 2 */ Corner([1, 3, 5], [1]),
/* 3 */ Corner([3, 4], [1, 2]),
/* 4 */ Corner([8, 4, 6], [2]),
/* 5 */ Corner([6, 7], [3]),
/* 6 */ Corner([7, 9], [3]),
/* 7 */ Corner([12, 10], [16, 17]),
/* 8 */ Corner([2, 10, 11], [17]),
/* 9 */ Corner([11, 13, 15], []),
/* 10 */
/* 10 */ Corner([5,13,14],[]),
/* 11 */ Corner([14,16,18],[]),
/* 12 */ Corner([8,16,17],[]),
/* 13 */ Corner([17,19,21],[]),
/* 14 */ Corner([9,19,20],[4]),
/* 15 */ Corner([20,22],[4,5]),
/* 16 */ Corner([23,25],[15]),
/* 17 */ Corner([12,23,24],[16]),
/* 18 */ Corner([24,26,28],[]),
/* 19 */ Corner([15,26,27],[]),
/* 10 */ Corner([5, 13, 14], []),
/* 11 */ Corner([14, 16, 18], []),
/* 12 */ Corner([8, 16, 17], []),
/* 13 */ Corner([17, 19, 21], []),
/* 14 */ Corner([9, 19, 20], [4]),
/* 15 */ Corner([20, 22], [4, 5]),
/* 16 */ Corner([23, 25], [15]),
/* 17 */ Corner([12, 23, 24], [16]),
/* 18 */ Corner([24, 26, 28], []),
/* 19 */ Corner([15, 26, 27], []),
/* 20 */
/* 20 */ Corner([27,29,31],[]),
/* 21 */ Corner([18,29,30],[]),
/* 22 */ Corner([30,32,34],[]),
/* 23 */ Corner([21,32,33],[]),
/* 24 */ Corner([33,35,37],[]),
/* 25 */ Corner([22,35,36],[5]),
/* 26 */ Corner([36,38],[6]),
/* 27 */ Corner([25,39],[15]),
/* 28 */ Corner([39,40,42],[14]),
/* 29 */ Corner([28,40,41],[]),
/* 20 */ Corner([27, 29, 31], []),
/* 21 */ Corner([18, 29, 30], []),
/* 22 */ Corner([30, 32, 34], []),
/* 23 */ Corner([21, 32, 33], []),
/* 24 */ Corner([33, 35, 37], []),
/* 25 */ Corner([22, 35, 36], [5]),
/* 26 */ Corner([36, 38], [6]),
/* 27 */ Corner([25, 39], [15]),
/* 28 */ Corner([39, 40, 42], [14]),
/* 29 */ Corner([28, 40, 41], []),
/* 30 */
/* 30 */ Corner([41,43,45],[]),
/* 31 */ Corner([31,43,44],[]),
/* 32 */ Corner([44,46,48],[]),
/* 33 */ Corner([34,46,47],[]),
/* 34 */ Corner([47,49,51],[]),
/* 35 */ Corner([37,49,50],[]),
/* 36 */ Corner([50,53,52],[7]),
/* 37 */ Corner([38,53],[6]),
/* 38 */ Corner([42,54],[14,13]),
/* 39 */ Corner([54,55,57],[13]),
/* 30 */ Corner([41, 43, 45], []),
/* 31 */ Corner([31, 43, 44], []),
/* 32 */ Corner([44, 46, 48], []),
/* 33 */ Corner([34, 46, 47], []),
/* 34 */ Corner([47, 49, 51], []),
/* 35 */ Corner([37, 49, 50], []),
/* 36 */ Corner([50, 53, 52], [7]),
/* 37 */ Corner([38, 53], [6]),
/* 38 */ Corner([42, 54], [14, 13]),
/* 39 */ Corner([54, 55, 57], [13]),
/* 40 */
/* 40 */ Corner([45,55,56],[]),
/* 41 */ Corner([56,58,60],[]),
/* 42 */ Corner([48,58,59],[]),
/* 43 */ Corner([59,61,63],[]),
/* 44 */ Corner([51,61,62],[]),
/* 45 */ Corner([62,65,64],[8]),
/* 46 */ Corner([52,65],[7,8]),
/* 47 */ Corner([57,66],[12]),
/* 48 */ Corner([67,66],[12]),
/* 49 */ Corner([60,67,68],[11]),
/* 40 */ Corner([45, 55, 56], []),
/* 41 */ Corner([56, 58, 60], []),
/* 42 */ Corner([48, 58, 59], []),
/* 43 */ Corner([59, 61, 63], []),
/* 44 */ Corner([51, 61, 62], []),
/* 45 */ Corner([62, 65, 64], [8]),
/* 46 */ Corner([52, 65], [7, 8]),
/* 47 */ Corner([57, 66], [12]),
/* 48 */ Corner([67, 66], [12]),
/* 49 */ Corner([60, 67, 68], [11]),
/* 50 */
/* 50 */ Corner([68,69],[11,10]),
/* 51 */ Corner([69,70,63],[10]),
/* 52 */ Corner([70,71],[9]),
/* 53 */ Corner([64,71],[9]),
]
/* 50 */ Corner([68, 69], [11, 10]),
/* 51 */ Corner([69, 70, 63], [10]),
/* 52 */ Corner([70, 71], [9]),
/* 53 */ Corner([64, 71], [9]),
],
};
interface StaticDataTile {
type: ResourceType;
card: number;
}
const staticData = {
tiles: [
{ type: "desert", card: 0 },
@ -281,8 +292,8 @@ const staticData = {
{ type: "sheep", card: 3 },
{ type: "brick", card: 0 },
{ type: "brick", card: 1 },
{ type: "brick", card: 2 }
],
{ type: "brick", card: 2 },
] as StaticDataTile[],
pips: [
{ roll: 5, pips: 4 },
{ roll: 2, pips: 1 },
@ -302,7 +313,7 @@ const staticData = {
{ roll: 6, pips: 5 },
{ roll: 3, pips: 2 },
{ roll: 11, pips: 2 },
{ roll: 7, pips: 0 }, /* Robber is at the end or indexing gets off */
{ roll: 7, pips: 0 } /* Robber is at the end or indexing gets off */,
],
borders: [
["bank", undefined, "sheep"],
@ -310,8 +321,8 @@ const staticData = {
["bank", undefined, "brick"],
[undefined, "wood", undefined],
["bank", undefined, "wheat"],
[undefined, "stone", undefined]
]
[undefined, "stone", undefined],
],
};
export {