| General | Hosted Sites | Civ5 | CivRev | Civ4Col | Civ4 | Civ3 | Civ2 | Civ1 | Misc | Marketplace |
![]() |
|
|
Welcome to Civilization Fanatics' Center. You are currently viewing our site as a guest which gives you limited access to our site features. By joining our free community, you will be able to participate in the discussions, search the forum, send private messages, vote in polls, upload your own screenshots to the gallery, and access many other special features. Registration is fast, simple and absolutely free, so sign up today! If you have any problems with the registration process or your account login, please contact support. |
|
|||||||
![]() |
|
|
Thread Tools |
|
|
#661 | |||
|
King
Join Date: Jan 2006
Location: Boston, MA, USA
Posts: 611
|
Quote:
The system I've set up modifies AI_getH/HWeight() directly to start with the health and happiness values for each city it's considering as if all civics were off: basically "int iCityHappy = pLoopCity->happyDifferenceWithoutCivics()". This function mostly just reads off stored values, and the ones it does compute on the fly are simple if/else things that don't loop over any long lists. It will run MUCH faster than what you were proposing. The PROBLEM with it, which I just realized before I went to sleep last night, is that you can't update health/happiness on a per-civic-category basis as you select a civic in each category as you go... But I don't think your approach is a good idea either - it will simply be too slow, especially when you consider we're already slowing things down a bunch by making it look at all an AI's cities instead of just the first 7... Meh. Quote:
The problem with what you're suggesting Roland, is you're trying to come up with exact precise perfect values for the weight and that's not a good idea. The speed of this code is important, the stats of a civ empire change quickly as turns pass anyway, and a good estimate is all you need or want here I'm pretty sure. There are "good estimate" values all OVER both the vanilla and BBAI code... if you wanted to start turning them all into extremely-accurate numbers we'd be here discussing this all year heh. Basically I need a formula of the form: some sort of unit count, times some sort of scale coefficient to factor in the logistical realities of managing an army, divided by some sort of city count. Quote:
__________________
MongooseMod 4.1 is nearing completion... If you check it out there's a good chance you'll fall in love! ![]() <-- BBAI/UP Contributor, Original BTS Sevopedia and PW3 Civ4 Port Author |
|||
|
|
|
|
|
#662 | |
|
King
Join Date: Jan 2006
Location: Boston, MA, USA
Posts: 611
|
Quote:
I actually added another tracking value to the player structure (at this point I figured why not heh, I've already broken savegames), that mirrors getNumMilitaryUnits() except it checks MilitaryHappiness instead, to which I would also add whether it has UNITAI_CITY_DEFENSE, so I wouldn't be counting units. I didn't know you could get a count from UNITAI_CITY_DEFENSE directly though, how does that work?
__________________
MongooseMod 4.1 is nearing completion... If you check it out there's a good chance you'll fall in love! ![]() <-- BBAI/UP Contributor, Original BTS Sevopedia and PW3 Civ4 Port Author |
|
|
|
|
|
|
#663 |
|
The White Wizard
|
GET_PLAYER(getOwnerINLINE()).AI_getNumAIUnits(UNIT AI_CITY_DEFENSE)
__________________
"A Witty Saying Proves Nothing" -Voltaire Civilization 4 Mods: Rise of Mankind - A New Dawn 1.75 Civilization 5 Mods: Active City Defense, Tech Diffusion Minecraft Mods: Spout & Spoutcraft Lead Developer |
|
|
|
|
|
#664 | |
|
King
Join Date: Jan 2006
Location: Boston, MA, USA
Posts: 611
|
Quote:
Gandalf-dood: I knooooow! Mwa ha ha...
__________________
MongooseMod 4.1 is nearing completion... If you check it out there's a good chance you'll fall in love! ![]() <-- BBAI/UP Contributor, Original BTS Sevopedia and PW3 Civ4 Port Author |
|
|
|
|
|
|
#665 | |
|
Deity
Join Date: Apr 2003
Location: the Netherlands
Posts: 4,281
|
Quote:
__________________
If in other sciences we should arrive at certainty without doubt and truth without error, it behooves us to place the foundations of knowledge in mathematics. |
|
|
|
|
|
|
#666 |
|
The White Wizard
|
Yeah, I have a really good memory; I tend to remember all the code I read. Anyway, that's tracked all throughout the game, so it should work very well for your purposes.
__________________
"A Witty Saying Proves Nothing" -Voltaire Civilization 4 Mods: Rise of Mankind - A New Dawn 1.75 Civilization 5 Mods: Active City Defense, Tech Diffusion Minecraft Mods: Spout & Spoutcraft Lead Developer |
|
|
|
|
|
#667 | |
|
The White Wizard
|
Quote:
Code:
int iLoop;
int iNumDefenders = AI_getNumAIUnits(UNITAI_CITY_DEFENSE);
for (CvCity* pLoopCity = firstCity(&iLoop); pLoopCity != NULL; pLoopCity = nextCity(&iLoop))
{
int iNewHappy = std::min(iNumDefenders / iNumCities, pLoopCity->AI_neededDefenders())
//if iNumCities == 0, the loop will never run, so no division by zero.
//this is a conservative estimate, change std::min to std::max to have a more liberal estimate
}
__________________
"A Witty Saying Proves Nothing" -Voltaire Civilization 4 Mods: Rise of Mankind - A New Dawn 1.75 Civilization 5 Mods: Active City Defense, Tech Diffusion Minecraft Mods: Spout & Spoutcraft Lead Developer |
|
|
|
|
|
|
#668 | |
|
Deity
Join Date: Apr 2003
Location: the Netherlands
Posts: 4,281
|
Quote:
I just commented that the happiness effect of hereditary rule is a bit better than the average number of defenders in a city because more units are typically placed in the cities that need more happiness. I can discuss formulas, but I don't understand all lines of code easily as I've spent very little time of my life reading code. As a mathematician, I do like to think about formulas to approximate stuff. Maybe the happiness bonus can be based on the number of defenders the AI wants to place in each city. This is also calculated somewhere to determine AI's defensive tactics. It's likely a decent approximation of how many units the AI will place in the city. Or is the AI intelligent enough to place more units in unhappy cities when using hereditary rule?
__________________
If in other sciences we should arrive at certainty without doubt and truth without error, it behooves us to place the foundations of knowledge in mathematics. |
|
|
|
|
|
|
#669 | ||
|
The White Wizard
|
Quote:
Quote:
Code:
int iLoop;
int iNumDefenders = AI_getNumAIUnits(UNITAI_CITY_DEFENSE);
for (CvCity* pLoopCity = firstCity(&iLoop); pLoopCity != NULL; pLoopCity = nextCity(&iLoop))
{
int iNewHappy = std::min(iNumDefenders / iNumCities, pLoopCity->AI_neededDefenders())
//if iNumCities == 0, the loop will never run, so no division by zero.
//this is a conservative estimate, change std::min to std::max to have a more liberal estimate
}
__________________
"A Witty Saying Proves Nothing" -Voltaire Civilization 4 Mods: Rise of Mankind - A New Dawn 1.75 Civilization 5 Mods: Active City Defense, Tech Diffusion Minecraft Mods: Spout & Spoutcraft Lead Developer |
||
|
|
|
|
|
#670 | |
|
King
Join Date: Jan 2006
Location: Boston, MA, USA
Posts: 611
|
Quote:
This could undoubtedly use some improvement as well. Gee, I sure wish JDOG!!!, were here... ... Though I can probably do it myself. Sigh. Why are SO many things broken in the vanilla code? This is getting ridiculous heh.
__________________
MongooseMod 4.1 is nearing completion... If you check it out there's a good chance you'll fall in love! ![]() <-- BBAI/UP Contributor, Original BTS Sevopedia and PW3 Civ4 Port Author |
|
|
|
|
|
|
#671 |
|
King
Join Date: Jan 2006
Location: Boston, MA, USA
Posts: 611
|
Alright, some code submissions at last heh. I've made one extremely slight improvement to CvPlayerAI::AI_doCivics() since I posted it two days ago - removing an unnecessary iBestValue assignment - so rather than update that I'm just going to repost it here:
Spoiler:
Next, the thing I just added to the bottom of CvCityAI::AI_neededDefenders(): Spoiler:
That should make the AIs add more units to cities that currently need happiness if they're operating the Monarchy civic. Now then, moving back to basic functionality updates to the PlayerAI stuff that will have to do for now til we can get a full system working b/c I need to post an update to my mod and this is taking forever lol: Spoiler:
That makes the weight functions consider all cities, weight them by population (without an offset - changed my mind again and completely agree with Fuyu lol), and use Fuyu's min(5) bound checks for the integral math so very high levels of happiness don't mess it up. Then we have in CvPlayerAI::AI_civicValue(): Spoiler:
This uses Fuyu's kludge in all 4 places (he just posted one originally ), and switches the Monarchy effect's value from assuming a flat 3 units will be present on average to using UNITAI_CITY_DEFENSE over getNumCities(). I feel this is still a good approximation since all existing defense units will still be accounted for, just not necessarily in the right places... it makes a near-optimal estimation when most of the player's cities are near or at their happiness limits... And I'd really prefer to avoid adding a city loop here for speed if possible.
__________________
MongooseMod 4.1 is nearing completion... If you check it out there's a good chance you'll fall in love! ![]() <-- BBAI/UP Contributor, Original BTS Sevopedia and PW3 Civ4 Port Author Last edited by LunarMongoose; Jul 19, 2010 at 07:13 PM. |
|
|
|
|
|
#672 |
|
The White Wizard
|
Watch out, your getNumCities call isn't checked for nonzero values. It's going to cause CTD's.
__________________
"A Witty Saying Proves Nothing" -Voltaire Civilization 4 Mods: Rise of Mankind - A New Dawn 1.75 Civilization 5 Mods: Active City Defense, Tech Diffusion Minecraft Mods: Spout & Spoutcraft Lead Developer |
|
|
|
|
|
#673 | |
|
King
Join Date: Jan 2006
Location: Boston, MA, USA
Posts: 611
|
Quote:
![]() Anyway, there's a self-proclaimed semi-official update that makes a lot of improvements without breaking savegames, and shouldn't have any bugs left in it. I'm going to stop for a little bit to work on my mod's patch and info threads, but we do need to finish a better health/happiness evaluation system here. Btw Afforess, the problem with going through and adding up each city's AI_neededDefenders(), aside from the fact that AI_neededDefenders() now depends on the civic you'd be considering so once you adopt it it might return a different value which would be messy... is that AI_neededDefenders() is just a target value that the AI is trying to reach, not the number of troops currently/actually available, and the civics will be re-evaluated every turn anyway I assume. Besides, you may be losing a lot of units to enemies you're fighting at the moment, which would make the target values farther off from being reached, but the civic choice should be based on what you can do with what you currently have. Which is the same reason I ultimately went with no offset to the population weighting - it doesn't matter if the happiness will be really valuable to the small cities later once they've (quickly) grown some; it just matters if it's valuable to them now, b/c the civics will be re-evaluated later anyway - although now I'm wondering if a smaller offset like 5 wouldn't still be a good idea heh. Edit - And in the interests of erring on the side of caution... and the fact that JDog uses offsets a lot... and the fact that I'm a little nervous completely marginalizing the effect of size 1-2 cities when I don't have to... I went ahead and put an offset of 5 in there, which is still a lot smaller than the 10 I was originally planning to use heh. Anyway, sorry for the confusion; I'm done updating the update now.
__________________
MongooseMod 4.1 is nearing completion... If you check it out there's a good chance you'll fall in love! ![]() <-- BBAI/UP Contributor, Original BTS Sevopedia and PW3 Civ4 Port Author Last edited by LunarMongoose; Jul 19, 2010 at 07:18 PM. |
|
|
|
|
|
|
#674 | |
|
The White Wizard
|
Quote:
__________________
"A Witty Saying Proves Nothing" -Voltaire Civilization 4 Mods: Rise of Mankind - A New Dawn 1.75 Civilization 5 Mods: Active City Defense, Tech Diffusion Minecraft Mods: Spout & Spoutcraft Lead Developer |
|
|
|
|
|
|
#675 |
|
King
Join Date: Jan 2006
Location: Boston, MA, USA
Posts: 611
|
Well right, except that 1) at that point it's not worth the cost of having a city loop in the code, 2) if you're using min() then you might occasionally have a value lower than the UNITAI_CITY_DEFENSE level and I don't see why you'd ever want to base it off less than the number of troops you currently have, and 3) if you're using max() then you're back to my original point where the target troop level values don't really matter for this since you don't actually have them yet and the civics will be re-evaluated on subsequent turns when they might be part of your actual troops anyway.
__________________
MongooseMod 4.1 is nearing completion... If you check it out there's a good chance you'll fall in love! ![]() <-- BBAI/UP Contributor, Original BTS Sevopedia and PW3 Civ4 Port Author |
|
|
|
|
|
#676 | |
|
The White Wizard
|
Quote:
2.) If you are at war, some city defenders may be moving in-between cities, in which case, a conservative estimate has more false negatives than false positives, and false negatives, IMHO are better than false positives. 3.) See 2.)
__________________
"A Witty Saying Proves Nothing" -Voltaire Civilization 4 Mods: Rise of Mankind - A New Dawn 1.75 Civilization 5 Mods: Active City Defense, Tech Diffusion Minecraft Mods: Spout & Spoutcraft Lead Developer |
|
|
|
|
|
|
#677 | |
|
King
Join Date: Jan 2006
Location: Boston, MA, USA
Posts: 611
|
Quote:
Not necessarily, b/c false negatives can cause the civic to not be adopted in the first place by a lower-than-actual value-score for it, but false-positives can be corrected once it's adopted by making more troops or, more importantly, deploying existing troops more intelligently now that my code will actually make them do that. (This was argued quite a bit above, that we were underestimating the value of this civic ability b/c of redistribution to boost specific cities vs taking an empire-wide average effect.)
__________________
MongooseMod 4.1 is nearing completion... If you check it out there's a good chance you'll fall in love! ![]() <-- BBAI/UP Contributor, Original BTS Sevopedia and PW3 Civ4 Port Author |
|
|
|
|
|
|
#678 | ||
|
The White Wizard
|
Quote:
![]() Quote:
__________________
"A Witty Saying Proves Nothing" -Voltaire Civilization 4 Mods: Rise of Mankind - A New Dawn 1.75 Civilization 5 Mods: Active City Defense, Tech Diffusion Minecraft Mods: Spout & Spoutcraft Lead Developer |
||
|
|
|
|
|
#679 | |
|
Emperor
Join Date: Nov 2009
Location: Austria
Posts: 1,147
|
Quote:
With some CvCivicInfo::isAny(ImprovementYieldChange |BuildingHappinessChange |BuildingHealthChange |FeatureHappinessChange), and isCanChangeValueOfOtherCivics and isConstantValue, I think I can make doCivics as a whole fast enough. The real slowdown, that would be the loop over all cities for the happy/health weights instead of only the first 7 cities, but there is no way to optimize that. Creating the vacuum and working with it is still better than the "imperfect kludge/hack" even if it might look expensive in comparison. The first thought I had there was to add a new argument "bLimited = false" to CvPlayer::processCivics, and if (bLimited) then let the function skip everything that doesn't affect the values of other civics, most importantly the parts that would cause triggering updateTradeRoutes() because that would really be expensive in advanced stages of a game and there woud be no gain at all. @LM: I don't know what your CvCityAI::AI_neededDefenders() does but as far as I can see, in BBAI it is not where you should try to handle military happiness, it will cause the city to build UNITAI_ATTACK units that won't stay in the city, it might call units from other continents but they won't be fortifying in the city either. If you use AI_minDefenders() then the city will build city defenders before it tries to build happiness buildings but at least the effects are what you expect: building and calling for more city defenders. Something like AI_minDefenders(bool bIncludeUnitsForMilitaryHappiness = false) could work without having that sideeffect if you make sure to call the function with true whereever it makes sense. CityAI: Code:
//20 means 5g or ~2 happiness...
if (AI_chooseBuilding(iEconomyFlags, 15, 20))
{
if( gCityLogLevel >= 2 ) logBBAI(" City %S uses choose iEconomyFlags 2", getName().GetCString());
return;
}
//minimal defense - military happiness.
if (iPlotCityDefenderCount < (AI_minDefenders(true) + iPlotSettlerCount))
{
if (AI_chooseUnit(UNITAI_CITY_DEFENSE))
{
if( gCityLogLevel >= 2 ) logBBAI(" City %S uses choose min defender for military happiness", getName().GetCString());
return;
}
}
if (!bLandWar)
{
if (AI_chooseBuilding(iEconomyFlags, 40, 8))
{
if( gCityLogLevel >= 2 ) logBBAI(" City %S uses choose iEconomyFlags 3", getName().GetCString());
return;
}
Civic bonus groups
fix: Code:
if (kCivic.isStateReligion() || isStateReligion())
{
if (iHighestReligionCount > 0)
{
if (kCivic.isStateReligion())
{
iValue += iHighestReligionCount;
}
iValue += ((kCivic.isNoNonStateReligionSpread()) ? ((getNumCities() - iHighestReligionCount) * 2) : 0);
iValue += (kCivic.getStateReligionHappiness() * iHighestReligionCount * 4);
iValue += ((kCivic.getStateReligionGreatPeopleRateModifier() * iHighestReligionCount) / 20);
iValue += (kCivic.getStateReligionGreatPeopleRateModifier() / 4);
iValue += ((kCivic.getStateReligionUnitProductionModifier() * iHighestReligionCount) / 4);
iValue += ((kCivic.getStateReligionBuildingProductionModifier() * iHighestReligionCount) / 3);
iValue += (kCivic.getStateReligionFreeExperience() * iHighestReligionCount * ((bWarPlan) ? 6 : 2));
So much fun waiting for me
Last edited by Fuyu; Jul 20, 2010 at 03:00 PM. |
|
|
|
|
|
|
#680 |
|
The White Wizard
|
I'm highly interested in the results though. Please do post them.
__________________
"A Witty Saying Proves Nothing" -Voltaire Civilization 4 Mods: Rise of Mankind - A New Dawn 1.75 Civilization 5 Mods: Active City Defense, Tech Diffusion Minecraft Mods: Spout & Spoutcraft Lead Developer |
|
|
|
![]() |
| Bookmarks |
|
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Questionable Ads | BCalchet | Site Feedback | 13 | Apr 25, 2008 12:04 PM |
| A Really Questionable Thread | pxpdoo | Civ4 - General Discussions | 6 | Jan 14, 2008 04:49 AM |