[Introduction task] AI building city action immunity value

Do you want to help out with Freeciv development? Then check out this forum.
sveinung
Elite
Posts: 430
Joined: Wed Feb 20, 2013 4:50 pm

[Introduction task] AI building city action immunity value

Postby sveinung » Wed Mar 19, 2014 10:31 pm

I think working on this would be a good way to gain experience in changing Freeciv if you have some of the required skills. Your patch will probably be shorter than this post. I hereby offer to give feed back on your patch, and when (/if) it becomes good enough, add it to Freeciv.

Skills you must learn/have to do this:
  • Playing Freeciv
  • Change a rule set (for testing)
  • Running Freeciv auto games
  • Compile the Freeciv source code
  • Get the source code of Freeciv trunk from SVN
  • A little bit of C coding
  • Create a patch

Background
In Freeciv 2.6 it is possible to create a rule set that has a building that makes a city immune to spy actions like poison, steal a tech and establish an embassy. (In 2.5 and below it is only possible to protect a city against the incite spy action) This is done by editing the action enabler(s) (new concept in Freeciv 2.6) of the spy action you wish the building to block.

The Freeciv AI makes some decisions, like what building to build in a city, based on utility. That is a fancy way of saying that it calculates a number to represent how much it wants a particular building and use that number when deciding what to build next. Support for considering action immunity was just added to the evaluation of buildings.

The task
Your patch will adjust the values representing how bad the AI think it is that one of its cities could become a target of the spy actions poison city, sabotage a random building (/the production), sabotage a specific building (or the production), steal a random tech, steal a specific tech, establish an embassy and investigate the city. The value of incite city may need adjustment too. You can do this in the function action_target_neg_util() in the file ai/default/aicity.c. The goal of adjusting ("balancing") them is to make the AI play better.

Your patch should be for the current trunk branch of Freeciv. When this is done post your patch to patch #4623.

Hints
For some actions it is natural to make the value depend on knowledge about the city it self. The city is given in the parameter pcity. You can get a lot of information from it. (Want to know what techs its owner has? Get the owner from the city and get his list of known techs!) It may also be a good idea to consider other rules/settings like diplchance. (The badness of incite use diplchance)

You will have to test your changes to know your new values actually are better. Run auto games so you won't have to wait for human players to move. Make sure you have loaded the ruleset you modified before starting to test. Make sure you are running the version of Freeciv you just modified. You don't have to install Freeciv again each time you make a change. The script fcser allows you to run the Freeciv server from the folder where you compiled it. The script fcgui allows you to start a client the same way.

To test you changes you will have to modify a rule set. I recommend starting with a copy of the classic ruleset. Action enablers live in the ruleset file game.ruleset. Buildings live in the ruleset file buildings.ruleset. The classic ruleset live in data/classic. To make a building in the target city block an action you must first find all action enablers that enable it. (Classic currently only have one one action enabler for each action) Then find the target_reqs requirement vector. If it don't have one add one. Add the building as a requirement and set present to FALSE.

How to create a patch, get Freeciv trunk from SVN and compile Freeciv is documented online. You can find good introductions to C for the programming skill set you already have by using Google. Try to remember reading your patch before sending it to make sure that test data like ruleset modifications wasn't accidentally included.

Edited 5th June 2015: Freeciv 2.6 isn't trunk any more. Make it clear that trunk, curretnly 3.0, is the main target.
Last edited by sveinung on Fri Jun 05, 2015 4:20 pm, edited 1 time in total.

sveinung
Elite
Posts: 430
Joined: Wed Feb 20, 2013 4:50 pm

Re: [Introduction task] AI building city action immunity val

Postby sveinung » Wed Jun 03, 2015 12:41 pm

Update: The trunk version of Freeciv, currently Freeciv 3.0, has actions that 2.6 is missing. (Example: the new city targeted action Join City) Create your patch for the trunk version of Freeciv. The current trunk is supposed to become Freeciv 3.0.

A back port of your patch is a version of your patch for an older version of Freeciv. Including a back port is nice but not required. There is a risk that your back port won't be used even if the trunk version is used. That risk goes up as the older version becomes more stable.