def __init__(self): self.id = str(uuid.uuid4()) self.build_hexes = hexes.build_hexes.copy() self.icebreakers = icebreakers.get_all() self.research = research.get_all() self.ships = ship.get_all() self.ships[0].active = True self.icebreakers[0].progress = self.icebreakers[0].maximum_progress self.research[0].progress = self.research[0].maximum_progress self.last_request = self.ct() self.money = start_money self.research_level = 1 self.datacenters = [] self.datacenter_cost = 0 self.set_next_dc_cost() self.quests = quests.get_all() self.ice_field = Ice() self.status = 0 self.last_quest_got = self.ct() - int( round((quest_frequency_per_ship - first_quest_start) * (1000 / ticks_per_second)))
def init_levels(self): level1 = Level() self.generate_ground(level1) for i in range(2, 8): level1.blocks.add( Crate((1200, self.window_height - 102 * i), (0, 0), 100, 100, "crate")) level1.blocks.add( Stone((1500, self.window_height - 310), (0, 0), 200, 200, "stone")) level1.enemies.add( Sheep((1500, self.window_height - 400), (0, 0), 100, 100, "sheep")) level2 = Level() self.generate_ground(level2) level2.blocks.add( Crate((1200, self.window_height - 200), (0, 0), 100, 100, "crate")) level2.blocks.add( Stone((1300, self.window_height - 200), (0, 0), 100, 100, "stone")) level2.blocks.add( Ice((1400, self.window_height - 200), (0, 0), 100, 100, "Ice")) level2.enemies.add( Sheep((1500, self.window_height - 200), (0, 0), 100, 100, "sheep")) level2.enemies.add( Sheep((1000, self.window_height - 200), (0, 0), 100, 100, "sheep")) level3 = Level() self.generate_ground(level3) level3.enemies.add(Ice((400, 900), (0, 0), 100, 100, "Ice")) level3.enemies.add(Sheep((300, 900), (0, 0), 100, 100, "sheep")) self.levels = [level1, level2, level3]
def move(self, grid, pos, mandalorian): if self.alive == 0: return new_coordinates = {} for i in self.__coordinates: new_coordinates[i] = [] for j in self.__coordinates[i]: grid[i][j] = Playarea() new_coordinates[i].append(j - 3) if j - 3 <= pos: self.alive = 0 flag = 0 for i in new_coordinates: for j in new_coordinates[i]: if grid[i][j].player == 1 or grid[i][j+1].player == 1 or grid[i][j+2].player == 1: self.alive = 0 if mandalorian.shield == 1: mandalorian.shield = 0 else: mandalorian.life -= 1 if mandalorian.life == 0: mandalorian.game_over() flag = 1 break if flag == 1: break if self.alive == 0: return self.__coordinates = new_coordinates cnt1 = 0 for i in new_coordinates: cnt2 = 0 for j in new_coordinates[i]: grid[i][j] = Ice(self.num, self.__disp[cnt1][cnt2]) cnt2 += 1 cnt1 += 1
def __init__(self, num, upper_row, column, grid): # Bullet.__init__(self) #here self.__alive = 1 self.__num = num self.__coordinates = { upper_row: [column - 1], upper_row + 1: [column - 2, column], upper_row + 2: [column - 2, column - 1, column] } self.__disp = { 0 : [Fore.WHITE + Style.BRIGHT + '_' + Style.RESET_ALL], 1 : [Fore.WHITE + Style.BRIGHT + '/' + Style.RESET_ALL, Fore.WHITE + Style.BRIGHT + '\\' + Style.RESET_ALL], 2 : [Fore.WHITE + Style.BRIGHT + '\\' + Style.RESET_ALL, Fore.WHITE + Style.BRIGHT + '_' + Style.RESET_ALL, Fore.WHITE + Style.BRIGHT + '/' + Style.RESET_ALL] } cnt1 = 0 cnt2 = 0 for i in self.__coordinates: cnt2 = 0 for j in self.__coordinates[i]: grid[i][j] = Ice(num, self.__disp[cnt1][cnt2]) cnt2 += 1 cnt1 += 1
class GameState: def __init__(self): self.id = str(uuid.uuid4()) self.build_hexes = hexes.build_hexes.copy() self.icebreakers = icebreakers.get_all() self.research = research.get_all() self.ships = ship.get_all() self.ships[0].active = True self.icebreakers[0].progress = self.icebreakers[0].maximum_progress self.research[0].progress = self.research[0].maximum_progress self.last_request = self.ct() self.money = start_money self.research_level = 1 self.datacenters = [] self.datacenter_cost = 0 self.set_next_dc_cost() self.quests = quests.get_all() self.ice_field = Ice() self.status = 0 self.last_quest_got = self.ct() - int( round((quest_frequency_per_ship - first_quest_start) * (1000 / ticks_per_second))) # print(self.last_quest_got, self.ct(), self.ct() - self.last_quest_got, "last got") def ct(self): return int(round(time.time() * 1000)) def ships_count(self): cnt = sum(1 for x in self.icebreakers if x.progress >= x.maximum_progress) return max(cnt, 1) def set_next_dc_cost(self): if self.datacenter_cost == 0: self.datacenter_cost = datacenter_start_cost else: self.datacenter_cost = int( round(self.datacenter_cost * datacenter_cost_coeff)) def update_all(self): t = self.ct() diff = round(t - self.last_request) ticks = round(diff / tick_duration) # print(ticks, file=sys.stdout) for _ in range(ticks): self.update() self.last_request = t self.check_if_get_quest() def check_if_get_quest(self): diff = self.ct() - self.last_quest_got wait = int( round(quest_frequency_per_ship / self.ships_count()) * 1000 / ticks_per_second) # print(diff, wait) if diff >= wait: self.last_quest_got = self.ct() + int( round(random.randint(-100, 100) / self.ships_count())) # print("get quest", self.last_quest_got, diff, wait) quests = list( filter( lambda q: not q.taken and not q.failed and not q.completed, self.quests)) if len(quests) > 0: idx = random.randint(0, len(quests) - 1) quest = quests[idx] # print("quest found") quest.take_quest() def check_if_complete_quest(self, hex): for q in self.quests: if q.taken and not q.completed and not q.failed: coords = q.coordinates for i in [-3, -2, -1, 0, 1, 2, 3]: for k in [-3, -2, -1, 0, 1, 2, 3]: if hex[0] + i == coords[0] and hex[1] + k == coords[1]: q.complete_quest(self) return None def update(self): if self.status == 0: for brkr in self.icebreakers: brkr.update(self) res = self.check_if_any_research_in_progress() if res: res.update() for shp in self.ships: shp.update(self) for q in self.quests: q.update() self.ice_field.update() self.check_status() def disable_ice(self): self.ice_field.enabled = False def check_status(self): count_q = sum(1 for x in self.quests if x.failed) if count_q >= fail_quests_count: self.status = -1 count_s = self.ships_count() if count_s >= len(self.icebreakers): self.status = 1 def build_datacenter(self): if self.money >= self.datacenter_cost: # free_hexes = [x for x in hexes.build_hexes if self.not_busy(x)] # if len(free_hexes) > 0: # index = random.randint(0, len(free_hexes) - 1) # hex = free_hexes[index] # dc = DataCenter(hex[0], hex[1]) dc = DataCenter(0, 0) self.datacenters.append(dc) self.money -= self.datacenter_cost self.set_next_dc_cost() self.research_level += 1 def not_busy(self, hex): for dc in self.datacenters: if dc.row == hex[0] and dc.col == hex[1]: return True return False def activate_ship(self, id): for shp in self.ships: if shp.id == id: shp.active = True # TODO event? break def get_research_by_id(self, research_id): return list(filter(lambda x: x.id == research_id, self.research))[0] def get_icebreaker_by_id(self, icebreaker_id): return list(filter(lambda x: x.id == icebreaker_id, self.icebreakers))[0] def get_ship_by_id(self, ship_id): return list(filter(lambda x: x.id == ship_id, self.ships))[0] def check_if_any_research_in_progress(self): res = list( filter( lambda x: x.progress > 0 and x.progress < x.maximum_progress, self.research)) if res: return res[0] return None def parse_action(self, req_data): # print(req_data, "parse_action") try: action = req_data['action'] except: action = '' if action == 'Research': research_id = req_data['researchId'] res = self.get_research_by_id(research_id) res.start_research(self) if action == 'Icebreaker': icebreaker_id = req_data['icebreakerId'] brkr = self.get_icebreaker_by_id(icebreaker_id) brkr.start_building(self) if action == 'Datacenter': self.build_datacenter() if action == 'ControlShip': ship_id = req_data['shipId'] direction = list(req_data['direction']) shp = self.get_ship_by_id(ship_id) shp.force_move(self, direction) def __getstate__(self): state = self.__dict__.copy() del state['ice_field'] if self.ice_field.enabled: state['ice'] = self.ice_field.current_field else: state['ice'] = [] return state def to_json(self): return jsonpickle.encode(self, unpicklable=False)
# ------------------------- General Initialization ---------------------------- # set random seeds if settings.RANDOM_SEED: tf.set_random_seed(settings.RANDOM_SEED) np.random.seed(settings.RANDOM_SEED) if settings.CPU_ONLY: config = tf.ConfigProto(device_count={'GPU': 0}) else: # don't allocate the entire vRAM initially config = tf.ConfigProto(gpu_options=tf.GPUOptions(allow_growth=True)) session = tf.Session(config=config) # ----------------------------- Model Definition ------------------------------ # initialize the ice ice_true = Ice() ice_true.homogeneous_init(l_abs=settings.L_ABS_TRUE, l_scat=settings.L_SCAT_TRUE) ice_pred = Ice(placeholders=True) ice_pred.homogeneous_init() # initialize the detector detector = Detector(dom_radius=settings.DOM_RADIUS, nx_strings=settings.NX_STRINGS, ny_strings=settings.NY_STRINGS, doms_per_string=settings.DOMS_PER_STRING, l_x=settings.LENGTH_X, l_y=settings.LENGTH_Y, l_z=settings.LENGTH_Z)
from flask import Flask from ice import Ice from flask_cors import CORS app = Flask(__name__) CORS(app) iceapp = Ice(app) iceapp.set_configs('configs.py') # import all database models from profile.model import User from session.model import Session, SessionRound iceapp.initialize_extensions() # import all blueprints print('initializing database') from profile import profile_blueprint as profile_bp from session import session_blueprint as session_bp iceapp.initialize_blueprints(profile_bp, session_bp) @app.route('/') def hello_world(): return 'Hello World!' if __name__ == '__main__': app.run()
def __init__(self, screen, timer, custom=False): self.screen = screen self.timer = timer '''Game Mode''' if custom != False: # 0, if no platforms are drawn self.custom = True if isinstance(custom, list): self.customPlatTypes = custom self.customNumPlatforms = None else: self.customNumPlatforms = custom self.customPlatTypes = None else: self.custom = False '''Game Mechanics''' self.totalGameTime = 1000 self.gameover = False self.gameover_image = None self.gameover_rect = None self.pause = False self.done = False font = load.load_font("OpenSans-Semibold", 40) self.pause_image = font.render("Paused", True, (236, 247, 255)) self.pause_rect = self.pause_image.get_rect() self.pause_rect.center = self.screen.get_rect().center self.exit = True self.showFPS = False self.noCrashes = False '''Background''' self.bg = Surface((32, 32)) self.bgTime = 0 self.bgColor = Game.bgColor self.sundownTime = 0 self.rainStart = random.randint(0, self.totalGameTime) self.rainEnd = self.rainStart + random.randint(150, 500) self.rainEndColor = None self.darkenTime = (self.rainEnd - self.rainStart) / 3 self.lightenTime = 2 * (self.rainEnd - self.rainStart) / 3 self.raining = self.darkening = self.lightening = False self.snowing = False self.snow = Snow() '''Game entities''' self.entities = pygame.sprite.Group() self.rocks = pygame.sprite.Group() self.trees = pygame.sprite.Group() self.birds = pygame.sprite.Group() self.coins = pygame.sprite.Group() self.ice = pygame.sprite.Group() self.player = Player() self.entities.add(self.player) self.coinCount = 0 self.flyingBirds = [] self.collectedCoins = [] self.clouds = None '''Score''' self.score = Score() self.scoreSprite = pygame.sprite.Group() self.scoreSprite.add(self.score) '''Platforms''' self.platforms = [] self.numPlatforms = 30 self.generatePlatforms() self.createPlatforms() '''Camera''' self.totalWidth = 1024 * len(self.platformTypes) self.totalHeight = 800 self.camera = Camera(complex_camera, self.totalWidth, self.totalHeight) '''Generating obstacles''' self.iceCoords = makeIce(self.platforms) rockInfo = makeRock(self.platforms) self.treeDict = makeTrees(self.platforms) self.birdDict = generateBirds(self.platforms) self.coinDict = makeCoins(self.platforms) (self.rockRects, self.rockCoords, self.rockAngles) = \ (rockInfo[0], rockInfo[1], rockInfo[2]) # ROCKS offset = 1024 for item in range(1, len(self.rockRects)): currentPlatform = self.platforms[item] x = self.rockRects[currentPlatform][0] + offset y = self.rockRects[currentPlatform][1] angle = self.rockAngles[currentPlatform] obstacle = random.choice("001") rock = Rock(x, y, angle) if obstacle == "0" else Penguin( x, y, angle) self.rocks.add(rock) offset += 1024 # ICE iceOffset = 0 for item in range(self.numPlatforms): currentPlatform = self.platforms[item] x = iceOffset ice = Ice(x, 299, currentPlatform, self.iceCoords) self.ice.add(ice) iceOffset += 1024 # TREES offset = 0 for item in range(len(self.treeDict)): currentPlatform = self.platforms[item] treeCoords = self.treeDict[currentPlatform] for tree in treeCoords: x = offset + tree[0] yOffset = random.randint(5, 20) y = tree[1] + 300 + yOffset tree = Tree(x, y) self.trees.add(tree) offset += 1024 # BIRBS & COINS offset = 0 for item in range(self.numPlatforms): currentPlatform = self.platforms[item] coords = self.birdDict[currentPlatform] coinCoords = self.coinDict[currentPlatform] if coords != None: for point in coords: x = offset + point[0] y = point[1] bird = Bird(x, y, 0) self.birds.add(bird) if coinCoords != None: for coin in coinCoords: x = offset + coin[0] y = coin[1] coin = Coin(x, y) self.coins.add(coin) offset += 1024
from tqdm import trange from ice import Ice from detector import Detector from model import Model from logger import Logger import settings # ------------------------------ Initialization ------------------------------- # set random seeds if settings.RANDOM_SEED: tf.set_random_seed(settings.RANDOM_SEED) np.random.seed(settings.RANDOM_SEED) # initialize the ice ice_true = Ice() ice_true.init(l_abs=settings.L_ABS_TRUE, l_scat=settings.L_SCAT_TRUE) ice_pred = Ice(trainable=True) ice_pred.init(l_abs=settings.L_ABS_START, l_scat=settings.L_SCAT_TRUE) # initialize the detector detector = Detector(dom_radius=settings.DOM_RADIUS, nx_strings=settings.NX_STRINGS, ny_strings=settings.NY_STRINGS, doms_per_string=settings.DOMS_PER_STRING, l_x=settings.LENGTH_X, l_y=settings.LENGTH_Y, l_z=settings.LENGTH_Z) # initialize the models