AI doesn't move at all

Describe your experience with the latest version of FreeOrion to help us improve it.

Moderator: Oberlus

Forum rules
Always mention the exact version of FreeOrion you are testing.

When reporting an issue regarding the AI, if possible provide the relevant AI log file and a save game file that demonstrates the issue.
Message
Author
gvdm
Space Floater
Posts: 43
Joined: Sun Nov 06, 2011 11:04 am

AI doesn't move at all

#1 Post by gvdm »

Recently built 0.4.4 (r7696) to have another go at FO but was dissappointed when the AI never moved any ships (or took any actions at all it would seem) on any of my games. The AI was tried on Maniacal, Aggressive and Typical. What further debug information is needed? Running on Fedora built with libraries from the repos.

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 12801
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: AI doesn't move at all

#2 Post by Geoff the Medio »

gvdm wrote:What further debug information is needed?
AI and server log files to start. Start a new game, play one turn, located and attach the logs to a post.

User avatar
Dilvish
AI Lead and Programmer Emeritus
Posts: 4768
Joined: Sat Sep 22, 2012 6:25 pm

Re: AI doesn't move at all

#3 Post by Dilvish »

please attach one of the AI log files (such as AI_1.log) found in the same directory as config.xml
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

gvdm
Space Floater
Posts: 43
Joined: Sun Nov 06, 2011 11:04 am

Re: AI doesn't move at all

#4 Post by gvdm »

Attached
Attachments
freeorion.log
(341.11 KiB) Downloaded 30 times
freeoriond.log
(260.74 KiB) Downloaded 28 times
AI_1.log
(49.62 KiB) Downloaded 33 times

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 12801
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: AI doesn't move at all

#5 Post by Geoff the Medio »

Is default/AI/timing.py present? Does it contain a definition for Timer?

Does anything change if you delete all the .pyc files that are generated? I'm not sure where these would be on Linux... possibly the same directory as the .py files?

User avatar
Dilvish
AI Lead and Programmer Emeritus
Posts: 4768
Joined: Sat Sep 22, 2012 6:25 pm

Re: AI doesn't move at all

#6 Post by Dilvish »

yes, the AI log makes it very clear what the problem was -- it wasn't able to do one of its imports. I would guess that you may for some reason be missing the default/AI/timer.py file. How did you install/update this installation of FO? Attached is a copy of the timer.py file that should probably work for you (unzip and drop into the default/AI/ folder of your freeorion installation).

If there is still any trouble, please attach a new AI logfile.
Attachments
timing.py.zip
(1.19 KiB) Downloaded 29 times
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

gvdm
Space Floater
Posts: 43
Joined: Sun Nov 06, 2011 11:04 am

Re: AI doesn't move at all

#7 Post by gvdm »

Yep, I came across it as well.

At the beginning I see:
2014-09-07 16:22:22,518 ERROR AI : File "freeorion-code/FreeOrion/default/AI/InvasionAI.py", line 14, in <module>
2014-09-07 16:22:22,519 ERROR AI : from timing import Timer
2014-09-07 16:22:22,520 ERROR AI : ImportError: cannot import name Timer
and later I see AttributeError: 'NoneType' object has no attribute 'generateOrders' and similar for many.

I installed FO via SVN, checked it out, I've also run svn update default/AI/timer.py which did not download it. I do see a timing.py but not a timer.py, timing.py does include the Timer class but I don't know why it isn't imported/found. Something to do with the Python path for libraries maybe?

Nothing changes if all the .pyc files are deleted.

User avatar
Dilvish
AI Lead and Programmer Emeritus
Posts: 4768
Joined: Sat Sep 22, 2012 6:25 pm

Re: AI doesn't move at all

#8 Post by Dilvish »

gvdm wrote:I installed FO via SVN, checked it out, I've also run svn update default/AI/timer.py which did not download it. I do see a timing.py but not a timer.py,
right, the file is timing.py

timing.py does include the Timer class but I don't know why it isn't imported/found. Something to do with the Python path for libraries maybe?
the python path looks fine, and I don't see how a problem with it would lead to this particular problem (other local imports are apparently working fine).

It looks like default/AI/__init__.py is no longer in the repository -- I'll try to track down what happened, and fix it in svn. If you don't have one in your default/AI folder, then just create a blank one such as with

Code: Select all

touch default/AI/__init__.py
and see if that fixes things
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

gvdm
Space Floater
Posts: 43
Joined: Sun Nov 06, 2011 11:04 am

Re: AI doesn't move at all

#9 Post by gvdm »

It looks like default/AI/__init__.py is no longer in the repository -- I'll try to track down what happened, and fix it in svn. If you don't have one in your default/AI folder, then just create a blank one such as with

Code: Select all

touch default/AI/__init__.py
and see if that fixes things
No joy with __init__.py - AI is still bricked.

Any idea why

Code: Select all

from tools import dict_from_map, tech_is_complete
in default/AI/InvasionAI.py is fine but

Code: Select all

from timing import Timer
is not?

Also, is default/AI/InvasionAI.py one of the first or first files to run? Is it the first to try importing Timer? My thinking is to narrow down whether it is a generic issue (just happens to crop up here because it runs first) or an issue with InvasionAI (other places import Timer fine before that) or with Timer (this is the first place to try importing Timer).

User avatar
Dilvish
AI Lead and Programmer Emeritus
Posts: 4768
Joined: Sat Sep 22, 2012 6:25 pm

Re: AI doesn't move at all

#10 Post by Dilvish »

gvdm wrote:No joy with __init__.py - AI is still bricked.
Ah, yeah, I guess it's not needed here because of how the first of these modules gets loaded into python. For some reason in one of my installations there was a /default/AI/__init__.py (but not added to SVN), is what threw me off.
Any idea why

Code: Select all

from tools import dict_from_map, tech_is_complete
in default/AI/InvasionAI.py is fine but

Code: Select all

from timing import Timer
is not?
not yet
Also, is default/AI/InvasionAI.py one of the first or first files to run? Is it the first to try importing Timer?
'No' to the first question, and it looks like 'Yes' to the second. FreeOrionAI.py is the first to be loaded, and although it also includes an import of both InvasionAI and Timer, the import chain first reaches InvasionAI somewhat indirectly vi aAIstate etc. (you can see the full listing of files in as part of the error log in the AI log file).

To explore import sequence issue slightly you could edit FreeOrionAI.py to move line 24 ("from timing import Timer") up to just before line 11 (import AIstate) -- that causes no problem on my system but on yours it may cause the import trouble to be triggered immediately at that point rather than waiting for InvasionAI. (but before you try that check status as mentioned below)

My thinking is to narrow down whether it is a generic issue (just happens to crop up here because it runs first) or an issue with InvasionAI (other places import Timer fine before that) or with Timer (this is the first place to try importing Timer).
The thing is, this seems to be only a problem for you, not anyone else. if you do

Code: Select all

svn status default/AI/
does it give any output?
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

gvdm
Space Floater
Posts: 43
Joined: Sun Nov 06, 2011 11:04 am

Re: AI doesn't move at all

#11 Post by gvdm »

The svn status just shows I added __init__.py and edited FreeOrionAI.py to make below happen, otherwise, it is exactly as SVN repo.

Making FreeOrionAI.py import Timer first makes it throw the error first:

Code: Select all

2014-09-07 20:52:51,940 ERROR AI : Traceback (most recent call last):
2014-09-07 20:52:51,940 ERROR AI :   File "freeorion-code/FreeOrion/default/AI/FreeOrionAI.py", line 11, in <module>
2014-09-07 20:52:51,940 ERROR AI :     from timing import Timer
So, I'm stumped. Seems kinda strange that it is only Timer that has the issue (other stuff in same fir works fine).

User avatar
Dilvish
AI Lead and Programmer Emeritus
Posts: 4768
Joined: Sat Sep 22, 2012 6:25 pm

Re: AI doesn't move at all

#12 Post by Dilvish »

and then that part you quoted is followed by the same "ImportError: cannot import name Timer"?

one thing that might add a small bit of clarity is to change the manner of import -- instead of

Code: Select all

from timing import Timer
perhaps try

Code: Select all

import timing
Timer = timing.Timer
It might possibly give a more informative error message when trying "import timer"

It would be nice to figure this out, but also in the meantime, if you want to just play some, the timer is not actually critical -- in InvasionAI.py you could simply comment out the Timer import and all the lines involving "invasion_timer", and do something similar in the other files that import Timer
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

gvdm
Space Floater
Posts: 43
Joined: Sun Nov 06, 2011 11:04 am

Re: AI doesn't move at all

#13 Post by gvdm »

A little more interesting, I replaced all occurences of

Code: Select all

from timing import Timer
with

Code: Select all

import timing
Timer = timing.Timer
as suggested and this results in

Code: Select all

2014-09-07 22:39:36,989 ERROR AI :   File "freeorion-code/FreeOrion/default/AI/InvasionAI.py", line 16, in <module>
2014-09-07 22:39:36,989 ERROR AI :     Timer = timing.Timer
2014-09-07 22:39:36,990 ERROR AI : AttributeError: 'module' object has no attribute 'Timer'
Any clues forthcoming?

User avatar
Dilvish
AI Lead and Programmer Emeritus
Posts: 4768
Joined: Sat Sep 22, 2012 6:25 pm

Re: AI doesn't move at all

#14 Post by Dilvish »

gvdm wrote:Any clues forthcoming?
well it does seem to get us a little closer. to get some more info please try this: edit timing.py to comment out the line "import freeOrionAIInterface as fo" (just add a '#' at the start of the line). Then at the command line cd to default/AI and then run python, then "import timing" and then "help(timing)" and paste the results here.
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

gvdm
Space Floater
Posts: 43
Joined: Sun Nov 06, 2011 11:04 am

Re: AI doesn't move at all

#15 Post by gvdm »

As follows:

Code: Select all

Help on module timing:

NAME
    timing

FILE
    /home/gvdm/freeorion-code/FreeOrion/default/AI/timing.py

CLASSES
    __builtin__.object
        Timer
    
    class Timer(__builtin__.object)
     |  Methods defined here:
     |  
     |  __init__(self, timer_name, write_log=False)
     |      Creates timer. Timer name is name that will be in logs header and part of filename if write_log=True
     |      If write_log true and timers logging enabled (DUMP_TO_FILE=True) save timer info to file.
     |  
     |  end(self)
     |      Stop timer, output result, clear checks.
     |      If dumping to file, if headers are not match to prev, new header line will be added.
     |  
     |  start(self, section_name)
     |      Stop prev timer if present and starts new.
     |  
     |  stop(self, section_name='')
     |      Stop timer if running. Specify section_name if want to override its name.
     |  
     |  ----------------------------------------------------------------------
     |  Data descriptors defined here:
     |  
     |  __dict__
     |      dictionary for instance variables (if defined)
     |  
     |  __weakref__
     |      list of weak references to the object (if defined)

FUNCTIONS
    make_header(*args)
    
    time(...)
        time() -> floating point number
        
        Return the current time in seconds since the Epoch.
        Fractions of a second may be present if the system clock provides them.

DATA
    DUMP_TO_FILE = False
    TIMERS_DIR = 'timers'

Post Reply