Generally speaking it's the CPU with the highest clockspeed in the series. Core counts stop mattering after a certain point eg. usually around 6 cores/12 threads, so the higher core count chips on the HEDT platforms like X299 and X399 can actually be detrimental to gaming performance.
For AMD the best gaming CPUs in each series would be R3 1300x, R5 2600x, R7 2700x, Threadripper TR2920x or possibly 2950x depending on how the Turbo behaviour on it works. Buying Threadripper for solely gaming is kind of stupid though, as games simply don't scale across that many cores.
For Intel most of their best gaming CPUs just released and are mostly not available in stores right now. The older 8th gen products are more available and are quite close though. The best in each series would be i3 8350k, i5 9600k, i7 9700k (the 8700k is within a couple of percentage points though and does technically have more threads) i9 9900k (8700k is also extremely close to this one as few games scale up to 8 cores and 16 threads).