Yeah its by nation numbers.
And it only allies AI with AI (just to save 10 people the wasted effort of trying to get the AI to ally with their player nation)
The game ignores the ally line if the nation isnt in the game. One of my programming routines added a couple dozen
#allies <random #> <random #>
to a map when it generated one just to make the games interesting. For it to matter, the alliance had to be one of the random ones and they had to randomly land close to each other when you created a game on that map. So you could play it many times with very different results.