Why does the AI prefer communism?
By now, I've probably played a hundred games against the medium and hard AI. I've noticed that once an AI-controlled player discovers communism, it will not hesitate to switch to communism. Communism is the most advanced government in the technology tree. Democracy and republic are discovered before communism, and yet I have observed lots of AIs skip over republic and democracy. When the AI has switched to communism, it rarely changes governments any more. I've only observed AI changing from communism to democracy twice, and in both of those cases, the AI switched back to communism once it became clear that they could not defend their cities under democracy (due to lack of free unit maintenance).
Does the Freeciv AI really prefer communism? Is it because it is the most advanced government in the technology tree? Is it because of the good balance between free unit maintenance and low corruption that makes large empires stable? Or am I just seeing things wrong?
Solution 1:
The AI for evaluating government types is really, really complicated (at a rough estimate, it's about 6000 lines of code). At a high level, it works by computing two things: how productive a civilization's cities would be under a given government type (a weighted average of food, shield, gold, science, and luxury output), and what civilization-wide benefits a given government type would provide (everything from the ability to build veteran spies, to the bonuses from having more than half the citizens being happy). It then adds a penalty for the cost of switching governments, and picks the government with the highest score.
There's no hard-coded preference in the AI for communism. Rather, by the time communism becomes available, it typically provides the best balance of city productivity and global benefits.