示例#1
0
    def position_on_circle(self, radius, center):
      x,y = -1,-1

      while not isValidSquare( (x,y), self.mapsize):
        angle = random.randint(0,360)
        x = center[0] + radius * math.sin(angle)
        y = center[1] + radius * math.cos(angle)
      return (x,y)        
示例#2
0
    def establish_perimeter(self, distance):
        self.perimeter_distance = distance
        self.perimeter = []

        # center
        cx = self.building.position[0]
        cy = self.building.position[1]

        # upper left
        x = cx - distance
        y = cy - distance
        while not isValidSquare((x, y), self.ai.mapsize):
            x += 1
            y += 1
        self.perimeter.append((x, y))

        # upper right
        x = cx + distance
        y = cy - distance
        while not isValidSquare((x, y), self.ai.mapsize):
            x -= 1
            y += 1
        self.perimeter.append((x, y))

        # lower right
        x = cx + distance
        y = cy + distance
        while not isValidSquare((x, y), self.ai.mapsize):
            x -= 1
            y -= 1
        self.perimeter.append((x, y))

        # lower left
        x = cx - distance
        y = cy + distance
        while not isValidSquare((x, y), self.ai.mapsize):
            x += 1
            y -= 1
        self.perimeter.append((x, y))

        self.perimeter_cycler = itertools.cycle(self.perimeter)
示例#3
0
from world import isValidSquare

AIClass = "RushAI"
EXPLORER_RATIO = 4
AREA_SIZE = 8


def fuzz_position((x, y), sight, mapsize):
    dx = int((sight - random.randint(0, 3)) * random.choice([-1, 1]))
    dy = int((sight - random.randint(0, 3)) * random.choice([-1, 1]))

    ox, oy = x, y
    x += dx
    y += dy
    attempts = 30
    while not isValidSquare((x, y), mapsize) and attempts > 0:
        x, y = ox, oy
        dx = int((sight - random.randint(0, 3)) * random.choice([-1, 1]))
        dy = abs(sight - abs(dx)) * random.choice([-1, 1])
        x += dx
        y += dy
        attempts -= 1
    return x, y

    return int(x), int(y)


def to_area((x, y)):
    return x / AREA_SIZE * AREA_SIZE, y / AREA_SIZE * AREA_SIZE

示例#4
0
from collections import defaultdict
from world import isValidSquare

AIClass = "RushAI"
EXPLORER_RATIO=4
AREA_SIZE = 8

def fuzz_position((x, y), sight, mapsize):
  dx = int((sight - random.randint(0, 3)) * random.choice([-1, 1]))
  dy = int((sight - random.randint(0, 3)) * random.choice([-1, 1]))

  ox,oy = x,y
  x += dx
  y += dy
  attempts = 30
  while not isValidSquare((x,y), mapsize) and attempts > 0:
    x,y = ox,oy
    dx = int((sight - random.randint(0, 3)) * random.choice([-1, 1]))
    dy = abs(sight - abs(dx)) * random.choice([-1, 1])
    x += dx
    y += dy
    attempts -= 1
  return x,y

  return int(x),int(y)
def to_area((x,y)):
   return x/AREA_SIZE*AREA_SIZE, y/AREA_SIZE*AREA_SIZE

class RushAI(ai.AI):
    def _init(self):
      AREA_SIZE = self.mapsize / 12
示例#5
0
    def form_circle(self, units, (x, y), radius, ro=0):
        if not units:
            return

        # So, use radians (2pi form a circle)
        radian_delta = (2 * math.pi) / len(units)
        radian_offset = ro
        for unit in units:
            attempts = 0
            while True:
                radian_offset += radian_delta
                pos_x = x + (radius * math.cos(radian_offset))
                pos_y = y + (radius * math.sin(radian_offset))
                attempts += 1
                if isValidSquare((pos_x, pos_y), self.mapsize):
                    break

                if attempts >= 3:
                    return

            unit.move((pos_x, pos_y))

    def collapse_circle(self, units, (x, y)):
        # So, use radians (2pi form a circle)
        for unit in units:
            unit.move((x, y))

    def _unit_died(self, unit):
        pass