Selecting easily distinguishable colors

I am writing a game and I need a choose a color for each player. The colors need to be easily distinguishable so that a human can identify the player by the color relatively easily. I need about 20 colors (the more, the better).

How do I approach this problem? Are there some rules that I can apply in order to make my choice of colors?