For 165 Hz gaming, a 7700K would be better, even though it has pretty terrible value today. If you have plans for keeping the CPU for a long time, then get Ryzen, even though it'll bottleneck at times at that refresh rate. The extra cores will offer longevity, while the 7700K will last a maximum of 3 years, maybe 3.5 if you push it. After that its 4 cores will really hold back performance.
But if you want to game at 165 FPS, and you want the current best without giving a peanut about future-proofing, the 7700K is your only choice for 165 Hz gaming.