Download presentation
Presentation is loading. Please wait.
Published byAvice Baldwin Modified over 9 years ago
1
1 The FreeCiv AI Zack Ives Steve Wolfman CSE 590AG April 20, 1999
2
2 Cheesy Heuristics! Mostly a series of rules with weights and randomness Different options are evaluated for desirability Roulette-wheel-style ai_fuzzy function decides whether AI will follow heuristics Mostly a peer-model agent structure with a bit of hierarchy, mostly re-evaluating at each turn Different AI’s to control cities, tech advances, units, etc. (Though military AI is somewhat hierarchical; both coordinator to assign roles and a unit-level AI) Each AI gets “votes” weighting decisions
3
3 The AI Files aihand - main AI routines aicity - city-level AI aitech - tech goal AI aitools - utility routines (choose wonders, govt) aiunit - unit-level AI; settlers - settler AI (in server) advdomestic - intra-city advisor (worker placement, valuation of improvements) advisland, advscience, advtrade, advattitude - blank advmilitary - offense & defense for units server/citytools - city/worker reasoning functions
4
4 General AI Components In aihand, several important functions: ai_manage_units - control units, assess defense & offense & needs ai_manage_cities - control city building, spending ai_manage_taxes - set tax/science/luxury rate ai_manage_government - set government style ai_manage_tech - tech advances No coordinating AI, but inter-module communication
5
5 Interesting Ideas Bodyguard if city already defended, defensive unit will try to find a low- defense “charge” and AI will coordinate movement Urgency and value Cities and domestic and military advisors collaboratively determine how valuable improvements, reinforcements, or new technologies will be, and how urgently they’re needed Tech is valued according to needs noticed throughout movement, building, … Sacrifice If city is ready to be conquered, try to sell what you can
6
6 What the AI Emphasizes Wonders and caravans Diplomats If opponent’s diplomat or spy is nearby, builds diplomat for defense Builds up money to buy improvements If troops not serving purpose, AI brings them home Transports try to land near destination Republic and “We love the consul day”
7
7 Cheats Apparently not as many as we’d think! AI has knowledge of full map and enemy unit locations AI has no penalty for changing what’s being built At higher difficulty levels, AI not constrained by maximum rates on tax, science, etc. Civil disorder - last-second fix for unhappy city (though does suffer effects if unable to make city happy) AI changes government for free (no Anarchy)
8
8 The Unit AI - Structure In aiunit and advmilitary Main function ai_manage_units ai_manage_settler ai_manage_caravan ai_manage_ferryboat ai_manage_explorer ai_manage_military: based on role, auto-settle, build city, defend home, attack, fortify, run, escort, explore Can ask for units (ai_wants_role_unit) and get closest possible match (due to tech limitations)
9
9 The Unit AI - What It Does Settlers - auto_settler_findwork Check terrain for value as city Rate usefulness of mining, roads, irrigation, detox, etc. Exploration Top priority = huts Then randomly explore Caravan Find city building wonder not near completion, send caravan
10
10 Unit AI - Military Calculate belligerence (offensive rating), vulnerability (defensive rating) of units Military finds victim based on attack power vs. vulnerability Bodyguard - extra defensive unit finds vulnerable unit, becomes its bodyguard; AI synchronizes movement Assigns roles to units (auto-settle, build city, defend home, attack, fortify, run, escore, explore) find_something_to_kill - main controlling function for coordinating attacks generate_warmap - assessment of distances, possibilities, & costs of moving & attacking Choose most appealing targets, send forces to eradicate
11
11 Military Advisor Assess danger due to opposing forces Assess city defenses If city in danger, may specify desire for coastal fortress, SAM, SDI Based on this, may want prerequisite new technologies Assess offensive capability and desires May wish to build new units, acquire new technologies Decide what to kill
12
12 The City AI - structure In aicity and advdomestic Main function in aicity is ai_manage_cities ai_manage_city - arrange workers ai_manage_buildings - globally important bldgs (palace & wonders) ai_city_choose_build - locally evaluate buildings (calls domestic advisor) Main function in advdomestic is ai_eval_buildings individually rates each type of building according to food/prod/gold/bulb considers luxury result in terms of new available workers
13
13 Money Management in the City AI Money spent based on collaborative needs (“votes”) Considers cities in order of greatest need Tries to buy something for every city Becomes frugal with remaining money if ever it cannot afford something “important” (highly desired) Some heuristics restrict buying Don’t spend too much at once (except for high want) Don’t build Wonder in threatened city
14
14 Taxes, Luxury, and Sciency (oh my!) Handled in ai_manage_taxes (in aihand ) Luxuries considered first Only if government is Republic Try to maximize population gain from “we love the consul” Sacrifice if leaves insufficient tax rate to acquire needed funds or if unable to reach optimal celebration point Taxes next Gathers enough money to cover expenses plus population dependent “spare change” requirements Science gets leftovers
15
15 Government changes Simple module (partly because AI cheats!) Different possible goal governments define track Change as soon as next government on track becomes available No backtracking to earlier government Current AI hardwired to Republic track
16
16 Useful code AI code is hard to reuse AI uses many server structures unavailable to client (e.g., warmap) Shared structures (such as tech_want ) are hard to disentangle from code Smallest functions most useful City calculations in advdomestic such as pollution caused/ameliorated by an improvement Danger assessments?
17
17 Bonus: FreeCiv AI Fun! “hhjj” is a structure used to calculate celebration levels in cities at various luxury levels… what does hhjj stand for?
18
18 Technology tech_want structure maintains desire levels for various techs Each component can up tech requirements Military wants better units/transports Missing wonder/governments cause want for enabling techs Global AI adds hardwired want for Republic track techs Cities want enabling techs for buildings Global AI fudges philosophy want upward (if not developed yet) Prerequisites of desired tech weighted Weights reduced according to time to reach tech
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.