Untitled

 avatar
unknown
plain_text
a year ago
3.0 kB
11
Indexable
type Tile = {
  r: number;
  c: number;
  label: string;
  free?: boolean;
  image?: string;
  prompt?: string;
  photoChallenge?: boolean;
};

function generateBoard({
  theme,
  seed,
  mode = "text",
  enablePhotoChallenge = false
}: {
  theme: string;
  seed: string;
  mode: "text" | "image" | "hybrid";
  enablePhotoChallenge: boolean;
}): Tile[] {
  const rng = mulberry32(hash(seed)); // deterministic PRNG
  const candidates = aiDraft(theme, 40); // AI generates 40 kid-safe experiences
  const pool = filterSafeUnique(candidates); // remove duplicates, unsafe items
  const picked = sampleDeterministic(pool, 24, rng);

  const photoIndices = enablePhotoChallenge
    ? sampleDeterministic([...Array(25).keys()].filter(i => i !== 12), 5, rng) // pick 5 spaces (excluding FREE center)
    : [];

  let i = 0;
  const tiles: Tile[] = [];
  for (let r = 0; r < 5; r++) {
    for (let c = 0; c < 5; c++) {
      if (r === 2 && c === 2) {
        tiles.push({ r, c, label: "FREE", free: true });
        continue;
      }
      const idx = r * 5 + c;
      const label = picked[i++];
      const tile: Tile = { r, c, label };
      if (mode !== "text") {
        tile.prompt = `chibi ${label.toLowerCase()} sticker, flat, bold outline, kid-safe, 256x256`;
        tile.image = getOrGenerateImage(tile.prompt);
      }
      if (photoIndices.includes(idx)) tile.photoChallenge = true;
      tiles.push(tile);
    }
  }
  return tiles;
}
let tripleTapCount = 0;
const maxTripleTaps = 3;

function onTileTap(tile: Tile) {
  if (tile.photoChallenge && photoChallengeEnabled) {
    openCamera(tile); // ask player to take a photo
    return;
  }
  markTile(tile); // normal marking
}

function onTileTripleTap(tile: Tile) {
  if (tripleTapCount >= maxTripleTaps) return;
  tripleTapCount++;
  replaceTile(tile); // AI generates new random experience from same theme
}

function replaceTile(tile: Tile) {
  const newLabel = sampleFromPool(themePool, seed);
  tile.label = newLabel;
  if (mode !== "text") {
    tile.prompt = `chibi ${newLabel.toLowerCase()} sticker, flat, bold outline, kid-safe, 256x256`;
    tile.image = getOrGenerateImage(tile.prompt);
  }
  tile.photoChallenge = false; // reset challenge for replaced tile
  animateTilePop(tile); // cartoon effect
}
let photoChallengeEnabled = false;

function togglePhotoChallenge(enabled: boolean) {
  photoChallengeEnabled = enabled;
  broadcastToPlayers({ type: "photoChallengeToggle", enabled });
}

// Example in lobby UI
function renderLobbyControls() {
  return (
    <Switch
      value={photoChallengeEnabled}
      onValueChange={(val) => togglePhotoChallenge(val)}
      label="Enable Photo Challenge"
    />
  );
}

// During board generation
const board = generateBoard({
  theme: selectedTheme,
  seed: roomID + timestamp,
  mode: "hybrid",
  enablePhotoChallenge: photoChallengeEnabled
});
Editor is loading...
Leave a Comment