[Patch] AI debugging facility

Discuss the new AI features ("NoAI") introduced into OpenTTD 0.7, allowing you to implement custom AIs, and the new Game Scripts available in OpenTTD 1.2 and higher.

Moderator: OpenTTD Developers

Post Reply
User avatar
Bilbo
Tycoon
Tycoon
Posts: 1710
Joined: 06 Jun 2007 21:07
Location: Czech Republic

[Patch] AI debugging facility

Post by Bilbo » 30 Apr 2009 20:31

I created patch to aid with AI debugging.

It adds console command debug_ai - first parameter is number of company, or "c" for current company, rest of the prameters are the debugging parameters.

The command will call Debug() method in the main AI class, passing rest of the parameters as specified on the commandline as strings.

for example,

Code: Select all

ai_debug 1 p1 blah
will call

Code: Select all

Debug("p1","blah");
on AI controller in first company.

It also adds alias "ad", that will call "debug_ai c" and pass the rest of the parameters - intended usage of the alias is that you use cheat to switch to company you wish to debug and they you type just "ad" in console to save some keystrokes.

Some example of how the Debug() function may look like:

Code: Select all

 function Debug(...) {
  if (vargc<1) {
    print("Need at least one parameter")
    return;
  }
  print("Debug called");
  for(local i = 0; i< vargc; i++) print("parameter "+i+" = "+vargv[i]);
 }
What the Debug() call will actually do is up to the AI author - it can print out some of its variables, test something, run some internal debugging, change its settings in runtime, whatever ...

Advantage is, that AI using these debug features can run even with unpatched OpenTTD without any modifications - you just won't be able to take advantage of calling the Debug() function...

Planned future improvements:

Print return value in console (so you can see response in the game console, which could be slightly more comfortable than having the AI debug console with the target AI opened)

So .... what are your oppinions about this patch?

Edit: update to newest trunk
Attachments
ai_debug-16188.patch
(3.83 KiB) Downloaded 258 times
ai_debug-19627.patch
(3.59 KiB) Downloaded 195 times
Last edited by Bilbo on 14 Apr 2010 14:09, edited 1 time in total.
If you need something, do it yourself or it will be never done.

My patches: Extra large maps (1048576 high, 1048576 wide) (FS#1059), Vehicle + Town + Industry console commands (FS#1060), few minor patches (FS#2820, FS#1521, FS#2837, FS#2843), AI debugging facility

Other: Very large ships NewGRF, Bilbo's multiplayer patch pack v5 (for OpenTTD 0.7.3)

Morloth
Transport Coordinator
Transport Coordinator
Posts: 378
Joined: 07 Feb 2008 14:06
Location: Glasgow

Re: [Patch] AI debugging facility

Post by Morloth » 30 Apr 2009 22:53

Hi Bilbo,

I like this patch. I haven't check it yet, but I like the idea. It will make development a lot easier this way, at least it will limit the time spend searching / diagnosing a torrent of prints to the debug window. I'm not sure if it's such a good idea to print the data in the command window, the debug screen has the advantage of having a scroll bar which is very convenient for reading through your logs.

Nice work :)!

User avatar
Bilbo
Tycoon
Tycoon
Posts: 1710
Joined: 06 Jun 2007 21:07
Location: Czech Republic

Re: [Patch] AI debugging facility

Post by Bilbo » 01 May 2009 09:01

The plan is that command will print the return value (if any) - so it will be up to AI author where will the debug info end up (AI console, regular console, or maybe both :) If the function won't return anything, nothing will be printed.

Note that you can scroll the console too (Shift+pageup, shift+ pagedown, shift+up, shift+down), so I don't think not having scroollbars is any issue :)
If you need something, do it yourself or it will be never done.

My patches: Extra large maps (1048576 high, 1048576 wide) (FS#1059), Vehicle + Town + Industry console commands (FS#1060), few minor patches (FS#2820, FS#1521, FS#2837, FS#2843), AI debugging facility

Other: Very large ships NewGRF, Bilbo's multiplayer patch pack v5 (for OpenTTD 0.7.3)

User avatar
Bilbo
Tycoon
Tycoon
Posts: 1710
Joined: 06 Jun 2007 21:07
Location: Czech Republic

Re: [Patch] AI debugging facility

Post by Bilbo » 14 Apr 2010 14:11

I've updated the patcdh to newest trunk (r19627).
Get the updated patch in the first post.
If you need something, do it yourself or it will be never done.

My patches: Extra large maps (1048576 high, 1048576 wide) (FS#1059), Vehicle + Town + Industry console commands (FS#1060), few minor patches (FS#2820, FS#1521, FS#2837, FS#2843), AI debugging facility

Other: Very large ships NewGRF, Bilbo's multiplayer patch pack v5 (for OpenTTD 0.7.3)

Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 3 guests