How in race game Identify the Race Leader

Thank a lot, I will try understand and reproduce