def insertImprovement (current_slides, insert_index, insert_slide): # print("insertImprovement") old_score = current_slides[insert_index - 1].next_score new_score = (getScore( current_slides[insert_index - 1], insert_slide ) + getScore( insert_slide, current_slides[insert_index] ) / 2) return new_score - old_score
def test_add(self): # positive test row = ['Lions 3', ' Snakes 3'] got = {} want = {'Lions': 1} score.add(got, score.getName(row[0]), score.getScore(row[0]) - score.getScore(row[1])) value = {k: want[k] for k in want if k in got and want[k] == got[k]} self.assertEqual(len(value), 1) # negative test got = {} want = {'Tarantulas': 1} score.add(got, score.getName(row[0]), score.getScore(row[0]) - score.getScore(row[1])) value = {k: want[k] for k in want if k in got and want[k] == got[k]} self.assertEqual(len(value), 0)
def removeImprovement (current_slides, remove_index): # print("removeImprovement") old_score = (current_slides[remove_index].prev_score + current_slides[remove_index].next_score) / 2 new_score = getScore( current_slides[remove_index - 1], current_slides[remove_index + 1] ) return new_score - old_score
def collide(self): collidedict = pygame.sprite.groupcollide(self.bombs, self.targets, True, False) collidedict1 = pygame.sprite.groupcollide(self.missiles, self.planes, False, False) if collidedict1: for value1 in collidedict1.values(): for currentSprite1 in value1: print(currentSprite1) currentSprite1.shield -= 1 shield1 = currentSprite1.shield if shield1 <= 0: self.planes.remove(currentSprite1) self.bombs.remove(self.bomb_static) if bool(self.planes) == False: self.time_r = seconds = ( (pygame.time.get_ticks() - self.start_ticks) / 1000) writescore(self.time_r) endgame = getScore() self.running = False ##remove target if missile hits target if collidedict: for value in collidedict.values(): #print(value) for currentSprite in value: currentSprite.shield -= 1 shield = currentSprite.shield self.shield_name = currentSprite.name if shield <= 0: self.targets.remove(currentSprite) shield_name = '' shield = 3
def play_function(difficulty, font): """ Main game function :param difficulty: Difficulty of the game :param font: Pygame font :return: None """ difficulty = difficulty[0] assert isinstance(difficulty, str) if difficulty == 'EASY': f = font.render('Playing as baby', 1, COLOR_WHITE) elif difficulty == 'MEDIUM': f = font.render('Playing as normie', 1, COLOR_WHITE) elif difficulty == 'HARD': f = font.render('Playing as god', 1, COLOR_WHITE) else: raise Exception('Unknown difficulty {0}'.format(difficulty)) # Draw random color and text bg_color = random_color() f_width = f.get_size()[0] # Reset main menu and disable # You also can set another menu, like a 'pause menu', or just use the same # main_menu as the menu that will check all your input. main_menu.disable() main_menu.reset(1) while True: # Clock tick clock.tick(60) if main_menu.is_disabled(): #main_menu.enable() print('star') star = bomber.main_game() star.main_loop() ##score?? MOLLY = getScore() print(MOLLY) ##score?? main_menu.enable() #if main_menu.is_enabled(): # Application events playevents = pygame.event.get() for e in playevents: if e.type == QUIT: exit() elif e.type == KEYDOWN: if e.key == K_ESCAPE: if main_menu.is_disabled(): main_menu.enable() # Quit this function, then skip to loop of main-menu on line 197 return # Pass events to main_menu main_menu.mainloop(playevents) # Continue playing surface.fill(bg_color) surface.blit(f, ((WINDOW_SIZE[0] - f_width) / 2, WINDOW_SIZE[1] / 2)) pygame.display.flip()
from score import getScore from score import writescore ABOUT = [ 'PygameMenu {0}'.format(pygameMenu.__version__), 'Author: {0}'.format(pygameMenu.__author__), PYGAMEMENU_TEXT_NEWLINE, 'Email: {0}'.format(pygameMenu.__email__) ] COLOR_BACKGROUND = (128, 0, 128) COLOR_BLACK = (0, 0, 0) COLOR_WHITE = (255, 255, 255) FPS = 60.0 MENU_BACKGROUND_COLOR = (228, 55, 36) WINDOW_SIZE = (800, 800) MOLLY = getScore() # ----------------------------------------------------------------------------- # Init pygame pygame.init() os.environ['SDL_VIDEO_CENTERED'] = '1' # Create pygame screen and objects surface = pygame.display.set_mode(WINDOW_SIZE) pygame.display.set_caption('PygameMenu example 2') clock = pygame.time.Clock() dt = 1 / FPS # Global variables DIFFICULTY = ['EASY']
def doRandomInsert (current_slides, unused_slides_H, unused_slides_V, force): # print("doRandomInsert") if (not force and len(current_slides) < 2): # print("2 or more current slides needed for insert check.") return if (len(current_slides) > 3): insert_index = random.randint(1, len(current_slides)-1) else: insert_index = 0 # Randomly check a V-insert or H-insert v_case = random.randint(0,100) > 50 * ( ( len(unused_slides_H) + 1) / (len(unused_slides_V)+1) ) h_case = not v_case if (v_case): if (len(unused_slides_V) < 3): # print("2 or more unused slides needed for V insert.") return # V-case random_unused_index_1 = random.randint(0, len(unused_slides_V)-2) # print("random_unused_index_1: " + str(random_unused_index_1)) random_unused_index_2 = random.randint(0, len(unused_slides_V)-2) # print("random_unused_index_2: " + str(random_unused_index_2)) while (random_unused_index_1 == random_unused_index_2): random_unused_index_2 = random.randint(0, len(unused_slides_V)-2) # Build a new slide temporarily random_unused_slide = Slide( v_image_1 = unused_slides_V[ random_unused_index_1 ].v_image_1, v_image_2 = unused_slides_V[ random_unused_index_2 ].v_image_1, v_tags_1 = unused_slides_V[ random_unused_index_2 ].v_tags_1, v_tags_2 = unused_slides_V[ random_unused_index_2 ].v_tags_1 ) if ( force or insertImprovement(current_slides, insert_index, random_unused_slide) > 0 ): current_slides.insert(insert_index, random_unused_slide) if(insert_index > 0): current_slides[insert_index].prev_score = getScore( current_slides[insert_index - 1], current_slides[insert_index]); else: current_slides[insert_index].prev_score = 0; if(insert_index < len(current_slides) - 2): current_slides[insert_index].next_score = getScore( current_slides[insert_index], current_slides[insert_index + 1]); else: current_slides[insert_index].next_score = 0; if (random_unused_index_1 > random_unused_index_2): del unused_slides_V[random_unused_index_1] del unused_slides_V[random_unused_index_2] else: del unused_slides_V[random_unused_index_2] del unused_slides_V[random_unused_index_1] if (h_case): if (len(unused_slides_H) < 1): # print("1 or more unused slides needed for H insert.") return # H-slides are being used random_unused_index = random.randint(0, len(unused_slides_H)-1) random_unused_slide = unused_slides_H[random_unused_index] if ( force or insertImprovement(current_slides, insert_index, random_unused_slide) > 0 ): current_slides.insert(insert_index, random_unused_slide) if(insert_index > 0): current_slides[insert_index].prev_score = getScore( current_slides[insert_index - 1], current_slides[insert_index]); else: current_slides[insert_index].prev_score = 0; if(insert_index < len(current_slides) - 2): current_slides[insert_index].next_score = getScore( current_slides[insert_index], current_slides[insert_index + 1]); else: current_slides[insert_index].next_score = 0; del unused_slides_H[random_unused_index]
f.write(input_data) f.close() call ('./ambulance') inputFile = 'input' cityMap = parseInput(inputFile) startTime = clock() scoreHelper = readdata(inputFile) bestOutput = None bestScore = None while clock() - startTime < 60: output = run(cityMap) score = getScore(output, scoreHelper) #print(score) ======= startTime = clock() inputFile = 'input' cityMap = parseInput(inputFile) scoreHelper = readdata(inputFile) bestOutput = None bestScore = None while clock() - startTime < 60 * 0.10: output = run(cityMap) score = getScore(output, scoreHelper) print(score) >>>>>>> f2da8660fcc2857eb2c91f988b5d53989b6820c4 if bestOutput == None:
def test_getScore(self): # positive test self.assertEqual(score.getScore("Lions 3"), 3)