def Run(self): self._universe = Universe() w = World(self._universe, 0, self._maze._entrance, self._maze, "", {}, "") self._universe.AddWorldsForEvaluation([w]) solutionWorld = self._universe.Run() print(f"Short path to solution is {solutionWorld._generation}.") return solutionWorld._generation
def __init__(self, info, lx, ly, max_age, split_energy, is_debug=False): self.universe = Universe(info, lx, ly) self.spotties = list() self.population = dict() self.population_tot = 0 self.max_age = max_age self.split_energy = split_energy self._is_debug = is_debug
def start_game(self): newUniverse = Universe(self.regions) regionNum = random.randint(0, 9) player = app.player player.ship = Ship("Clipper") player.region = Universe.get_instance().regions[regionNum] if (self.difficulty is 'easy'): player.credits = 1000 elif (self.difficulty is 'medium'): player.credits = 500 else: player.credits = 100
def steps_to_repeat_per_axis(universe): initial_universe = copy(universe) steps_to_repeat = [] for axis in ['x', 'y', 'z']: moons = [parse_moon(str) for str in inputs] universe = Universe(moons) universe.step() while not universe.equal_on_axis(axis, initial_universe): universe.step() steps_to_repeat.append(universe.steps) return steps_to_repeat
def start_game(self, player, difficulty): """Starts the game and instantiates all objects/attributes player -- the player that's added to the game difficulty -- the game's difficulty """ self.difficulty = difficulty self.player = player self.universe = Universe( ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'], [], self.player.credits) self.curr_region = self.universe.pick_random_region() self.npc = None
def reset(): global region_name_list region_name_list = [ "Blue light", "Ard", "Shreyu", "North Avenue East", "Florida Man", "Cookout", "Emory", "Bidet", "Braces", "Gorilla" ] global universe universe = Universe(region_name_list, 0, None) global universe_list universe_list = universe.__str__() global special_item_key special_item_key = randint(0, 9) global engineer engineer = 0 global pilot pilot = 0 global merchant merchant = 0 global fighter fighter = 0 global region region = Universe.regions[1] global credit credit = 0 global inventory inventory = {} player.set_engineer(0) player.set_pilot(0) player.set_merchant(0) player.set_fighter(0) player.set_fighter(0) player.set_region(Universe.regions[1]) player.set_credit(0) player.set_inventory({}) global npc_encounter npc_encounter = False global old_location old_location = "" global flee flee = False global karma karma = 0 player.get_ship().ship_health = player.get_ship().max_ship_health player.get_ship().fuel_capacity = player.get_ship().max_fuel_capacity player.get_ship().cargo_space = player.get_ship().max_cargo_space
def run(): '''does the things''' name = input('Input file => ') print(name) data = json.loads(open(name).read()) collisions = [] step = 0 stopped = set() p_by_u = dict() #{universe: [portals]} r_by_u = dict() #{universe: [rewards]} u_by_r = dict() #{reward: universe} universes = [ Universe(uni['universe_name'], uni['rewards'], uni['portals']) for uni in data ] for uni in universes: p_by_u[uni.name] = uni.portals r_by_u[uni.name] = uni.rewards for uni in universes: for reward in uni.rewards: u_by_r[reward[3]] = uni.name persons = [Person(person[0], person[1], uni['universe_name'], person[2], person[3], person[4],\ person[5], uni['universe_name']) for uni in data for person in uni['individuals']] start(universes, data) for person in persons: #check boundary conditions loc_check = bool(person.x <= 0 or person.x >= 1000 or person.y <= 0 or person.y >= 1000) speed_check = bool(-10 < person.dx < 10 or -10 < person.dy < 10) if person.movable and (loc_check or speed_check): person.movable = False temp = deepcopy(person) fix(temp) print('{} stopped at simulation step {} at location ({},{})\n'.format(\ temp.name, step, temp.x, temp.y)) stopped.add(person) while step < 100 and len(stopped) < len(persons): step += 1 for person in persons: #check if the person can move if person.movable: person.move() for person in persons: #check boundary conditions if person.movable and (person.x <= 0 or person.x >= 1000 or person.y <= 0 or person.y >= 1000): person.movable = False temp = deepcopy(person) fix(temp) print('{} stopped at simulation step {} at location ({},{})\n'.format(\ temp.name, step, temp.x, temp.y)) stopped.add(person) #Check for rewards for person in persons: #check if person can do anything if person not in stopped: #check if person is near reward for reward in r_by_u[person.current_universe]: if sqrt((person.x - reward[0])**2 + (person.y - reward[1])**2) <= person.radius: temp = r_by_u[person.current_universe] name = reward[3] person.rewards.append(temp.pop(temp.index(reward))) n = len(person.rewards) new = pickup_r(person, n) person.dx, person.dy = new[0], new[1] print('{} picked up "{}" at simulation step {}'.format( person.name, name, step)) temp = copy(person) print(temp, end='\n\n') #check stop conditions if abs(person.dx) < 10 or abs(person.dy) < 10: person.movable = False temp = copy(person) print('{} stopped at simulation step {} at location ({},{})\n'.format(\ temp.name, step, temp.x, temp.y)) stopped.add(person) #Check for collisions for person in persons: #check if person can do anything if person not in stopped: #check for collisions for other in persons: if other not in stopped: if person.name != other.name and person.current_universe == other.current_universe: temp1, temp2 = copy(person), copy(other) distance = sqrt((temp1.x - temp2.x)**2 + (temp1.y - temp2.y)**2) if distance <= (person.radius + other.radius) and\ (other.name, person.name) not in collisions: collisions.append((person.name, other.name)) print('{} and {} crashed at simulation step {} in universe {}'.format\ (person.name, other.name, step, person.current_universe)) if person.rewards: post_col(person, u_by_r, r_by_u) if other.rewards: post_col(other, u_by_r, r_by_u) temp1 = copy(person) temp2 = copy(other) print(str(temp1), str(temp2), '', sep='\n') elif distance > person.radius + other.radius: if (other.name, person.name) in collisions: collisions.remove( (other.name, person.name)) if (person.name, other.name) in collisions: collisions.remove( (person.name, other.name)) #Check for portals for person in persons: #check if person can do anything if person not in stopped: #check for portalling for portal in p_by_u[person.current_universe]: if sqrt((person.x - portal[0])**2 + (person.y - portal[1])**2) <= person.radius: person.x, person.y, person.current_universe = portal[ 3], portal[4], portal[2] print( '{} passed through a portal at simulation step {}'. format(person.name, step)) temp = copy(person) print(temp, end='\n\n') if (abs(person.dx) < 10 or abs(person.dy) < 10) and person.movable: person.movable = False temp = copy(person) print('{} stopped at simulation step {} at location ({},{})\n'.format(\ temp.name, step, temp.x, temp.y)) stopped.add(person) for person in persons: fix(person) results = (persons, stopped, step) end(results)
def main(): uni = Universe(2**10)
def __init__(self, initial_configuration=0, dimension=8): self.dimension = dimension self.initial_configuration = initial_configuration self.universe = Universe(initial_configuration, dimension)
print("SPACE TRADER \n") input_name = input("Enter your name: ") print("NAME: " + input_name) allocate_points() choose_difficulty() test_player = Player(input_name, skills, difficulty) print(test_player.get_name()) print(test_player.get_skills()) print(test_player.get_difficulty()) print(test_player.get_credits()) print(test_player.get_ship_type()) test_universe = Universe() for solar in test_universe.get_solar_systems(): print(solar.get_name()) print(solar.get_coords()) print(solar.get_tech_level()) print(solar.get_resources()) print("END")
f = open("Input12.txt") inputs = f.read().splitlines() f.close() def parse_moon(string): m = re.search(r'<x=(-?\d+), y=(-?\d+), z=(-?\d+)>', string) x, y, z = int(m.group(1)), int(m.group(2)), int(m.group(3)) return Moon(x, y, z) # --- Part 1 --- moons = [parse_moon(str) for str in inputs] universe = Universe(moons) for _ in range(1000): universe.step() print(universe.total_energy()) # --- Part 2 --- def lowest_common_multiple(nums): lcm = nums[0] for i in nums[1:]: lcm = int(lcm*i/math.gcd(lcm, i)) return lcm def steps_to_repeat_per_axis(universe):
# app = Flask(__name__) # # #http://flask.palletsprojects.com/en/1.1.x/quickstart/#rendering-templates import os import sys from flask import Flask, render_template, request from Universe import Universe, Player, Item, Market from random import randint app = Flask(__name__) region_name_list = [ "Blue light", "Ard", "Shreyu", "North Avenue East", "Florida Man", "Cookout", "Emory", "Bidet", "Braces", "Gorilla" ] universe = Universe(region_name_list, 0, None) universe_list = universe.__str__() special_item_key = randint(0, 9) name = "RITHIK" engineer = 0 pilot = 0 merchant = 0 fighter = 0 region = Universe.regions[1] credit = 0 ship = "None" inventory = {} player = Player(name, engineer, pilot, merchant, fighter, region, credit, ship, inventory) wood = Item("Wood", 27, [ "AGRICULTURE", "MEDIEVAL", "RENAISSANCE", "INDUSTRIAL", "MODERN",
def main(): my_universe = Universe(2**15) my_universe.display_universe() my_probe = Probe(my_universe, randint(2**3, 2**64), randint(2**3, 2**64), randint(2**3, 2**64)) my_probe.search_for_life()
from Map import Map import numpy as np from City import City from Universe import Universe from pyquil.quil import Program map_matrix = np.matrix('1 1 1 1; 1 1 1 1; 1 1 1 1; 1 1 1 1') map = Map(map_matrix) cities = [City(identity=i) for i in range(4)] program = Program() universe = Universe(cities=cities, map=map, program=program)