The whole thing is based on turn order.
I believe (but am not sure) that turn order is the same order you see in the space race screen.
Basically each AI is given a turn much as the human is. Even the barbs go on their own turn.
This is what leads to some interesting wonder cascades and is why you will sometimes see 3 or 4 wonders built by the AI on the same turn. All were building pyramids, first one gets it, next ai cascades to oracle, next to colossus, 4th gets left out in the cold.