def __init__(self): self.pointSet = set() self.upperRBT = rbtree.RBTree() self.bottomRBT = rbtree.RBTree() self.leftmost = None self.rightmost = None self.pointCounter = 0 self.drawQueue = []
def load_level(self, level): level_file_name = "./level/" + level level_file = open(level_file_name, "r") level_obj = json.load(level_file) self.world_row = level_obj['worldRow'] self.world_col = level_obj['worldCol'] self.block_size = level_obj['blockSize'] self.scale = level_obj['scale'] self.canvas = pygame.Surface(((self.world_col * self.block_size) + 1, (self.world_row * self.block_size) + 1)) self.canvas_width, self.canvas_height = self.canvas.get_size() self.default_camera = camera.Camera( self.scale, (self.canvas_width, self.canvas_height), (self.window_width, self.window_height), (self.canvas_width, self.canvas_height), self.block_size) self.debug_camera = camera.Camera( 1, (self.canvas_width / 2, self.canvas_height), (self.window_width, self.window_height), (self.canvas_width, self.canvas_height), self.block_size) self.camera = self.default_camera self.camera.update_camera_rect() self.start_point = level_obj["start"] self.ch = character.Character(self.start_point["x"], self.start_point["y"], 32, 32) self.default_camera.pos['x'] = self.ch.x self.default_camera.pos['y'] = self.ch.y self.background = [] self.camera_background = [] self.world = rbtree.RBTree() self.blocks = level_obj["blocks"] index = 0 for block in self.blocks: self.new_block(block, index) index += 1 self.ready = True for bg in level_obj["camera_background"]: x = self.default_camera.rect.w * bg["x"] y = self.default_camera.rect.h * bg["y"] key = bg["key"] self.camera_background.append((x, y, key))
def new_block(self, block, block_id): x = block['x'] y = block['y'] w = block['w'] h = block['h'] for row in range(0, h): for col in range(0, w): pos_y = y + row if pos_y not in self.world: self.world.insert(pos_y, rbtree.RBTree()) row_tree = self.world[pos_y] pos_x = x + col row_tree.insert(pos_x, block_id) if "gen" in block: obj = block["gen"] prob = 0 if "prob" not in block else block["prob"] if random.randint(0, 100) < prob: index = random.randint(0, len(obj) - 1) self.background.append( (pos_x + obj[index]["x"], pos_y + obj[index]["y"], obj[index]["key"]))
import bintrees.rbtree as rbtree tree1 = rbtree.RBTree(zip(range(1, 100, 7), range(101, 200, 7))) tw = tree1.get_walker() tw.goto(50) for i in tw.iteritemsforward(): print i for i in tw.iteritemsbackward(): print i tree1[6:16] [i for i in tree1.itemslice(16, 6, reverse=True)] from IncrHull import *
import numpy as np import matplotlib.pyplot as plt import bintrees.rbtree as rbtree import time import threading import concurrent.futures ankunft_tree = rbtree.RBTree() lmb = 0.1 mue = 0.2 nmax = 20000 nmaxthreads = nmax / 2 zwischenankunft = np.random.exponential(1. / lmb, nmax) ankunft = np.cumsum(zwischenankunft) bearbeitungszeit = np.random.exponential(1. / mue, nmax) for z in zip(ankunft, bearbeitungszeit): ankunft_tree.insert(z[0], z[1]) tic = time.perf_counter() start: list = [] end: list = [] latest = 0. def do_work(key: float, value: float): global latest time.sleep(value) if latest < key: start.append(key)