feat: improve combination search and offline build
This commit is contained in:
@@ -8,12 +8,21 @@ type BeamState<T extends CombinationSearchCard> = {
|
||||
score: number;
|
||||
};
|
||||
|
||||
export function resolveCandidateAwakening(
|
||||
configuredAwakening: number,
|
||||
owned: boolean,
|
||||
ownedAwakening: number
|
||||
): number {
|
||||
return owned ? Math.max(configuredAwakening, ownedAwakening) : configuredAwakening;
|
||||
}
|
||||
|
||||
export function generateCombinationCandidates<T extends CombinationSearchCard>(
|
||||
fixedCards: readonly T[],
|
||||
candidateCards: readonly T[],
|
||||
targetSize: number,
|
||||
scoreCard: (card: T) => number,
|
||||
beamWidth = 800
|
||||
beamWidth = 800,
|
||||
scoreCombination?: (cards: readonly T[]) => number
|
||||
): T[][] {
|
||||
if (targetSize < fixedCards.length) throw new Error('목표 카드 수가 고정 카드 수보다 작습니다.');
|
||||
if (new Set(fixedCards.map((card) => card.characterId)).size !== fixedCards.length) {
|
||||
@@ -24,7 +33,7 @@ export function generateCombinationCandidates<T extends CombinationSearchCard>(
|
||||
const pool = candidateCards.filter((card) => !fixedIds.has(card.id) && !fixedCharacters.has(card.characterId));
|
||||
let beam: BeamState<T>[] = [{
|
||||
cards: Array.from(fixedCards),
|
||||
score: fixedCards.reduce((sum, card) => sum + scoreCard(card), 0)
|
||||
score: scoreCombination?.(fixedCards) ?? fixedCards.reduce((sum, card) => sum + scoreCard(card), 0)
|
||||
}];
|
||||
|
||||
for (let size = fixedCards.length; size < targetSize; size += 1) {
|
||||
@@ -35,9 +44,10 @@ export function generateCombinationCandidates<T extends CombinationSearchCard>(
|
||||
for (const card of pool) {
|
||||
if (usedIds.has(card.id)) continue;
|
||||
if (usedCharacters.has(card.characterId)) continue;
|
||||
const cards = [...state.cards, card];
|
||||
const nextState = {
|
||||
cards: [...state.cards, card],
|
||||
score: state.score + scoreCard(card)
|
||||
cards,
|
||||
score: scoreCombination?.(cards) ?? state.score + scoreCard(card)
|
||||
};
|
||||
const key = nextState.cards.map((entry) => entry.id).sort().join('|');
|
||||
if (!expanded.has(key)) expanded.set(key, nextState);
|
||||
|
||||
Reference in New Issue
Block a user