Skip to content

Commit a5509e7

Browse files
Fix homophone collision in answer matching
Problem: When limitedMatches contained duplicate words (same kanji, same reading appearing multiple times), the progress counter would jump by 2+ when finding one word. For example, typing "いる" once would match both duplicate entries, making the count go from 0/10 to 2/10. Solution: Deduplicate matches by word before using them for the game. Keep first occurrence and log warning when duplicates are removed. This fixes the issue where games would reach 10/10 after only entering 5 unique answers. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent c3c2c9a commit a5509e7

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

src/components/games/WhatCouldMatch.jsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,19 @@ function WhatCouldMatch({ word, onComplete, mode = 'verb-to-noun', matchCount =
116116
matches = await getLimitedNounMatchesWithProgress(word.japanese, data, matchCount, newWordsTarget, filteredMatches);
117117
}
118118

119-
setLimitedMatches(matches);
120-
setTotalMatches(matches.length);
119+
// Deduplicate matches by word (keep first occurrence)
120+
const seenWords = new Set();
121+
const uniqueMatches = matches.filter(m => {
122+
if (seenWords.has(m.word)) {
123+
console.warn(`[WhatCouldMatch] Removing duplicate word: ${m.word} (${m.reading})`);
124+
return false;
125+
}
126+
seenWords.add(m.word);
127+
return true;
128+
});
129+
130+
setLimitedMatches(uniqueMatches);
131+
setTotalMatches(uniqueMatches.length);
121132

122133
// Load hints for this word
123134
const hintMode = (mode === 'noun-to-verb' || mode === 'noun-to-adjective') ? 'reverse' : 'forward';

0 commit comments

Comments
 (0)