def test_radius_calculation(self): c = Coords(x, y) self.assertEqual(c.radius_calculation(), (c.x**2 + c.y**2)**(0.5), 'incorrect radius-vector')
def __generate_start_position(self, players_ids): players_count = len(players_ids) planets = [[0, Planet(Coords(0, 0), PlanetType.BIGGEST), 0]] alpha = random.randint(0, int(360 / players_count)) for player_id in players_ids: coord = Coords() tang = math.tan(alpha * math.pi / 180) if alpha >= 360: alpha -= 360 if alpha == 90 or alpha == 270: coord.x = 0 coord.y = self.__screen_height * math.sin( alpha * math.pi / 180) / 2 elif alpha == 180 or alpha == 0: coord.y = 0 coord.x = self.__screen_length * math.cos( alpha * math.pi / 180) / 2 elif 0 < alpha < 90: if alpha >= self.__border_angle: height_border = self.__screen_height / 2 coord.x = height_border / tang coord.y = height_border else: height_border = self.__screen_length / 2 coord.y = height_border * tang coord.x = height_border elif 180 < alpha < 270: if alpha >= self.__border_angle + 180: height_border = self.__screen_height / 2 coord.x = -height_border / tang coord.y = -height_border else: height_border = self.__screen_length / 2 coord.y = -height_border * tang coord.x = -height_border elif 90 < alpha < 180: if alpha <= 180 - self.__border_angle: height_border = self.__screen_height / 2 coord.x = height_border / tang coord.y = height_border else: height_border = self.__screen_length / 2 coord.y = abs(height_border * tang) coord.x = -height_border elif 270 < alpha < 360: if alpha <= 360 - self.__border_angle: height_border = self.__screen_height / 2 coord.x = abs(height_border / tang) coord.y = -height_border else: height_border = self.__screen_length / 2 coord.y = height_border * tang coord.x = self.__screen_length / 2 planets.append([ coord.radius_calculation(), Planet(coord, PlanetType.BIG, player_id), alpha ]) alpha += 360 / players_count min_rad = min(planets[1:], key=lambda x: x[0]) self.__start_position_radius = min_rad[ 0] - self.__planet_free_space_radius for i in planets[1:]: i[1].coords.x = int(self.__start_position_radius * math.cos(i[2] * math.pi / 180)) i[1].coords.y = int(self.__start_position_radius * math.sin(i[2] * math.pi / 180)) i[0] = self.__start_position_radius self.__planets += [planet[1] for planet in planets]