コード例 #1
0
 def __init__(self, name):
     self.bb = BlackBoard()
     pub.subscribe(self.onUnitCreate, 'preUnitCreate')
     pub.subscribe(self.onUnitDiscover, 'preUnitDiscover')
     pub.subscribe(self.onUnitMorph, 'preUnitMorph')
     pub.subscribe(self.onUnitComplete, 'preUnitComplete')
     pub.subscribe(self.onUnitEvade, 'preUnitEvade')
     pub.subscribe(self.onUnitDestroy, 'preUnitDestroy')
コード例 #2
0
    def __init__(self, worker, unit_type, position, build_on_top_of_unit,
                 builder_expert):
        self.bb = BlackBoard()
        self.worker = worker
        self.unit_type = unit_type
        self.position = position
        self.build_on_top_of_unit = build_on_top_of_unit
        self.builder_expert = builder_expert

        if self.build_on_top_of_unit:
            morph_unit = self.build_on_top_of_unit
        else:
            morph_unit = worker
        self.events = {
            self.on_frame:
            event_constants.onFrame,
            self.on_unit_destroy:
            event_constants.event_x_for_u(event_constants.onUnitDestroy,
                                          worker),
            self.on_unit_morph:
            event_constants.event_x_for_u(event_constants.onUnitMorph,
                                          morph_unit)
        }

        for handler, event in self.events.iteritems():
            pub.subscribe(handler, event)

        self.reserve_funds()
        bb.drones_on_way_to_build[worker.getID()] = worker

        self.log("Going to build a {0} at {1}".format(unit_type, position))
コード例 #3
0
    def __init__(self, name):
        self.bb = BlackBoard()
        self.name = name

        pub.subscribe(self.on_frame, event_constants.onFrame)
        pub.subscribe(self.unit_destroyed, event_constants.onUnitDestroy)
        pub.subscribe(self.unit_morphed, event_constants.onUnitMorph)

        self.build_jobs = {}
コード例 #4
0
    def _onStart(self):

        self.game = self.mirror.getGame()
        self.player = self.game.self()
        self.game.enableFlag(1)
        self.game.setLocalSpeed(42)

        bb = BlackBoard()
        bb.player = self.player
        bb.game = self.game
        bb.BWTA = BWTA

        print "Analyzing map..."
        BWTA.readMap()
        BWTA.analyze()
        print "Map data ready"

        pub.sendMessage('onStart')
コード例 #5
0
    def onUnitDestroy(self, unit):
        bb = BlackBoard()
        if unit.getType() == UnitType.Unknown:
            return
        unit = self.find_or_wrap_unit(unit)
        unit.dead = True

        del bb.wrapped_unit_lookup[unit.getID()]

        #if unit.destroy_callback:
        #    unit.destroy_callback(unit)

        print "Destroy: {0}: {1}".format(unit.getType(), unit.name)
        #pub.sendMessage(event_constants.onUnitDestroy, unit=unit)
        event_constants.send_event_x_for_u(event_constants.onUnitDestroy, unit)
コード例 #6
0
    def onUnitMorph(self, unit):
        if unit.getType() == UnitType.Unknown:
            return

        bb = BlackBoard()
        unit = self.find_or_wrap_unit(unit)

        previous_type = unit.unit_type
        if not unit.claimed:
            bb.remove_unit_from_free(unit, previous_type)
        unit.unit_type = unit.getType()
        unit.unit_player = unit.getPlayer()

        #if unit.unit_type == UnitType.Zerg_Extractor and unit.getPlayer().getID() == bb.player_id:
        #    bb.extractor_morphed_callback(unit)
        #if unit.morph_callback:
        #    unit.morph_callback(unit)

        if not unit.claimed:
            bb.add_unit_to_free(unit)

        print "Morph: {0}: {1}".format(unit.getType(), unit.name)
        #pub.sendMessage(event_constants.onUnitMorph, unit=unit)
        event_constants.send_event_x_for_u(event_constants.onUnitMorph, unit)
コード例 #7
0
ファイル: scheduler.py プロジェクト: brownzach125/PJBot
def construct():
    print 'construct scheduler'
    BlackBoard().scheduler = SchedulerExpert('Scheduler Expert')
コード例 #8
0
def construct():
    BlackBoard().builder_expert = BuilderExpert('Builder Expert')
コード例 #9
0
from bwapi_mirror_wrapper.bwapi.UnitType import UnitType
from bwapi_mirror_wrapper.bwapi.TilePosition import TilePosition
from bwapi import MouseButton

from pubsub import pub
import logging
from AI.src import event_constants
from AI.src.subscribe import every
from AI.src.blackboard import BlackBoard

bb = BlackBoard()


@every(event_constants.onStart)
def construct():
    BlackBoard().builder_expert = BuilderExpert('Builder Expert')


@every('mouse_click.' + str(MouseButton.M_LEFT))
def build_on_click(position):
    if bb.build_on_click:
        print position


class BuildJob(object):
    def log(self, message):
        full_message = "{0}@{1} {2}".format(self.worker.name,
                                            self.worker.getTilePosition(),
                                            message)
        logging.debug(full_message)
コード例 #10
0
def construct():
    print 'construct resource collector'
    BlackBoard().res_collector = ResourceCollectorExpert('Resource Collector')
コード例 #11
0
 def __init__(self):
     self.mirror = Mirror()
     self.game = None
     self.player = None
     self.experts = []
     self.bb = BlackBoard()
コード例 #12
0
ファイル: expert.py プロジェクト: brownzach125/PJBot
 def __init__(self, name):
     self.name = name
     self.unit_trackers = []
     self.bb = BlackBoard()
コード例 #13
0
class UnitExpert:
    def __init__(self, name):
        self.bb = BlackBoard()
        pub.subscribe(self.onUnitCreate, 'preUnitCreate')
        pub.subscribe(self.onUnitDiscover, 'preUnitDiscover')
        pub.subscribe(self.onUnitMorph, 'preUnitMorph')
        pub.subscribe(self.onUnitComplete, 'preUnitComplete')
        pub.subscribe(self.onUnitEvade, 'preUnitEvade')
        pub.subscribe(self.onUnitDestroy, 'preUnitDestroy')
        
    def find_or_wrap_unit(self, unit):
        bb = self.bb

        if unit.getID() not in bb.wrapped_unit_lookup:
            bb.wrapped_unit_lookup[unit.getID()] = UnitWrapper(unit)

        return bb.wrapped_unit_lookup[unit.getID()]

    def onUnitCreate(self, unit):
        if unit.getType() == UnitType.Unknown:
            return
        unit = self.find_or_wrap_unit(unit)
        # TODO not sure if I want this
        #bb.add_unit_to_free(unit)
        print "Create: {0}: {1}".format(unit.getType(), unit.name)

        #pub.sendMessage(event_constants.event_x_for_u(event_constants.onUnitCreate, unit), unit=unit)
        event_constants.send_event_x_for_u(event_constants.onUnitCreate, unit)

    def onUnitDiscover(self, unit):
        if unit.getType() == UnitType.Unknown:
            return

        bb = self.bb
        unit = self.find_or_wrap_unit(unit)
        print "Discover: {0}: {1}".format(unit.getType(), unit.name)
        # TODO could a unit be discovered that someone already owns??? I guess if the become inaccesible
        bb.add_unit_to_free(unit)
        #pub.sendMessage(event_constants.onUnitDiscover, unit=unit)
        event_constants.send_event_x_for_u(event_constants.onUnitDiscover, unit)

    def onUnitMorph(self, unit):
        if unit.getType() == UnitType.Unknown:
            return

        bb = BlackBoard()
        unit = self.find_or_wrap_unit(unit)

        previous_type = unit.unit_type
        if not unit.claimed:
            bb.remove_unit_from_free(unit, previous_type)
        unit.unit_type = unit.getType()
        unit.unit_player = unit.getPlayer()

        #if unit.unit_type == UnitType.Zerg_Extractor and unit.getPlayer().getID() == bb.player_id:
        #    bb.extractor_morphed_callback(unit)
        #if unit.morph_callback:
        #    unit.morph_callback(unit)

        if not unit.claimed:
            bb.add_unit_to_free(unit)

        print "Morph: {0}: {1}".format(unit.getType(), unit.name)
        #pub.sendMessage(event_constants.onUnitMorph, unit=unit)
        event_constants.send_event_x_for_u(event_constants.onUnitMorph, unit)

    def onUnitComplete(self, unit):
        if unit.getType() == UnitType.Unknown:
            return
        unit = self.find_or_wrap_unit(unit)

        #if unit.complete_callback:
        #    unit.complete_callback(unit)

        if not unit.claimed:
            self.bb.add_unit_to_free(unit)

        print "Complete: {0}: {1}".format(unit.getType(), unit.name)
        #pub.sendMessage(event_constants.onUnitComplete, unit=unit)
        event_constants.send_event_x_for_u(event_constants.onUnitComplete, unit)

    def onUnitEvade(self, unit):
        if unit.getType() == UnitType.Unknown:
            return
        unit = self.find_or_wrap_unit(unit)
        print "Evade: {0}: {1}".format(unit.getType(), unit.name)
        #pub.sendMessage(event_constants.onUnitEvade, unit=unit)
        event_constants.send_event_x_for_u(event_constants.onUnitEvade, unit)

    def onUnitDestroy(self, unit):
        bb = BlackBoard()
        if unit.getType() == UnitType.Unknown:
            return
        unit = self.find_or_wrap_unit(unit)
        unit.dead = True

        del bb.wrapped_unit_lookup[unit.getID()]

        #if unit.destroy_callback:
        #    unit.destroy_callback(unit)

        print "Destroy: {0}: {1}".format(unit.getType(), unit.name)
        #pub.sendMessage(event_constants.onUnitDestroy, unit=unit)
        event_constants.send_event_x_for_u(event_constants.onUnitDestroy, unit)
コード例 #14
0
def construct():
    logging.info("Creating Unit Expert")
    BlackBoard().unit_expert = UnitExpert('Unit Expert')