When Tournament Directors assign colors to players, they have to consider a set of specific rules that's in US Chess Rules of Chess.
Rule 29E addresses how colors are determined for each players in any given round.
It is a complicated and tough subject, so it comes as no surprise that the matter is discussed and detailed out in almost 10 pages in the rule book!
Let's try to list some of the basic principles:
Two Principle Guidelines
1) If a tournament has an even number of rounds, players should ideally get white and black the same number of times; in an event with an odd number of rounds, each player should receive no more than one extra white or black above an even allocation.
This is called EQUALIZING of colors.
2) In addition to the above guideline, the director, after the first round, tries to alternate colors, meaning switch white and black, by giving as many players as possible their due (correct or expected) color, round by round. This is called ALTERNATING of colors.
The due color is usually the color a player did not have in the previous round, but not always. For example, a player who had white in rounds one and two and black in round three, has a due color of black in round four, as equalization has priority over alternation.
First round colors in the top section is decided usually by coin toss. Consecutive sections are determined based on the open section. As many players as possible are given their due colors in each round, so long as the pairings conform to the basic chess rules.
What’s a due color?
A player who has had an unequal number of whites and blacks is due the color that tends to equalize the number of whites and blacks. A player who has had an equal number of whites and blacks is due the opposite color to that he received in the most recent round. Unplayed games, including byes and forfeits, do not count for color. This means forfeit wins, and byes!
So what’s the priority? Equalizing the number of whites and blacks? Or Alternating the colors?
Equalization of colors takes priority over alternation of colors. First, as many players as possible are given the color that tends to equalize the number of times they have played white and black. After that is accomplished, as many players as possible should be given the color opposite to that which they played in the previous round.
What about pairing players due the same color?
1. If one player has had an unequal number of whites and blacks, while the other has had equal colors, the player who has had unequal colors gets due color. Example: WBW gets black over BxW, where x denotes any unplayed game—full-point bye, half-point bye, forfeit win, forfeit loss, etc.
2. If both players have had an unequal number of whites and blacks, the player with the greater total color imbalance gets due color. Example: WWBW gets black over xWBW.
3. If both players have had an equal number of whites and blacks, or both are equally out of balance, and if they had opposite colors in the previous round, the players should be given colors opposite to that which they played in the previous round. Example: WWB gets white over WBW.
4. If both players have had an equal number of whites and blacks, or both are equally out of balance, and if they had different colors in one or more prior rounds, priority for assigning color should be based on the latest round in which their colors differed. One or both players should be assigned the color opposite to that which they played in that round. Example 1: WBWB gets white over BWWB, because the first player had black in round two, the latest round in which colors differed. Example 2: BWxBW gets white over BWBxW, because the first player had black and the second had no color in round 4, the latest round in which colors differed.
5. If both players have had the same color sequence, the higher-ranked player gets due color. The higher ranked player is the player with the higher score. If the players have the same score, the higher-ranked player is the higher-rated.
One extra help: when we print out the pairing sheet, we try to indicate what's the player's due color: w, W, or WW, or b, B, or BB. This indicate how "urgent" it is for any player to get their due color.