Code:
Problem description:
After finally designing my AI I realized I have no idea how to implement the town management math part.
It might be a silly problem but anyway I'm stuck...
The AI goal is to assign resources (gold) to three sectors 1.Domestic 2.Military 3.Economic. To do that it has to consider some variables, but I can't manage to make the main variable work properly. That variable is Fullness ranging from 0-100 and stands for how full the sector is, so the AIs goal is to increase that number so it reaches 100 (by assigning gold to improve the sector)
If you need more details please post. or If you suggest a different splitting logic tell me
So here is the problem:
I have to assign resources as follows
1.Higher fullness == lower priority (since it's already more developed than the rest)
2.when a sector full (Fullness==100) no resources are assigned to that sector.
E=economy M=Military D=Domestic
ex1. E=50 M=50 D=50 So all will equally receive 33.3% each
ex2. E=100 M=0 D=0 E will receive 0% and M=D=50%
ex3. E=25 M=50 D=75 E will receive 50% M33.3% D=16.6%
I would suggest generalizing this, because you might decide you want more sectors and you also might want the player to have a say in which sectors get priority.
sector This approach means that a player (or AI making a determination based on current goals) could say that military matters twice as much as the other sectors, and therefore would weight it higher. |
Thanks for the replies guys, I was stuck for a week :D
Lummox thanks for the advice, but I already have a fairly good town management AI system, fullness is just a variable, there are more like threat,goal,supplies and more... But the idea of automating the user town management is good, I hadn't thought of that and create a scroll bar for each sector, yeah that's a good idea. Anyway thanks for the replies, I think it would take me a month to come up with that
|
Basically what you want to do is total up the fullness of each sector, and subtract that from 300 (the total possible for all three). This will give you how much fullness the entire group has left. Then you calculate how much fullness a particular sector has left to grow, and divide that by how much the whole group has left.
percentForSector is a ratio from 0 to 1.
The (sectorFullness < 100) check helps indirectly prevent a division by zero (where if all three sectors are completely full, 300 - 300 will be 0)