 |
|  |
 |
|
Pedrunn
|
 |
of Natal, Brazil
Jul 2001 time: 02:27
|
|
Sunday i come up with an idea. I will do the best AI combat handler ever done for CTP2!
Ideas:
1) Find the best city to launch an attack ever evaluating the city by inumerous variables like owner diplomatic relation, location, defense, distance, etc... Once chosen all strategy will be done there!
2) Teach the AI to orgqanize Stacks. The idea is to make the AI check the city defense according to a threat level when building a unit. If the city has the defense according to this threat level already this units is sent to field! All field units will merge in a stack until a size 12 stack is built. If the building is complete it will make another stack!
3) A brach from number two but teach the AI how to construct stacks.
4) Check how many size 10-12 unit is need to conquer the best target which was already evaluated in the first topic. And send all needed units there. The AI will only attack once all the stacks sent to the location are only one tile away from the target!
5) Make a alghorith good enough to find out if a city is in another continent. And if it is teach the AI to make Cross Water Attacks. No ideas yet but still want to check Peter Triggs work in the other thread.
5) Teach the AI to make strategies for water battles. and water navies creation.
6) Teach the AI what to build according to the needs of the cities and not by dark/unknow priorits of strategis.txt!
So Far
With this intent i started coding without testing! Just plain coding. Achieving a really good code with 400 lines for topic 1, 2 and part of 4 in which i am really proud. But when looking the agenda kind of scared me because the to do list is still enormous and the bug-freeing work will be enourmous.
Recruiting:
So i decide to ask for help!
Specially coders for two task:
1) Actual coding! Peter Triggs, Locutus, Martin, Dale, MrBaggins, IW, mapfi, ahenobarb or any other avaible coder around here to recruit to make those topics come through and workable with the others parts of the slic!
2) Bug-freers! Anyone coder i mentioned before or any other to help me find the flaws of my code and help me with the testing of the existing code!
But not only coders but I am also open for suggestions if anyone has a better idea bout my ideas.
And Testers. Some guys to hep me test the in-game stuff of the code. What is working and what isnt!
This can be the chance to make the CTP2 AI the best possible using slic with the help of all community.
So, is anyone interested?
The unfinished code I have worked already will follow after i hear some comments! 
Last edited by Pedrunn on 09-04-2003 at 07:01
|
|
|  |
 |
|
Locutus
|
|
ACS CTP1/2 Manager & Civ4 Co-Manager
|
 |
Hengelo, The Netherlands
Nov 1999 time: 06:27
|
|
Well, I've been working on revamping the AI as well, using a more generic pattern (a bit like ahenobarb is talking about, only worse ).
My idea is to completely rewrite the AI in SLIC. I've suggested this before and at the time it was more a dream than a real ambition, but I'm more serious now: I do think that if a couple of people put their heads together, it *can* be done. Such a design can easily be split in independent modules, so that each module works on its own. This way even if a complete model is never finished, a lot of useful and usable code is still produced.
I've attached a diagram of initial module design below. IMO the AI should approach the game the same way humans do: the eventual goal/desire for an AI is to win the game. Through what type of victory partially depends on circumstances and partially on personality. To accomplish this desire, a strategy (ranked list of overall goals) is created: destroy the Austrian civ, prevent war with the Germans, get an alliance with the Thai, rush to Monarchy, build up the economy, etc. To accomplish these goals, the various parts of the game (diplomacy, military, cities (including trade), infrastructure and science) need to be optimized for them. Seperate modules can be written to deal with each of these parts of the game (though eventually some communication between these modules may be needed). For each part of the game, the ideal situation that should be strifed for (= desire) is modeled and a new strategy to accomplish this is created by determining more (sub)goals (i.e. if a strategic goal is to destroy the Austrians, the military desire is to control or destroy all Austrian cities and the subgoals could for example be to conquer Graz, to get a peace treaty with the Germans, to research Catapults, etc). Finally, these goals need to be executed.
This system of modules is good because one can simply develop one set of modules while the AI still controls all the other: while developing military code, you don't have to worry about how the AI handles science or PW as the existing built-in AI already does that for you. Also, the top layers of this model can easily be kept empty or very simple as you're developing the bottom layer(s).
Basically the stuff Pedrunn is talking about in this thread (including Peter's naval invasion code) is part of the MilitaryStrategy and MilitaryRealization modules (which are by far the largest part of my diagram and will certainly need to be refined and split up in submodules). These can (and should) be written without having access to any other module in my diagram. But of course, in the end a kick-ass military AI will still loose the war if the economy is geared towards building Wonders and the diplomacy policy creates more enemies than allies...
Though I was still thinking things out, Pedrunn's recruiting pretty much coincides with what I wanted to do myself. The main difference is that I do want to work a little more systematically: blindly starting to write some random code without thinking things through or debugging anything is suicide and bound to fail miserably. It's this attitude that causes 90% of professionally developed software products to take 50% longer to develop than initially calculated, cost about 200% more and in the end still doesn't do what they're supposed to (I don't know the precise numbers, I pulled those out of my arse, but the general trend is real: getting these numbers down is the biggest challenge of professional IT development today). CtP2 itself is a fine example of this
As Pedrunn pointed out: the total amount of work that needs to be done is enormous and without any kind of structure anyone would loose sight of things in no-time. If you take some time in advance to make a design of your final product and properly split your design in modules which can be developed and tested independently, you avoid a lot of problems. The amount of work involved seems far less overwhelming, you have a far more manageable and controllable project, you can test modules seperately (Ever tried to debug 50,000+ lines of code which haven't been debugged before? You'll need at least 2 weeks to get the syntax errors out alone and you'll almost certainly never find all the bugs), you can far more easily work together in a group (without people producing double or incompatible code), etc, etc. The advantages are numerous.
In my opinion the best thing to do right now is to make an inventory of all code that already exists (debugged or not). Since this is probably (almost) all military AI code, the next step could be to discuss what the military AI should look like. If my design of desires/strategy modules is deemed a workable model, we'd need to flesh out the design of the military branch (splitting it up in lots smaller, independent submodules) and continue to develop that. By the time that's done it's probably 2006, so if anyone is still here by then we can see how to continue after that 
Attachment: ctp2ai.png
This has been downloaded 183 time(s).
|
|
|  |
 |
|
Pedrunn
|
 |
of Natal, Brazil
Jul 2001 time: 02:27
|
|
ahenobarb, I would love to know about your ideas for the part of the code you want to do.
Locutus, your ideas pretty much coincide with mine. With the DG going on we are playing how the human strategy is build up. You divided the AI in the branchs: Diplomacy, Military, Domestic Affairs, Infrastructure and Science (from left to right). Which coincides immensily with the governments positios of the DG. And that is exacly what I have in mind!!!
My project is looking for the Military and Domestic Affairs of the AI. But first a work focused in the Military. Still i planned to extend it to these other areas specially diplomacy.
The way the AI handles diplomacy, which is as important as miltary since it is terrible broken in the game (more then military). So indeed thats something to work on!
But i rather work not doing like Peter Triggs did in the Diplomod2 and not like Richard Meyers. Doing a proposal type checking to accept according to this typ but i would like to work in the value of the proposal arguments using functions like GetLastNewProposalArg(sender, receiver,int,param/int), GetLastNewProposalArg(sender, receiver,0,tmpCity) and GetNewProposalResult(sender,receiver,player,type).
The last one was tested by me and serves the best for my wishs.
Arccording to the alues of the proposals arguments the AI willl Accept or decline. So count me in to make the diplomatic advisor code.
As for the Infrastrucure branch, indeed we need to make some work on this! The way CTP2 handles is terrble since we have no control and commerce is not included!
The Science branch would be nice to work too but not really that needed.
Waiting feedback from the people willing to help me about my ideas, Locutus ideas discussion and my code 
About that I count Locutus, ahenobarb and me for this project. Anyone else?
Still what i've done in the Military Advisor code is here.
Note: I only did the stack arragement code, the find best target algorythm (both in the BeginTurn handler) and the check where to send built unit handler(if city is too well protected send unit outside the city is in the CreateUnit handler)
Attachment: pai.slc
This has been downloaded 12 time(s).
Last edited by Pedrunn on 09-04-2003 at 22:50
|
|
|  |
 |
|
ahenobarb
|
|
I reviewed the part of the code dealing with creating the stacks (MoveUnitsOutsideCities). I have some ideas on how to further elaborate and implement this portion of the code. The idea works like this:
code:
1) Establish rally points outside the city, i.e. build forts.
Store the location of these forts in an array.
2) When a city builds a unit in excess of what it currently
needs for city defense (determined by the Defense
Strategies in the “strategies.txt” file), look at array for
available rally points, then move excess units to the
rally points –build stacks.
3) When building stacks, create different types of stacks
depending on the “Conquest” flag Aggressive/neutral/passive)
in the “personalities.txt” file. There will be three types
of stacks:
a. Traditional stacks: 4 attack/4 ranged/
4 flankers
b. Stalwart stacks: 3 defensive/ 3 attack/
4 ranged/ 2 flankers
c. Hordes: 12 flankers (used to move quickly to
danger/undefended zones)
Passive personalities will build: 40% type a, 50% type b, and 10% c.
Neutral personalities will build: 50% type a, 30% b, and 20% c.
Aggressive personalities build: 60% type a, 10% b, and 30% type c.
Once that code is done, we can focus on improving the code to select the “best” rally points or forts locations (near capital & principal cities, near borders with opponent civs).
Last edited by ahenobarb on 10-04-2003 at 02:47
|
|
|  |
 |
|  |
 |
|
Peter Triggs
|
|
Gone Fishin, Canada
Jan 2000 time: 05:27
|
|
I'm available for debugging and general help, but actually I'm still debugging the cross water invasion stuff I've been working on. This is taking up a lot of time.
Also, I've got some half developed stuff on AI air tactics that I'd really like to finish off. So, I'm afraid you can't count on me to write a lot of code.
But, as Locutus says, the design should take top priority. There's plenty to think about here: not only what we'd like to do but also how we can incorporate it into the game engine.
|
|
|  |
 |
|  |
 |
|
Gilgamensch
|
|
France
Jun 2002 time: 06:27
|
|
Going back to Tamerlin:
that could be again an exploit by the human:
Make this city 'weak' put sufficiant troops around and you can slaughter him...........
For this somebody had a nice idea, I think it was MrBaggins. It would inlude some 'cheating' from the AI, but I don't know where he got with it..........It was that the AI calulated the thread in general and accordingly distibuted it's troops, the same it could do for attacking........
I'll try to find the threat again..........
|
|
|  |
 |
|
ahenobarb
|
|
I plan to do some work on 3.1 this weekend.
|
|
|  |
 |
|  |
 |
|
Pedrunn
|
 |
of Natal, Brazil
Jul 2001 time: 02:27
|
|
quote: Originally posted by Turambar
Great ideas!! I really like Locutus idea of completely re writing the AI in SLIC. But as he said this would need a lot of planning before the coding started.
|
So lets do it. Indeed Locutus ideas were the best. Very much like what i had in mind. So i say lets do it.
quote: Originally posted by ahenobarb
I plan to do some work on 3.1 this weekend. |
Good. Your ideas are terrific. So i hope to see the AI building good stacks too. But remember to make the things easily editable. The things that may chnge from mod to mod.
"Passive personalities will build: 40% type a, 50% type b, and 10% c.
Neutral personalities will build: 50% type a, 30% b, and 20% c.
Aggressive personalities build: 60% type a, 10% b, and 30% type c."
This is the main thing to discuss in your ideas. So remember to make it very much changeble.
The rest of you ideas are already too good. Though they are too complex, specially the building of the 3 different types of stacks (probably making open the addition of other types would be great too. And a possible change in personality which i would like to implemeted. Remember to save the armies in arrays with all the data about it: Owner, type, etc... Keep always uploading it what you have. I want to check its evolvement very closely.
quote: Originally posted by Immortal Wombat
My concern is that we can construct models complex enough that they don't become too obvious for the human to see and outwit. | Actually formulas like the CheckCityValue as you can find in my slic for example uses variables that our impossible to be known by the human and the complexity of the formula cant be predicited. So i do believe that it will be very difficulty predicted unless if very time consuming.
quote: Originally posted by Immortal Wombat
I was at one point meaning to focus the AI advance lists better. In fact, does that file actually work? Given that all the lists in the default files are the same, and other AI files do nothing, do we know if this one works properly? If not, it'll need its own workaround. |
I guess our knowlegde of working files isnt bigger than yours. The best would be to jus work with slic since we have plenty of controll over it. But i guess we dont have as many function for researching than other areas. But locutus diagram has a whole module for science in which we dont have much people working on it. Would you want to grab this module? If yes, gives us your ideas 
quote: Originally posted by Immortal Wombat
What precisely the "City" module contain? Placement, build queues and specialists? |
Placemement would be something good to work with it but i guess the use of the flag 'Score' in the terrain.txt if well adjusted may give some good placements. Indeed something good to work on if by slic or text.
The build queue should be one of our main focus together with military and diplomacy of this project.
We can mod the specialist distribution as you may know 
quote: Originally posted by Immortal Wombat
This could require very close correlation with other modules. Should be good fun to code though | Actually the idea is to make the modules first and the correlation later. This will work well enough in this first stage. Since so far we have only few fronts: ahenobarb, with stack creation, and me, with moving units and map awareness work. So thats whay some more feedback from you guys that want to join us is important.
quote: Originally posted by Big Mc
Yes I think a lot of us a willing to lend a claw but all we need is some one to give the nod to what we are to code. |
Good. Any interest in one of the Locutus module?
Turambar, the lesser the cheats the better. But some our impossible. And some cheats will show up for sure. But as the project evolves they will be removed.
And unfortunetly i bring the first best news When testing the GetContinentSize function of my slic i found out that the function code:
INT IsContinentBiggerThan(location, size)
indeed is broken as reported before. It always return true. So as my first work since the beginning of this project is to create a function to replace it. Probably also making the AI making some map awareness. By drawing in arrays the map. How? By traking the beaches and trenchs of the map.
Whish me lucky and await some more info and feedback on this tomorrow. Since today I have got to sleep. But i wish to have something concrete this weekend 
Last edited by Pedrunn on 11-04-2003 at 14:55
|
|
|  |
 |
|
ahenobarb
|
|
quote: Originally posted by Pedrunn
Good. Your ideas are terrific. So i hope to see the AI building good stacks too. But remember to make the things easily editable. The things that may chnge from mod to mod.
"Passive personalities will build: 40% type a, 50% type b, and 10% c.
Neutral personalities will build: 50% type a, 30% b, and 20% c.
Aggressive personalities build: 60% type a, 10% b, and 30% type c."
This is the main thing to discuss in your ideas. So remember to make it very much changeble.
The rest of you ideas are already too good. Though they are too complex, specially the building of the 3 different types of stacks (probably making open the addition of other types would be great too. And a possible change in personality which i would like to implemeted. Remember to save the armies in arrays with all the data about it: Owner, type, etc... Keep always uploading it what you have. I want to check its evolvement very closely.
|
The percentage variables will be desinged so that they can be changed and eventually they will be better if the percentages are based on different strategic states being adopted by the AI. So if it is on the attack or is surrounded by a powerful neighbor (high FEAR_MILITARY_RANK & FEAR_INVASION) the defensive stacks will increase while the AI prioritizes science in order to get some better equipment.
Stack types will be changeable too, or more likely you'll be able to add different type stacks to the code. Each type will have a numeric flag (1,2,3). If you want a different type of stack use a flag 4 and define the new type of stack you want.
Structuring the array properly is the key to getting this to work, so it will take some time to design.
quote: Originally posted by Pedrunn
And unfortunetly i bring the first best news When testing the GetContinentSize function of my slic i found out that the function code:
INT IsContinentBiggerThan(location, size)
indeed is broken as reported before. It always return true. So as my first work since the beginning of this project is to create a function to replace it. Probably also making the AI making some map awareness. By drawing in arrays the map. How? By traking the beaches and trenchs of the map.
Whish me lucky and await some more info and feedback on this tomorrow. Since today I have got to sleep. But i wish to have something concrete this weekend |
This gets back to the need to write better functions for looking at the map squares. GetNeighbor isn't capable enough. GetNeighbor of course is good for looking in the immediate circle around a location, but it would be good if there were a function that searched all the tiles in the production zone of a size 2 city, and then one for a size 3, size 4, and so on. These of course could be used to map terrain.
A second feature I want to add to these functions is the ability to control the direction of the searches: top to bottom, bottom to top, left to right, right to left, spiral clockwise, spiral counter-clock wise. Sounds complicated, but its just mathematics and the results would be worth it.
|
|
|  |
 |
|
Pedrunn
|
 |
of Natal, Brazil
Jul 2001 time: 02:27
|
|
quote: Percentvariables will be desinged so that they can be changed and eventually they will be better if the percentages are based on different strategic states being adopted by the AI. So if it is on the attack or is surrounded by a powerful neighbor (high FEAR_MILITARY_RANK & FEAR_INVASION) the defensive stacks will increase while the AI prioritizes science in order to get some better equipment. |
My willing is to do a GetThreatLevel(location_t ) right after the the continent mapping one.
quote: Stack types will be changeable too, or more likely you'll be able to add different type stacks to the code. Each type will have a numeric flag (1,2,3). |
Exacly what i had in mind
quote:
but it would be good if there were a function that searched all the tiles in the production zone of a size 2 city, and then one for a size 3, size 4, and so on. These of course could be used to map terrain. | I already have worked with such a function in the CityExpasion code. But the function is BlueO works.
quote:
A second feature I want to add to these functions is the ability to control the direction of the searches: top to bottom, bottom to top, left to right, right to left, spiral clockwise, spiral counter-clock wise. Sounds complicated, but its just mathematics and the results would be worth it. |
But never worked with something like this Still using BlueO logics it can even be even a simpler function than blueO's ones that searchs all directions 
The Continent mapping algoriyh i plan to use has the following algorith:
1) Scroll over all map searching a beach. Once done stop.
2) From this beach using GetNeighbor function map all beachs in one neighbor to another neighbor until finding and saving the arrays all beachs of the contitnent. (Note: Be careful to continents only one tile away from the other and continent aside map borders). Saving the location, the x-value and the y-value of these beachs. And the continent they belong (numeric flags)
4) After that do all again makin sure the beach that will be used for the mapping doesnt belong to a continent. This way all continent will be mapped.
5) It will be needed a simular function to that to map Oceans. But thats a bit harder for sure since many oces can be interconected.
6) GetContinentID(location_t) function. If there are in the contitnent array two beachs with the same X-value of the location and other two beachs with the same Y-value for the location. You've got a winner. So just get this contitnet ID.
7) IsSameContinent(location_t, location_t) fuction a simple GetContinentID(location_t) == GetContinentID(location_t).
8) GetContitnentSize(location_t) function. Very easily done after all that. Just search beachs in the same continent with same x-values. find the distance of those two. And um with the value of other x-values of the same continent.
Any other important function idea? Or critics for my algorithm (how do i spell this anyway)?
Last edited by Pedrunn on 11-04-2003 at 20:22
|
|
|  |
 |
|
Gilgamensch
|
|
France
Jun 2002 time: 06:27
|
|
Some idea, which Tamerlin and me discussed and we want to present it to you (also, to check, if it is possible):
Instead of having the AI cheating (like for the stack-count in cities):
Why not changing the vision-range to see the # of units in a city but not their composition? That would give the AI a possibility to calculate the 'strength' without cheating, the same function could be enabled for the human, though. And again, just the # of units, but not which units. If the AI could also take into account the science-level of a human, like for 5 rounds hoplite discovered so, max of 10% defenders = hoplite. That I think could increase the AI behaviour as well..................
Just some thoughts..........
|
|
|  |
 |
|  |
 |
|
ahenobarb
|
|
Here are two of the new search functions I was discussing. There are several others that need to be done, but I wanted to share what I have so far.
The first one is:
code:
GetTile([loc], [tilenumber], [direction]);
^
Your For loop
counter number
When used in a for loop, it searches the immediate 8 tiles surrounding a location, much like GetNeighbor. However, you can choose the direction of the search. The available directions are in the read me. There are 11 different ones.
There was a problem getting SLIC functions to return a location, so I had to store the location in a global variable. When the function has been called, just make your Loc variable equal to GT0_RetLoc, like so:
code:
tmpLoc = GT0_RetLoc;
The second function is GetTile1, it searches all the tiles available for a city to use after it has expanded one time. The sytax is:
code:
GetTile1 ([loc], [tilenumber], [direction]);
^
Your For loop
counter number
Again there are 11 search directions available. When you have used the function, set the value of your Loc variable equal to GT1_RetLoc, like so:
code:
tmpLoc = GT1_RetLoc;
See the readme.txt for more details.
Check the image below for a visual explanation of the search directions for the second function.
Attachment: search.zip
This has been downloaded 5 time(s).
Last edited by ahenobarb on 13-04-2003 at 11:46
|
|
|  |
 |
|
ahenobarb
|
|
dp
Last edited by ahenobarb on 13-04-2003 at 11:38
|
|
|  |
All times are GMT. The time now is 05:27. Apolyton Time is 00:27. |
top of page
|
| archivepost |
|
Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is ON
vB code is ON
Smilies are ON
[IMG] code is ON
|
|
|
|
|
|