One way to do this is the following: Only call accept_connection if you know that less than 20 people are playing. How can you tell if someone is done playing the game though? One way to do this is to open a pipe between the server process and each game-playing process. When the game-playing process is finished, the server can detect this because the other end of the pipe will be gone (the server can also call wait() here and get rid of zombies). Write the code to do exactly this.
You should not attempt to make this code threaded. Instead you should write it using select().