AI/Auto Traders and Promotions

Kailric

Jack of All Trades
Joined
Mar 25, 2008
Messages
3,100
Location
Marooned, Y'isrumgone
As mentioned in the Economy thread we have started work on an AI for Traders/Peddlers. In the current development version we have implemented a new command, "Peddle Wares". Simply load your Peddler with goods and hit this command. The unit will then search for the best price in his Plotgroup, travel there, sale his wares, and then return home.

Current Features/Limitations:
-Requires the player to own at least one City for the command to appear
-Requires a Home City assigned to the unit. If you click the command and the unit has no Home City you will get a popup to choose one, you then must set the unit to Peddle Wares again (I bet I can set him to automate as soon as he has a home city)
-If the unit has no sellable Goods he will wait until you load some and then he will leave for the best city
-Contingencies such as war, losing a trade connection, losing its Home City, or target city being destroyed have been added to the AI. In such cases the AI will choose a different target city if possible, or drop its automation.
-If the Trader is on a foreign city that is not connected to its Home City and you issue this command the Unit will Auto Trade its wares at the current city. If it is connected to its Home City it will choose the best city in the Plotgroup and travel there which may not be its current plot city.
Question: Should this command only be available if the Unit is on a Plotgroup tile that is not connected to the Player, and otherwise the Player must trade manually?

Future Features/Ideas

New Trader Command: this command will allow you to do several things
-Set the Goods the Trader should Buy/Sell
-Set the Priority of these Goods
-Set the Amount of Gold the Trader has to spend
-Set wether the unit should return the Goods to his Home City or Distribute them to importing Cities.

Other Commands/Features/Ideas
-Fully Automate: The Trader will use his own judgement and the amount of gold you have set for him to Buy and Sell in order to make you profit. The Unit will find low priced Goods to buy and Markets where he can sell it to make a profit.
-Trader Promotions: As the Trader makes deals he gains experience which can be spent on New Trader Promotions

These are some of the initial features and ideas. Please feel free to add your own ideas
and comments.

Explanation of Code posts
http://forums.civfanatics.com/showpost.php?p=13639671&postcount=13
 
"Question: Should this command only be available if the Unit is on a Plotgroup tile that is not connected to the Player, and otherwise the Player must trade manually?"

Does this question mean, a player will only have the option to auto trade if the trader is in a player owned plotgroup. If it is not in a player owned plot group then the player has to trade manually.

I would probably 'tentatively' say yes, a trader can only do this kind of autmating in his own plot group. This way the player is rewarded for improving the road network not only domestically, but out to foreign powers as well. (This may need to be revised, depending on the ai's road building abilities in it's own empires.)

Is another group of features going to potential involve automation with the 'trade screens' as well?

I like the way this is sounding, very excited!
 
I have been wondering about improved automated transport for a while and I would like to incorporate peddler automation settings to warehouse settings.

I think I would like to add a cargo yield JIT array for trader threshold. Automated traders then ignore import/export settings as well as threshold and will pick up anything, which is higher than trader threshold. The default value can then be no trader actions. For performance reasons, I propose having no off setting from a coding perspective, but the interface off would then be a ridiculously high number, such as 30k. That's the largest nice number you can have in a signed 16 bit int (ever wondered why you can't have more than 30k money etc in a number of old games. Now you know).

Automated traders returning to the home city will then load whatever it can find, which exceeds the trader threshold.

Having such a trader threshold will allow advanced setups like: (all yields are wine)
City A has import/export on and threshold of 50
City A has trader threshold of 100
All other cities have feeder and export for 50

The result will be that the automated transports will fill up all cities to feed local demands (lets forget about plotgroup shared sells here) and when everything is filled up, the excess is unloaded in city A. If the excess goes beyond 100, the trader will start to locate foreign wine drinkers and generate a profit from those.

I'm sure we can come up with more interesting setups. The key here is that setup should be strait forward and fairly easy to figure out while at the same time be powerful enough to really be customized to fit the current game situation and playing style.


Should automated traders be able to export to trade screens?
Should automated traders be able to buy yields? Using an import trader threshold, the automated traders could be made to steadily obtain ore or similar useful yields. That would be quite useful in the unlucky case where you can't produce everything yourself.

Still wondering what to do about a user interface. We talked earlier about moving the city code to a python file of its own. Maybe that would be the best option because that would (likely) allow us to make "tabs" where we keep the top bar and yields at the bottom while everything in between can be replaced with a number of different setup "windows".
 
I would probably 'tentatively' say yes, a trader can only do this kind of autmating in his own plot group. This way the player is rewarded for improving the road network not only domestically, but out to foreign powers as well. (This may need to be revised, depending on the ai's road building abilities in it's own empires.)
The vanilla AI code will make the AI build "the best" type of route between all the cities it own. The best is greatly simplified and might not be clever enough to figure out all XML setup options. However plotgroups don't care for "the best", only that the cities are connected, which mean for this purpose the AI works well.

The AI will however not build roads to connect to foreign cities and/or natives. We can deal with that later.
 
I think it will be good if the auto trade can work with the trade screens as well, I know they did this in doane and it was helpful (although I remember something about it being 'off' for me, I can't think what though as it was like a whole year ago that I played it.) I think it would be good to have some functionality in 'connecting' with trade screens as they are a big part of the core game, but I think that will be version 2 or 3 talk!
 
"Question: Should this command only be available if the Unit is on a Plotgroup tile that is not connected to the Player, and otherwise the Player must trade manually?"

Does this question mean, a player will only have the option to auto trade if the trader is in a player owned plotgroup. If it is not in a player owned plot group then the player has to trade manually.

Yes, the "not" in not connected should not have been there :mischief:

I would probably 'tentatively' say yes, a trader can only do this kind of autmating in his own plot group. This way the player is rewarded for improving the road network not only domestically, but out to foreign powers as well. (This may need to be revised, depending on the ai's road building abilities in it's own empires.)

This is what I was thinking too.

Is another group of features going to potential involve automation with the 'trade screens' as well?

I like the way this is sounding, very excited!

That's the idea, the question is how much will it take away from the player's involvement. The current state of the Auto Trader I believe is adding to the game as it is quite a pain to do all that manually for the same results. And I think adding the ability for the Trader's to Buy goods will add to the game as well as this is a pain as well trying to find where Sheep are and manually sending your Trader's to buy them to supply your cities.

Should automated traders be able to export to trade screens?
Should automated traders be able to buy yields? Using an import trader threshold, the automated traders could be made to steadily obtain ore or similar useful yields. That would be quite useful in the unlucky case where you can't produce everything yourself.

First question is still in debate, but I think yes on second question. I like your posted ideas on the Trader Threshold. What to do about that was something brewing in the back of my mind but I haven't put any thought into it. But, your pretty much posted a brilliant idea on it. Is that something you'll be able to work on as that may be the next thing I'd like to see done as it ties into the Trader's buy goods from Cities.

Still wondering what to do about a user interface. We talked earlier about moving the city code to a python file of its own. Maybe that would be the best option because that would (likely) allow us to make "tabs" where we keep the top bar and yields at the bottom while everything in between can be replaced with a number of different setup "windows".

I guess with play testing we can decide if something extra needs done.



The vanilla AI code will make the AI build "the best" type of route between all the cities it own. The best is greatly simplified and might not be clever enough to figure out all XML setup options. However plotgroups don't care for "the best", only that the cities are connected, which mean for this purpose the AI works well.

The AI will however not build roads to connect to foreign cities and/or natives. We can deal with that later.

Yes, this is something I want to address with this so I'll be looking into improving the AI. I also want to get Natives to improving their city plots with Roads and other applicable improvements.
 
I don't think providing automations will remove player involvement, for one if a player wants to be that involved he can just not push the button! :D

Secondly I think it changees the nature of the players involvement, again it moves from Micro-Management to Macro-Management.

A king doesn't accompany his traders and looks over their shoulder on every 'distant voyage' he says "we have 1000 gold and 100 wine, we need spice! Bring me Spice!!" then underlings go off and make it happen.

You still define the overall state of things, what comes in and what goes out, and you only need to intervene when it is not working.

In essence you build the economic model you want or think is right, then let it go and see if it works while you focus on the next problem, like building a new sheep farm!

These kinds of things will become increasingly important as it moves towards the WHM goal, of many trade screens and many continents and many cities etc. you decide what resources get applied where, then the underlings go about it.

You send out 12 ships with all the wine you make to travel the south america route to bring back well south americy things... and 12 workers to build your domestic road network.

You just don't have to go down there and load all the ships and point to each worker saying, "build road there, then build road there, ok now build road...mmmm there!" You say "I want my cities to be connected by pretty roads! You 3, go make me roads!"
 
I hesitate a little to code a new threshold. The issue is the GUI. The only thing I can think of is adding a new spinbutton to import/export. That is... not that great to say the least. Sure we can improve on it later, but later being 2020? 2071?

Other than that, adding a new array and make it update in network games seems fairly trivial.

The thing is, this threshold is something I may want with this pretty soon so I maybe adding it myself with a little spinner perhaps to start with. I haven't thought through what all concepts that will go into AI Traders Buying goods but this threshold seems to fit well.




The thing is, as soon as something is in game, it begins to shoot up the priority list for 'make it better'.

Otherwise it jsut sort of floats in the realm of maybe, sort of, could do, kinda.

Exactly, I've started on this and aim to see it through. The whole mod itself as well.:goodjob:
 
M:C as in only the xml branch? I thought I pushed them all, I'll do that here in a few. I won't start coding again until Thursday.


Edit: Yeah, I just pushed everything again but when I look at SourceForge I don't see the Python or SourceDLL, that's not right correct?
 
I added a trader threshold setting to the import/export window (city screen).

I added an array to CvCity and included it in savegames. The only real issue was altering the setting. Right now everything from the import/export window is send using TASK_YIELD_TRADEROUTE. However all ints in that command is already in use. I started writing a new task, but realized it would be way better to keep the code together with the rest of the settings from that window. I came up with this:

One of the bools are now called bAltSettings. When it's false, it sends the vanilla settings+feeder status. Nothing new there.

However when bAltSettings is true, the new behavior is this:
eYield and iLevel is always included.
The 3 remaining bools are used as an int, which provides 8 combos.

This effectively allows us to add the ability to set no less than 8 yield arrays without adding new tasks. We currently use 2 meaning we have remaining room for an additional 6 with very minimal coding.

Trader threshold is accessed through these commands:
Code:
int getTraderThreshold(YieldTypes eYield) const;
bool hasTraderThreshold() const;
The first is obvious while the second tells if one or more yields have a non-default setting. It can be used for code like
Code:
if (pCity->hasTraderThreshold())
{
    loop yields and check pCity->getTraderThreshold()
While the output is the same, the performance isn't. There is no need to spend time looping all yields if we know the answer before looping.

Writing to the variable can only be done through TASK_YIELD_TRADEROUTE, hence it will have to go through the window (unless you code a lot to access it).
 
Was you able to access the sourceDLL for the AI_Trader branch, If so why does it not appear in SourceForge?
It's present in git and it works just fine. However last time I tried using SF's homepage, they ran in failsafe mode due to severe backend problems and only the most basic functions were working.

SF looks fine now and AI_Trader is present in the code modules.
 
Ok. Well, we really could use a new interface for this and the import/export altogether, like it's a hassle to have to find a yield that you want to export in the popup menu. We could add a right click menu for each yield like we mentioned before. We could also add buttons to each yield for certain tasks. Like an import/export button, Click it once the Yield is imported, twice exported, the third time turns it off again. That would go well with the right click menu for Transport Units. You could click to set Lumber to import, switch Cities and set Lumber to export, right click a Unit and set it this new Trade Route.
 
That sounds like a fairly solid idea.

Being able to quickly sweep across the yields and set them to feeder would be nice.

When I set up my transport network, I set all my unit producing yields like armour, weapons, tools. To import/export to like 100 then just let my caravans auto transport the stuff.

So perhaps it could be something like options to set the value at multiples of say 1 slot of transport capacity so you could quickly set your yield values without having to type in all the numbers and scrolling through the pop up window on every city screen.

Doable?
 
There are plenty of options for making import/export setup easier. We could do something like "copy city X" or even "autoupdate to match city X". To make that even more interesting, city X might not be a real city, just the settings to be cloned by cities.

I also added a consumption multiplier to the window. It's not implemented yet, but the idea is that if we set it to say 5, the computer will look at the buildings. Say there are 2 carpenter slots and each unit consumes 3 lumber each turn. This gives 2 units* 3 yields * 5 turns = 30 lumber. That will then be the setting for feeder service. Say we improve the lumber mill and it now has 3 slots. The threshold will then become 3*3*5=45 lumber. You didn't alter anything. It was just based on expected increased consumption.

My plan lacks some details, but that's the general idea. While it sounds useful, it will totally rule for the AI as it will unlock having blacksmith in one city and ore mining in another. Essentially it is a feature designed for the AI, but it should also be accessible in the GUI for human player automation if the player wants that.

Right click actions sounds like a good idea. How about making right click open a popup window. This mean that the right click should be detected in python and then call the window code in the DLL (like the import/export buttons, except it's right click). If the yield is then given as argument, the window can contain all options for that yield only. That will provide plenty of room as it doesn't matter if we use 2 or 4 lines for that yield and the DLL windows are rather easy to handle. We also have the backend (variable update through network) more or less written already as it is the same as for the current window.

I would still like some full screen python window to give overview and orders for yield handling.
 
Ok, right clicking now brings up a single yield popup with all the current options. Now we still have other mouse options. The Yield Icons where only set to react to Drag and Drop in the DLL but the other options are easily added, we have available...

Right Click: Brings up Yield Options menu (the newest feature)
Left Click: Unassigned
Double Click: set the Yield to sell on Market if able (Note: this is tied to left or right clicks and not sure if it can be separated)
Shift-Right Click: Unassigned
Shift-Left Click: Unassigned
Then Alt, Ctrl clicks as well with multiple combinations.

What are all our current Yield Option:

Set/Remove Import
Set/Remove Export
Set Threshold
Set Trader Threshold
Set to sell on Market
Consumption Multiplier (which btw, sounds like a really cool addition)

Did I miss anything? Perhaps as I suggested we could use the Left Clicks to set to Import/Export with each click changing the status. A little icon could then appear letting you know what status the Yield has.

Shift Left Click could be used to set the Threshold by 10 units, Ctrl by 100 Units(was something like this what you requested Lib?) then Alt to remove 10 Units, Shift+Alt to reset to 0, etc. This number could be displayed in the above mentioned Import/Export icon, and at the least in mouse hover yield help text. Shift Double Clicks could be used to set the Trader Threshold but this info would need to be displayed somewhere on the Resource Bar so you would know what the current setting is. We may be starting to get too much info in one small Yield Box. Anyway, any thoughts on this?

Edit: Here is an idea for the Shift Clicks, when you Shift Click text will appear somewhere on the screen letting you know what option you are modifying, for what Yield, and how much of a change was made, Like "Wine Threshold +10". Then after a few seconds that you do not click a Yield the text goes away.

Also, perhaps when you hold Alt key text appears over the Yields detailing what the Thresholds are.
 
Top Bottom