Research Buddy

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!
Post Reply
shadow98cat
Greenhorn
Posts: 8
Joined: 15 Sep 2010, 00:34
Location: Clovis, CA

Research Buddy

Post by shadow98cat »

Hi,

I would like to present my Research Buddy 1.0. This is an AI addon that will only do research, as a research partner. It requires its own simple base and player slot on a map that you ally with. The particular research types it goes through are; Power, Sensors, Bodies, Propulsion, Armor, Wall and Structure Defense. It does do a few weapons, but only prerequisites as needed. The particular order it does the research in is based on my preference of what I think is highest priority first. That's not to say it can't be improved, I've just spent quite a bit of time playing with the order already.

The way to use this is start a skirmish map with RB bases, make it fixed teams and start with bases or advanced bases. Choose RB from the AI list for the appropriate starting position and set the teams. It is not required that all or none have an RB teammate, it can be unbalanced. For the difficulty setting; easy and medium have a delayed start and delay between research topics, with easy being slower. Hard and insane will start instantly and have no delay between research topics. At the moment, hard and insane are identical.

I have tested this almost exclusively on Warzone 3.1.1 and it works really well. I did one test on the master version found here http://buildbot.wz2100.net/files/warzon ... f201f4.exe. If I understand correctly, this is the not yet released version 3.2.

I had this idea several years ago, but trying to do just make a map and then box in the default AI from that time did not work. This is only possible thanks to NoQ's NullBot, which my code is over 95% copied from and stripped down. I do not know JavaScript and the https://warzone.atlassian.net/wiki/disp ... script+API website was incredibly helpful. I just want to say thank you so much because I could not have done this by myself.

I am hoping that there are several reasons this will appeal to a wide group. For one, the research tree is large and complex. Maybe this would help someone that doesn't get to play that often or has a hard time remembering all those prerequisites. Just focusing on weapons research might be easier to memorize some of those specific paths. Also, using an RB ally (one for each team) would significantly quicken the pace to get high level tech. That would allow for more time spent focusing on building, attacking, etc. Also, this could be used to produce a sort of handicap for matches with less experienced players. I played against NullBot on hard with both of us having an RB on hard, and it seemed to work really well.
ResearchBuddy1.1.wz
Load this file into C:\Program Files (x86)\Warzone 2100-3.1.1\mods\autoload
(6.15 KiB) Downloaded 210 times
I have added a Research Buddy base to both players on my Royal Castles map so it will be easy to test out. I have provided 1 CC, 1 truck, 1 power, 4 oils, and 4 research facilities to the royal Castles map. Technically, I suppose the minimum requirement would be 1 CC, 1 truck, 1 power, 1 oils, and 1 research facility. The truck and CC aren't really needed, except as a requirement of any Warzone map.

I don't think it would be to difficult to modify existing maps in FlaMe to add in RB base positions. Provided it is a maximum 5 player map and there is enough room inside the base to tuck RB bases behind. If there are any specific requests for maps to be outfitted with RB bases, I would be happy to try (I'm still improving at FlaMe).

Part of my intention is that the RB base needs to be defended, and attacking / destroying it could very quickly turn the tide in a fair match. One idea I had was to make RB bases in a separate location on the map from the main base, so it could add extra difficulty of defending it.
2c-RoyalCastlesRB.wz
Royal Castles map with Research Buddy extra players
(52.82 KiB) Downloaded 223 times
In-game preview of main base with Research Buddy base tucked behind
In-game preview of main base with Research Buddy base tucked behind
As far as licensing, everything is CC-BY-3.0 + GPLv2+
Last edited by shadow98cat on 29 Aug 2014, 08:19, edited 1 time in total.
shadow98cat
Greenhorn
Posts: 8
Joined: 15 Sep 2010, 00:34
Location: Clovis, CA

Re: Research Buddy

Post by shadow98cat »

Hi again,

I have a few ideas that I could not get to work. I tried repeatedly and I apparently just never got the syntax right or something. Just to say it again, I do not know JavaScript. Any help would be greatly appreciated.

1. I would like to see the truck demolish the CC at the start of a match, and then self-destruct. These 2 aren't needed and will just be in the way of building your own base. I tried:

Code: Select all

orderDroidObj((enumDroid(DROID_CONSTRUCT, me)),DORDER_DEMOLISH,A0CommandCentre);
and some other variations but that truck never budged. I never tried the destruct part (since I couldn't get the prior to work) but I'm guessing it's something like:

Code: Select all

removeObject(enumDroid(DROID_CONSTRUCT, me));
2. For the insane difficulty AI, I would I like to start it off with some free research. I tried many variations of this:

Code: Select all

function CheatRB() {
		hackNetOff();
		completeResearch("R-Struc-Research-Module", me);
		completeResearch("R-Struc-Research-Upgrade01", me);
		completeResearch("R-Struc-Research-Upgrade02", me);
		completeResearch("R-Struc-Research-Upgrade03", me);
		completeResearch("R-Struc-Research-Upgrade04", me);
		completeResearch("R-Struc-Research-Upgrade05", me);
		completeResearch("R-Struc-Research-Upgrade06", me);
		completeResearch("R-Struc-Research-Upgrade07", me);
		completeResearch("R-Struc-Research-Upgrade08", me);
		completeResearch("R-Struc-Research-Upgrade09", me);
		hackNetOn();
}
I'm sure my code is probably not optimal and welcome any suggestions to simplify it (and make it work of course). I called it in the function eventStartLevel(). I am open to any other suggestions, and would really appreciate any help getting these 2 items to work.

Thanks.
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: Research Buddy

Post by NoQ »

Yay nice. If there's ever an option to "replace the disconnected player with an AI", it should be something like that, not a generic skirmish AI.

In fact some people might be annoyed by the fact that it researches structure upgrades, as those are quite path-specific (unless you consciously decide to turtle, you barely ever need those).

And yeah, i guess it needs to build a base, a few labs and modules at least. People often play with no bases.

Code: Select all

orderDroidObj((enumDroid(DROID_CONSTRUCT, me)),DORDER_DEMOLISH,A0CommandCentre);
              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Nonono, you need to iterate over the list of droids (obtained via enumDroid()) and give orders personally to each droid.

Code: Select all

orderDroidObj((enumDroid(DROID_CONSTRUCT, me)),DORDER_DEMOLISH,A0CommandCentre);
                                                               ~~~~~~~~~~~~~~~
Nonono, you need to iterate over the list of structures of a certain type (obtained via enumStruct()) and assign a particular structure to each droid.

See also here:

Code: Select all

function recycleDefenses() {
    var trucks = enumTrucks().filter(truckFree); // my own wrappers here, you're probably fine with `enumDroid(me, DROID_CONSTRUCT)'
    if (trucks.length <= 0)
        return false;
    var list = listOutdatedDefenses(); // another custom function, should be your own stuff here
    for (var i = 0; i < list.length; ++i)
        for (var j = 0; j < trucks.length; ++j)
            if (droidCanReach(trucks[j], list[i].x, list[i].y)) {
                orderDroidObj(trucks[j], DORDER_DEMOLISH, list[i]);
                return true;
            }
    return false;
}
Whoops, you cannot recycle droids on 3.1, for that you need orderDroid function without object or location arguments (similarly to stop the droids, etc.).

And i'd better go fix the docs now.

Code: Select all

function CheatRB() {
      hackNetOff();
      ...
This might actually be impossible. There are two sorts of scripts: game rules scripts, like rules.js, are run on all computers in a multiplayer game, while AI scripts are run only on host computer. If you enable technology on only one computer, the game might desynchronize (break).
shadow98cat
Greenhorn
Posts: 8
Joined: 15 Sep 2010, 00:34
Location: Clovis, CA

Re: Research Buddy

Post by shadow98cat »

Hi NoQ,

Thank you for the help and suggestions. I fixed the demolishing CC thing, which wasn't that difficult. I tried using the backport to get the truck to self destruct, but could not get it. There seems to still be an issue that was mentioned here in the comments, that was giving me errors.
In fact some people might be annoyed by the fact that it researches structure upgrades
I am not sure what you mean. I only included R-Defense-WallUpgrade# and R-Struc-Materials# upgrades. I guess I didn't see those as path-specific if that's what you meant. Do you think those should be a lower priority on the research list?
And yeah, i guess it needs to build a base, a few labs and modules at least. People often play with no bases.
I prefer to play with no bases as well, it was just a lot easier for me to make a base in FlaMe. So I have been working on the base building, and have a few questions. I copied the oil capturing and structure building from NullBot, and they work well for my build order. As for capturing oil, when I play on the Royal Castles map, my RB ally will not capture the oil right next to it. Instead it seems to randomly go after any oil on the map and only rarely goes for the oil right next to it. I think it has to do with the close proximity of allied bases, which will be an issue. I don't really see this AI working very well on most existing maps, because it would be so defenseless. At the minimum, an existing map would need to have a few trucks and oils added behind the normal bases. I think the issue is in the excerpt below, but I'm not sure.

Code: Select all

	if (!danger || random(15)==0) {
		var tmp=getNearestCCPlayer(list[j].x,list[j].y,0); // friendly AIs shouldn't capture your oil
		if (typeof(tmp)=="undefined" || tmp==me) {
			var n=oillist.length;
			oillist[n]=list[j];
			oillist[n].stat=stat;
		}
	}
What would be the simplest way to make sure the trucks always go for the oil nearest their startPosition first? Then proceed outward only until the max oils to capture is reached. By the way, what does the 'random(15)==0' do in there?

Okay so the other problem I am having is my buildgroup is building the base all over. My build order starts with a generator, and then alternates between capturing oil and building labs. What I end up with is labs being built right next to wherever they capture the oil. I tried adding returnToBase(droidlist); to the function 'buildBasicStructure' but it didn't help. Is there any way to make sure that all structures are built as close to startPosition as possible? I do not have a separate oilergroup, as there are sometimes only 2 starting trucks on a map.
This might actually be impossible.

I think I get what you are saying. My goal was to give the insane difficulty an extra advantage over hard, and that seemed like the best way. Do you have any other ideas of how I could give a research related advantage to the insane difficulty?

Thank you so much for all your help and please go easy on me. JavaScript is not something I ever looked at before until about 2 weeks ago. I have been using Notepad++ and it seems pretty good. What it doesn't have is all of the Warzone custom functions in there.
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: Research Buddy

Post by NoQ »

I think the issue is in the excerpt below, but I'm not sure.
I'm strictly forbidding NullBot to take oil that's closer to a human's command center than to his command center; that's what the check for getNearestCCPlayer means. Otherwise, NullBot always takes oil closest to his trucks (or at least should; not sure what exactly happens in the old NullBot).
Is there any way to make sure that all structures are built as close to startPosition as possible?
Sure, just pass startPosition coordinates to pickStructLocation().
Do you have any other ideas of how I could give a research related advantage to the insane difficulty?
Whenever you ask for this, you're technically asking something very similar to a possibility of cheating in a multiplayer game; while it should be possible to discriminate between human and AI cheating somehow, i don't think it's well-enough coded right now to be a supported feature. That said, Nexus AI still has fast-research-cheat enabled, as far as i remember; but anyway it shouldn't. The power-cheat for INSANE on development builds, afaik, an example of sanely implemented AI-only thing.
backport

Code: Select all

// use specific recycling structure (factory or repair station)
orderDroidObj(myDroid, DORDER_RECYCLE, recycleStructure);
I haven't tried this, but it *might* work.
By the way, what does the 'random(15)==0'
Once in 15 times, randomly try to capture oil even if the location is known to be dangerous.
Cyp
Evitcani
Evitcani
Posts: 784
Joined: 17 Jan 2010, 23:35

Re: Research Buddy

Post by Cyp »

NoQ wrote:That said, Nexus AI still has fast-research-cheat enabled, as far as i remember; but anyway it shouldn't.
If I remember right, that's true in single-player mode, but disabled in multiplayer due to it breaking synch.
shadow98cat
Greenhorn
Posts: 8
Joined: 15 Sep 2010, 00:34
Location: Clovis, CA

Re: Research Buddy

Post by shadow98cat »

Hi,

I have uploaded Research Buddy 1.1. Major change is; now constructs a simple base from scratch and captures oil. I also tweaked the difficulty settings so it will adjust to number of labs. My next step is to include building of a few defensive structures and producing additional builders. So for now, RB is still totally defenseless and only builds as fast as the initial # of trucks.

By the way, the insane difficulty is probably not going to work well on low oil maps. RB will attempt to capture 8 oils on that setting. I do have a reason for that, I just haven't got to it yet.

NoQ, I just left out the backport and I'm just going to forget about any kind of cheating for now. Thanks for all your help. I did have one question about executing the build order. In the code below, does it 1. attempt to finish structures, 2. build from build order, then 3. upgrade structures only if other 2 completely fail? The problem I am having is they will upgrade structures on a map that starts with basic power/labs, before capturing oil. I put capturing oil in my build order, I know that probably isn't ideal but it made sense to me at the time.

Code: Select all

function executeBuildOrder() {
	if (!finishBuildings())
		if (!BuildOrderRB())
			if (!upgradeStructures())
	return false;
}
I would really appreciate it if anyone has (or will) test out this AI, please let me know what you think about it.

Thanks.
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: Research Buddy

Post by NoQ »

shadow98cat wrote:

Code: Select all

function executeBuildOrder() {
   if (!finishBuildings())
      if (!BuildOrderRB())
         if (!upgradeStructures())
             ...
}
Uhm. I've been just looking closely at this part of my code in the old nb, and i already hate it (:

This thing is very fragile, look very carefully how the functions are defined.
The `if' you quoted is read straightforwardly: if one of the functions returns "true", interrupt; otherwise, try the next function.
Since executeBuildOrder() is called repeatedly, it will start again from the first function even if all functions return "false".

So, returning "true" or "false" has nothing to do with successfully giving an order to build things; it's about whether a phase [this function is responsible for] is "completed" (and hence not blocking further progress) or not.

buildOrder procedure is organized differently:

Code: Select all

	if (genCount < 1 && isStructureAvailable(generator,me))
		return buildBasicStructure(generator);
This reads as "If i have enough generators or i cannot build them at all, try something else; otherwise block the build order until i have enough generators". So it's actually a three-way switch: we can return true, return false, fall through to the next "if".

For instance, in old NullBot, there are two groups of trucks: one group for building base structures, another for capturing oils. If all base trucks are busy, buildBasicStructure here returns "false", which blocks further build order execution, but would not block capturing oil by the oil trucks.

So,
The problem I am having is they will upgrade structures on a map that starts with basic power/labs, before capturing oil. I put capturing oil in my build order, I know that probably isn't ideal but it made sense to me at the time.
you need to carefully look through all return values and see if they are intended. The "intended" is actually not quite obvious, takes thinking. I'm seeing at least one problem on your v1.1 code: there's no return statement at the end of BuildOrderRB().

Also, try to have a look at my fixes on NullBot2 when i push them, some may fix your issues as well. Edit: not much to see actually, but try applying the fix to finishBuildings() shown here.
Post Reply