diff --git a/frontend/public/logos/alfa-romeo-logo.png b/frontend/public/logos/alfa-romeo-logo.png new file mode 100644 index 0000000..d2abfa4 Binary files /dev/null and b/frontend/public/logos/alfa-romeo-logo.png differ diff --git a/frontend/public/logos/aston-martin-logo.png b/frontend/public/logos/aston-martin-logo.png new file mode 100644 index 0000000..ad7a32f Binary files /dev/null and b/frontend/public/logos/aston-martin-logo.png differ diff --git a/frontend/public/logos/audi-logo.png b/frontend/public/logos/audi-logo.png new file mode 100644 index 0000000..47ab753 Binary files /dev/null and b/frontend/public/logos/audi-logo.png differ diff --git a/frontend/public/logos/bmw-logo.png b/frontend/public/logos/bmw-logo.png new file mode 100644 index 0000000..5aded71 Binary files /dev/null and b/frontend/public/logos/bmw-logo.png differ diff --git a/frontend/public/logos/bugatti-logo.png b/frontend/public/logos/bugatti-logo.png new file mode 100644 index 0000000..805b7a0 Binary files /dev/null and b/frontend/public/logos/bugatti-logo.png differ diff --git a/frontend/public/logos/byd-logo.png b/frontend/public/logos/byd-logo.png new file mode 100644 index 0000000..d6cfb07 Binary files /dev/null and b/frontend/public/logos/byd-logo.png differ diff --git a/frontend/public/logos/chevrolet-logo.png b/frontend/public/logos/chevrolet-logo.png new file mode 100644 index 0000000..00bc64f Binary files /dev/null and b/frontend/public/logos/chevrolet-logo.png differ diff --git a/frontend/public/logos/ferrari-logo.png b/frontend/public/logos/ferrari-logo.png new file mode 100644 index 0000000..ac05675 Binary files /dev/null and b/frontend/public/logos/ferrari-logo.png differ diff --git a/frontend/public/logos/fiat-logo.png b/frontend/public/logos/fiat-logo.png new file mode 100644 index 0000000..65fbd9d Binary files /dev/null and b/frontend/public/logos/fiat-logo.png differ diff --git a/frontend/public/logos/ford-logo.png b/frontend/public/logos/ford-logo.png new file mode 100644 index 0000000..6fe10c3 Binary files /dev/null and b/frontend/public/logos/ford-logo.png differ diff --git a/frontend/public/logos/honda-logo.png b/frontend/public/logos/honda-logo.png new file mode 100644 index 0000000..4b6f26b Binary files /dev/null and b/frontend/public/logos/honda-logo.png differ diff --git a/frontend/public/logos/hyundai-logo.png b/frontend/public/logos/hyundai-logo.png new file mode 100644 index 0000000..654e0b7 Binary files /dev/null and b/frontend/public/logos/hyundai-logo.png differ diff --git a/frontend/public/logos/jeep-logo.png b/frontend/public/logos/jeep-logo.png new file mode 100644 index 0000000..084908a Binary files /dev/null and b/frontend/public/logos/jeep-logo.png differ diff --git a/frontend/public/logos/kia-logo.png b/frontend/public/logos/kia-logo.png new file mode 100644 index 0000000..c529e7f Binary files /dev/null and b/frontend/public/logos/kia-logo.png differ diff --git a/frontend/public/logos/lamborghini-logo.png b/frontend/public/logos/lamborghini-logo.png new file mode 100644 index 0000000..c141c6d Binary files /dev/null and b/frontend/public/logos/lamborghini-logo.png differ diff --git a/frontend/public/logos/land-rover-logo.png b/frontend/public/logos/land-rover-logo.png new file mode 100644 index 0000000..0f37418 Binary files /dev/null and b/frontend/public/logos/land-rover-logo.png differ diff --git a/frontend/public/logos/lexus-logo.png b/frontend/public/logos/lexus-logo.png new file mode 100644 index 0000000..d1b3aeb Binary files /dev/null and b/frontend/public/logos/lexus-logo.png differ diff --git a/frontend/public/logos/lucid-motors-logo.png b/frontend/public/logos/lucid-motors-logo.png new file mode 100644 index 0000000..b97e8b4 Binary files /dev/null and b/frontend/public/logos/lucid-motors-logo.png differ diff --git a/frontend/public/logos/mclaren-logo.png b/frontend/public/logos/mclaren-logo.png new file mode 100644 index 0000000..de36fb6 Binary files /dev/null and b/frontend/public/logos/mclaren-logo.png differ diff --git a/frontend/public/logos/mercedes-benz-logo.png b/frontend/public/logos/mercedes-benz-logo.png new file mode 100644 index 0000000..eecc1f0 Binary files /dev/null and b/frontend/public/logos/mercedes-benz-logo.png differ diff --git a/frontend/public/logos/mini-logo.png b/frontend/public/logos/mini-logo.png new file mode 100644 index 0000000..f778c32 Binary files /dev/null and b/frontend/public/logos/mini-logo.png differ diff --git a/frontend/public/logos/morgan-motor-company-logo.png b/frontend/public/logos/morgan-motor-company-logo.png new file mode 100644 index 0000000..8ddc130 Binary files /dev/null and b/frontend/public/logos/morgan-motor-company-logo.png differ diff --git a/frontend/public/logos/nio-logo.png b/frontend/public/logos/nio-logo.png new file mode 100644 index 0000000..734be49 Binary files /dev/null and b/frontend/public/logos/nio-logo.png differ diff --git a/frontend/public/logos/porsche-logo.png b/frontend/public/logos/porsche-logo.png new file mode 100644 index 0000000..c087716 Binary files /dev/null and b/frontend/public/logos/porsche-logo.png differ diff --git a/frontend/public/logos/rivian-logo.png b/frontend/public/logos/rivian-logo.png new file mode 100644 index 0000000..d88083c Binary files /dev/null and b/frontend/public/logos/rivian-logo.png differ diff --git a/frontend/public/logos/rolls-royce-logo.png b/frontend/public/logos/rolls-royce-logo.png new file mode 100644 index 0000000..b0a33cc Binary files /dev/null and b/frontend/public/logos/rolls-royce-logo.png differ diff --git a/frontend/public/logos/subaru-logo.png b/frontend/public/logos/subaru-logo.png new file mode 100644 index 0000000..5003e34 Binary files /dev/null and b/frontend/public/logos/subaru-logo.png differ diff --git a/frontend/public/logos/toyota-logo.png b/frontend/public/logos/toyota-logo.png new file mode 100644 index 0000000..a111926 Binary files /dev/null and b/frontend/public/logos/toyota-logo.png differ diff --git a/frontend/public/logos/volkswagen-logo.png b/frontend/public/logos/volkswagen-logo.png new file mode 100644 index 0000000..4b80cd2 Binary files /dev/null and b/frontend/public/logos/volkswagen-logo.png differ diff --git a/frontend/public/logos/volvo-logo.png b/frontend/public/logos/volvo-logo.png new file mode 100644 index 0000000..7b005f2 Binary files /dev/null and b/frontend/public/logos/volvo-logo.png differ diff --git a/frontend/src/components/mahjong/Mahjong.tsx b/frontend/src/components/mahjong/Mahjong.tsx index d473c74..34aa806 100644 --- a/frontend/src/components/mahjong/Mahjong.tsx +++ b/frontend/src/components/mahjong/Mahjong.tsx @@ -12,7 +12,41 @@ export function Mahjong() { const g = Game.random( FieldTemplate.decode(TEMPLATE_2), (a, b) => a === b, - ['atom', 'bentley', 'tesla', 'atom', 'bentley'], + [ + 'alfa-romeo', + 'aston-martin', + 'atom', + 'audi', + 'bentley', + 'bmw', + 'bugatti', + 'byd', + 'chevrolet', + 'ferrari', + 'fiat', + 'ford', + 'honda', + 'hyundai', + 'jeep', + 'kia', + 'lamborghini', + 'land-rover', + 'lexus', + 'lucid-motors', + 'mclaren', + 'mercedes-benz', + 'mini', + 'morgan-motor-company', + 'nio', + 'porsche', + 'rivian', + 'rolls-royce', + 'subaru', + 'tesla', + 'toyota', + 'volkswagen', + 'volvo', + ], ) g.onTilesChange = setTiles g.onSelectedTileChange = setSelected diff --git a/frontend/src/components/mahjong/field-template.ts b/frontend/src/components/mahjong/field-template.ts index faf50ad..d7d3191 100644 --- a/frontend/src/components/mahjong/field-template.ts +++ b/frontend/src/components/mahjong/field-template.ts @@ -106,8 +106,8 @@ export const TEMPLATE_2: EncodedTemplate = [ [ [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], - [1, 1, 1, 1, 1], - [2, 2, 2, 2, 2], + [0, 1, 1, 1, 0], + [0, 2, 2, 2, 0], [0, 0, 0, 0, 0], ], ] diff --git a/frontend/src/components/mahjong/game.ts b/frontend/src/components/mahjong/game.ts index 9719ac7..889e52a 100644 --- a/frontend/src/components/mahjong/game.ts +++ b/frontend/src/components/mahjong/game.ts @@ -31,7 +31,7 @@ export class Game { public static random( template: FieldTemplate, comparator: Comparator, - kinds: string[], + allKinds: string[], maxRetries = 100, ): Game { const availableCoords = [...template.tileCoords] @@ -40,16 +40,37 @@ export class Game { throw new Error(`The number of tile positions (${availableCoords.length}) must be even`) } - if (availableCoords.length !== kinds.length * 4 && availableCoords.length !== kinds.length * 2) { - throw new Error(`The number of tile positions (${availableCoords.length}) must be equal to the number of choices (${kinds.length}) times 4 or times 2`) + const kinds: string[] = [] + if (availableCoords.length / 4 > allKinds.length) { + kinds.push(...allKinds) + for (let i = 0; i < availableCoords.length / 4 - allKinds.length; i++) { + kinds.push(allKinds[Math.floor(Math.random() * allKinds.length)]) + } + } + else if (availableCoords.length / 4 === allKinds.length) { + kinds.push(...allKinds) + } + else { + const leftoverKinds = [...allKinds] + shuffleArray(leftoverKinds) + kinds.push(...leftoverKinds.slice(0, Math.ceil(availableCoords.length / 4))) } for (let retry = 0; retry < maxRetries; retry++) { const tiles: Tile[] = [] - const tilePerKind = availableCoords.length / kinds.length for (const kind of kinds) { - for (let i = 0; i < tilePerKind; i++) { - tiles.push({ kind, coord: null as any }) + if (availableCoords.length - tiles.length >= 4) { + for (let i = 0; i < 4; i++) { + tiles.push({ kind, coord: null as any }) + } + } + else if (availableCoords.length - tiles.length === 2) { + for (let i = 0; i < 2; i++) { + tiles.push({ kind, coord: null as any }) + } + } + else { + throw new Error('Invalid number of available coordinates') } } // Shuffle tiles