Exemple #1
0
def initFreeOrionAI():  # pylint: disable=invalid-name
    """Called by client when Python AI starts, before any game new game starts or saved game is resumed."""
    ai_config = fo.getAIConfigStr()
    print "Initialized FreeOrion Python AI with ai_config string '%s'" % ai_config
    user_dir = fo.getUserDataDir()
    print "Path to folder for user specific data: %s" % user_dir
    print(sys.path)
Exemple #2
0
def initFreeOrionAI():  # pylint: disable=invalid-name
    """Called by client when Python AI starts, before any game new game starts or saved game is resumed."""
    ai_config = fo.getAIConfigStr()
    print "Initialized FreeOrion Python AI with ai_config string '%s'" % ai_config
    user_dir = fo.getUserDataDir()
    print "Path to folder for user specific data: %s" % user_dir
    print(sys.path)
Exemple #3
0
def _get_timers_dir():
    try:
        if os.path.isdir(fo.getUserDataDir()) and not os.path.isdir(TIMERS_DIR):
            os.makedirs(TIMERS_DIR)
    except OSError:
        sys.stderr.write("AI Config Error: could not create path %s\n" % TIMERS_DIR)
        return False

    return TIMERS_DIR
Exemple #4
0
def _get_timers_dir():
    try:
        if os.path.isdir(fo.getUserDataDir()) and not os.path.isdir(TIMERS_DIR):
            os.makedirs(TIMERS_DIR)
    except OSError:
        sys.stderr.write("AI Config Error: could not create path %s\n" % TIMERS_DIR)
        return False

    return TIMERS_DIR
Exemple #5
0
        def wrapper(*args, **kwargs):
            base_path = os.path.join(fo.getUserDataDir(), 'profiling')
            path = os.path.join(base_path, foAI.foAIstate.uid)

            pr = cProfile.Profile()
            pr.enable()
            start = time.clock()
            result = function(*args, **kwargs)
            end = time.clock()
            pr.disable()
            print "Profile %s tooks %f s, saved to %s" % (function.__name__, end - start, path)
            s = StringIO.StringIO()
            ps = pstats.Stats(pr, stream=s).strip_dirs().sort_stats(sort_by)
            ps.print_stats()

            if not os.path.exists(base_path):
                os.makedirs(base_path)
            with open(path, 'a') as f:
                f.write(s.getvalue())
                f.write('\n')

            return result
Exemple #6
0
        def wrapper(*args, **kwargs):
            base_path = os.path.join(fo.getUserDataDir(), 'profiling')
            path = os.path.join(base_path, foAI.foAIstate.uid)

            pr = cProfile.Profile()
            pr.enable()
            start = time.clock()
            result = function(*args, **kwargs)
            end = time.clock()
            pr.disable()
            print "Profile %s tooks %f s, saved to %s" % (function.__name__,
                                                          end - start, path)
            s = StringIO.StringIO()
            ps = pstats.Stats(pr, stream=s).strip_dirs().sort_stats(sort_by)
            ps.print_stats()

            if not os.path.exists(base_path):
                os.makedirs(base_path)
            with open(path, 'a') as f:
                f.write(s.getvalue())
                f.write('\n')

            return result
Exemple #7
0
from character.character_module import Aggression
from character.character_strings_module import get_trait_name_aggression, possible_capitals

main_timer = AITimer('timer', write_log=True)
turn_timer = AITimer('bucket', write_log=True)

using_statprof = False
try:
    import statprof
    # statprof.start()
    # using_statprof = True
except ImportError:
    pass


user_dir = fo.getUserDataDir()
debug("Path to folder for user specific data: %s" % user_dir)
debug('Python paths %s' % sys.path)


diplomatic_corp = None


def startNewGame(aggression_input=fo.aggression.aggressive):  # pylint: disable=invalid-name
    """Called by client when a new game is started (but not when a game is loaded).
    Should clear any pre-existing state and set up whatever is needed for AI to generate orders."""
    empire = fo.getEmpire()
    if empire is None:
        fatal("This client has no empire. Ignoring new game start message.")
        return
Exemple #8
0
import os
import freeOrionAIInterface as fo
from time import time
from option_tools import get_option_dict, check_bool, DEFAULT_SUB_DIR
from option_tools import TIMERS_TO_FILE, TIMERS_USE_TIMERS, TIMERS_DUMP_FOLDER
import sys

# setup module
options = get_option_dict()

USE_TIMERS = check_bool(options[TIMERS_USE_TIMERS])
DUMP_TO_FILE = check_bool(options[TIMERS_TO_FILE])
TIMERS_DIR = os.path.join(fo.getUserDataDir(), DEFAULT_SUB_DIR, options[TIMERS_DUMP_FOLDER])


def make_header(*args):
    return ['%-8s ' % x for x in args]


def _get_timers_dir():
    try:
        if os.path.isdir(fo.getUserDataDir()) and not os.path.isdir(TIMERS_DIR):
            os.makedirs(TIMERS_DIR)
    except OSError:
        sys.stderr.write("AI Config Error: could not create path %s\n" % TIMERS_DIR)
        return False

    return TIMERS_DIR


class DummyTimer(object):
Exemple #9
0
import os
import freeOrionAIInterface as fo
from common import six
from common.timers import Timer
from common.option_tools import get_option_dict, check_bool, DEFAULT_SUB_DIR
from common.option_tools import TIMERS_TO_FILE, TIMERS_USE_TIMERS, TIMERS_DUMP_FOLDER
import sys

# setup module
options = get_option_dict()

try:
    USE_TIMERS = check_bool(options[TIMERS_USE_TIMERS])
    DUMP_TO_FILE = check_bool(options[TIMERS_TO_FILE])
    TIMERS_DIR = os.path.join(fo.getUserDataDir(), DEFAULT_SUB_DIR, options[TIMERS_DUMP_FOLDER])
except KeyError:
    USE_TIMERS = False


def make_header(*args):
    return ['%-8s ' % x for x in args]


def _get_timers_dir():
    try:
        if os.path.isdir(fo.getUserDataDir()) and not os.path.isdir(TIMERS_DIR):
            os.makedirs(TIMERS_DIR)
    except OSError:
        sys.stderr.write("AI Config Error: could not create path %s\n" % TIMERS_DIR)
        return False
Exemple #10
0
import os
import freeOrionAIInterface as fo
from common.timers import Timer
from common.option_tools import get_option_dict, check_bool, DEFAULT_SUB_DIR
from common.option_tools import TIMERS_TO_FILE, TIMERS_USE_TIMERS, TIMERS_DUMP_FOLDER
import sys

# setup module
options = get_option_dict()

USE_TIMERS = check_bool(options[TIMERS_USE_TIMERS])
DUMP_TO_FILE = check_bool(options[TIMERS_TO_FILE])
TIMERS_DIR = os.path.join(fo.getUserDataDir(), DEFAULT_SUB_DIR,
                          options[TIMERS_DUMP_FOLDER])


def make_header(*args):
    return ['%-8s ' % x for x in args]


def _get_timers_dir():
    try:
        if os.path.isdir(
                fo.getUserDataDir()) and not os.path.isdir(TIMERS_DIR):
            os.makedirs(TIMERS_DIR)
    except OSError:
        sys.stderr.write("AI Config Error: could not create path %s\n" %
                         TIMERS_DIR)
        return False

    return TIMERS_DIR