def _deploySquare(self): min_y = 0 max_y = Map.getMap().height min_x = 0 max_x = Map.getMap().width if self._clan_id == Clan.RED: min_x = 0 max_x = Map.getMap().width / 3 min_y = 0 max_y = Map.getMap().height / 3 else: min_x = (Map.getMap().width / 3) * 2 max_x = Map.getMap().width min_y = (Map.getMap().height / 3) * 2 max_y = Map.getMap().height pos_y = min_y dimensions = int(math.sqrt(self._size)) self._size = dimensions ** 2 for p in range(dimensions): pos_x = min_x pos_y += 1 for q in range(dimensions): pos_x += 1 self._addElement(pos_x, pos_y)
def _deployVertical(self): min_y = 0 max_y = Map.getMap().height if self._clan_id == Clan.RED: min_x = 0 max_x = Map.getMap().width / 3 else: min_x = (Map.getMap().width / 3) * 2 max_x = Map.getMap().width pos_x = min_x + 1 pos_y = min_y + 1 for p in range(self._size): self._addElement(pos_x, pos_y) pos_y += 1 if pos_y == max_y - 1: pos_y = min_y + 1 pos_x += 1
def _deployLowerDiag(self): b = math.ceil(math.sqrt(2 * self._size)) xmax = int(Map.getMap().width / 3) m = 0 f = False for i in range(b): for j in range(b - i): if (self._clan_id == Clan.RED): self._addElement(j, Map.getMap().height - i - 1) else: self._addElement(Map.getMap().width - j - 1, i) m += 1 if (m == self._size): f = True break if (f): break
def _deployHorizontal(self): min_x = 50 max_x = Map.getMap().width if self._clan_id == Clan.RED: min_y = 0 max_y = Map.getMap().height / 3 else: min_y = (Map.getMap().height / 3) * 2 max_y = Map.getMap().height pos_x = min_x + 1 pos_y = min_y + 1 for p in range(self._size): self._addElement(pos_x, pos_y) pos_x += 1 if pos_x == max_x - 1: pos_x = min_x + 1 pos_y += 1
def _deployerDownDiagonal(self): base = math.ceil(math.sqrt(2 * self._size)) xmax = int(Map.getMap().width / 3) count = 0 full = False for i in range(base): for j in range(base - i): if (self._clan_id == Clan.RED): self._addElement(j, Map.getMap().height - i - 1) else: self._addElement(Map.getMap().width - j - 1, i) count += 1 if (count == self._size): full = True break if (full): break
def _deployTriangle(self): n = math.ceil(math.sqrt(self._size)) base = int(Map.getMap().width / 3) mid = int(Map.getMap().height / 2) full = False count = 0 for i in range(n): for j in range(-i, i + 1, 1): if (self._clan_id == Clan.RED): self._addElement(base - i, mid + j) else: self._addElement(base * 2 + i, mid + j) count += 1 if (count == self._size): full = True break if (full): break
def _deployRandom(self): min_x = 50 max_x = Map.getMap().width if self._clan_id == Clan.RED: min_y = 0 max_y = Map.getMap().height / 3 else: min_y = (Map.getMap().height / 3) * 2 max_y = Map.getMap().height pos_x = min_x + 1 pos_y = min_y + 1 for p in range(self._size): self._addElement(pos_x, pos_y) pos_x += 1 rand = random.randint(1, 5) randGrand = random.randint(25, 50) if pos_x > randGrand: pos_x = rand pos_y += rand
def updateArmy(self) -> None: NewArmy = [] for x in range(len(self._army)): if (self._army[x].health > 0 and (self._army[x].x < Map.getMap().width or self._army[x].y < Map.getMap().height)): NewArmy.append(self._army[x]) self._army = NewArmy self._size = len(self._army) print("---------------------------------") print(self._clan_id) print(self._size)
def move(self, move_vector: (float, float)) -> bool: """This function represents the interaction between my character and the environment. The speed and terrain part that follows could be simplified in our current case, since all the terrain is the same and the speed of our army elements is all equal. But in a more complex situation, where the terrain is heterogeneous and we have a mixed army, this code would be able to handle properly the movement in such cases Returns ------- """ factor = Map.getTerrainAt(int(self._x), int(self._y)).cross() * self._speed m_x = move_vector[0] * factor m_y = move_vector[1] * factor new_x = self._x + m_x new_y = self._y + m_y if Map.getMap().width >= new_x >= 0: self._x = new_x elif Map.getMap().width < new_x: self._x = Map.getMap().width else: self._x = 0 if Map.getMap().height >= new_y >= 0: self._y = new_y elif Map.getMap().height < new_y: self._y = Map.getMap().height else: self._y = 0 return True
def _deployDiagonal(self): min_x = 50 max_x = Map.getMap().width if self._clan_id == Clan.RED: min_y = 0 max_y = Map.getMap().height / 3 else: min_y = (Map.getMap().height / 3) * 2 max_y = Map.getMap().height pos_x = min_x + 1 pos_y = min_y + 1 for p in range(self._size): self._addElement(pos_x, pos_y) pos_x += 1 if pos_x > 1: pos_x += 1 pos_y += 1 if pos_y > Map.getMap().height or pos_y < 0: pos_y = min_y elif pos_x > Map.getMap().width or pos_x < 0: pos_x = min_x
def move( self, e_center: (float, float), vectorCenterToCenter: (float, float) ) -> bool: """This function represents the interaction between my character and the environment. The speed and terrain part that follows could be simplified in our current case, since all the terrain is the same and the speed of our army elements is all equal. But in a more complex situation, where the terrain is heterogeneous and we have a mixed army, this code would be able to handle properly the movement in such cases Returns ------- """ factor = Map.getTerrainAt(int(self._x), int( self._y)).cross() * self._speed Vg = (e_center[0] - self._x, e_center[1] - self._y) Mag = sqrt(pow(Vg[0], 2) + pow(Vg[1], 2)) Vg = (Vg[0] / Mag, Vg[1] / Mag) Vt = (Vg[0] + vectorCenterToCenter[0], Vg[1] + vectorCenterToCenter[1]) mag2 = sqrt(pow(Vt[0], 2) + pow(Vt[1], 2)) move_vector = (Vt[0] / mag2, Vt[1] / mag2) m_x = move_vector[0] * factor m_y = move_vector[1] * factor new_x = self._x + m_x new_y = self._y + m_y if Map.getMap().width > new_x >= 0: self._x = new_x elif Map.getMap().width <= new_x: self._x = Map.getMap().width - 1 else: self._x = 0 if Map.getMap().height > new_y >= 0: self._y = new_y elif Map.getMap().height <= new_y: self._y = Map.getMap().height - 1 else: self._y = 0 return True