timotheeg / nestrischamps

A web-based OCR and restreamer system for NES Classic Tetris players
MIT License
45 stars 11 forks source link

Better block accounting: stop relying only on the first frame of clear animations #96

Closed timotheeg closed 3 years ago

timotheeg commented 3 years ago

Context

In layouts classic, das_trainer, tomellosoulman, block accounting assumes no frame drops and assumes it can capture the first frame of the line clear animation. This is a dangerous gambit: if the frame is missed, block accounting will go out of sync (possibly by counting a clear as an incorrect clear), piece counters will stop, and drought counter will stop.

This PR introduces a more resilient system, where clears are detected as long as any 2 frames of a particular clear are detected.

Approach

  1. List down explicitly the negative block counts that are possible and the sequence that can exist with this:
    const all_possible_negative_diffs = [
    -2, -4, -6, -8, -10, -12, -16, -18, -20, -24, -30, -32, -40,
    ];
    const clear_diffs = [
    [-2,  -4,  -6,  -8, -10],
    [-4,  -8, -12, -16, -20],
    [-6, -12, -18, -24, -30],
    [-8, -16, -24, -32, -40],
    ];
  2. Track full rows as piece moves

When a valid negative block count is seen

Benefits:

This is still weak, but should be much more resilient than the prior approach.

Tested on emulator locally

Risk

Since this is a new algorithm, there could be undetected edge cases. PR should get a bit more testing before being merged and deployed.