게시판SGF 기보로 학습하는 바둑 LLM 인공지능예제 소스

예제 소스

SGF 기보로 학습하는 바둑 LLM 인공지능 · 파일 169개

guest.ts

const GUEST_KEY = "mariago_guest_id";
const LAST_CODE_KEY = "mariago_last_game_code";
const LAST_KEY_KEY = "mariago_last_access_key";

function randomId(): string {
  if (typeof crypto !== "undefined" && crypto.randomUUID) {
    return crypto.randomUUID();
  }
  return `g_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 10)}`;
}

export function getOrCreateGuestId(): string {
  if (typeof window === "undefined") return "";
  let id = localStorage.getItem(GUEST_KEY);
  if (!id) {
    id = randomId();
    localStorage.setItem(GUEST_KEY, id);
  }
  return id;
}

export function rememberGame(code: string, accessKey: string): void {
  if (typeof window === "undefined") return;
  localStorage.setItem(LAST_CODE_KEY, code.toUpperCase());
  localStorage.setItem(LAST_KEY_KEY, accessKey);
  localStorage.setItem(`mariago_key_${code.toUpperCase()}`, accessKey);
}

export function loadRememberedGame(): { code: string; accessKey: string } | null {
  if (typeof window === "undefined") return null;
  const code = localStorage.getItem(LAST_CODE_KEY);
  const accessKey = localStorage.getItem(LAST_KEY_KEY);
  if (!code || !accessKey) return null;
  return { code, accessKey };
}

export function loadAccessKeyForCode(code: string): string | null {
  if (typeof window === "undefined") return null;
  return localStorage.getItem(`mariago_key_${code.toUpperCase()}`);
}