New analytical AI for Contingency (Work in progress)

Did you create a mod, map, music, or a tool? Present them here and earn feedback!
Note: addon requests do not belong here.
Note, everything uploaded to this forum, MUST have a license!
User avatar
Shadow Wolf TJC
Regular
Regular
Posts: 1047
Joined: 16 Apr 2011, 05:12
Location: Raleigh, NC

Re: New analytical AI for Contingency (Work in progress)

Post by Shadow Wolf TJC »

How about now?
shadowbot-contingency_pre_alpha3.wz
(8.65 KiB) Downloaded 216 times
Creator of Warzone 2100: Contingency!
Founder of Wikizone 2100: http://wikizone2100.wikia.com/wiki/Wikizone_2100
User avatar
Arreon
Trained
Trained
Posts: 324
Joined: 15 Feb 2009, 05:57
Contact:

Re: New analytical AI for Contingency (Work in progress)

Post by Arreon »

Shadow Wolf TJC wrote:How about now?
shadowbot-contingency_pre_alpha3.wz
Yep, the AI is doing stuff now. :) I'll keep you updated on any other things I find.

EDIT: Nope, wait. Got this:

Code: Select all

error   |12:09:00: [callFunction:109] 0 : <anonymous>()@multiplay/skirmish/shadowbot-contingency-main.js:448
info    |12:09:00: [callFunction:112] Uncaught exception calling function "eventStructureBuilt" at line 448: TypeError: Result of expression 'groupInfo[0].target' [undefined] is not an object.
info    |12:09:00: [callFunction:112] Assert in Warzone: qtscript.cpp:112 (false), last script event: 'N/A'
OS: Windows 7 Home Premium 64-bit
Processor: AMD Phenom II X6 1045T (6 CPUs), ~2.7GHz
Memory: 8192MB RAM
User avatar
Shadow Wolf TJC
Regular
Regular
Posts: 1047
Joined: 16 Apr 2011, 05:12
Location: Raleigh, NC

Re: New analytical AI for Contingency (Work in progress)

Post by Shadow Wolf TJC »

Good to hear. :)

Edit: Oh well. I still have a lot of work to do before it can even give the NEXUS AI a run for its money.
Creator of Warzone 2100: Contingency!
Founder of Wikizone 2100: http://wikizone2100.wikia.com/wiki/Wikizone_2100
User avatar
Arreon
Trained
Trained
Posts: 324
Joined: 15 Feb 2009, 05:57
Contact:

Re: New analytical AI for Contingency (Work in progress)

Post by Arreon »

Shadow Wolf TJC wrote:Good to hear. :)

Edit: Oh well. I still have a lot of work to do before it can even give the NEXUS AI a run for its money.
I'm here to help in any way I can. I'd love to see how this new AI turns out. :)

Maybe someday, we can have Nullbot and Shadowbot go head-to-head. :)
OS: Windows 7 Home Premium 64-bit
Processor: AMD Phenom II X6 1045T (6 CPUs), ~2.7GHz
Memory: 8192MB RAM
User avatar
Shadow Wolf TJC
Regular
Regular
Posts: 1047
Joined: 16 Apr 2011, 05:12
Location: Raleigh, NC

Re: New analytical AI for Contingency (Work in progress)

Post by Shadow Wolf TJC »

NoQ's going to have to update NullBot to make use of all the new stuff that's been added to Contingency. Otherwise, it'll most likely be no contest (if playing on Contingency). :P
Creator of Warzone 2100: Contingency!
Founder of Wikizone 2100: http://wikizone2100.wikia.com/wiki/Wikizone_2100
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: New analytical AI for Contingency (Work in progress)

Post by aubergine »

IIRC groups are deleted once they are emptied in 3.1 RC3 and earlier, which might be what's causing that undefined error you get above. Or the droid might have been killed (if you are caching droid lists you'll need to put plenty of try...except blocks around code that uses the cached list in case the droid is gone by the time you try to access it).
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: New analytical AI for Contingency (Work in progress)

Post by NoQ »

groupInfo isn't deleted as well, obviously.
Lord Apocalypse
Regular
Regular
Posts: 678
Joined: 29 Jul 2009, 18:01

Re: New analytical AI for Contingency (Work in progress)

Post by Lord Apocalypse »

Good luck with it. Will try it out on a 2 player map and see if it doesn't run around in circles.
User avatar
Iluvalar
Regular
Regular
Posts: 1828
Joined: 02 Oct 2010, 18:44

Re: New analytical AI for Contingency (Work in progress)

Post by Iluvalar »

Shadow Wolf TJC wrote: Personally, I doubt that there's a single tech path, in both vanilla Warzone 2100 and Contingency, that would work best for all maps. For example, a player that focuses on Flamers and Lasers would probably thrive on a map with lots of open space and pavement (which provides an engine power boost to all Wheeled, Half-Tracked, and Tracked droids), while a player that focuses on Artillery or VTOLs would probably struggle on said map. On the other hand, on a map with very little open space, and lots of mud and slush (which slows down all ground droids except for hovers), the Flamer player would probably struggle, while the Artillery and VTOL players would probably thrive.
Such map+mod combination would be either A) A cheat if only one player is aware of the map advantage. B) A complete waste of time if both players are aware of it. As they will both enter a memory test to see which of them recall the more exactly the best « flamer vs flamer » research path and will execute it with the less flaw.
Heretic 2.3 improver and proud of it.
User avatar
Shadow Wolf TJC
Regular
Regular
Posts: 1047
Joined: 16 Apr 2011, 05:12
Location: Raleigh, NC

Re: New analytical AI for Contingency (Work in progress)

Post by Shadow Wolf TJC »

I've been doing a bit of work on how the AI would act depending on its difficulty settings, and here's what I have planned:

Code: Select all

/*ShadowBot AI behavior that's planned depending on difficulty settings:

EASY: Plays like a n00b.
- Starts with a fairly n00bish RFC build order (lab, factory, hq, powgen).
- Prefers to secure the closest oil resources before moving on to more distant ones.
- Attempts to research everything, regardless of personality, though it'll still prioritize some research into personality-preferred techs.
- ONLY focuses on building personality-preferred units, even if more powerful weapons from a different line are available to it (since it believes that researching personality-preferred upgrades would eventually make its personality-preferred weapons more powerful).
- Doesn't recycle any units, nor does it demolish any structures.
- Prefers to build the most expensive units that its factories can build, even if the time that it takes to build them is prohibitive. (It basically thinks that bigger is always better.)
- Doesn't adapt production or research to counter threats.
- In fact, it doesn't even seem to understand the concepts of type effectiveness, overkill, or how the armor class system works, often choosing weapons based solely on their damage-per-second (against targets with 0 armor).
- Doesn't consider a component's weight or engine power when designing units, so it may occasionally design units that are grossly overweight (such as sticking a Heavy Cannon on a Leopard Tracks for example).
- Attempts to build as many factories and research labs as possible without considering whether or not it has enough power to support them all.
- Doesn't manage power effectively when low on power.
- In fact, it'll attempt to assign orders to all of its factories and research labs, regardless of whether or not there's enough power to handle it.
- Typically prefers to gradually capture and secure enemy-controlled Oil Derricks before assaulting enemy bases.
- Doesn't micromanage at all, not bothering to even retreat units for repairs, or keep a distance from shorter-ranged units (especially Flamers).
- Doesn't build outposts or forward bases, instead opting to expand its home base.
- Laughably uncooperative. In fact, rather than listening to its teammates, it'll often try to boss them around or berate them for their insubordination, constantly request more power, or demand an explanation as to why they aren't helping it in performing an ultimately futile task (such as attacking a well-fortified position), though thankfully, other ShadowBot AIs would often ignore them anyways.
- Will refuse to help out when a teammate is under attack, thinking itself as the better player (when in fact, it usually isn't). On the other hand, due to the AI being so rude and incompetent, other ShadowBot AI's would usually refuse to help it out if under attack (and even express relief if the AI is knocked out).
- When it attacks, it frequently informs the others that it's attacking, expecting them to join in immediately, regardless of whether or not they're actually ready (or willing).

MEDIUM: Plays like a reasonable (but still new) multiplayer player with a full understanding on how the game works.
- Starts with a more tried-and-true FRCRF build order (factory, lab, hq, lab, factory, powgen).
- Will send some starting trucks to attempt to secure the centermost oil on the map.
- Specializes research into personality-preferred techs.
- Will make use of non-personality-preferred weapons if they're more powerful than what personality-preferred techs they have.
- May recycle units and demolish structures that it deems worthless or obsolete, such as recycling old Light Cannon tanks if it has researched many more Rockets upgrades than Cannon upgrades.
- Will build a more diverse mix of units (from small Cyborgs to heavy tanks).
- Will attempt to adapt production and research to counter threats.
- When choosing which droids to produce, it'll take into account a weapon's type effectiveness, and what its damage-per-second is expected to be against the target's armor, but it won't take into account a weapon's accuracy.
- Takes into account a component's weight and engine power when designing units, though doesn't consider terrain bonuses/penalties to engine power.
- Will usually only build more factories or research labs if it has a surplus of power.
- Manages power fairly effectively, canceling build, production, and research orders if need be.
- Will aggressively harass enemy Oil Derricks, and send units to probe enemy bases, but will not perform rushes.
- Micromanages a little. It'll order some, but not all, damaged units to retreat for repairs, order attack forces to withdraw if taking too many losses, and try to keep a distance from short-ranged enemies, but will not make use of more advanced tactics.
- May build outposts with Repair Facilities, but will not build forward bases, instead opting to expand its home base.
- Pretty cooperative. It'll listen to its teammates, and attempt to coordinate attacks with them. However, self-preservation takes priority, meaning that it'll often ignore orders to attack enemy bases in favor of protecting its own base.
- Will attempt to help out when a teammate is under attack, even if it means donating a truck and some power to help rebuild.
- It may sometimes try to organize the team for a massed assault, but will wait or cancel the plan if its allies aren't ready.

HARD: Plays like a seasoned multiplayer player that attacks relentlessly, and doesn't hold back.
- Starts with a map-specific build order (that defaults to FRCRF if playing on a map that the AI doesn't recognize).
- Will send some starting trucks to attempt to secure the centermost oil on the map.
- May attempt to erect Tank Trap blockades early on in an effort to prevent its opponents from stealing some oil.
- Specializes research into personality-preferred techs.
- Will make use of non-personality-preferred weapons if they're more powerful than what personality-preferred techs they have.
- Will build a more diverse mix of units (from small Cyborgs to heavy tanks).
- May recycle units and demolish structures that it deems worthless or obsolete.
- Will attempt to demolish all structures, except for defenses, within a base if it seems that the base will fall soon.
- Will attempt to adapt production and research to counter threats.
- When choosing which droids to produce, it'll take into account a weapon's type effectiveness, what its damage-per-second is expected to be against the target's armor, and sometimes, even what the weapon's accuracy is.
- When designing units, it'll take into consideration a component's weight and engine power, and even terrain bonuses/penalties to engine power.
- Will build more factories or research labs if it has a surplus of power, or if it needs to shift power from production to research, research to production, cyborgs to tanks, tanks to cyborgs, etc.
- Manages power VERY effectively, actively waiting until it accumulates enough surplus power to pay for whatever it wants to build, produce, or research.
- May launch assaults on enemy bases early in the game, though would otherwise aggressively harass enemy Oil Derricks.
- Micromanages fairly often. Not only will it attempt to preserve its forces like with the NORMAL difficulty AI, but it will also employ more advanced tactics, such as attempting to encircle enemy forces that attack one of its bases, or assault a base from multiple directions.
- Will likely build outposts with Repair Facilities, as well as forward bases near some Oil Derricks.
- Will often send some trucks to escort its attack forces to build Repair Facilities near where the fighting is at, or just in case the AI needs to rebuild if its main base falls while its main forces are away.
- A true team player. It'll attempt to coordinate attacks with its teammates, and will even sacrifice its forces if it means victory for the entire team.
- Will attempt to help out when a teammate is under attack, even if it means donating a truck and some power to help rebuild.
- It may sometimes try to organize the team for a multi-front assault, but will wait or cancel the plan if its allies aren't ready.
- May attempt to specialize in production over research if it starts closer to the front lines, or vice-versa if it starts further away.

	INSANE: Same as HARD AI, other than the hard-coded cheats that it's bound to use, such as increased power generation, and preserving defenses regardless of base settings (in vanilla Warzone 2100, though not in Contingency).
- Doesn't add new units or structures instantly, nor does it cheat for more power or free research.
*/
During said planning, I realized that it would be funny if I came up with a list of messages that the AI would say to its partners. Here's what I have so far: (Warning! Mild profanity!) :!: :ninja:

Code: Select all

//Messages that the AI would use in co-op matches.

const messageAnnoyed = [
	"I've got better things to do than listening to your nonsense.",
	"Goddamnit Leeroy...",
	"Sigh... just ignore him...",
	"I'm afraid that I cannot comply with such a feeble order.",
	"Request denied. Doesn't meet standards of reasonable protocols.",
	"Blah, blah, blah. Will you ever shut up?"];

const messageAnnoyedNoob = [
	"Bug off, n00b!",
	"Get lost!",
	"Tch, as if.",
	"Why the bloody hell should I listen to you?",
	"Sod off! I'm busy.",
	"Piss off, ya wanker!"];

const messageNoobishTeammateKilled = [
	"Good riddance!",
	"Serves him right, bloody wanker.",
	"Guess that's one less prick to worry about, eh?",
	"Finally! That pompous bastard got his just desserts.",
	"Hallelujah! He's finally gone!",
	"Well, at least he provided for a decent distraction, right?"];

const messageTeammateKilledNoob = [
	"Wow! I can't believe I'm teamed up with a loser like him.",
	"That's what you get for not following my advice, n00b.",
	"Now then, let me show you how l33t players like me get things done.",
	"Learn to play better, n00b!",
	"I never want to partner up with him again.",
	"N00bs like him don't deserve a second chance."];

const messageTeammateKilled = [
	"Shoot! We lost a teammate!",
	"That had to hurt.",
	"Ouch! That looked painfully humiliating.",
	"No! I'll avenge you, brother!",
	"Dang. He was a true partner.",
	"Bloody hell! Our teammate's down."];

const messageOfferTruck = [
	"Do you need a truck?",
	"I can donate a truck if you'd like.",
	"If you need to borrow a truck, all you need to do is ask.",
	"Just say the word, and I'll give you one of my spare trucks for free.",
	"Sounds like you'll need a truck to get back into the game, right?",
	"If you'd like, I could give you one of my trucks so you can rebuild."];

const messageAttackNoob = [
	"What are you waiting for? Attack!",
	"C'mon! Let's get 'em!",
	"Help me take these losers down, will ya?",
	"Time for us to kick ass and chew bubblegum!",
	"Alright, let's do this! LEEEEEEEROOOOOOYYYY JEEENNNKIIINNNSSS!!!",
	"Hope you've got me covered, cuz here I go!"];

const messageAttack = [
	"Let's do this!",
	"Attack!",
	"Give 'em hell!",
	"Cleared for assault. GO!",
	"Waste 'em!",
	"Take no prisoners."];

const messageCoordinateAssault = [
	"Rendezvous here for a massed assault on the enemy.",
	"We'll be launching a coordinated attack soon. Rally here.",
	"Care to send your troops here, in preparation for a massed assault?",
	"Rally your forces here. We'll combine our forces for a massed assault.",
	"I'll need your forces here for a joint massed assault.",
	"I have a plan of attack, but I'll need both of our forces to move here."];

const messageCoordinateProngedAttack = [
	"You attack from here, while I attack from elsewhere.",
	"Rally here. We'll divide the enemy's attention with a two-pronged attack.",
	"Care to send your troops here, in preparation for a two-pronged attack?",
	"Rally your forces here. We'll attack them from multiple fronts simultaneously.",
	"I'll need your forces here for a two-pronged attack.",
	"I have a plan of attack, but I'll need your forces here for a two-pronged attack."];

const messageAffirmative = [
	"Affirmative.",
	"Consider it done.",
	"Roger.",
	"Acknowledged.",
	"Sure.",
	"Very well."];
Creator of Warzone 2100: Contingency!
Founder of Wikizone 2100: http://wikizone2100.wikia.com/wiki/Wikizone_2100
User avatar
Colonel Longhena
Greenhorn
Posts: 11
Joined: 24 Nov 2012, 15:25
Location: HQ

Re: New analytical AI for Contingency (Work in progress)

Post by Colonel Longhena »

Looking forward to when this will be finished and ported to vanilla wz :P , though by that time Nullbot might get much better as well too :P .
Lord Apocalypse
Regular
Regular
Posts: 678
Joined: 29 Jul 2009, 18:01

Re: New analytical AI for Contingency (Work in progress)

Post by Lord Apocalypse »

It'll be a bad day when the AI taunts you then wins.
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: New analytical AI for Contingency (Work in progress)

Post by NoQ »

message
To use chat, you need to make sure you run on master, which involves converting a *lot* of stuff to INIs.
though by that time Nullbot might get much better as well too
I'm not having any huge plans on nullbot; it's mostly finished on the gameplay side, only some extra features like chat support will be implemented whenever they're added to the game. Or maybe if i see any good ideas, whenever this AI starts becoming a challenge, i'd gladly participate in an AI race (:
____________

Anyway, just had a look at the code, and it's surely written better than mine. You're doing most of the things i want to but no longer can, like queueing tasks, and i'm really glad to see that.
User avatar
Shadow Wolf TJC
Regular
Regular
Posts: 1047
Joined: 16 Apr 2011, 05:12
Location: Raleigh, NC

Re: New analytical AI for Contingency (Work in progress)

Post by Shadow Wolf TJC »

I guess it's time for another progress report:

It seems as if I've hit a few snags that are making me rather frustrated with trying to develop this AI. I've been struggling to get the oil-hunting construction droids to not only seek out the closest available oil (which would be typical for an EASY AI difficulty), but to ONLY seek out oil that is not already being pursued by another truck. Somehow, I got it to work, though i'm not satisfied with how I got it to work, since I'm having to rely on an array that adds/subtracts indexes based on which trucks/derricks get destroyed, and which oil resources are being pursued by the AI's trucks.

Now, however, I'm struggling to make sure that, whenever a new structure is built, that the trucks that are in the group that finished the structure are able to build the next structure on their list, WITHOUT interfering with the other groups' trucks' respective build lists. (Sometimes, whenever one of my oil hunters finishes building a derrick, it's causing the trucks building the home base to suddenly stop work on what they're working on to build the next structure on their list. At other times, my oil hunting trucks would skip the 1st or 2nd closest Oil Derricks for some unknown reason.) I've been trying so hard to figure out a way to get the AI to figure out which group the droid that finished construction of the structure belongs to, but the answer continues to elude me. :(
Creator of Warzone 2100: Contingency!
Founder of Wikizone 2100: http://wikizone2100.wikia.com/wiki/Wikizone_2100
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: New analytical AI for Contingency (Work in progress)

Post by aubergine »

It might be worth making your own functions to issue orders to trucks.

For example, you might have: buildA(structure, near) function that 1) finds nearest free truck to 'near' object, 2) tells that truck to build 'structure' at a pickStructLocation() near 'near', and 3) logs what that truck is tasked with in an array.

A partial example of such code (without logging what trucks are tasked with) is here: example

Then, if you use buildA() exclusively you'll know that it will only ever give orders to a free truck, etc. In eventStructureBuilt() you'd go through the array of truck tasks, clearing any that relate to the structure just built.
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
Post Reply