FreeOrion

Forums for the FreeOrion project
It is currently Mon Jul 23, 2018 5:18 pm

All times are UTC




Post new topic Reply to topic  [ 15 posts ] 
Author Message
PostPosted: Thu Feb 12, 2015 10:58 pm 
Offline
AI Contributor
User avatar

Joined: Tue Jun 24, 2014 9:55 pm
Posts: 448
This patch allow to run interactive console in AI python environment.

I suggest to turn it on by default for test builds.

Usage:
enter help in chat
enter start 2
enter print fo.getEmpire().name
See screenshoot example https://drive.google.com/file/d/0B12sy1 ... FjVE0/view

PS. it is possible to use remote debugger:
It allow to inspect all variables in global scope and have interactive console.

PyDev
http://pydev.org/manual_adv_remote_debugger.html
http://stackoverflow.com/questions/25018869/pydev-how-to-invoke-debugging-specific-command-from-console-with-breakpoints/25065948#25065948 wrote:
Note that if you want to use the interactive console in the context of a breakpoint, a different approach would be selecting a stack frame (in the debug view) > right-clicking it > pydev > Debug Console (or you can also in the debug view create a new console view connected to the debug session for the same effect).


Attachments:
shell.patch [3.6 KiB]
Downloaded 24 times

_________________
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0
Top
 Profile  
 
PostPosted: Fri Feb 13, 2015 7:56 am 
Offline
Programming, Design, Admin
User avatar

Joined: Wed Oct 08, 2003 1:33 am
Posts: 12237
Location: Munich
Pretty neat, and seemingly useful. Seems to work for me. Nice that it's just an AI .py file change.

It's a bit awkward to have to send it to a particular AI, though... For me, only AI_5 responds to "help", and messages sent directly to one of the others get no response. (Click an AI name in the empires list to specify chat message recipients...)

Also, the list of AI ids is coloured, seemingly to better identify them. But the AI colours in the list of ids doesn't match the corresponding AI names, which is a bit weird... so perhaps it would be useful to also include the AI name in the list of IDs to make it clear that the number in an AI name isn't the same as its "debug" id?

It would also be preferable to have the debug init chat messages be looked up in the stringtable before being sent to the player.

Can you use this mechanism to force an AI to issue an order (or send an arbitrary chat message or diplomacy message)? A means to tell the debugged AI to not end its turn as soon as possible, or to otherwise interrupt the next normal turn-playing-in-response-to-server-update sequence would be useful.


Top
 Profile  
 
PostPosted: Tue Feb 17, 2015 9:52 pm 
Offline
AI Contributor
User avatar

Joined: Tue Jun 24, 2014 9:55 pm
Posts: 448
Geoff the Medio wrote:
Pretty neat, and seemingly useful. Seems to work for me. Nice that it's just an AI .py file change.

It's a bit awkward to have to send it to a particular AI, though... For me, only AI_5 responds to "help", and messages sent directly to one of the others get no response. (Click an AI name in the empires list to specify chat message recipients...)

Chat sends messages to all AI but only first response. AI did not know if chat to all or only for him.

Quote:
Also, the list of AI ids is coloured, seemingly to better identify them. But the AI colours in the list of ids doesn't match the corresponding AI names, which is a bit weird... so perhaps it would be useful to also include the AI name in the list of IDs to make it clear that the number in an AI name isn't the same as its "debug" id?
OK, chat dialog looks strange. I don't like that AI_? in it.

Quote:
It would also be preferable to have the debug init chat messages be looked up in the stringtable before being sent to the player.

I don't expect to see it release build. So why it should be translated?

Quote:
Can you use this mechanism to force an AI to issue an order (or send an arbitrary chat message or diplomacy message)? A means to tell the debugged AI to not end its turn as soon as possible, or to otherwise interrupt the next normal turn-playing-in-response-to-server-update sequence would be useful.
I think it is has same rights as generateOrders but triggers form other place. I expect, you can call any code from freeOrionAIInterface. I expect that then you call chat generateOrders is already finished. You can change variable in chat and access it in generateOrders.

upd. patch attached


Attachments:
shell_v2.patch [4.05 KiB]
Downloaded 21 times

_________________
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0
Top
 Profile  
 
PostPosted: Tue Feb 17, 2015 11:07 pm 
Offline
Programming, Design, Admin
User avatar

Joined: Wed Oct 08, 2003 1:33 am
Posts: 12237
Location: Munich
Cjkjvfnby wrote:
Chat sends messages to all AI but only first response. AI did not know if chat to all or only for him.
It might be indicated by the recipient ID of the message... if it's -1, then it might have been sent to all... (not sure about this, though...)
Quote:
I don't expect to see it release build. So why it should be translated?
non-english speakers might want to debug AI scripts. I would probably put this in the release... if people want to cheat by manipulating the AI, they already can.
Quote:
I expect that then you call chat generateOrders is already finished.
Yes, the AI would likely already have finished its turn by the time it got an interactive debug chat message. I meant could it set up to easily tell the AI script to wait on the next turn and not issue orders or end its turn until told to do so.


Top
 Profile  
 
PostPosted: Tue Feb 17, 2015 11:57 pm 
Offline
AI Contributor
User avatar

Joined: Tue Jun 24, 2014 9:55 pm
Posts: 448
Geoff the Medio wrote:
Cjkjvfnby wrote:
Chat sends messages to all AI but only first response. AI did not know if chat to all or only for him.
It might be indicated by the recipient ID of the message... if it's -1, then it might have been sent to all... (not sure about this, though...)

Message is used for diplomatic orders this get just int and str def handleChatMessage(senderID, messageText)


Quote:
Quote:
I don't expect to see it release build. So why it should be translated?
non-english speakers might want to debug AI scripts. I would probably put this in the release... if people want to cheat by manipulating the AI, they already can.
Ok.

Quote:
Quote:
I expect that then you call chat generateOrders is already finished.
Yes, the AI would likely already have finished its turn by the time it got an interactive debug chat message. I meant could it set up to easily tell the AI script to wait on the next turn and not issue orders or end its turn until told to do so.


If you want to open console inside generatingOrders you need to use remote debuger (see end of first post)

You can replace one generateOrder to another but you will not get interactive console inside it via chat.

_________________
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0


Last edited by Dilvish on Wed Feb 18, 2015 12:42 am, edited 1 time in total.
fixed quote markers


Top
 Profile  
 
PostPosted: Wed Feb 18, 2015 8:55 am 
Offline
Programming, Design, Admin
User avatar

Joined: Wed Oct 08, 2003 1:33 am
Posts: 12237
Location: Munich
Cjkjvfnby wrote:
You can replace one generateOrder to another but you will not get interactive console inside it via chat.
OK, but could you set a flag so that after the next time generateOrders runs, it doesn't end turn, so that the player could interactively control the AI via chat?

Not sure if you do this already, but if the AI is running on a computer with a graphical interface, can it generate its own window to use as an interactive console from within Python code (independent of the Ogre or SDL windows)?


Top
 Profile  
 
PostPosted: Wed Feb 18, 2015 12:32 pm 
Offline
AI Contributor
User avatar

Joined: Tue Jun 24, 2014 9:55 pm
Posts: 448
Geoff the Medio wrote:
Cjkjvfnby wrote:
You can replace one generateOrder to another but you will not get interactive console inside it via chat.
OK, but could you set a flag so that after the next time generateOrders runs, it doesn't end turn, so that the player could interactively control the AI via chat?
I think yes, but need to check it.

Quote:
Not sure if you do this already, but if the AI is running on a computer with a graphical interface, can it generate its own window to use as an interactive console from within Python code (independent of the Ogre or SDL windows)?
I will try to find info if it easy to do. It is not exactly what you ask, but have similar effect: http://pydev.org/manual_adv_remote_debugger.html

_________________
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0


Last edited by Vezzra on Wed Feb 18, 2015 1:02 pm, edited 1 time in total.
Fixed quotation tag


Top
 Profile  
 
PostPosted: Tue Mar 03, 2015 11:18 am 
Offline
Programming, Design, Admin
User avatar

Joined: Wed Oct 08, 2003 1:33 am
Posts: 12237
Location: Munich
Cjkjvfnby wrote:
upd. patch attached
committed

Edit: Is there any way to do multi-line python commands via chat? For example, doing a for loop that prints something for each value of the loop variable? I tried prepending my chat commands with spaces to indicate the loop body, but I think it's stripping the leading whitespace. Would this work if that wasn't removed?


Top
 Profile  
 
PostPosted: Thu Mar 05, 2015 7:55 pm 
Offline
AI Lead, Programmer
User avatar

Joined: Sat Sep 22, 2012 6:25 pm
Posts: 4683
Geoff the Medio wrote:
Edit: Is there any way to do multi-line python commands via chat? For example, doing a for loop that prints something for each value of the loop variable?
Although not commonly used, semicolons can be used to separate python commands:
Code:
 for n in [1,2,3]: print "n: %d" % n; print "and now n-squared: %d" % (n*n)

_________________
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0


Top
 Profile  
 
PostPosted: Thu Mar 05, 2015 11:30 pm 
Offline
AI Contributor
User avatar

Joined: Tue Jun 24, 2014 9:55 pm
Posts: 448
Dilvish wrote:
Geoff the Medio wrote:
Edit: Is there any way to do multi-line python commands via chat? For example, doing a for loop that prints something for each value of the loop variable?
Although not commonly used, semicolons can be used to separate python commands:
Code:
 for n in [1,2,3]: print "n: %d" % n; print "and now n-squared: %d" % (n*n)


I will make examples with reload and execfile when back from my trip.

_________________
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0


Top
 Profile  
 
PostPosted: Wed Mar 11, 2015 9:54 pm 
Offline
AI Contributor
User avatar

Joined: Tue Jun 24, 2014 9:55 pm
Posts: 448
I update wiki section.
http://freeorion.org/index.php/Python_D ... #Debugging

_________________
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0


Top
 Profile  
 
PostPosted: Wed Mar 11, 2015 11:39 pm 
Offline
AI Lead, Programmer
User avatar

Joined: Sat Sep 22, 2012 6:25 pm
Posts: 4683
Cjkjvfnby wrote:
I update wiki section.
It's a start, but I think it needs a fair bit more clarification (and probably we should make the operation more straightforward). For example, simply typing 'help' into the chat window currently appears to do nothing unless AI_1 is selected in the empires window, and if one then simply follows the instructions to try to debug a different AI without having changed the selection in the empires window then again nothing happens. It could be that instead of giving more info on how it needs to interact with the empires window we should instead have the AIs also check messages which get sent to 'ALL_EMPIRES' as you briefly considered above. If "help" gets sent to all empires, then just the first AI responds, and if 'start #' gets sent to all empires then that AI responds and thereafter that AI will consider all chat to all empires to be (potential) debugging commands to itself until it gets a 'stop'

I also think that the entire thing should be described right there in the Internal Debugging section, rather than just mentioning it and then referring them down to Tips and Tricks. This section should also include some description/examples of what can be done with the local vars u,e, and ai.

_________________
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0


Top
 Profile  
 
PostPosted: Sun Jun 17, 2018 7:47 am 
Offline
Programming, Design, Admin
User avatar

Joined: Wed Oct 08, 2003 1:33 am
Posts: 12237
Location: Munich
Is this broken currently? I'm not having any success trying to start the debugging in the chat...

Or perhaps I'm just not getting any AI chat?

Edit: Seems to only be an issue with the first AI... with 2, the second has working chat messages, but still doesn't respond to "help" or "start 0" or "start 1" or similar chat messages. /Edit

Messages in Game wrote:
Creating AI Clients
Generating Universe
Begin Turn 1
Saving...
Saved 43127 bytes to file: C:\Users\Geoff\AppData\Roaming\FreeOrion\save\auto\FreeOrion_Human_Player_Terran_0001_20180617_094100.sav
[17 Jun 09:41:01] AI_1: Affiliation (Turtle):
[17 Jun 09:41:12] Human_Player: help
[17 Jun 09:41:23] Human_Player: test
[17 Jun 09:41:24] Human_Player: debug
[17 Jun 09:43:33] Human_Player: help
[17 Jun 09:44:14] Human_Player: start 1
[17 Jun 09:44:17] Human_Player: start 0
[17 Jun 09:44:18] Human_Player: start 2
[17 Jun 09:44:21] Human_Player: print "test"

AI_1.log wrote:
09:41:01.884209 [debug] python : DiplomaticCorp.py:85 - Received diplomatic status update to war about empire 2 and empire 1
09:41:12.265709 [debug] python : DiplomaticCorp.py:90 - Midgame chat received from player 1, message: help
09:41:23.526782 [debug] python : DiplomaticCorp.py:90 - Midgame chat received from player 1, message: test
09:41:24.688324 [debug] python : DiplomaticCorp.py:90 - Midgame chat received from player 1, message: debug
09:43:33.222839 [debug] python : DiplomaticCorp.py:90 - Midgame chat received from player 1, message: help
09:44:14.687801 [debug] python : DiplomaticCorp.py:90 - Midgame chat received from player 1, message: start 1
09:44:17.376070 [debug] python : DiplomaticCorp.py:90 - Midgame chat received from player 1, message: start 0
09:44:18.835064 [debug] python : DiplomaticCorp.py:90 - Midgame chat received from player 1, message: start 2
09:44:21.904235 [debug] python : DiplomaticCorp.py:90 - Midgame chat received from player 1, message: print "test"


Top
 Profile  
 
PostPosted: Sun Jun 17, 2018 10:11 am 
Offline
AI Contributor

Joined: Tue Feb 17, 2015 11:54 am
Posts: 238
It must be activated by an AI config option:
allow_debug_chat=1

You may want to start freeorion using
--ai-config .\default\python\AI\ai_debug_config.ini

_________________
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0


Top
 Profile  
 
PostPosted: Sun Jun 17, 2018 4:19 pm 
Offline
AI Lead, Programmer
User avatar

Joined: Sat Sep 22, 2012 6:25 pm
Posts: 4683
Morlic wrote:
It must be activated by an AI config option:
allow_debug_chat=1

You may want to start freeorion using
--ai-config .\default\python\AI\ai_debug_config.ini

I've now added that info to the Wiki page on the debug mode.

_________________
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 15 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group