当前位置: 首页>>代码示例>>Python>>正文


Python AI.run方法代码示例

本文整理汇总了Python中ai.AI.run方法的典型用法代码示例。如果您正苦于以下问题:Python AI.run方法的具体用法?Python AI.run怎么用?Python AI.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ai.AI的用法示例。


在下文中一共展示了AI.run方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from ai import AI [as 别名]
# 或者: from ai.AI import run [as 别名]
def main():
  #personality = Personality('Test', '/tmp/test-ai/')
  personality = Personality('Phong', '/tmp/phong-ai/')
  ai = AI(personality)
  ai.loadModule(Context(ai))
  ai.loadModule(Markov(ai))
  ai.loadModule(ConsoleFeedback(ai))
  ai.run()
  while True:
    ai.processEvent(InstrumentationEvent())
    if sys.stdin.isatty():
      sys.stdout.write("> ")
    try:
      line = sys.stdin.readline()
    except KeyboardInterrupt:
      ai.stop()
      return
    event = IncomingEvent(text=line.strip(), sender='console', recipient=personality.name)
    ai.processEvent(event)
开发者ID:gregimba,项目名称:phong,代码行数:21,代码来源:main.py

示例2: __init__

# 需要导入模块: from ai import AI [as 别名]
# 或者: from ai.AI import run [as 别名]

#.........这里部分代码省略.........
            self.game_name = message['args']['name']
            print("Game created: {}".format(self.game_name))
            return True
        else:
            #Game creation failed
            return False

    #Receive Player ID from server
    def recv_player_id(self):
        self.wait_for('player_id')
        return True

    #Runs before main_loop has began.
    def init_main(self):
        self.wait_for('start_game')

        self.ai.init()
        return True

    #Runs after main_loop has finished.
    def end_main(self):
        self.ai.end()
        return True

    #Main connection loop until end of game.
    def main_loop(self):
        while True:
            message = self.wait_for('start_turn', 'game_over')
            if message['type'] == 'game_over':
                return True

            if self.ai.my_player_id == self.ai.player_id:
                utility.v_print("Turn Number: {}".format(self.ai.turn_number))
                self.ai.run()
                utility.send_string(self.serv_conn, json.dumps(client_json.end_turn))

     
    def get_log(self):
        log_json = client_json.get_log.copy()
        utility.send_string(self.serv_conn, json.dumps(log_json))

        message = self.wait_for('success', 'failure')
        if message['type'] == "success":
            file = open(self.game_name + '.glog', 'wb')
            file.write(message['args']['log'].encode('utf-8'))
            file.close()

    #Update game from message
    def update_game(self, message):
        if message.get("type") != "changes":
            return False

        for change in message.get("args").get("changes"):
            if change.get("action") == "add":
                self.change_add(change)

            elif change.get("action") == "remove":
                self.change_remove(change)

            elif change.get("action") == "update":
                self.change_update(change)

            elif change.get("action") == "global_update":
                self.change_global_update(change)

        return True
开发者ID:mojomojomojo,项目名称:zeronet,代码行数:70,代码来源:game.py

示例3: __init__

# 需要导入模块: from ai import AI [as 别名]
# 或者: from ai.AI import run [as 别名]
class Game:

    def __init__(self, conn, addr, port, name):
        self.serv_conn = conn
        self.serv_addr = addr
        self.serv_port = port
        self.game_name = name
        self.ai = AI()
        self.ai.connection = self.serv_conn

    #Attempt to connect to the server
    def connect(self):
        while True:
            try:
                #Attempting to connect
                self.serv_conn.connect((self.serv_addr, self.serv_port))
            except socket.error:
                #Failed to connect
                time.sleep(1)
            else:
                #Client connected
                return True

    def receive(self):
        data = utility.receive_string(self.serv_conn)
        message = json.loads(data)

        if message['type'] == 'changes':
            self.update_game(message)
        elif message['type'] == 'player_id':
            self.ai.my_player_id = message['args']['id']
        elif message['type'] == 'game_over':
            raise GameOverException(message["args"]["winner"], message["args"]["reason"])
        return message

    def wait_for(self, *types):
        while True:
            message = self.receive()
            if message['type'] in types:
                return message

    #Attempt to login to the server
    def login(self):
        login_json = client_json.login.copy()
        login_json['args']['username'] = self.ai.username

        utility.send_string(self.serv_conn, json.dumps(login_json))

        message = self.wait_for('success', 'failure')
        if message['type'] == 'success':
            #Login success
            return True
        else:
            #Login failed
            return False

    #Attempt to create a game on the server
    def create_game(self):
        create_game_json = client_json.create_game.copy()
        if self.game_name is not None:
            create_game_json['args']['game_name'] = self.game_name

        utility.send_string(self.serv_conn, json.dumps(create_game_json))

        message = self.wait_for('success', 'failure')
        if message['type'] == "success":
            self.game_name = message['args']['name']
            print("Game created: {}".format(self.game_name))
            return True
        else:
            #Game creation failed
            return False

    #Receive Player ID from server
    def recv_player_id(self):
        self.wait_for('player_id')
        return True

    #Runs before main_loop has began.
    def init_main(self):
        self.wait_for('start_game')

        self.ai.init()
        return True

    #Runs after main_loop has finished.
    def end_main(self):
        self.ai.end()
        return True

    #Main connection loop until end of game.
    def main_loop(self):
        while True:
            message = self.wait_for('start_turn', 'game_over')
            if message['type'] == 'game_over':
                return True

            if self.ai.my_player_id == self.ai.player_id:
                utility.v_print("Turn Number: {}".format(self.ai.turn_number))
                self.ai.run()
#.........这里部分代码省略.........
开发者ID:Anoghastra,项目名称:python-client,代码行数:103,代码来源:game.py


注:本文中的ai.AI.run方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。