clone

a daily shikaku puzzle for phones: one seeded puzzle per date, solved by dragging rectangles

main
rect.run / lib / shikaku / day_stack_state.ts
day_stack_state.ts 1.5K
1export interface DayStackStateInput {2 date: string;3 today: string;4 stackIndex: number;5 playableStackIndex: number;6 mostRecentStackIndex: number;7 isReplay: boolean;8}910export interface DayStackState {11 mode: "playable" | "readonly" | "locked";12 message: string;13 canReset: boolean;14}1516export interface InitialStackIndexInput {17 date: string;18 today: string;19 selectedStackIndex: number;20 playableStackIndex: number;21}2223export function getInitialStackIndex(input: InitialStackIndexInput): number {24 return input.date === input.today25 ? Math.max(input.selectedStackIndex, input.playableStackIndex)26 : input.selectedStackIndex;27}2829export function resolveDayStackState(30 input: DayStackStateInput,31): DayStackState {32 if (input.date > input.today) {33 return {34 mode: "locked",35 message: "Locked until this day.",36 canReset: false,37 };38 }3940 if (input.date < input.today) {41 if (input.isReplay) {42 return { mode: "playable", message: "Replay mode.", canReset: true };43 }4445 return {46 mode: "readonly",47 message: "Past day. View only.",48 canReset: true,49 };50 }5152 if (input.stackIndex > input.playableStackIndex) {53 return {54 mode: "locked",55 message: `Locked. Finish stack ${input.playableStackIndex} first.`,56 canReset: false,57 };58 }5960 if (input.stackIndex < input.playableStackIndex) {61 return {62 mode: "readonly",63 message: "Earlier stack. View only.",64 canReset: false,65 };66 }6768 return { mode: "playable", message: "Drag. One clue.", canReset: true };69}