|
|
@ -30,6 +30,10 @@ export interface ChaseRound { |
|
|
}; |
|
|
}; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export interface GenerateChaseRoundOptions { |
|
|
|
|
|
generateAttempt?: (seed: number, difficulty: Difficulty) => ChaseRound; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
function coordKey(q: number, r: number): CoordKey { |
|
|
function coordKey(q: number, r: number): CoordKey { |
|
|
return `${q},${r}`; |
|
|
return `${q},${r}`; |
|
|
} |
|
|
} |
|
|
@ -202,13 +206,17 @@ function generateGraphAttempt(seed: number, difficulty: Difficulty): ChaseRound |
|
|
}; |
|
|
}; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
export function generateChaseRound(input: GenerateChaseRoundInput): ChaseRound { |
|
|
export function generateChaseRound( |
|
|
|
|
|
input: GenerateChaseRoundInput, |
|
|
|
|
|
options: GenerateChaseRoundOptions = {}, |
|
|
|
|
|
): ChaseRound { |
|
|
const baseSeed = normalizeSeed(input.seed); |
|
|
const baseSeed = normalizeSeed(input.seed); |
|
|
const minPathLength = minimumPathByDifficulty(input.difficulty); |
|
|
const minPathLength = minimumPathByDifficulty(input.difficulty); |
|
|
|
|
|
const generateAttempt = options.generateAttempt ?? generateGraphAttempt; |
|
|
|
|
|
|
|
|
for (let attempt = 0; attempt < MAX_ATTEMPTS; attempt += 1) { |
|
|
for (let attempt = 0; attempt < MAX_ATTEMPTS; attempt += 1) { |
|
|
const attemptSeed = normalizeSeed(baseSeed + attempt * 0x9e3779b9); |
|
|
const attemptSeed = normalizeSeed(baseSeed + attempt * 0x9e3779b9); |
|
|
const round = generateGraphAttempt(attemptSeed, input.difficulty); |
|
|
const round = generateAttempt(attemptSeed, input.difficulty); |
|
|
const isPlayable = |
|
|
const isPlayable = |
|
|
isConnected(round.snapshot.graph) && |
|
|
isConnected(round.snapshot.graph) && |
|
|
round.meta.hasEscapePath && |
|
|
round.meta.hasEscapePath && |
|
|
|