def makeMap(self, blocks, dots, powerPills): size = self.settings.rectSize for row in self.lines: for chars in row: if chars == "X": newBlock = Blocks(self.screen) newBlock.rect.x, newBlock.rect.y = self.xShift, self.yShift self.xShift += size blocks.add(newBlock) elif chars == ".": newDot = Dot(self.screen, self.settings) newDot.rect.x, newDot.rect.y = self.xShift +size/4, self.yShift +size/4 self.xShift += size dots.add(newDot) elif chars ==" ": self.xShift += size elif chars == "o": newPill = PowerPill(self.screen, self.settings) newPill.rect.x, newPill.rect.y = self.xShift +size/4, self.yShift +size/4 powerPills.add(newPill) self.xShift += size elif chars == "x": newBlock = Blocks(self.screen) newBlock.rect.x, newBlock.rect.y = self.xShift, self.yShift newBlock.type = 1 self.xShift += size blocks.add(newBlock) self.xShift = 0 self.yShift += size
def __init__(self, rnn_type, ntoken, ninp, nhid, nlayers, n_out=10, dropout=0.5, tie_weights=False, use_cudnn_version=True, use_adaptive_softmax=False, cutoffs=None, discrete_input=True, num_blocks=[6], topk=[4], do_gru=False, use_inactive=False, blocked_grad=False, layer_dilation = -1, block_dilation = -1, num_modules_read_input=2): super(RNNModel, self).__init__() self.topk = topk self.use_cudnn_version = use_cudnn_version self.drop = nn.Dropout(dropout) if discrete_input: self.encoder1 = nn.Embedding(ntoken, ninp//3) self.encoder2 = nn.Embedding(ntoken, ninp//3) self.encoder3 = nn.Embedding(ntoken, ninp//3) else: self.encoder1 = nn.Linear(ntoken, ninp//3) self.encoder2 = nn.Linear(ntoken, ninp//3) self.encoder3 = nn.Linear(ntoken, ninp//3) self.num_blocks = num_blocks self.nhid = nhid self.discrete_input = discrete_input self.sigmoid = nn.Sigmoid() self.sm = nn.Softmax(dim=1) self.use_inactive = use_inactive self.blocked_grad = blocked_grad self.rnn_type = rnn_type self.nlayers = nlayers self.use_adaptive_softmax = use_adaptive_softmax print("Dropout rate", dropout) self.decoder = nn.Linear(nhid[-1], n_out) self.init_weights() self.model = Blocks(ninp, nhid, nlayers, num_blocks, topk, use_inactive, blocked_grad)
def __init__(self, backend, debug=False): # Debug mode means printing stack trace on errors self.debug = debug self.env = Environment( loader=PrefixLoader({ 'blocks-'+backend: PackageLoader('dematik', 'blocks-'+backend), 'macros-'+backend: PackageLoader('dematik', 'macros-'+backend) }), autoescape=select_autoescape(['j2']), undefined=StrictUndefined ) self.env.globals = { "now": datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S"), "get_text" : self.get_text, "get_md_text" : self.get_md_text, "get_items" : self.get_items, "get_rows" : self.get_rows, "get_columns" : self.get_columns, "get_varname" : self.get_varname, "get_id" : self.get_id, "get_date_min" : self.get_date_min, "get_date_is_futur" : self.get_date_is_futur, "get_date_max" : self.get_date_max, "get_date_in_past" : self.get_date_in_past, "get_date_can_be_today" : self.get_date_can_be_today, "is_in_listing" : self.is_in_listing, "is_in_filters" : self.is_in_filters, } self.fields_data = FieldData() self.blocks = Blocks(self.env, ['blocks-'+backend]) self.reset()
def makeMap(screen, maze, MyShield): line = "" allLines = [] deltaX = 0 deltaY = 0 file = open("pacmanportalmaze.txt", "r") if file.mode == 'r': contents = file.read() for chars in contents: if chars != '\n': line += chars else: allLines.append(line) line = "" for line in allLines: for char in line: if char == 'X': newBlock = Blocks(screen) newBlock.rect.x, newBlock.rect.y = deltaX, deltaY maze.add(newBlock) elif char == 'o': newShield = Shield(screen) newShield.rect.x, newShield.rect.y = deltaX, (deltaY) MyShield.add(newShield) deltaX += 13 deltaX = 0 deltaY += 13
def __init__(self, rnn_type, ntoken, ninp, nhid, nlayers, dropout=0.5, tie_weights=False, use_cudnn_version=True, use_adaptive_softmax=False, cutoffs=None, discrete_input=True, num_blocks=[6], topk=[4], do_gru=False, use_inactive=False, blocked_grad=False, layer_dilation = -1, block_dilation = -1): super(RNNModel, self).__init__() self.topk = topk self.use_cudnn_version = use_cudnn_version self.drop = nn.Dropout(dropout) if discrete_input: self.encoder = nn.Embedding(ntoken, ninp) else: self.encoder = nn.Linear(ntoken, ninp) self.num_blocks = num_blocks self.nhid = nhid self.discrete_input = discrete_input self.sigmoid = nn.Sigmoid() self.sm = nn.Softmax(dim=1) self.use_inactive = use_inactive self.blocked_grad = blocked_grad self.rnn_type = rnn_type self.nlayers = nlayers self.use_adaptive_softmax = use_adaptive_softmax print("Dropout rate", dropout) self.decoder = nn.Linear(nhid[-1], ntoken) if tie_weights: print('Tying Weights!') if nhid[-1] != ninp: raise ValueError('When using the tied flag, nhid must be equal to emsize') self.decoder.weight = self.encoder.weight self.init_weights() self.model = Blocks(ninp, nhid, nlayers, num_blocks, topk, use_inactive, blocked_grad)
def __init__(self, data, parameters): self.parameters = parameters self.input = data.inputs self.labels = data.labels self.input_file_names = data.file_names self.blocks = Blocks() self.data = data self.models = {"default_mfcc_model": self.default_mfcc_model, "unfinished_model": self.unfinished_model} self.models[self.parameters['model']]()
def __init__(self, xy, text, action, size): super(MenuItem, self).__init__(size) from blocks import Blocks self.b = Blocks(size) self.action = action self.hovered = False self.text = text self.w, self.h = self.font.size(text) x, y = xy[0] - self.w / 2, xy[1] self.rect = pygame.Rect(x, y, self.w, self.h) self.s = pygame.Surface((self.b.size * 1.5 + self.w, self.h), pygame.SRCALPHA, 32) self.s.convert_alpha() self.image = self.font.render(self.text, True, self.normalc) self.s.blit(self.image, (self.b.size * 1.5, 0)) self.image = self.s
def __init__(self, row, column, block_input, init_list=None): if row == None or column == None or block_input == None: print('argument : row, col, block_list, init_list.') else: # self.dimension = (row, column) self.blocks = Blocks(block_input) self.table_row = row self.table_col = column length = row * column self.table = {n: 'x' for n in range(1, length + 1)} if init_list == None: self.init_list = [] else: self.init_list = init_list print("init_list :", self.init_list) self.load_block_init() print('table created. row:', row, ' x col:', column)
def __init__(self): pygame.init() #初始化背景设置 self.blocks_right = c * (block_size + 1) #计算方格区右边界 height = r * (block_size + 1) if height < 300: height = 300 #保证按键显示完全 self.screen = pygame.display.set_mode( (self.blocks_right + 100, height)) pygame.display.set_caption("Game Of Life") #设置标题 self.screen.fill(bg_color) self.core = Core(r, c) self.__init_lives() self.blocks = Blocks(r, c, block_size, self.screen, self.core.get_now_state()) self.blocks.draw_board() self.running = False self.time = time.time() self.__add_buttons() self.speed = 1 return
def readFile(screen, blocks, shield, powerpills, intersections): file = open("images/otherpacmanportalmaze.txt", "r") contents = file.read() line = '' all_lines = [] for chars in contents: if chars != '\n': line += chars else: all_lines.append(line) line = '' i = 0 j = 0 intersection_num = 0 for rows in all_lines: for chars in rows: if chars == 'X': new = Blocks(screen) new.rect.x, new.rect.y = 13 * i, 13 * j blocks.add(new) elif chars == 'd': thepowerpill = Powerpills(screen) thepowerpill.rect.x, thepowerpill.rect.y = 13 * i, 13 * j powerpills.add(thepowerpill) elif chars == 'b': thepowerpill = Powerpills(screen, 'big') thepowerpill.rect.x, thepowerpill.rect.y = 13 * i, 13 * j powerpills.add(thepowerpill) elif chars == 'i': intersection = Intersections(screen, intersection_num) intersection_num += 1 intersection.rect.x, intersection.rect.y = 13 * i, 13 * j intersections.add(intersection) elif chars == 'o': theshield = Shield(screen) theshield.rect.x, theshield.rect.y = 13 * i, 13 * j shield.add(theshield) i += 1 i = 0 j += 1
def __init__(self, data, parameters): """ :param training: If this is true some update ops and input pipeline will be created. The update ops are not necessarily used because training is True. """ self.batch_size = parameters['batch_size'] self.training = parameters["training"] self.label_on_value = parameters["label_on_value"] self.label_off_value = parameters["label_off_value"] self.decay_rate = parameters["decay_rate"] self.filter_size = parameters["filter_size"] self.stride_length = parameters["stride_length"] self.bigram_model = parameters["bigram_model"] self.num_bigrams = parameters["num_bigrams"] self.max_model_width = parameters["max_model_width"] self.global_avg_pooling = parameters["global_avg_pooling"] self.use_adam = parameters["use_adam"] self.sigmoid_unknown = parameters["sigmoid_unknown"] self.accuracy_regulated_decay = parameters["accuracy_regulated_decay"] self.loss_regulated_decay = parameters["loss_regulated_decay"] self.blocks = Blocks(self.training, parameters) self.model_width = parameters["model_width"] # 32 self.model_setup = map( lambda x: int(x.strip()), parameters["model_setup"].split(',')) # [0, 4, 4] self.input = data.inputs self.labels = data.labels self.input_file_names = data.file_names self.learning_rate = None self.logits = self.inference(self.input) self.top_1_accuracy = None self.loss = None self.train_step = None self.global_step = None self.one_hot_truth = None self.optimizer = None self.evaluation() self.optimize()
def __init__(self, k, parameters): ''' \fn Level(u, parameters) \brief Constructor default \param k - Level of fovea \param parameters - Parameters of fovea structure ''' self.k = k # Save level # Updating the image size parameter ( U ) was done in configuration of fovea if (parameters.typeShape == 0): # Blocks self.boundingBox = [] # Clear boundingBox self.shapeLevel = [] # Clear shapeLevel self.boundingBox.append(self.getDelta(parameters)) self.boundingBox.append(self.getSize(parameters)) block = Blocks(self.boundingBox) self.shapeLevel.append(block) else: # Polygons print("Shape wasn't configured")
def readFile(screen, blocks, shield, powerpills, portal): file = open("images/otherpacmanportalmaze.txt", "r") contents = file.read() line = '' all_lines = [] for chars in contents: if chars != '\n': line += chars else: all_lines.append(line) line = '' i = 0 j = 0 for rows in all_lines: for chars in rows: if chars == 'X': new = Blocks(screen) new.rect.x, new.rect.y = 13 * i, 13 * j blocks.add(new) elif chars == 'd': thepowerpill = Powerpills(screen) thepowerpill.rect.x, thepowerpill.rect.y = 13 * i, 13 * j powerpills.add(thepowerpill) elif chars == 'o': theshield = Shield(screen) theshield.rect.x, theshield.rect.y = 13 * i, 13 * j shield.add(theshield) # This is where the horizontal portal is supposed to be elif chars == 'h': pass # Vertical portal? elif chars == 'P': theportal = Portal(screen) theportal.rect.x, theportal.rect.y = 13 * i, 13 * j portal.add(theportal) pass i += 1 i = 0 j += 1
def main(): if len(sys.argv) != 2: print('usage:', sys.argv[0], '<filename>') exit(1) filename = sys.argv[1] try: stdscr = curses.initscr() curses.noecho() curses.cbreak() #stdscr.keypad(True) blocks = Blocks(stdscr) blocks.add_stdout('Stdout/Stderr', 8) manager = JupyterManager(blocks, sys.argv[1]) manager.launch() manager.load(filename) stdscr.clear() print('Ctrl-J: Move block down') print('Ctrl-K: Move block up') print('Ctrl-P t: Create terminal') print('Ctrl-P e: Run external python') print('Ctrl-P o/O: Create new cell') print(' -> Press u for history') print(' -> Press Tab for eval') while True: try: blocks.render() blocks.wait() manager.clear_buffers() manager.save(filename) except KeyboardInterrupt: break finally: curses.nocbreak() stdscr.keypad(False) curses.echo() curses.endwin()
from ball import Ball from blocks import Blocks from scoreboard import ScoreBoard # setting up the game screen game_screen = Screen() game_screen.setup(width=600, height=650) game_screen.bgcolor("black") game_screen.title("Breakout Game") game_screen.tracer(0) game_screen.listen() # setup and display each game component user_paddle = Paddle() game_ball = Ball() game_blocks = Blocks() scores = ScoreBoard() game_on = True def end_game(): """A function that ends the game abruptly""" global game_on game_on = False # move the paddle up and down on key presses game_screen.onkey(user_paddle.move_up, "Up") game_screen.onkey(user_paddle.move_down, "Down")
def create_bg_blocks(ai_settings, screen, image, bg_blocks, rx, ry, xx, type_): block = Blocks(ai_settings, screen, image, rx, ry, 0, type_) block.rect.y = ry block.rect.x = rx block.x = xx bg_blocks.add(block)
def plansza3(self): """Rysuje trzecią planszę.""" for i in range(2): self.add_speed = Extensions( random.randrange(30, self.screen_width - 30), random.randrange(30, self.screen_height / 2), "data/add_speed.png") self.AddSpeedSprite.add(self.add_speed) for i in range(2): self.add_speed = Extensions( random.randrange(30, self.screen_width - 30), random.randrange(30, self.screen_height / 2), "data/substract_speed.png") self.SubstractSpeedSprite.add(self.add_speed) i = 10 j = 35 while i < self.screen_width - 10: block = Blocks(i, j, 'data/gray_brick.png') self.BlocksSprite.add(block) i = i + 87.5 i = 97.5 j = 70 while i < self.screen_width - 97.5: block = Blocks(i, j, 'data/wood_brick.png') self.BlocksSprite.add(block) i = i + 87.5 i = 185 j = 105 while i < self.screen_width - 185: block = Blocks(i, j, 'data/gray_brick.png') self.BlocksSprite.add(block) i = i + 87.5 i = 272.5 j = 140 while i < self.screen_width - 272.5: block = Blocks(i, j, 'data/wood_brick.png') self.BlocksSprite.add(block) i = i + 87.5 #### block = Blocks(360, 175, 'data/gray_brick.png') self.BlocksSprite.add(block) #### i = 272.5 j = 210 while i < self.screen_width - 272.5: block = Blocks(i, j, 'data/wood_brick.png') self.BlocksSprite.add(block) i = i + 175 i = 185 j = 245 while i < self.screen_width - 185: block = Blocks(i, j, 'data/gray_brick.png') self.BlocksSprite.add(block) i = i + 175 i = 97.5 j = 280 while i < self.screen_width - 97.5: block = Blocks(i, j, 'data/wood_brick.png') self.BlocksSprite.add(block) i = i + 175 i = 10 j = 315 while i < self.screen_width - 10: block = Blocks(i, j, 'data/gray_brick.png') self.BlocksSprite.add(block) i = i + 175 #### i = 10 for k in range(3): block = Blocks(i, 175, 'data/light_wood_brick.png') self.BlocksSprite.add(block) i = i + 87.5 j = 140 for k in range(2): block = Blocks(97.5, j, 'data/light_wood_brick.png') self.BlocksSprite.add(block) j = j + 70 i = 535 for k in range(3): block = Blocks(i, 175, 'data/light_wood_brick.png') self.BlocksSprite.add(block) i = i + 87.5 j = 140 for k in range(2): block = Blocks(622.5, j, 'data/light_wood_brick.png') self.BlocksSprite.add(block) j = j + 70 self.counter = len(self.BlocksSprite)
def plansza2(self): """Rysuje drugą planszę.""" j = self.screen_height / 2 - 50 while j > 30: block = Blocks(10, j, 'data/gray_brick.png') self.BlocksSprite.add(block) j = j - 60 j = self.screen_height / 2 - 25 while j > 30: block = Blocks(90, j, 'data/wood_brick.png') self.BlocksSprite.add(block) j = j - 60 j = self.screen_height / 2 - 50 while j > 30: block = Blocks(170, j, 'data/gray_brick.png') self.BlocksSprite.add(block) j = j - 60 #### j = self.screen_height / 2 - 50 while j > 30: block = Blocks(self.screen_width - 90, j, 'data/gray_brick.png') self.BlocksSprite.add(block) j = j - 60 j = self.screen_height / 2 - 25 while j > 30: block = Blocks(self.screen_width - 170, j, 'data/wood_brick.png') self.BlocksSprite.add(block) j = j - 60 j = self.screen_height / 2 - 50 while j > 30: block = Blocks(self.screen_width - 250, j, 'data/gray_brick.png') self.BlocksSprite.add(block) j = j - 60 ### j = self.screen_height / 2 - 50 for k in range(8): block = Blocks(270, j, 'data/light_wood_brick.png') self.BlocksSprite.add(block) j = j - 30 j = self.screen_height / 2 - 50 for k in range(8): block = Blocks(450, j, 'data/light_wood_brick.png') self.BlocksSprite.add(block) j = j - 30 block = Blocks(360, 40, 'data/light_wood_brick.png') self.BlocksSprite.add(block) block = Blocks(360, 250, 'data/light_wood_brick.png') self.BlocksSprite.add(block) i = 10 while i < self.screen_width: block = Blocks(i, self.screen_height / 2 + 20, 'data/light_wood_brick.png') self.BlocksSprite.add(block) i = i + 175 i = 100 while i < self.screen_width: block = Blocks(i, self.screen_height / 2 + 55, 'data/light_wood_brick.png') self.BlocksSprite.add(block) i = i + 175 self.counter = len(self.BlocksSprite)
def plansza1(self): """Rysuje pierwszą planszę.""" i = 5 j = self.screen_height / 2 - 50 while j > 0: block = Blocks(i, j, 'data/gray_brick.png') self.BlocksSprite.add(block) i = i + 33.75 j = j - 30 i = 90 j = self.screen_height / 2 - 50 while j > 70: block = Blocks(i, j, 'data/gray_brick.png') self.BlocksSprite.add(block) i = i + 33.75 j = j - 30 i = self.screen_width - 85 j = self.screen_height / 2 - 50 while j > 0: block = Blocks(i, j, 'data/wood_brick.png') self.BlocksSprite.add(block) i = i - 33.75 j = j - 30 i = self.screen_width - 2 * 85 j = self.screen_height / 2 - 50 while j > 70: block = Blocks(i, j, 'data/gray_brick.png') self.BlocksSprite.add(block) i = i - 33.75 j = j - 30 j = self.screen_height / 2 + 50 while j > 0: block = Blocks(360, j, 'data/wood_brick.png') self.BlocksSprite.add(block) j = j - 30 j = self.screen_height / 2 + 50 while j > 150: block = Blocks(275, j, 'data/gray_brick.png') self.BlocksSprite.add(block) j = j - 30 j = self.screen_height / 2 + 50 while j > 150: block = Blocks(445, j, 'data/wood_brick.png') self.BlocksSprite.add(block) j = j - 30 self.counter = len(self.BlocksSprite)
from turtle import Screen from paddle import Paddle from ball import Ball from scoreboard import ScoreBoard from blocks import Blocks import time screen = Screen() screen.bgcolor("black") screen.setup(width=800, height=600) screen.title("Breakout!") screen.tracer(0) paddle = Paddle((0, -250)) scoreboard = ScoreBoard() blocks = Blocks() ball = Ball() screen.listen() screen.onkey(paddle.go_left, "Left") screen.onkey(paddle.go_right, "Right") game_is_on = True red_contact_first_time = False orange_contact_first_time = False red_contact = False orange_contact = False hits = 0 lives = 3 while game_is_on:
from blocks import Blocks, block_dataset blocks = Blocks(block_dataset) # print("test", block.block_list) print("test", blocks.block_used) print("mark #2 block used") blocks.show_blocks() blocks.mark_used(2) blocks.show_blocks()
def setUp(self): self.tetris = Tetris() self.display = pygame.display.set_mode((800, 700)) self.gameloop = GameLoop(self.display) self.blocks = Blocks()