AI Tribes pick randomly from the available colors, sometimes there just aren't enough to go around.
During world generation AI tribes are placed, those are defined in the XML files. "wg_ai_placement.xml" in BaseMod defines the placement of the masklings. The ai_placement element defines what biomes the tribe will prefer, what territory size they'll prefer, and what javascript functions to use for generation and ai. I'm not sure how well multiple races will work, I haven't had a chance to test that yet.