fix(cheat-detection): align complexity-speed with each move's own think time - #942
Open
abdulwaarith0 wants to merge 1 commit into
Conversation
…nk time scoreComplexitySpeed collected complex-position indices from playerMoves but read think times via thinkTimes[idx]. Those arrays are in different index spaces: thinkTimes starts at move 1 and is compacted by an elapsed filter, so thinkTimes[i] is the gap before playerMoves[i+1], not the think time of playerMoves[i]. The heuristic therefore matched each complex move to a neighbour's think time (systematic off-by-one) and silently dropped higher-index complex moves via the length guard. Compute each complex move's think time directly from its own previous move's timestamp instead of indexing the compacted array. Add vitest coverage. Closes OpenKnight-Foundation#940
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
Fixes #940.
CheatDetectionEngine.scoreComplexitySpeed()correlated complex-position moves with the wrong think times.complexMoveIndicesheld indices intoplayerMoves, but the code readthinkTimes[idx]. Those two arrays live in different index spaces:thinkTimes(fromcomputeThinkTimes) starts at move1and is compacted by theelapsed > 0 && elapsed < 300000filter, sothinkTimes[i]is the gap beforeplayerMoves[i + 1]— not the think time ofplayerMoves[i].Result: every complex move was matched to a neighbour's think time (systematic off-by-one), and higher-index complex moves were silently skipped by the
idx < thinkTimes.lengthguard — corrupting thecomplexitySpeedcomponent of the suspicion score that's shown live during play (useCheatDetection→app/play/[slug]/page.tsx).Fix
Compute each complex move's think time directly from its own previous move's timestamp (
playerMoves[i].timestamp - playerMoves[i - 1].timestamp, fori >= 1), instead of indexing into the compactedthinkTimesarray. The first move has no preceding own move, so it's excluded.Tests
Adds
frontend/__tests__/cheatDetection.test.ts(vitest):complexitySpeed === 0— this fails on the old off-by-one code (which pulled the fast gap onto a complex move) and passes now.complexitySpeed > 0.Both new tests pass locally (
vitest run __tests__/cheatDetection.test.ts), and the change is isolated tocheatDetection.ts.