Unit category sorter class + functions

Unit category sorter class + functions

Here is where ideas can be collected for the skirmish AI in development

Moderators: hoijui, Moderators

User avatar
krogothe
AI Developer
Posts: 1050
Joined: 14 Nov 2005, 17:07

Unit category sorter class + functions

Post by krogothe »

Woot, my AI can build and my economic system is ready for testing! Now all i need is a class that will sort units out into their categories, independently of the mod.
I would do it but my knowledge of C++ is still too sucky to build it, so i was wondering if you guys wanted to help, as you could use this class too and it will speed up my AI so i can release it earlier so you can have fun killing/getting killed (unlikely) by it!

Here├óÔé¼Ôäós the plan:

It will first get the UnitDefs of every unit currently running with the mod at the beginning of the game.
Then different methods could extract that data and convert it into useful information by building categories. I need to organize all energy makers, metal makers and metal extractors in their respective categories, then save them into an array containing ID (eg. ARMEX), Side which builds it (easily done by doing taking the first 3 letters of its ID and converting it into a bool) and specifics such as costs in the 3 resources (metal, energy, buildtime), health and footprint (serving as weights in a score calculation). It should also create some sort of hierarchy so one can quickly find out which type of unit can build what.
Once processed and organized all that data is saved so no processing is needed after the first game.

The result is you can then make your AI completely independent of mods:

INSTEAD OF:
Get ARMCV OR CORCV to Build ARMEX OR CORMEX when Y

Get ARMACV OR CORACV toBuild ARMMOHO OR CORMOHO when Z

Build X ARMMAV AND Y ARMHAM then attack


^^^^^^
| | | | | |
Hundreds of the above to make sure the AI will build a variety of units and buildings

YOULL HAVE:
Build Metal extractor of highest score under current situation. A function will calculate score based on income, tech level, etc. The builder is automatically picked from the pool of units that can build that metal extractor, based on idleness, movespeed and buildspeed.

Build a land-based attacking force of strength X. X is determined by a function of costs, HP, firepower, current tech level of the units, etc)


That will surely save quite a lot of code and will make the AI forever compatible. Random factors in the functions and a bit of coding creativity can create a randomized attack force system while still being surprisingly effective. The only limits are the amount of coding you put into the functions that determine the units to be built, add a bit of learning and you have a kickass multi-mod AI that will always make great use of its resources!

Either way, I have a very good notion of how the sorting functions will work. I just need help writing the organizer, still haven├óÔé¼Ôäót got my head around how to code it.


EDIT: Damn it seems Sub is doing just that! Hope some of this is still useful for you guys :P
Berion
Posts: 33
Joined: 01 Oct 2005, 15:15

Post by Berion »

I am working at the same and when I am finished I will give you the code. I started today, but tomorrow the basic code should be finished. (Hopefully :-) ) Maybe we can help each other or work together.

Alex
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

Look at how TAI 0.1 did it, it has a similair system sorting unti names into an array.

My method is to score the untis ability to fullfill a role, then when a construction unit wants to build a mex it compares it's list of untis that ti can build to the overrall scores and selects the unti with the highest score for that particular function.

A heirarchy or tree system would be ok but I dont think it's simple and elegant enough a solution.

Try and make rgular updates as quickly as possible, rather than working then releasing at the very end. Mail me if you have any specifics you wanna go over, otherwise I'm happy to work on this.
User avatar
krogothe
AI Developer
Posts: 1050
Joined: 14 Nov 2005, 17:07

Post by krogothe »

Well i NEED to learn C++ before i can actually make useful code...
I have lots of things on paper and in my brain but in actual code i only have test methods.
The path I'm taking makes for a better AI but i need a lot of modules running to have it even build its energy buildings:


I would first need the sorter class

then I'd need a function like this:

ENERGY BUILDINGS (X < repeat for all unitIDs in the game)

If X's (energymake-energyupkeep)>0, store X in array Y
Get units from array Y and remove units with efficiency below Z (separates actual energy plants from units that produce a little energy to save time on the scoring function)
Save array Y as UNITSTHATPRODUCEENERGY into a file with the mod's name in it for later reference.

Then Id need a scoring function (have one but its giving me errors atm)

Then I would need a function/class that will decide when its time to build energy buildings and what percentage of resources should be allocated to it. Im planning to have a system where you can specify what % of income should be used for resources, defenses, plants and attacking, and later have a scoring system so the percentages are worked out automatically (or at least modified in certain circumstances such as after an enemy attack or before a massive invasion).


Since most AIs seem to have the actual sorter, I should probably be able to make my own from them, I just need to get familiar with pointers and classes a bit more.

This gave me a good idea however!
Since Mine, Berions and to some extent Subarine's AIs will be pretty modular we should actually be able to work together!
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

Can you scan in your notes or write them on this forum?
User avatar
krogothe
AI Developer
Posts: 1050
Joined: 14 Nov 2005, 17:07

Post by krogothe »

I suppose I could, but I├óÔé¼Ôäód doubt anyone would like to read tens of pages like this:

http://putfile.com/pic.php?pic=11/32211510186.jpg&s=x12

Ill post Ideas as they become more concrete. The Energy scoring system is ready for implementation, there├óÔé¼Ôäós only a few minor variants of it to be tested and after a couple of games the best one will easily stand out.

I am now thinking about how the defence/attacking system will work, my initial idea is to divide the map into low-res quadrants, each square being able to take several scores in terms of strategic importance, need for defences (broken down into nuclear, land and AA), value etc...

Each building placed would affect its quadrant and the nearby ones, depending on what it does, so an Annihilator would reduce the need for land defence by X within a radius of Y.

X would be affected by something like (firepower*accuracy)/(rate of fire*)(distance from annihilator)^2
Y would be a function of the range of the Anni minus its "unfolding" time.

A cross section of the circle created would give an inverted bell-shaped curve, where the Y axis is the modifier in the need for defence at its X coordinate.

A fusion reactor would create an upright bell curve with a smaller radius in the need for defence in all 3 areas.

An anti-nuke would set all needs for anti-nuke to zero in all quadrants inside its range and so on....

The quadrants are low-res because the algorithm for working out the best placement for each building has to read all quadrants in the map. This could of course be optimized by only making it read quadrants that have been modified so empty or inactive zones will not be processed twice. That algorithm could also split the load between many frames, checking only a fraction of the quadrants at each frame.

The same would work for attacking, some zones would have a higher danger rating, some would have a nuke protection rating, so the AI will never waste a nuke, always using it on the best spot (and not just the most expensive enemy area, since the score functions would add modifiers to it).


Of course this system will not take into account issues like LOS and LOF (line of sight and fire) and might place defences in stupid places, but these functions can later be upgraded by including terrain information etc.
its modularity at its best since each function is 100% independent form the others!

I have plans for builder fetching functions, a sort of A* path finding for plane units that desire to avoid enemy fire (enemy zones with lots of weak expensive buildings will be lower cost while defences will increase the cost) so that planes will attack in the most efficient fashion and so on.

Learning AI's are great on paper! But words alone cannot describe the amount of anal abuse they receive when fighting against good linear AIs or players in RTS games. If you want proof, download DarwinBots, and try to evolve a bot better than "The One", a programmed bot. Even if you spend DAYS on a dual processor high end server your evolved bots will get plastered by the programmed bots! That├óÔé¼Ôäós the reason I'd rather make a more predictable but more challenging AI.
It won├óÔé¼Ôäót even be that predictable, since this scoring system generates chaos. Destroying a single mex can completely change the overall base layout of the AI later in the game, which in turn will change its attacking patterns etc...


BTW:

the energy system works for metal buildings as well, since it uses an exchangeable resource formula (not present in the posted solution)

ALSO:

heres a graph of the newest energy scoring system, with wind, solar, geothermal, cloakable fusion and standard fusion. The first one to correctly guess which lines represent which energy source gets a cookie!! gogogo.

http://putfile.com/pic.php?pic=11/32212284547.gif&s=x12
Hint: Since the resource production will increase exponentially, the X axis can be also read as a linear function of time with each units representing K minutes
User avatar
Triaxx2
Posts: 422
Joined: 29 Aug 2004, 22:24

Post by Triaxx2 »

I'm going to say series 3. It produces lots of energy, does it in a stable manner for a fair amount of time, and doesn't take forever to get there. The next highest generation puts out massive amounts, but takes forever to get that far up, and doesn't seem to stabilize at all. The other three are too low output to generate any kind of economy.
User avatar
krogothe
AI Developer
Posts: 1050
Joined: 14 Nov 2005, 17:07

Post by krogothe »

lol triaxx you got me wrong!
each line is one of the following:
wind
solar
geo
c.fusion
fusion

you have to match the above to each line (color)
User avatar
Triaxx2
Posts: 422
Joined: 29 Aug 2004, 22:24

Post by Triaxx2 »

Ah... Two of those colors are too dark to tell them apart against that background.
User avatar
krogothe
AI Developer
Posts: 1050
Joined: 14 Nov 2005, 17:07

Post by krogothe »

Okay:
Dark blue = Wind - Starts out as the highest scorer until about x=4 since its the best way to start off with
then Geothermal stays at the top for most of the game, meaning the AI should build one whenever possible (its by far the most efficient source).
If it cant find any nearby geo spots, it will build solars (pink)which are more resilient and wont take up as much space.
Later in the game it will build fusions (purple).
In this model cloakable fusions (light blue) never score high enough to actually be used, which should be fine provided the AI has enough space to build.
User avatar
Maelstrom
Posts: 1950
Joined: 23 Jul 2005, 14:52

Post by Maelstrom »

This AI is just sounding better and better. Good luck actually writing it.
User avatar
krogothe
AI Developer
Posts: 1050
Joined: 14 Nov 2005, 17:07

Post by krogothe »

Well it does sound good, since it can produce a graph like that for any energy producing unit. I theory it should take the best resource building strategy for any mod at any point in the game. In fact it sounds pretty amazing if you saw the whole of the plans, since it will be using a similar system for 100% dynamically managing attack, defence independently of what it has available! But that├óÔé¼Ôäós on paper, it could actually suck on actual implementation...


NOW TO AN IMPORTANT REQUEST TO THE SPRING COMMUNITY:

Is there a way for the AI to cheat and have knowledge of the whole map(maphack)? If not I am honestly thinking we should. Sure it is cheating, but it is one of the least degrading forms of cheating gameplay-wise, and allows for an AI that is both more challenging and fun with the same amount of coding, since instead of writing huge chunks for effective, efficient scouting, the developer can simply tell the AI to attack a player's weakest spots, which in turn keeps him on his toes, greatly increasing the overall fun factor of the game, as well as developing a player's skills (against a high end AI, that is).

Imagine this:
you place light AA all around your base so the AI cannot scout your base without heavy losses, and if it does it wont be able to do it often. So the AI, not having the technical know-how that a player has, no matter how shiny flashy and evolutionary it is, no clue how to do it properly so it will generally just send troops to the slaughter. It might learn from that and then attack another location in the next wave. The problem lies in the fact that the players learn a lot better and in a couple of games will know the pattern and will make the AI generally boring to play with.

Actual thinking, strategizing, supposing and learning is best left to humans. We took 4 billion years to be able to think this good so why would computers, which are 80 million times younger than us be much good at it????
However, in just 50 years, computers are IMMENSELY more able to calculate things efficiently, take decisions quickly and control many things at once.

In my opinion, there is a reason pretty much every attempt at a learning AI for games falls very short of their expectations. Programmers don├óÔé¼Ôäót take the two above points into consideration. They make an AI that plays 1000's of games will learn just to learn an effective strategy, while a human player will after just a few minutes in ONE game be able to counter that strategy the AI took so long to learn.

History is all the evidence you need, if a team of 200 MIT researchers with access to world-class parallel supercomputers cant make a damn robot that learns how to tell a square from a triangle in months, how the hell will one guy, working part time make an AI that will consider hundreds of factors in a game that are all dynamically interlinked and then learn from them in a few hours on a crappy Pentium 3????

The AI needs things chewed out so it can process it the way it does best at: with speed! The system above uses a computer's speed to come out with the optimal resource building plan. I done all the thinking for it! It would take humans days or years to calculate the amount of formulas the AI calculates in one minute. Full proof is shown when I see really good players putting all their resources into a fusion when they are only making 15M 200M├óÔé¼┬ª Does that analogy sound familiar? AIs should capitalize on the strengths of computers and try to not do things it's weak at!

Scouting and attacking are hell to program effectively, the worst bits by far. Heck, at least attacking can be made a lot better if the AI knows the enemy situation. It all pretty much falls down to scouting. Forcing the AI to do it effectvely (since it cant attack well and therefore win without it)is to waste programming time on a function that the AI will never excel at! Its intentional handicapping, its a crime against each and every AI programmer.

Hope that convinced someone that can actually program c++ to hack that interface and let the AI have a maphack :lol:.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

Ok you got your GlobalAICallback at first, from which you can get 2 interfaces. The IAICallback we've all used, and the IAICheat callbakc functions which are just some of the callback functions without constraints such as LOS implemented.

Are you scannign those pieces of paper or taking photos?

I think ti would be beneficial if you posted the design stuff scanned in in a big zip file. Try to use imageshack and fileuniverse instead of putfile.

Your AI doesnt sound amazing, but it doesnt sound crap at all.

It simply sounds well thought out. Many ideas you're putting forward arent new and have either been said by em ro zaphod or submarines screenshots, you're just taking a new approach to it.

i suggest you split this thread in two, one for all your AI discussion, and another for the scoring thign. The scorer class would be of use to me you and many others, but it's being drowned by all your notes.
History is all the evidence you need, if a team of 200 MIT researchers with access to world-class parallel supercomputers cant make a damn robot that learns how to tell a square from a triangle in months,
Using a copy of NEAT and a pentium 2 computer, and a large set fo bitmaps with squares and triangles, I can teach a neural net to differentiate between squares and triangles in an hour.

The cpu intensive part is th actual evolving of the nets or algorithms. Once an algorithm has bene found ti is usually a lot faster. Unless you're comapring thigns that are allways this or that against a central archive of saved files, such as a 7 will always be pritned the same shape and size and way, versus a neural net trying to find sevens in handwritten text.

Dont create an AI that learns and evolves totally. A hybrid is better. Besides give the AI the ability to observe a humans tactics then use them itself and see how a human counters would be better than spending hudnreds fo games trying to devise a totally new strategy.
User avatar
krogothe
AI Developer
Posts: 1050
Joined: 14 Nov 2005, 17:07

Post by krogothe »

Its not a feasible task to scan my notes because only I can make much sense of them, that picture had the intent of showing that. I have never been a very organized person and these notes are being basically passed on to this thread. Most of the stuff is relevant to the organized class.
The maphack request, which is still bit bit relevant to the subject has been separated by the big fat red letters. I'm afraid that is as organized as I can be for now if you dont want to wait until actuall implementation of the code.

The AI does seem amazing because in theory it can produce the perfect gameplay provided enough information is processed in the functions, and even if that is an impossible task, it can come very near that ideal if well designed, plus its 100% modular, universally compatible and not all that CPU intensive, as well as providing great diversification and allowing for a comprehensive difficulty level which can adapt to the player. As i said, in theory the system is the best i can think of, but it could still work out crap (come on we have all seen AIs with complicated weigthing and learning systems that look and play crappy in many games)

For your NEAT example, you still need a large set of bitmaps, which are already chewed out pieces for the AI since it is getting a real world concept of a shape and converting it into an easy to read and process array of pixels. Plus you have to create the neural net first and make all the bitmaps etc. It really is a lot more work than you should be getting benefits for.

My approach is that i think that i can work out a gameplay solution faster than a computer can evolve by itself, and that i can work out a better solution as well. We surely both agree recognizing a 7 is trivial compared to managing an army of thousands of units in a real-time, 3d environment, and since evolution times are not linear to the amount of information to be processed, we are talking about a timescale beyond the scope that we desire.

I would evolve things like the IncomeMultiplier in my resource scorer, which is a single value with a single maximum, so evolution will converge it in the space of a few games. anything more than a couple of variables would increase the evolution time exponetially.

By the way, how would you implement a system where the AI will observe a human tactic and use it? How would it tell from what is part of the tactic or not? how would it know what bits are dynamic and which are stable? How would it know if unit X is better against Y or just if player W is better than Z? It would still take an awfully long time to derive anything useful from it.

Have you ever player NERO? You train your robots and their neural networks evolve them. Some people spent incredible amounts of time evolving theirs and I am pretty sure i could code a team of robots that could massacre them in a few minutes.

Then there is the problem of "local peaks", where a current variable is at an apparent maximum efficiency since increasing or decreasing it seems to reduce the overall score, but there might be a value further away which will produce a higher score.Sometimes The only way to prevent these is to have a mutation system that allows for complete mutation of an individual (that would be extremely rare to allow for proper evolution), and in a complex setting this could take a time close to infinity and even a ridiculous approach like generating a borges library for that variable would be faster provided the variable is discrete (and that is theoretically the slowest way to find an optimal solution).

I agree to disagree, in my opinion evolving AIs are more of a curiosity than an useful concept (except in certain niche settings, such as the IncomeMultiplier)

The function is described fully in the first few posts anyways, so i dont mind the Evolving AI discussion taking over.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

Those are cases where evolution controls every aspect.
NEAT is not a name, it is the implementation that creates and evolves the neural net given the modifications and imputs you employed.

For the tactical bit read gabbas research.

And again on your maphack thing, look at the definitions forthe callback itnerfaces. There is a cheat callback interface.

Heck if i wanted an unbeatable NTAI I would tell the cheat interface to spawn 100 krogoths in the centre of the enemies base, and make buildings build instantly, for free.

It looks like you've researched AI before you could implement any of what you read. I'm researching neural nets atm, and I've been reading on and off about genetic algorithms and different theories and methods for the last few months.
User avatar
krogothe
AI Developer
Posts: 1050
Joined: 14 Nov 2005, 17:07

Post by krogothe »

Yes, i know NEAT isnt just a name but i am sure you must set it up in some way.

Ill have a look at the different researches (i take it they are all on this forum), some of it looks interesting!

The Cheats callback bit has this:

Code: Select all

	virtual int GetEnemyUnits(int *units)=0;					//returns all known enemy units
would that include units out of LOS? (im guessing so since its a cheat but dont have the skills to test it atm)

Now the objective of my AI is not to be unbeatable!
Spawning kroags and free instant building would be cheating just like a maphack, but it would not give the player any challenge (hed just die everytimg) and would not increase the fun factor, which is based on challenge, feedback, novelty and association. The maphack would increase the challenge and novelty factors, thus making the gameplay more enjoyable!

Neural nets and genetics are very innefient but sometimes the only way to solve a problem you dont know how to solve (such as spotting patterns).
Building a base and attacking the enemy is a problem anyone whos played an RTS can solve and thus program. with that achieved, AI can instantly KNOW from the unit tables and formulas the best decisions to take in most cases with a good degree with accuracy, whereas an evolving AI would first have to figure out what the problem is in first place.

Personally i love Evolving AIs and will certainly use my aquired C++ skills to program something like NERO or DarwinBots with it, just because they are so much fun!
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

Yah, it's identical to the equivilant in the normal interface but with no checking against LOS or radar.
User avatar
krogothe
AI Developer
Posts: 1050
Joined: 14 Nov 2005, 17:07

Post by krogothe »

I had a look at Gabba's research, and although i found most of it irrelevant to the problems of spring and AI in general, i did especially like the bit about plotting a single route with clearance for a group instead of a route per unit. It should be quite helpful!
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

Then I bid you read ti again with a more open mind, for ym view of it shows me thigns yours doesnt ^_^ To see why go read the NTAI X thread.
User avatar
Targ Collective
Posts: 202
Joined: 12 Nov 2005, 14:16

Post by Targ Collective »

Don't forget to scale your attacking forces by distance. Alantai has yet to implement this in NTAI, which is why the AI plays best on, say, Volcano Isles rather that Mars.
Post Reply

Return to “AI”