Skip to content
mattsc edited this page Oct 8, 2012 · 9 revisions

It is possible to debug the Freelands grunt rush AI (Fred) by evaluating and/or executing individual CAs from the right-click menu. This mode requires two steps for activation:

  • Variable 'debug_CA_mode' in function 'debug_CA' in file 'lua/eval_exec_CA.lua' needs to be set to 'true'
  • Debug mode needs to be activated
    • This is as a safeguard, we should never be able to get into this mode in normal gameplay. Nevertheless, we should make sure that 'debug_CA_mode=false' is set for any release version.
Important: The CA debugging mechanism only works while the user is in control of Fred's side, that is, Side 1. An error message is displayed otherwise.

Table of Contents

Setting up CA debugging of a new game

This mode is mostly useful for setting up artificial situation in order to test the behavior of a CA under well defined circumstances. To use this mode:

  • Put the game into debug mode, either by starting it from a terminal with the -d option, or by typing ':debug' while in a game
    • This needs to be done before the steps listed below
  • Go through the MP lobby and set up a game with Fred in control of Side 1 in the usual way
  • Any choices can be made for Side 2
    • Side 2 is disabled during the 1-turn activation cycle (see below)
    • After that, control of the side is turned over to the user, so that units of that side can be manipulated both by being in control of the side or with debug commands
  • When starting the game, it first needs to go through a 1-turn activation cycle (see below), after which the turn number is reset to 1.
  • The user then takes control of Side 1 and can start the CA debugging process described below

Setting up CA debugging of a saved game

Important Note: This only works for games played with Fred in control of Side 1 that were started with a version of AI Demos that has the current version of the CA debugger built in (v0.11.2 or later).

  • Simply put Wesnoth into debug mode by one of the methods described above, and load the saved game
  • After loading, the game will go through its 1-turn activation cycle (see below for reasons). Afterward, the turn number will be reset to that of the saved game.

Using CA debugging mode

In CA debugging mode, the user can manipulate Side 1 units with the usual debug commands or simply by moving them around. In addition, there are several right-click menu options available:

  • Evaluate single CA: does just that, and displays the CA evaluation score in the chat window
  • Evaluate and execute single CA: evaluates a CA and executes it if the score is positive
    • Note that some CAs do only one move of the type the CA is responsible for per execution. For example, 'recruit_orcs' recruits one unit or 'zone_control' might only do one attack of the grunt rush (although that can be an attack combination involving several AI units). To see all moves for this CA, simply choose this menu option several times, until it returns a score of zero.
  • Choose CA: choose the CA to be evaluated and/or executed from a menu
    • The choice remains active until it is changed again with the same or another menu option
    • Before this choice is made the first time, evaluation and execution defaults to the 'recruit_orcs' CA
  • Find highest scoring CA: goes through the evaluations of all CAs and displays which of them has the highest score
    • This CA is also selected for evaluation or execution. It is not necessary to use "Choose CA" next in order to evaluate or execute it
    • Note that evaluation of all CAs can take a little bit of time, depending on the situation on the map
  • Play an enitre AI turn: should be self-explanatory
    • A message will be displayed before each CA execution, indicating which CA move is about to be done
    • In some situations, there might be units with moves/attacks left at the end of this. In "real Fred AI" mode, these might still be moved by the RCA AI. This cannot be simulated by the CA debugger.
  • Kill unit under cursor: this option is provided for convenience and is independent of the CA debugging mechanism
  • Reset or display 'self.data' table:
    • Temporary information needed by Fred is stored in the 'self.data' table. Some of this information needs to persist during a turn. This menu option either displays or resets the table to the beginning-of-turn state. This can be useful depending on which type of move is supposed to be tested.
    • The table is automatically reset at the beginning of each turn and when "Play entire AI turn" is chosen.
    • Resetting and displaying the table are combined into one menu option because only 7 custom menu options can be set up.
There are two choices for modifying Side 2 units:
  • Use the debug command options as for Side 1
  • End the Side 1 turn and move them around, then end the Side 2 turn to get control back for Side 1 (Fred's side)
    • Important: CA debugging only works while the user is in control of Side 1

Notes

Reason why the game has to advance through a turn when CA debugging is started:

  • CA executing requires the 'ai' table to be initialized. This only happens when the AI takes control of a side for at least one turn. Thus, the game needs to be advanced through a turn, with Fred's side in AI mode.
During that turn, the following happens:
  • To speed things up, all units (except the leaders) are taken off the map during that turn
  • Gold, units and units stats are reset when side control is handed over to the user
  • The turn number is reset to that of the saved game