Chess openings are easy to learn and easy to forget. Flashcard apps like Anki solve exactly this problem for vocabulary, so for Top Line I wanted the same thing for chess lines. I expected the scheduling part to be complicated. It's about fifty lines.
The idea
You forget things on a curve: quickly at first, then more slowly. Every time you successfully recall something, the curve gets flatter, so the next review can wait longer. Spaced repetition schedules each review for just before you'd forget. Things you know well come back rarely, things you keep getting wrong come back tomorrow.
SM-2 in one function
SM-2 is the algorithm from SuperMemo that Anki's scheduler grew out of. Each card keeps a few numbers:
- interval: days until the next review
- ease: how fast the interval grows (starts at 2.5)
- reps: successful reviews in a row
After each review you give a grade, and the card's numbers change:
switch grade {
case Again: // forgot it
s.Reps = 0
s.Interval = 0
s.Ease = math.Max(1.3, s.Ease-0.2)
s.Due = now.Add(time.Minute) // see it again right away
return s
case Hard:
s.Interval = math.Max(1, s.Interval*1.2)
s.Ease = math.Max(1.3, s.Ease-0.15)
case Good:
switch s.Reps {
case 0:
s.Interval = 1
case 1:
s.Interval = 3
default:
s.Interval *= s.Ease
}
case Easy:
s.Interval = math.Max(4, s.Interval*s.Ease*1.3)
s.Ease += 0.15
}
s.Reps++
s.Due = now.Add(time.Duration(s.Interval * float64(24*time.Hour)))
(Simplified a little: "Hard" and "Easy" on a brand-new card get fixed first intervals.)
Answer "Good" every time and a card comes back after 1 day, then 3, then 7.5, 19, 47… The intervals grow exponentially, which is why you can keep thousands of cards in rotation with a few minutes a day. Every "Hard" or "Again" lowers the ease, so a card you struggle with grows more slowly from then on. The floor of 1.3 stops a difficult card from getting stuck forever.
| Review | “Good” every time | One “Hard” at review 3 |
|---|---|---|
| 1 | 1 day | 1 day |
| 2 | 3 days | 3 days |
| 3 | 7.5 days | 3.6 days |
| 4 | 18.8 days | 8.5 days |
| 5 | 46.9 days | 19.9 days |
| 6 | 117.2 days | 46.7 days |
Days until the next review. One stumble at the third review and the card is due in 47 days after six reviews instead of 117.
What's different about chess lines

One card is a whole line, not one move. A line is a sequence like 1.e4 c5 2.Nf3 d6 3.d4. Reviewing it means playing all of your moves in order against the line's replies. That's how you'll meet it in a real game.
Nobody wants to grade themselves after every line. In Anki you press Again/Hard/Good/Easy yourself. In a chess drill that would interrupt practice every thirty seconds, and people are bad at grading themselves honestly anyway. So Top Line grades the run itself:
| How the run went | Grade |
|---|---|
| No mistakes, no hints | Good |
| A hint, or one wrong move | Hard |
| More than that | Again |
It never gives "Easy". Playing a line cleanly once doesn't tell me you'd find it effortless.
Extra practice shouldn't count. If you practice a line that isn't due yet, the schedule stays as it is. Otherwise cramming the night before a tournament would push all your reviews far into the future.
Changing a line resets it. If you edit the moves, it's a different line now, and it goes back to "to learn". Renaming it or editing the notes keeps its schedule.
What I took from it
- A lot of "smart" features are small, well-understood algorithms. It's worth reading the original before reaching for a library.
- The algorithm was the easy part. The decisions around it took longer: what counts as one card, who grades it, and what doesn't update the schedule.
- Showing progress helps. Each line shows a strength meter from New to Mastered, which is really just the interval with friendlier names.
