From 261a4d864e0f85ebcf8cb54252a51426dcc967d7 Mon Sep 17 00:00:00 2001 From: tiennm99 Date: Tue, 7 Apr 2026 20:51:36 +0700 Subject: [PATCH] feat: add emoji pool and difficulty-based selection --- superpowers/src/game/emoji.ts | 17 +++++++++++++++ superpowers/tests/game/emoji.test.ts | 32 ++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 superpowers/src/game/emoji.ts create mode 100644 superpowers/tests/game/emoji.test.ts diff --git a/superpowers/src/game/emoji.ts b/superpowers/src/game/emoji.ts new file mode 100644 index 0000000..f465639 --- /dev/null +++ b/superpowers/src/game/emoji.ts @@ -0,0 +1,17 @@ +import { Difficulty } from "../types"; +import { DIFFICULTY_CONFIGS } from "./constants"; + +export const EMOJI_POOL: string[] = [ + "🐶", "🐱", "🐭", "🐹", "🐰", "🦊", "🐻", "🐼", + "🐨", "🐯", "🦁", "🐮", "🐷", "🐸", "🐵", "🐔", + "🐧", "🐦", "🦆", "🦅", "🦉", "🦇", "🐺", "🐗", + "🐴", "🦄", "🐝", "🐛", "🦋", "🐌", "🐞", "🐢", + "🐍", "🦎", "🐙", "🦑", "🦐", "🦀", "🐡", "🐠", + "🐟", "🐬", "🐳", "🐊", +]; + +export function getEmojisForDifficulty(difficulty: Difficulty): string[] { + const count = DIFFICULTY_CONFIGS[difficulty].pairCount; + const shuffled = [...EMOJI_POOL].sort(() => Math.random() - 0.5); + return shuffled.slice(0, count); +} diff --git a/superpowers/tests/game/emoji.test.ts b/superpowers/tests/game/emoji.test.ts new file mode 100644 index 0000000..cdbbad5 --- /dev/null +++ b/superpowers/tests/game/emoji.test.ts @@ -0,0 +1,32 @@ +import { describe, it, expect } from "vitest"; +import { EMOJI_POOL, getEmojisForDifficulty } from "../../src/game/emoji"; + +describe("emoji", () => { + it("pool has at least 40 unique emoji", () => { + expect(EMOJI_POOL.length).toBeGreaterThanOrEqual(40); + expect(new Set(EMOJI_POOL).size).toBe(EMOJI_POOL.length); + }); + + it("returns correct count for easy", () => { + const emojis = getEmojisForDifficulty("easy"); + expect(emojis.length).toBe(12); + expect(new Set(emojis).size).toBe(12); + }); + + it("returns correct count for medium", () => { + const emojis = getEmojisForDifficulty("medium"); + expect(emojis.length).toBe(24); + }); + + it("returns correct count for hard", () => { + const emojis = getEmojisForDifficulty("hard"); + expect(emojis.length).toBe(40); + }); + + it("returned emojis are a subset of the pool", () => { + const emojis = getEmojisForDifficulty("hard"); + for (const e of emojis) { + expect(EMOJI_POOL).toContain(e); + } + }); +});