Пример #1
0
def produce():
  units = BoScript.allPlayerUnits(ai.player)
  for u in units:
    # AB: unitAdvanceWork(u) == 0 means that the unit is idle
    if BoScript.canUnitProduce(u) and BoScript.unitAdvanceWork(u) == 0:
      boprint("debug", "start production algorithm for unit %d" % u)
      prod = BoScript.productionTypes(u)
      canProduceFacilities = 0
      canProduceMobiles = 0
      for p in prod:
        isMobile = BoScript.isUnitTypeMobile(ai.player, p)
        if isMobile:
          canProduceMobiles = 1
        else:
          canProduceFacilities = 1
      if canProduceFacilities:
        produceFacilities(u)
      if canProduceMobiles:
        produceMobiles(u)
Пример #2
0
def placeUnit(factory, unitType):
  if(BoScript.isUnitTypeMobile(ai.player, int(unitType)) == False):
    boprint("debug", "Ok , building")
    pos = BoScript.unitPosition(int(factory))
    x = int(pos[0])
    y = int(pos[1])
    tmpx = x
    tmpy = y

    # AB: don't make unlimitied tries (avoid infinite loop)
    tries = 0
    while BoScript.canPlaceProductionAt(factory, unitType, int(tmpx), int(tmpy)) != 1 and tries < 30:
      distance = randint(0, 20)
      tmpx = randint(x-distance, x+distance)
      tmpy = randint(y-distance, y+distance)
      if(tmpx < 0):
        tmpx = x
      if(tmpy < 0):
        tmpy = y
      tries = tries + 1
    boprint("debug","placed tmpx %d,tmpy %d " % (tmpx,tmpy))
    BoScript.placeProduction(int(factory), tmpx, tmpy)
Пример #3
0
def produceMobiles(factory):
  boprint("debug", "produceMobiles()")
  prod = BoScript.productionTypes(factory)

  minerals = BoScript.minerals(ai.player)
  oil = BoScript.minerals(ai.player)

  # build at least one harvester per kind
  boprint("debug", "  rule 1: harvesters!")
  haveMineralHarvesters = BoScript.playerUnitsOfTypeCount(ai.player, 10003)
  haveOilHarvesters = BoScript.playerUnitsOfTypeCount(ai.player, 10002)
  if haveMineralHarvesters < 1 or haveOilHarvesters < 1:
    boprint("debug", "  rule 1: not fullfilled")
    # AB: we use two loops, as we prefer mineral harvesters over oil harvesters
    #     (we usually need more minerals faster than oil)
    for p in prod:
      if p == 10003 and haveMineralHarvesters < 1:
        BoScript.produceUnit(factory, p)
        return
    for p in prod:
      if p == 10002 and haveOilHarvesters < 1:
        BoScript.produceUnit(factory, p)
        return
    boprint("debug", "  rule 1: cannot fullfill rule.")

    if minerals < 10000 or oil < 10000: # don't abort production if we have many resources
      # AB: this is a two-sided sword.
      #     it is important that we don't do any further productions: if we
      #     produce tanks now, then we maybe won't be able to build harvesters
      #     once the refineries are constructed.
      #
      #     however the other side is that if we cannot/don't want to build 
      #     harvesters on this map (e.g. no resources on this map), then we
      #     won't ever build any mobiles.
      boprint("debug", "          aborting productions, we need to build harvesters first!")
      return


  # have at least 2 harvester per kind if minerals/oil is low
  boprint("debug", "  rule 2: harvesters for bad times!")
  needMineralHarvesters = 0
  needOilHarvesters = 0
  if haveMineralHarvesters < 2 and minerals < 1500:
    needMineralHarvesters = 1
  if haveOilHarvesters < 2 and oil < 1500:
    needOilHarvesters = 1
  if needMineralHarvesters > 0 or needOilHarvesters > 0:
    boprint("debug", "  rule 2: not fullfilled")
    for p in prod:
      if p == 10003 and needMineralHarvesters > 0:
        BoScript.produceUnit(factory, p)
        return
    for p in prod:
      if p == 10002 and needOilHarvesters > 0:
        BoScript.produceUnit(factory, p)
        return
    boprint("debug", "  rule 2: cannot fullfill rule")

  # have at least 3 tanks
  boprint("debug", "  rule 3: battle units!")
  tankTypes = [10010, 10008, 10018] # tiger, leopard, wolf
  haveTanks = countUnitsOfType(tankTypes)
  if haveTanks < 3:
    boprint("debug", "  rule 3: not fullfilled")
    shuffle(tankTypes)
    for type in tankTypes:
      if tryProduce(factory, type):
        return
    boprint("debug", "  rule 3: cannot fullfill rule")


  # if have refinery: have >= 3 harvesters
  boprint("debug", "  rule 4: more harvesters!")
  haveMineralRefinery = BoScript.playerUnitsOfTypeCount(ai.player, 13)
  haveOilRefinery = BoScript.playerUnitsOfTypeCount(ai.player, 8)
  if haveMineralRefinery > 0 and haveMineralHarvesters < 3:
    needMineralHarvesters = 1
  if haveOilRefinery > 0 and haveOilHarvesters < 3:
    needOilHarvesters = 1
  if needMineralHarvesters > 0 or needOilHarvesters > 0:
    boprint("debug", "  rule 4: not fullfilled")
    for p in prod:
      if p == 10003 and needMineralHarvesters > 0:
        BoScript.produceUnit(factory, p)
        return
    for p in prod:
      if p == 10002 and needOilHarvesters > 0:
        BoScript.produceUnit(factory, p)
        return
    boprint("debug", "  rule 4: cannot fullfill rule")


  # have at least 2 harvesters per refinery
  # (AB: note: already fullfilled by rule "have >= 3 harvesters", if we have
  # only one refinery)
  boprint("debug", "  rule 5: harvesters for everyone!")
  if haveMineralHarvesters < 2 * haveMineralRefinery:
    needMineralHarvesters = 1
  if haveOilHarvesters < 2 * haveMineralRefinery:
    needOilHarvesters = 1
  if needMineralHarvesters > 0 or needOilHarvesters > 0:
    boprint("debug", "  rule 5: not fullfilled")
    list = []
    if needOilHarvesters > 0:
      list = list + [10002]
    if needMineralHarvesters > 0:
      list = list + [10003]
    shuffle(list)
    for harvester in list:
      for p in prod:
        if p == harvester:
          BoScript.produceUnit(factory, p)
          return
    boprint("debug", "  rule 5: cannot fullfill rule")


  # just build something to fight with
  boprint("debug", "  rule 6: fight!")
  # build all kinds of mobile units, except of harvesters
  allowedList = []
  for p in prod:
    if BoScript.isUnitTypeMobile(ai.player, p):
      if p != 10002 and p != 10003:
        allowedList = allowedList + [p]
  shuffle(allowedList)
  for p in allowedList:
    BoScript.produceUnit(factory, p)
    return

  boprint("debug", "  rule 6: cannot fullfill rule")