Beispiel #1
0
def get_graph():
    graph = dict()

    with open("graph.txt") as f:
        for line in f.readlines():
            town = Town(line[0]) if line[0] not in graph else graph[line[0]]

            town.set_dist(line[1], int(line[2]))
            graph[line[0]] = town

    return graph
Beispiel #2
0
 def add_town(self, country):
     """Добавление города"""
     cities_and_belonging = self.board.cities_and_belonging
     dop = []
     i = self.x
     j = self.y
     size_x = self.board.get_count_cells_x()
     size_y = self.board.get_count_cells_y()
     cities_and_belonging[i][j] = (country.name, True)
     if i % 2 == 1:
         if i >= 1 and j >= 1:
             cities_and_belonging[i - 1][j - 1] = (country.name, False)
             dop.append(self.board.get_cell(i - 1, j - 1))
         if i >= 1:
             cities_and_belonging[i - 1][j] = (country.name, False)
             dop.append(self.board.get_cell(i - 1, j))
         if j < size_y - 1:
             cities_and_belonging[i][j + 1] = (country.name, False)
             dop.append(self.board.get_cell(i, j + 1))
         if i < size_x - 1:
             cities_and_belonging[i + 1][j] = (country.name, False)
             dop.append(self.board.get_cell(i + 1, j))
         if i < size_x - 1 and j >= 1:
             cities_and_belonging[i + 1][j - 1] = (country.name, False)
             dop.append(self.board.get_cell(i + 1, j - 1))
         if j >= 1:
             cities_and_belonging[i][j - 1] = (country.name, False)
             dop.append(self.board.get_cell(i, j - 1))
     if i % 2 == 0:
         if i >= 1:
             cities_and_belonging[i - 1][j] = (country.name, False)
             dop.append(self.board.get_cell(i - 1, j))
         if i >= 1 and j < size_y - 1:
             cities_and_belonging[i - 1][j + 1] = (country.name, False)
             dop.append(self.board.get_cell(i - 1, j + 1))
         if j < size_y - 1:
             cities_and_belonging[i][j + 1] = (country.name, False)
             dop.append(self.board.get_cell(i - 1, j + 1))
         if i < size_x - 1 and j < size_y - 1:
             cities_and_belonging[i + 1][j + 1] = (country.name, False)
             dop.append(self.board.get_cell(i + 1, j + 1))
         if i < size_x - 1:
             cities_and_belonging[i + 1][j] = (country.name, False)
             dop.append(self.board.get_cell(i + 1, j))
         if j >= 1:
             cities_and_belonging[i][j - 1] = (country.name, False)
             dop.append(self.board.get_cell(i, j - 1))
     self.town = Town(self.x, self.y, self, dop, country)
     self.town_on_cell = True
     self.unit_on_cell = False
     self.unit.live = 0
     self.unit = None
Beispiel #3
0
    def parseTOWN(self, data):
        data = data.split(u' ')
        id = int(data[0])
        x = float(data[1])
        y = float(data[2])

        return Town(id, x, y)
def read_back_up():
    '''this function allows backup file to input string attributes to each person
       and bus, then it changes those string attributes into town objects'''
    personList.clear()
    busList.clear()
    townList.clear()
    # create objects whose attributes reflect the current state of the system
    infile = open("backup.txt", "r")
    for aline in infile.readlines():
        values = aline.split()
        if values[0] == "Person":
            personList.append(
                Person(values[3], values[7], values[5], values[9]))
        if values[0] == "Bus":
            busList.append(
                Bus(values[4:7], int(values[8]), int(values[10]), values[12:]))
        if values[0] == "Town":
            townList.append(Town(values[1], values[2:]))

    # change person.origin and person.destination into town objects
    for person in personList:
        for town in townList:
            if person.locate() == town.getName():
                person.setLocation(town)
                if person.getBus() == "None":
                    town.addPeople(
                        person
                    )  # add ppl who are not on bus to town.peoplelist
            if person.getDestination() == town.getName():
                person.setDestination(town)
        # change each person's bus information from string into bus object
        if person.getBus() == "None":
            person.setBus(None)
        else:
            personOnBus = int(person.getBus())
            # cannot use int(person.getBus()) in "for" loop because person.getBus()
            # ceases to be a string at one point and there will be an error in loop
            for bus in busList:
                if bus.getID() - 12 == personOnBus:
                    # subtract 12 because 12 bus objects have been created before
                    person.setBus(bus)

    # change items in bus.route list into town objects
    for n in range(len(busList[0].getRoute())):
        for bus in busList:
            for town in townList:
                if bus.getRoute()[n] == town.getName():
                    bus.setRoute(n, town)
    # change items in bus.peopleList list into person objects
    for bus in busList:
        if bus.getPeople() is not None:
            for n in range(len(bus.getPeople())):
                for person in personList:
                    if bus.getPeople()[n] == person.getName():
                        bus.getPeople()[n] = person
    # add buses to respective towns
    for town in townList:
        town.locateBus(busList)
Beispiel #5
0
    def add_town(self, shape, scale, octaves, persistence, lacunarity,
                 stretch):
        """Randomly place a town of a given (maximum) size on the map."""
        town_loc = self.find_buildable_location(shape[0])
        town_map = Town(shape, scale, octaves, persistence, lacunarity)
        town_map.generate_map(stretch)

        m = 0
        n = 0
        for i in range(town_loc[0] - shape[0] // 2,
                       town_loc[0] + shape[0] // 2 + shape[0] % 2 - 1):
            for j in range(town_loc[1] - shape[1] // 2,
                           town_loc[1] + shape[1] // 2 + shape[1] % 2 - 1):
                if town_map.pix[m, n] == 0:
                    self.pix[i, j] = Terrain.town
                n += 1
            n = 0
            m += 1
Beispiel #6
0
def eval_genome(genome, config):
    net = neat.nn.FeedForwardNetwork.create(genome, config)

    fitnesses = []

    for runs in range(runs_per_net):
        sim = Town()
        sim.load_empty_state(size=20)
        sim.spawn_citizen(location=(10, 10), ai_type="learning")
        offsetx = 0
        offsety = 0
        while np.abs(offsetx) < 2 or np.abs(offsety) < 2:
            offsetx = randint(-3, 3)
            offsety = randint(-3, 3)
        sim.spawn_hunter(location=(5 + offsetx, 5 + offsety))

        # Run the given simulation for up to num_steps time steps.
        fitness = 0.0
        caught = False
        max_sim_iterations = 100
        iteration = 0
        while iteration < max_sim_iterations:
            for citizen in sim.citizens:
                inputs = citizen.vision.flatten()
                citizen.action_preference = net.activate(inputs)

            sim.iterate()

            for citizen in sim.citizens:
                if citizen.score["caught"]:
                    caught = True
                fitness = ((citizen.score["survival_time"] * 100.) /
                           (citizen.score["steps"] + 1)) / (max_sim_iterations)
                fitness = (citizen.score["survival_time"]) / (
                    max_sim_iterations)
            if caught:
                break

            iteration += 1

        fitnesses.append(fitness)

    # The genome's fitness is its worst performance across all runs.
    return min(fitnesses)
Beispiel #7
0
def run_simulation():
    t = Town()
    t.load_empty_state(size=30)
    t.spawn_citizen(location=(15, 15))
    t.spawn_hunter()

    count = 0
    while True:
        if count > 50:
            break
        t.iterate()
        print(t)
        for citizen in t.citizens:
            if citizen.score["caught"]:
                print("DONE")
                print(citizen.score)
                return
        time.sleep(0.05)
        count += 1
Beispiel #8
0
def run_player_game():
    t = Town()
    t.load_empty_state(size=10)
    t.spawn_player()
    t.spawn_citizen(location=(5, 5), ai_type="smart")

    count = 0
    while True:
        for citizen in t.citizens:
            inputs = citizen.vision.flatten()
            print("Inputs", inputs)
            # citizen.action_preference = net.activate(inputs)

        if count > 1000:
            break
        print(t)
        t.iterate()
        for citizen in t.citizens:
            if citizen.score["caught"]:
                print("DONE")
                print(citizen.score)
                return
        count += 1
    c = pickle.load(f)

print('Loaded genome:')
print(c)

# Load the config file, which is assumed to live in
# the same directory as this script.
local_dir = os.path.dirname(__file__)
config_path = os.path.join(local_dir, 'configs/neat_config.cfg')
config = neat.Config(neat.DefaultGenome, neat.DefaultReproduction,
                     neat.DefaultSpeciesSet, neat.DefaultStagnation,
                     config_path)

net = neat.nn.FeedForwardNetwork.create(c, config)

sim = Town()
sim = Town()
sim.load_empty_state(size=10)
sim.spawn_citizen(location=(5, 5), ai_type="learning")
sim.spawn_hunter(location=(3, 3))

caught = False
max_sim_iterations = 100
iteration = 0
while iteration < max_sim_iterations:
    for citizen in sim.citizens:
        inputs = citizen.vision.flatten()
        print(inputs)
        print("Shape ", inputs.shape)
        citizen.action_preference = net.activate(inputs)
def main():
    t = Town("Dresden", 556780)
    print(t.toString())
    t.residents = -1
    print(t.toString())
Beispiel #11
0
from bus import Bus
from town import Town
from people import Person


townfile = open("town.txt","r")
for aline in townfile.readlines():
    values = aline.split()
    Town(values[1], values[3:]) # create Town objects

busfile = open("bus.txt","r")
for aline in busfile.readlines():
    values = aline.split()
    Bus(values) # create Bus objects

personfile = open("person.txt","r")
for aline in personfile.readlines():
    values = aline.split()
    Person(values[0], values[1], values[2]) # create Person objects


# Town Info Display
print(">>> There are twelve towns in this system... \n")
for town in Town.all:
    print(town.getName()+", which is connected to",town.getNeighbor())
print(" ")
print(" ")


# Bus Info Display
for bus in Bus.all:
Beispiel #12
0
class Cell:
    """Класс игровой клетки"""
    def __init__(self, coords: list, cell_size, board, x, y, type='Nothing'):
        """Создаем клетку и задаем её координаты"""
        self.color = pygame.Color('Black')
        self.coords = coords
        self.cell_size = cell_size
        self.color = ''
        self.type = type
        self.sustenance = 0
        self.board = board
        self.x = x
        self.y = y
        self.town = None
        self.unit = None
        self.town_on_cell = False
        self.unit_on_cell = False
        self.farm_on_cell = False

    def render(self):
        """Основная функция отрисовки"""
        pygame.draw.polygon(self.board.screen2, pygame.Color('black'),
                            self.coords, 4)
        pygame.draw.polygon(self.board.screen2, self.color, self.coords)
        if self.town_on_cell:
            self.town.render(self.coords, self.cell_size, self.board.screen2)
        if self.farm_on_cell:
            dop = pygame.transform.scale(
                self.image_farm,
                (int(self.cell_size - 15), int(self.cell_size - 15)))
            self.board.screen2.blit(
                dop, ((self.coords[0][0] + self.coords[5][0]) // 2 - 8,
                      (self.coords[0][1] + self.coords[5][1]) // 2 - 3))
        if self.unit_on_cell:
            self.unit.render(self.coords, self.cell_size, self.board.screen2)
        cities_and_belonging = self.board.cities_and_belonging
        i = self.x
        j = self.y
        size_x = self.board.get_count_cells_x()
        size_y = self.board.get_count_cells_y()
        if i % 2 == 1:
            if i >= 1 and j >= 1:
                if cities_and_belonging[i - 1][
                        j - 1][0] != cities_and_belonging[i][j][0]:
                    pygame.draw.line(
                        self.board.screen2, self.board.color_country[
                            cities_and_belonging[i][j][0]],
                        (self.coords[5][0] + 2, self.coords[5][1] + 2),
                        (self.coords[0][0] + 2, self.coords[0][1] + 2), 4)
            if i >= 1:
                if cities_and_belonging[
                        i - 1][j][0] != cities_and_belonging[i][j][0]:
                    pygame.draw.line(
                        self.board.screen2, self.board.color_country[
                            cities_and_belonging[i][j][0]],
                        (self.coords[0][0] - 2, self.coords[0][1] + 2),
                        (self.coords[1][0] - 2, self.coords[1][1] + 1), 4)
            if j < size_y - 1:
                if cities_and_belonging[i][
                        j + 1][0] != cities_and_belonging[i][j][0]:
                    pygame.draw.line(
                        self.board.screen2, self.board.color_country[
                            cities_and_belonging[i][j][0]],
                        (self.coords[1][0] - 2, self.coords[1][1]),
                        (self.coords[2][0] - 2, self.coords[2][1]), 5)
            if i < size_x - 1:
                if cities_and_belonging[
                        i + 1][j][0] != cities_and_belonging[i][j][0]:
                    pygame.draw.line(
                        self.board.screen2, self.board.color_country[
                            cities_and_belonging[i][j][0]],
                        (self.coords[2][0] - 2, self.coords[2][1] - 2),
                        (self.coords[3][0] - 2, self.coords[3][1] - 2), 5)
            if i < size_x - 1 and j >= 1:
                if cities_and_belonging[i + 1][
                        j - 1][0] != cities_and_belonging[i][j][0]:
                    pygame.draw.line(
                        self.board.screen2, self.board.color_country[
                            cities_and_belonging[i][j][0]],
                        (self.coords[3][0] + 2, self.coords[3][1] - 2),
                        (self.coords[4][0] + 2, self.coords[4][1] - 2), 5)
            if j >= 1:
                if cities_and_belonging[i][
                        j - 1][0] != cities_and_belonging[i][j][0]:
                    pygame.draw.line(
                        self.board.screen2, self.board.color_country[
                            cities_and_belonging[i][j][0]],
                        (self.coords[4][0] + 2, self.coords[4][1]),
                        (self.coords[5][0] + 2, self.coords[5][1]), 4)
        if i % 2 == 0:
            if i >= 1:
                if cities_and_belonging[
                        i - 1][j][0] != cities_and_belonging[i][j][0]:
                    pygame.draw.line(
                        self.board.screen2, self.board.color_country[
                            cities_and_belonging[i][j][0]],
                        (self.coords[5][0] + 2, self.coords[5][1] + 2),
                        (self.coords[0][0] + 2, self.coords[0][1] + 2), 4)
            if i >= 1 and j < size_y - 1:
                if cities_and_belonging[i - 1][
                        j + 1][0] != cities_and_belonging[i][j][0]:
                    pygame.draw.line(
                        self.board.screen2, self.board.color_country[
                            cities_and_belonging[i][j][0]],
                        (self.coords[0][0] - 2, self.coords[0][1] + 2),
                        (self.coords[1][0] - 2, self.coords[1][1] + 2), 4)
            if j < size_y - 1:
                if cities_and_belonging[i][
                        j + 1][0] != cities_and_belonging[i][j][0]:
                    pygame.draw.line(
                        self.board.screen2, self.board.color_country[
                            cities_and_belonging[i][j][0]],
                        (self.coords[1][0] - 2, self.coords[1][1]),
                        (self.coords[2][0] - 2, self.coords[2][1]), 5)
            if i < size_x - 1 and j < size_y - 1:
                if cities_and_belonging[i + 1][
                        j + 1][0] != cities_and_belonging[i][j][0]:
                    pygame.draw.line(
                        self.board.screen2, self.board.color_country[
                            cities_and_belonging[i][j][0]],
                        (self.coords[2][0] - 2, self.coords[2][1] - 2),
                        (self.coords[3][0] - 2, self.coords[3][1] - 2), 5)
            if i < size_x - 1:
                if cities_and_belonging[
                        i + 1][j][0] != cities_and_belonging[i][j][0]:
                    pygame.draw.line(
                        self.board.screen2, self.board.color_country[
                            cities_and_belonging[i][j][0]],
                        (self.coords[3][0] + 2, self.coords[3][1] - 2),
                        (self.coords[4][0] + 2, self.coords[4][1] - 2), 5)
            if j >= 1:
                if cities_and_belonging[i][
                        j - 1][0] != cities_and_belonging[i][j][0]:
                    pygame.draw.line(
                        self.board.screen2, self.board.color_country[
                            cities_and_belonging[i][j][0]],
                        (self.coords[4][0] + 2, self.coords[4][1]),
                        (self.coords[5][0] + 2, self.coords[5][1]), 4)

    def check_is_pressed(self, x: int, y: int) -> bool:
        """Проверяем была ли нажата именно эта клетка"""
        x += 500 - (600 + self.board.get_coords()[0])
        y += 500 - (600 + self.board.get_coords()[1])
        coords = self.coords
        fl = True
        for v in range(-1, 1):
            x1, y1, x2, y2 = coords[(v + 6) % 6][0], coords[(v + 6) % 6][1], coords[(v + 7) % 6][0], \
                             coords[(v + 7) % 6][1]
            if y < (x - x1) * (y2 - y1) / (x2 - x1) + y1:
                fl = False
        for v in range(2, 4):
            x1, y1, x2, y2 = coords[v][0], coords[v][1], coords[v + 1][0], \
                             coords[v + 1][1]
            if y > (x - x1) * (y2 - y1) / (x2 - x1) + y1:
                fl = False
        if x < coords[4][0] or x > coords[2][0]:
            fl = False
        if fl:
            return True
        else:
            return False

    def change_type(self, type):
        """Меняем тип клетки и задаем ее цвет"""
        self.type = str(type)
        if type == 'Forest':
            self.color = pygame.Color('#013220')
        elif type == 'Meadow':
            self.color = pygame.Color('#228b22')
        elif type == 'Ocean':
            self.color = pygame.Color('#4169e1')
        elif type == 'Tundra':
            self.color = pygame.Color('#e6e6fa')
        elif type == 'Desert':
            self.color = pygame.Color('#f7e96d')

    def change_size(self, type):
        """Изменить размер клетки"""
        if type == 1:
            for i in range(len(self.coords)):
                self.coords[i] = [
                    self.coords[i][0] * 1.05 - 32,
                    self.coords[i][1] * 1.05 - 18
                ]
            self.cell_size *= 1.035
        if type == -1:
            for i in range(len(self.coords)):
                self.coords[i] = [(self.coords[i][0] + 32) / 1.05,
                                  (self.coords[i][1] + 18) / 1.05]
            self.cell_size /= 1.035

    def get_coords(self):
        """Возвращает координаты клетки"""
        return self.coords

    def get_town(self):
        """Возращает город, если он существует"""
        if self.town_on_cell:
            return self.town
        return False

    def add_town(self, country):
        """Добавление города"""
        cities_and_belonging = self.board.cities_and_belonging
        dop = []
        i = self.x
        j = self.y
        size_x = self.board.get_count_cells_x()
        size_y = self.board.get_count_cells_y()
        cities_and_belonging[i][j] = (country.name, True)
        if i % 2 == 1:
            if i >= 1 and j >= 1:
                cities_and_belonging[i - 1][j - 1] = (country.name, False)
                dop.append(self.board.get_cell(i - 1, j - 1))
            if i >= 1:
                cities_and_belonging[i - 1][j] = (country.name, False)
                dop.append(self.board.get_cell(i - 1, j))
            if j < size_y - 1:
                cities_and_belonging[i][j + 1] = (country.name, False)
                dop.append(self.board.get_cell(i, j + 1))
            if i < size_x - 1:
                cities_and_belonging[i + 1][j] = (country.name, False)
                dop.append(self.board.get_cell(i + 1, j))
            if i < size_x - 1 and j >= 1:
                cities_and_belonging[i + 1][j - 1] = (country.name, False)
                dop.append(self.board.get_cell(i + 1, j - 1))
            if j >= 1:
                cities_and_belonging[i][j - 1] = (country.name, False)
                dop.append(self.board.get_cell(i, j - 1))
        if i % 2 == 0:
            if i >= 1:
                cities_and_belonging[i - 1][j] = (country.name, False)
                dop.append(self.board.get_cell(i - 1, j))
            if i >= 1 and j < size_y - 1:
                cities_and_belonging[i - 1][j + 1] = (country.name, False)
                dop.append(self.board.get_cell(i - 1, j + 1))
            if j < size_y - 1:
                cities_and_belonging[i][j + 1] = (country.name, False)
                dop.append(self.board.get_cell(i - 1, j + 1))
            if i < size_x - 1 and j < size_y - 1:
                cities_and_belonging[i + 1][j + 1] = (country.name, False)
                dop.append(self.board.get_cell(i + 1, j + 1))
            if i < size_x - 1:
                cities_and_belonging[i + 1][j] = (country.name, False)
                dop.append(self.board.get_cell(i + 1, j))
            if j >= 1:
                cities_and_belonging[i][j - 1] = (country.name, False)
                dop.append(self.board.get_cell(i, j - 1))
        self.town = Town(self.x, self.y, self, dop, country)
        self.town_on_cell = True
        self.unit_on_cell = False
        self.unit.live = 0
        self.unit = None

    def add_settlers(self, unit):
        """Добавление поселенцев на клетку"""
        self.unit_on_cell = True
        self.unit = unit
        unit.country.units_towns.append(unit)

    def add_builders(self, unit):
        """Добавление строителей в клетку"""
        self.unit_on_cell = True
        self.unit = unit
        unit.country.units_towns.append(unit)

    def have_unit(self):
        """Определяет есть ли в клетке юнит"""
        return self.unit_on_cell

    def have_town(self):
        """Определяет есть в клетке город"""
        return self.town_on_cell

    def get_unit(self):
        """Возвращает юнит, если тот существует"""
        if self.unit_on_cell:
            return self.unit

    def del_unit(self):
        """Удаление юнита из клетки"""
        # del self.unit.country.units_towns[self.unit.country.units_towns.index(self)]
        self.unit_on_cell = False
        self.unit = None

    def add_unit(self, unit):
        """Добавление юнита в клетку"""
        who = unit.who()
        if who == 'Поселенцы':
            self.add_settlers(unit)
        elif who == 'Строители':
            self.add_builders(unit)
        elif who == 'Воины':
            self.add_warriors(unit)

    def move_to(self, x, y):
        """Передвижение юнита на координаты x, y"""
        self.unit.move(x, y)

    def __copy__(self):
        """Возращает копию клетки"""
        return Cell(self.coords, self.cell_size, self.board, self.x, self.y)

    def __str__(self):
        """Приводит клетку в виду: x-координата y-координата юнит на этой клетке"""
        return ' '.join([str(self.x), str(self.y), str(self.unit)])

    def next_move(self):
        """Следующий ход"""
        if self.unit_on_cell:
            self.unit.update()
            self.unit.next_move()
        if self.town_on_cell:
            self.town.next_move()

    def add_farm(self, country):
        """Добавляет ферму в клетку"""
        if not self.farm_on_cell:
            self.farm_on_cell = True
            country.t_food += 3
            if self.unit is not None:
                self.unit.live = 0
            self.image_farm = load_image('buildings/farm.png', -1)

    def add_warriors(self, unit):
        """Добавление воинов на клетку"""
        self.unit_on_cell = True
        self.unit = unit
        unit.country.units_towns.append(unit)
Beispiel #13
0
import constants as c
from person import Person
from town import Town

Town()
Beispiel #14
0
def scene(viewer, shader_materials, shader_texture, shader_skinned):
    size = 10000
    """ -------------- create a scene and add objects ------------------- """
    # create ground object and add it to the viewer
    main_ground = ObjectLoadTextured(shader_texture,
                                     'models/models_OBJ/Ground.obj', light_dir)
    viewer.add(add_object(main_ground))

    # create mountain instances and add them to the viewer
    mountain = ObjectLoadTextured(shader_texture,
                                  'models/models_OBJ/Mountain.obj', light_dir)
    x_mountains = [-0.80, -0.80, 0.80, 0.80]
    y_mountains = [-0.80, 0.80, -0.80, 0.80]
    scales = [250, 230, 220, 200]
    rotation = rotate((1, 0, 0), 90)
    for x, y, z in zip(x_mountains, y_mountains, scales):
        viewer.add(
            add_object(
                mountain,
                translate(x * size, y * size, -100) @ rotation @ scale(z)))

    # create skybox and add it to the viewer
    skybox = ObjectLoadTextured(shader_texture, 'models/models_OBJ/SkyBox.obj',
                                light_dir)
    viewer.add(add_object(skybox))

    # create a town and add it to the viewer
    town = Town(shader_texture, shader_materials)
    town.construct_town(shader_texture, shader_materials,
                        translate(-0.2 * size, -0.2 * size, 175))
    viewer.add(*town.children)

    # create town ground and church ground
    town_ground = ObjectLoadTextured(shader_texture,
                                     'models/models_OBJ/GroundTown.obj',
                                     light_dir)
    church_ground = ObjectLoadTextured(shader_texture,
                                       'models/models_OBJ/church_ground.obj',
                                       light_dir)
    viewer.add(add_object(town_ground, translate(-0.2 * size, -0.2 * size, 2)))
    viewer.add(
        add_object(
            church_ground,
            translate(-0.03 * size, 0.06 * size, 5) @ rotate((0, 0, 1), -90)))

    # create forests
    forest = Forest(shader_materials)
    forest.construct_forest(translate(-2500, -6000, 0))
    viewer.add(*forest.children)

    # create a worker
    rotation = rotate((1, 0, 0), 90) @ rotate((0, 1, 0), 90) @ scale(0.5)
    worker = ObjectLoadSkinned(
        shader_skinned, 'models/characters/worker/worker_cutting_down.FBX',
        (-1, 0, 0))
    viewer.add(add_object(worker, transform=rotation))

    # create town's guards
    guard = ObjectLoadSkinned(
        shader_skinned,
        'models/characters/armored_swordman/armored_swordman_standing.FBX',
        (-1, 0, 0))
    transformation = translate(-0.2 * size, -0.2 * size, 0)

    translations = [
        translate(32.5 * 20, 33 * 20 - 50, 0),
        translate(87.5 * 20, 33 * 20 - 50, 0),
        translate(115 * 20, 33 * 20 - 50, 0),
        translate(172.5 * 20, 33 * 20 - 50, 0),
        translate(172.5 * 20 + 100, 105 * 20, 0),
        translate(172.5 * 20 + 100, 129 * 20, 0),
        translate(172.5 * 20 + 100, 159 * 20, 0),
        translate(172.5 * 20 + 100, 187.5 * 20, 0),
        translate(75 * 20, 187.5 * 20 + 50, 0),
        translate(20 * 20, 162.5 * 20 + 50, 0),
        translate(20 * 20, 131.5 * 20 + 50, 0),
        translate(20 * 20, 120.5 * 20 + 50, 0),
        translate(20 * 20 - 100, 92.5 * 20, 0),
        translate(120 * 20 - 100, 185 * 20, 0),
        translate(140 * 20 - 100, 185 * 20, 0)
    ]
    for t in translations:
        viewer.add(add_object(guard, transform=transformation @ t @ rotation))

    # create a non flat ground
    non_flat = ObjectLoadTextured(shader_texture,
                                  'models/models_OBJ/terre_eleve.obj',
                                  light_dir)
    viewer.add(
        add_object(non_flat, transform=translate(0.10 * size, 0.35 * size, 0)))

    # create a castle
    castle = Castle(shader_materials)
    castle.construct_castle(
        transform=translate(0.10 * size, 0.35 * size, 400) @ scale(40))
    viewer.add(*castle.children)

    # add an animated door
    translate_keys = {0: vec(0, 0, 300), 4: vec(0, 0, 100)}
    scale_keys = {0: 1, 4: 1}
    rotate_keys = {0: quaternion(), 4: quaternion()}
    door = ObjectLoadTextured(shader_texture, 'models/models_OBJ/door.obj',
                              light_dir)
    keynode = KeyFrameControlNode(translate_keys, rotate_keys, scale_keys)
    keynode.add(
        add_object(
            door,
            translate(30, -1300, 0) @ rotate((0, 1, 0), 90) @ rotate(
                (1, 0, 0), -90)))
    viewer.add(keynode)
Beispiel #15
0
from town import Town
from person import Person
from bus import Bus

townfile = open("town.txt", "r")
townList = []
for aline in townfile.readlines():
    values = aline.split()
    townList.append(Town(values[1],
                         values[3:]))  # create Town objects and add to list

busfile = open("bus.txt", "r")
busList = []
for aline in busfile.readlines():
    values = aline.split()
    busList.append(Bus(values))  # create Bus objects and add them to list

personfile = open("person.txt", "r")
personList = []
for aline in personfile.readlines():
    values = aline.split()
    personList.append(Person(values[0], values[1], values[2]))
    # create Person objects and add them to list

# change person.origin and person.destination into town objects
for person in personList:
    for town in townList:
        if person.locate() == town.getName():
            person.setLocation(town)
        if person.getDestination() == town.getName():
            person.setDestination(town)
Beispiel #16
0
#家から指定の場所までの経路情報

from town import Town
from shop import Shop

town_1 = Town('東京', '100', '電車+新幹線', '片道5000円超', '1時間30分')
town_2 = Town('栃木', '100', '車', '片道2500円', '2時間')
town_3 = Town('北海道', '1000', '自転車', '???', '1週間')

shop_1 = Shop('ベイシア', '自転車', '頻繁')
shop_2 = Shop('ダルマ大使', '自転車', '1ヶ月に1回')
shop_3 = Shop('アニメイト', '自転車+電車', '1ヶ月に1回未満')

towns = [town_1, town_2, town_3]
shops = [shop_1, shop_2, shop_3]

index = 1
for town in towns:
    print(str(index) + ':' + town.info_name())
    index += 1

for shop in shops:
    print(str(index) + ':' + shop.info_name())
    index += 1

number = int(input('詳細を知りたい行き先を選んでください。:')) - 1

if 0 <= number <= 2:
    select = towns[number]
    select.info()