[BTS] In game debug mode

jdog5000

Revolutionary
Joined
Nov 25, 2003
Messages
2,601
Location
California
Debug mode is kind of fun and extremely useful for figuring out why the AI has made the choices it has. Many of these comments work without BTS and this mod, but this mod has several customizations to make seeing certain things easier.

WARNING: Debug mode exposes the entire map, all cities and units (including spies). You may not want to do this on a game you intend to keep playing ...

1. With civ closed, open \My Games\BTS\CivilizationIV.ini and on the line CheatCode enter chipotle.

2. Start up civ and load/start a game. You can enter/exit debug mode at any time once the cheat code is entered, doesn't effect saves or anything like that.

Method 1:

3. Press Ctrl-Z to flip between debug mode and normal civ. (thanks Nor Me for the tip)

Method 2: (Python console instructions left for use running automation)

3. Press SHIFT+~ to open the in game Python console. This is a very useful tool for forcing things to happen in game to test them.

4. Type CyGame().toggleDebugMode() into the Python console. This turns debug mode on or off. The game will take a little while to expose the whole map.

5. Press SHIFT+~ to close the Python console.

In debug mode you can get all kinds of internal information on the state of the AI from the map. All civs in the game will show up in the scoreboard and you can see what they're researching. You can enter any city to see what it's doing as well as see every unit and what AI they're running.

In addition, as you move your mouse over the screen you can get extra info by holding down various combinations of CTRL, SHIFT, and ALT. Some particular highlights (some of which are specific to this mod):

  • ALT over owned territory - Strategies the owner is using, their area AI plus info on all wars they are in and what war plan they are using.
  • ALT over land - Values for city founding in that plot for all relevant players plus info on the number of sites an AI has selected in the area. If the plot is one of the selected ones for an AI then a yellow X appears next to the player.
  • CTRL over city - Closeness calculations for city and sum for player/team. Info on num of defenders the AI has/needs.
  • CTRL or SHIFT over unit - Mission and AI the unit is using or stats on the unit.
  • SHIFT and ALT near city - Whether the plot is being worked by the city, values the city assigns to working the plot, plus info on how important various resources are to different AIs.
  • SHIFT over empty owned territory - Values the AI assigns to various civics.
  • ALT over names in scoreboard to show war plans, power values
  • CTRL over names in scoreboard to show break down of score (like what you get mousing over your own name)

There are other bits of info as well, play around with various combinations. If you are curious what a particular value means for the AI you can search in CvGameTextMgr.cpp ... most label strings like "Closeness" or whatever are not loaded from XML so you can search for what you see to located the relevant selection in the code.

In addition, BBAI has added some colored circles to the map in Debug mode to help understand what the AI is up to. Right after starting Debug mode you have to click on a different unit or city to get the circles to show up the first time. The locations the AI has picked out for future city sites are shown in circles of the AI's color, although when these circles coincide only one color is shown. Tiles where the AI wants to place a new or different improvement are circled in red.

Finally, this mod includes AIAutoPlay and using it you can have the AI play for you to fully simulate the game. This can be run independently of debug mode, when not in debug mode you'll see only what one player sees. Open the Python console and enter CyGame().setAIAutoPlay(10) to simulate 10 turns.

EDIT: There's also a pretty good writeup about the in game debugging setup from Iustus as well with pictures, though some of the specific information shown doesn't apply to the current BTS AI setup.

EDIT2: An AI logging system has also been added to the mod, read more about how to get logs and how to interpret them below.
 
The python console? What's wrong with Ctrl-Z? That and chipotle works fine for me.

I've ported the Better AI declare war information code to Bts. With it holding alt and mousing over a civ gives the chances of declaring war and start war values. You might find that useful for the changes to AI war code.
 
Right. I tend to fortify my settler and press enter 400 times. That might be an improvement.
 
Do I need anything special installed to access the python console? Shift+~ doesn't seem to do anything, though Ctrl+Z works fine.
 
Do I need anything special installed to access the python console? Shift+~ doesn't seem to do anything, though Ctrl+Z works fine.

Answering my own question: on this UK keyboard, it seems that the key with ' and @ on it opens the python console, rather than the #/~ key.
 
One of the useful new features in BBAI 0.82 is an AI decision logging system. The idea behind this was to expose some of the bigger decisions the AI makes each turn so that they can be analyzed and improved, as we've been doing in the First 100 turns thread.

Here's how you can get these same kind of results at home in just three easy steps:

Step 1

You need a DLL that has been compiled with logging enabled. If you want to use just a BBAI DLL, then you can grab the development version of the mod here. The version up there right now is a Release build so it shouldn't be too much slower than the Final_Release version in the main BBAI download. If you are a modder and are building your own DLL with BBAI included, then you'll need to merge in the latest version of BBAI and then compile your mod with /DLOG_AI added to the compilation options. There are also some options in BetterBTSAI.h for controlling how much of different aspects is logged, and of course you can mimic some of the existing log code to add new features.

(I do not believe you need to enable the Civilization IV logging system to get BBAI logs, but in case logging isn't working for you try setting LoggingEnabled = 1 and OverwriteLogs = 1 in your BTS CivilizationIV.ini file)

Step 2

Run a game you want to test using a logging enabled DLL. You can definitely load a save and log the AI decisions from that point forward, or start a new game from scratch.

Step 3

Logging is only as useful as your ability to interpret what's in the log! First things first, the log will be called BBAI.log and located in your My Games/BTS/Logs folder. It's designed to be pretty self explanatory:

Code:
[2032.109] Player 1 (Aztec Empire) setTurnActive for turn 204
[2032.109]     Player 1 (Aztec Empire) has 6 cities, 45 pop, 340 power, 100 tech percent
[2032.125]     Team 1 has met: 0,2,;  at war with: 2,
[2032.125]     Enemy power perc: 116
[2033.125]     Settler heading for best found plot 30, 18
[2034.875]     Team 1 (Aztec Empire) acquires tech Optics
[2034.890]     City Tenochtitlan finishes production of building Shwedagon Paya
[2034.890]       City Tenochtitlan pop 11 considering new production: iProdRank 1, iBuildUnitProb 58
[2034.890]     City Tenochtitlan pushes production of unit Spy with UNITAI spy

So, this section of the log is from the Aztec Empire's turn on turn 204. The numbers to the left I believe are the time at which the lines are logged in seconds relative to when Civ was started, or something like that. The first couple lines for each turn give some statistics about the empire, so the Aztecs have 6 cities with a total population of 45, their power score is 340 and they are the tech leader. Tech percent is the percentage of the best known tech score that the player has, so 80% would mean the player was kind of behind in tech.

Next we see that the Aztecs have met players 0 and 2, and they're currently at war with player 2. Enemy power percent is a comparison of the relative power of this player's enemies to the enemies of this player's enemies ... so, 50% would mean that player 2 has only has half as much power as the Aztecs and anyone else player 2 is at war with. In this case the score is 116%, so the Aztecs are a little outgunned but nothing to be too scared about.

In the middle of the turn log will be any important unit decisions or consequences of unit actions. In this case, the Aztecs have a settler who is moving towards a city location. There are very few unit actions which are logged, so often there will be nothing from units.

The last section of information from this turn are the player and city level AI decisions made after units have moved. First we see that on this turn the Aztecs acquire Optics, they will pick their next tech on their next turn. Tenochtitlan finishes a building and decides to train a spy next. Not surprisingly, Tenochtitlan is the top ranked production city in the Aztec empire. Because Monte is a unit fiend and the Aztecs are at war, Tenochtitlan has a 58% chance of building a unit if it gets to the probabilistic building code ... much of the time city build decisions are made using special cases before the probabilistic decisions and sometimes there will be a note about which case was used. Note that city production finishes at the very end of a turn, so a unit completed on turn 204 won't be available to give orders to until turn 205.

The logging system is new so it doesn't log everything, there are a number of things I intend to add. If there are some particular decisions you really want to see included, ask or try your hand at adding it yourself.

Enjoy!
 
Are you using a Makefile? If so then you would be adding it in there. Look for something like:

Debug_GLOBAL_CFLAGS=

and make it:

Debug_GLOBAL_CFLAGS= /DLOG_AI

This would make it so that a Debug build is built with logging enabled. You would need to do similar things for Final_Release builds.

If your setup doesn't have that line in it, you could search for /D_USRDLL and add /DLOG_AI after it where it appears.
 
I'm still having trouble getting the logging to work. Whenever I try to compile I get errors like this for whatever files I have logging code in:

Code:
1>CvCityAI.obj : error LNK2019: unresolved external symbol "void __cdecl logBBAI(char *,...)" (?logBBAI@@YAXPADZZ) referenced in function "public: virtual void __thiscall CvCityAI::AI_chooseProduction(void)" (?AI_chooseProduction@CvCityAI@@UAEXXZ)

I have the include text in place, and the two BetterBTSAI files are in the project, so I'm not sure what's going on. Do I need to do something special to have it compile the code from the BetterBTSAI files?
 
Debug_GLOBAL_CFLAGS= /DLOG_AI

OK. I'm trying this again. Both the BETTER AI .cpp and .h files are being compiled now. I have the /DLOG_AI flag set in my makefile, when I start the game and mouseover the nation flag, it says that AI logging is turned on, but yet I see no log anywhere. I assume it would be in the Logs folder?
 
Whenever I open civ, the file changes back to CheatCode = 0, and pressing CTRL-Z or Shift+~ does nothing. Saving the file normally works fine, I can close it and open it and it still says CheatCode = chipotle. But when I open civ it resets.

EDIT: Nevermind, I was trying to change the .Bak (Backup) file instead of the actual .ini file. It works now.
 
Top Bottom