コード例 #1
0
def runAIClient(options):
    import time
    import traceback
    import sys
    import os

    # tweak PYTHONPATH
    basepath = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

    sys.path.insert(0, os.path.join(basepath, "client/osci"))

    for item in ("libsrvr", "server/lib"):
        path = os.path.join(basepath, item)
        if os.path.exists(path):
            sys.path.insert(0, path)
            break

    from config import Config

    import osci, random, time
    import ige.version
    from ige import log
    import os, os.path
    import re

    # log initialization
    log.message("Starting Outer Space Client", ige.version.versionString)
    log.debug("sys.path =", sys.path)
    log.debug("os.name =", os.name)
    log.debug("sys.platform =", sys.platform)
    log.debug("os.getcwd() =", os.getcwd())
    log.debug("sys.frozen =", getattr(sys, "frozen", None))

    # create required directories
    if not os.path.exists(options.configDir):
        os.makedirs(options.configDir)

    # client
    import ai_client as client
    from igeclient.IClient import IClientException
    if options.ai:
        try:
            ai = __import__("AIs." + options.ai)
            ai = sys.modules["AIs." + options.ai]
        except:
            # This prints the type, value, and stack trace of the
            # current exception being handled.
            traceback.print_exc()
            raise
    else:
        raise Exception, 'You have to provide AI.'

    import ige.ospace.Const as Const

    import gdata
    # reload is here for multiprocessing support (as the process is used more
    # than once
    reload(client)
    gdata.config = Config(os.path.join(options.configDir, 'ais_dummy'))
    client.initialize(options.server, options)

    import gettext
    tran = gettext.NullTranslations()
    tran.install(unicode=1)

    if options.login:
        login = options.login
    else:
        raise Exception, 'You have to provide login.'

    if options.password:
        password = options.password
    else:
        raise Exception, 'You have to provide password.'

    # first get list of sessions, then iterate over them
    # this is to prevent exceptions flooding logs
    # TODO: make session optional argument for main_ai_pool
    if client.login(options.game, login, password):
        activePositions = client.cmdProxy.getActivePositions()
        client.logout()
        if options.test:
            return True
    else:
        return False

    for playerID, galaxyName, playerType in activePositions:
        if options.galaxies and galaxyName not in options.galaxies:
            continue
        client.login(options.game, login, password)
        client.cmdProxy.selectPlayer(playerID)
        client.updateDatabase()
        try:
            ai.run(client)
        except Exception as e:
            # This prints the type, value, and stack trace of the
            # current exception being handled.
            traceback.print_exc()
            raise e
        client.logout()
コード例 #2
0
def runAIClient(options):
    import time
    import sys
    import os

    # tweak PYTHONPATH
    basepath = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

    sys.path.insert(0, os.path.join(basepath, "client/osci"))

    for item in ("libsrvr", "server/lib"):
        path = os.path.join(basepath, item)
        if os.path.exists(path):
            sys.path.insert(0, path)
            break

    from config import Config

    import osci, random, time
    import ige.version
    from ige import log
    import os, os.path
    import re

    # log initialization
    log.message("Starting Outer Space Client", ige.version.versionString)
    log.debug("sys.path =", sys.path)
    log.debug("os.name =", os.name)
    log.debug("sys.platform =", sys.platform)
    log.debug("os.getcwd() =", os.getcwd())
    log.debug("sys.frozen =", getattr(sys, "frozen", None))

    # create required directories
    if not os.path.exists(options.configDir):
        os.makedirs(options.configDir)

    # client
    import ai_client as client
    import ai_handler
    from igeclient.IClient import IClientException
    if options.ai:
        ai = __import__("AIs." + options.ai)
        ai = sys.modules["AIs." + options.ai]
    else:
        raise Exception, 'You have to provide AI.'

    import ige.ospace.Const as Const

    import gdata
    # reload is here for multiprocessing support (as the process is used more
    # than once
    reload(client)
    gdata.config = Config(os.path.join(options.configDir, 'ais_dummy'))
    client.initialize(options.server, ai_handler, options)

    import gettext
    tran = gettext.NullTranslations()
    tran.install(unicode = 1)

    if options.login:
        login = options.login
    else:
        raise Exception, 'You have to provide login.'

    if options.password:
        password = options.password
    else:
        raise Exception, 'You have to provide password.'

    client.login(options.game, login, password)
    # event loop
    client.updateDatabase()
    ai.run(client)

    client.logout()

    log.debug("Shut down")
コード例 #3
0
ファイル: main_ai.py プロジェクト: ospaceteam/outerspace
def runAIClient(options):
    import time
    import traceback
    import sys
    import os

    # tweak PYTHONPATH
    basepath = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

    sys.path.insert(0, os.path.join(basepath, "client/osci"))

    for item in ("libsrvr", "server/lib"):
        path = os.path.join(basepath, item)
        if os.path.exists(path):
            sys.path.insert(0, path)
            break

    from config import Config

    import osci, random, time
    import ige.version
    from ige import log
    import os, os.path
    import re

    # log initialization
    log.message("Starting Outer Space Client", ige.version.versionString)
    log.debug("sys.path =", sys.path)
    log.debug("os.name =", os.name)
    log.debug("sys.platform =", sys.platform)
    log.debug("os.getcwd() =", os.getcwd())
    log.debug("sys.frozen =", getattr(sys, "frozen", None))

    # create required directories
    if not os.path.exists(options.configDir):
        os.makedirs(options.configDir)

    # client
    import ai_client as client
    from igeclient.IClient import IClientException
    if options.ai:
        try:
            ai = __import__("AIs." + options.ai)
            ai = sys.modules["AIs." + options.ai]
        except:
            # This prints the type, value, and stack trace of the
            # current exception being handled.
            traceback.print_exc()
            raise
    else:
        raise Exception, 'You have to provide AI.'

    import ige.ospace.Const as Const

    import gdata
    # reload is here for multiprocessing support (as the process is used more
    # than once
    reload(client)
    gdata.config = Config(os.path.join(options.configDir, 'ais_dummy'))
    client.initialize(options.server, options)

    import gettext
    tran = gettext.NullTranslations()
    tran.install(unicode = 1)

    if options.login:
        login = options.login
    else:
        raise Exception, 'You have to provide login.'

    if options.password:
        password = options.password
    else:
        raise Exception, 'You have to provide password.'

    # first get list of sessions, then iterate over them
    # this is to prevent exceptions flooding logs
    # TODO: make session optional argument for main_ai_pool
    if client.login(options.game, login, password):
        activePositions = client.cmdProxy.getActivePositions()
        client.logout()
        if options.test:
            return True
    else:
        return False

    for playerID, galaxyName, playerType in activePositions:
        if options.galaxies and galaxyName not in options.galaxies:
            continue
        client.login(options.game, login, password)
        client.cmdProxy.selectPlayer(playerID)
        client.updateDatabase()
        try:
            ai.run(client)
        except Exception as e:
            # This prints the type, value, and stack trace of the
            # current exception being handled.
            traceback.print_exc()
            raise e
        client.logout()
コード例 #4
0
ファイル: ai_main.py プロジェクト: Lukc/ospace-lukc
if not os.path.exists(options.configDir):
    os.makedirs(options.configDir)

# client
import ai_client as client
import ai_handler
from igeclient.IClient import IClientException
if options.ai:
	exec ("import AIs." + options.ai + " as ai")
else:
	raise Exception
from ige.ospace.Const import *

import gdata
gdata.config = Config(os.path.join(options.configDir, 'ais_dummy'))
client.initialize(options.server, ai_handler, options)

import gettext
tran = gettext.NullTranslations()
tran.install(unicode = 1)

if options.login:
	login = options.login
else:
	raise Exception, 'You have to provide login.'

if options.password:
	password = options.password
else:
	raise Exception, 'You have to provide password.'