class App: def __init__(self): pyxel.init(128, 128, caption="Snake Game", fps=5) pyxel.load( os.path.dirname(os.path.abspath(__file__)) + "/assets.pyxel") pyxel.run(self.update, self.draw) def update(self): if pyxel.btnp(pyxel.KEY_Q): pyxel.quit() self.item.update() self.me.update() if self.item.x == self.me.x and self.item.y == self.me.y: self.eat() def draw(self): pyxel.cls(0) self.me.draw() self.item.draw() self.score.draw() def eat(self): self.item.alives = False self.score.point += 1 self.me.ghosts += 1 me = me.Me() item = item.Item() score = score.Score()
def game(): pygame.init() game_settings = settings.Settings() screen = pygame.display.set_mode( (game_settings.width, game_settings.height)) pygame.display.set_caption("Space Invaders") play_button = play.Button(settings, screen, "Play") stats = statistics.GameStats(game_settings) scoreboard = score.Score(game_settings, screen, stats) player_render = ship.Ship(screen, game_settings) bullets = pygame.sprite.Group() alien_group = pygame.sprite.Group() functions.alien_fleet(game_settings, screen, alien_group) while True: functions.check_events(game_settings, screen, player_render, bullets, play_button, stats, alien_group, scoreboard) if stats.game_active: player_render.update() functions.update_bullets(alien_group, bullets, screen, game_settings, scoreboard, stats) functions.update_aliens(game_settings, stats, player_render, alien_group, screen, bullets, scoreboard) functions.update_screen(game_settings, screen, player_render, alien_group, bullets, play_button, stats, scoreboard)
def event(self, event): if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: globes.Globals.RUNNING = False if event.type == pygame.KEYDOWN and event.key == pygame.K_UP: self.option = (self.option - 1) % self.num_options if event.type == pygame.KEYDOWN and event.key == pygame.K_DOWN: self.option = (self.option + 1) % self.num_options if event.type == pygame.KEYDOWN and \ (event.key == pygame.K_SPACE or event.key == pygame.K_RETURN): if self.option == 0: globes.stop_music() globes.play_music("angryTwain.ogg") globes.Globals.GAME = game.Game() globes.Globals.LVLS_UNLOCKED = 1 globes.Globals.STATE = cutscene1.Hack() elif self.option == 1: globes.stop_music() globes.Globals.STATE = score.Score() elif self.option == 2: globes.Globals.STATE = options.Options(True) elif self.option == 3: globes.Globals.RUNNING = False elif self.option == 4: globes.stop_music() globes.play_music("game.ogg") if globes.Globals.MINIGAME is not None: globes.Globals.STATE = globes.Globals.MINIGAME else: globes.Globals.STATE = globes.Globals.GAME
def __init__(self, options, after_pause, seed=None): """ @rtype: None """ state_engine.GameState.__init__(self) self.current_opts = options self.after_pause = after_pause self.players = [] for i in range(int(self.current_opts["NUMBER_OF_PLAYER"])): if i < len(CONFIG_JUMP_KEY): new_player = Player(50 + i * 100, 0, 8, 0, self.current_opts["CHARACTER"], CONFIG_JUMP_KEY[i]) else: new_player = Player(50 + i * 100, 0, 8, 0, self.current_opts["CHARACTER"], CONFIG_JUMP_KEY[CONST_DEFAULT_JUMP_KEY]) self.players.append(new_player) self.items = item.ItemManager() self.monsters = monster.MonsterManager() self.game_map = Map(self.items, seed) self.acceleration_x = 0 # As said, x variables is not of any use at the moment self.acceleration_y = 1 self.frame = 0 # Number of frame since beginning self.max_speed = self.game_map.dim_bloc self.next_state = "MAIN_MENU" self.score = score.Score("", 0) self.difficulty = 1
def test_close_by_right(self): qstat1 = QuadServiceStat() qstat1.update_with( prev_score=sc.Score("5-1"), prev_ingame=("30", "40"), prev_left_service=False, score=sc.Score("5-2"), ingame=("0", "0"), left_service=True, ) self.assertEqual(WinLoss(1, 0), qstat1.srv_win_loss(co.RIGHT, co.ADV)) self.assertEqual(WinLoss(0, 0), qstat1.srv_win_loss(co.RIGHT, co.DEUCE)) self.assertEqual(WinLoss(0, 0), qstat1.srv_win_loss(co.LEFT))
def __init__(self, width, height, fps): game_mouse.Game.__init__(self, "Pygame Starter", width, height, fps) self.ball = ball.Ball(width, height) self.paddle = paddle.Paddle(width, height, 20) self.paddle2 = paddle.Paddle(width, height, width - 40) self.score = score.Score() return
def game_on(): pygame.init() pygame.mixer.init() screen = pygame.display.set_mode([1080, 640]) pygame.display.set_caption("Thunder Game") ship = warship.Warship(screen) but = button.Button(screen) stat = status.Status() sco = score.Score(screen, stat) sounds = sound.Sounds() bullets = pygame.sprite.Group() aliens = pygame.sprite.Group() gf.init_aliens(screen, aliens) booms = [] pygame.mixer.music.load("sound/background.mp3") pygame.mixer.music.set_volume(0.3) pygame.mixer.music.play() while True: gf.check_events(ship, but, stat) gf.check_hit_alien(screen, bullets, aliens, booms, sco) gf.check_hit_warship(ship, aliens, bullets, stat) gf.show_all(screen, ship, bullets, aliens, booms, but, stat, sco)
def main(): global ents, sc, run run = True graphics.init(con.SCR_WIDTH, con.SCR_HEIGHT) sc = score.Score() try: pygame.mixer.pre_init(44100, -16, 2, 4096) pygame.mixer.init() except: print "You don't have audio support." con.audio_support = False if con.audio_support: audio.load_audio() pygame.mixer.music.load(os.path.join('audio', 'jl_music2.ogg')) pygame.mixer.music.set_volume(.9) while run: game_start() game_loop() game_end() pygame.quit()
def main(): player = Player() globals.PLAYER = player globals.NAME = globals.NAME.get_value() globals.SCORE = score.Score(globals.NAME) save = s.Save() globals.NB_MORTS = globals.SCORE.get() if globals.LOGS: print("NB_morts", globals.NB_MORTS) globals.NUM_LVL = save.get_lvl(globals.NAME) lvl = globals.NUM_LVL run = True load_lvl(lvl) fonts.font_init() while run: globals.LT = clock.tick(60) gameIcon() if globals.LVL_CHANGED: load_lvl(globals.NUM_LVL) globals.WIN.fill(colors.GREY) # background level.show(globals.MAP) # tiles for m in mobs.mobs: m.drawMob() globals.PLAYER.draw() # player if globals.Jour: # day hud.draw_bar(globals.PLAYER.energie) else: # night pygame.draw.polygon(globals.WIN, colors.BLACK, blindPoints) hud.draw_bar(globals.PLAYER.energie) hud.draw_lvl() hud.draw_deaths() if globals.NUM_LVL == 1: scenario.draw(0) elif globals.NUM_LVL == 2: scenario.draw(1) elif globals.NUM_LVL == 3: scenario.draw(2) pygame.display.flip() # show for event in pygame.event.get(): if event.type == pygame.QUIT: run = False globals.SCORE.add(globals.NB_MORTS) save.add(globals.NAME, globals.NUM_LVL) if not player.moving: player.move() else: player.moveAnim() player.checkState() for m in mobs.mobs: m.act() pygame.quit()
def test_close_by_left_then_fresh_right(self): qstat1 = QuadServiceStat() qstat1.update_with( prev_score=sc.Score("5-1"), prev_ingame=("30", "40"), prev_left_service=False, score=sc.Score("6-1 0-0"), ingame=("0", "40"), left_service=True, ) # closing: right broken by 3 points self.assertEqual(WinLoss(0, 2), qstat1.srv_win_loss(co.RIGHT, co.ADV)) self.assertEqual(WinLoss(0, 1), qstat1.srv_win_loss(co.RIGHT, co.DEUCE)) # freshing: left loss 3 points self.assertEqual(WinLoss(0, 2), qstat1.srv_win_loss(co.LEFT, co.ADV)) self.assertEqual(WinLoss(0, 1), qstat1.srv_win_loss(co.LEFT, co.DEUCE))
def test_close_by_left_then_fresh_left_tiebreak(self): qstat1 = QuadServiceStat() qstat1.update_with( prev_score=sc.Score("6-4 5-6"), prev_ingame=("30", "40"), prev_left_service=True, score=sc.Score("6-4 6-6"), ingame=("2", "0"), left_service=True, ) # closing: left hold by win 3 points: ADV(2), DEUCE(1) # freshing: right opener by loss 1 point: DEUCE(0) # freshing: left by win 1 point: ADV(1) self.assertEqual(WinLoss(3, 0), qstat1.srv_win_loss(co.LEFT, co.ADV)) self.assertEqual(WinLoss(1, 0), qstat1.srv_win_loss(co.LEFT, co.DEUCE)) self.assertEqual(WinLoss(0, 1), qstat1.srv_win_loss(co.RIGHT, co.DEUCE)) self.assertEqual(WinLoss(0, 0), qstat1.srv_win_loss(co.RIGHT, co.ADV))
def main(): pygame.init() screen = pygame.display.set_mode((800, 526)) background1 = pygame.image.load("./image/background.png") background2 = pygame.image.load("./image/background.png") ground1 = pygame.image.load("./image/ground.png") ground2 = pygame.image.load("./image/ground.png") title_obj = start_and_end.Title(screen) bird_obj = bird.Bird(screen) # 创建鸟对象 pillar_obj = pillar.Create(screen) # 创建柱子对象 pillar_obj.cre() # 创建柱子对象 tap_obj = start_and_end.Tap(screen) # 创建tap提示对象 start_button_obj = start_and_end.Startbutton(screen) b = 0 # 移动背景用的数字 # 窗口名字 pygame.display.set_caption('flappy bird') score_num = score.Score() score_num.score() while True: # 小鸟跳 bird_obj.jump() # 移动背景 b -= bird.Bird.b move_background(screen, background1, background2, b) if b < -800: b = 0 # 小鸟死 bird_obj.check_die(bird_obj) # 显示标题 title_obj.display() # 显示柱子 pillar_obj.display() # 显示地面 move_background(screen, ground1, ground2, b) # 显示小鸟 bird_obj.display() # 开始按钮 try: start_button_obj.display() if bird_obj.start_flag: del start_button_obj except UnboundLocalError: pass # 显示tap提示 try: if bird_obj.down_speed: del tap_obj elif bird_obj.start_flag: tap_obj.display() except UnboundLocalError: pass # 刷新 pygame.display.update() # 帧数 clock = pygame.time.Clock() clock.tick(200)
def test_continue_bp(self): stat1 = AllowBreakPointStat() prev_score = sc.Score("5-2") prev_left_service = False prev_ingame = ("30", "30") ingame = ("40", "30") stat1.continue_current(prev_score, prev_ingame, prev_left_service, ingame) self.assertEqual((0, 1), stat1.get_counts())
def __init__(self, fam: family.Family, gender: Optional[Gender] = None): self.score = score.Score() self.gender: Gender = apply_gender(gender) self.biological_parents = BiolParents(fam) if not isinstance(self.biological_parents.father, human.Human): raise InnocentError("Произошло непорочное зачатие. Жена без мужа.") self.age = ZERO_DATE self.genes = genetics.Genes(self) self.genes.define()
def __init__(self): rospy.on_shutdown(self.shutdown) rospy.init_node('robocops') self.mover = movement.Movement(self) self.detector = detection.Detection(self) self.scorer = score.Score() self.after = aftergettingshot.AfterGettingShot(self) self.rate = rospy.Rate(50) self.TO_SHOOT_OR_NOT_TO_SHOOT = 15 self.cool_down = timer() - 15 self.prev_disabled = False
def test_ito_kukushkin(self): plr1 = Player(ident=8313, name="Tatsuma Ito", cou="JPN") plr2 = Player(ident=9043, name="Mikhail Kukushkin", cou="KAZ") match = Match( first_player=plr1, second_player=plr2, score=sc.Score("4-6 7-6(3) 7-6(6)"), rnd=Round("Second"), date=datetime.date(2017, 2, 1), ) h2hdir = HeadToHead(sex="atp", match=match, completed_only=True).direct() self.assertEqual(h2hdir, None)
def event(self, event): """ Override State object's event handler. """ if event.type == pygame.KEYDOWN: if (event.key == pygame.K_ESCAPE or event.key == pygame.K_RETURN or event.key == pygame.K_SPACE): # save entry & change state name = '' for index in self.name_list: if index == 9: name += 'I' else: name += EndGame.LETTERS[index] globes.Globals.HIGHSCORES.add_score((name, self.score)) globes.Globals.STATE = S.Score(True) self.update_name(event.key)
def create_score_object(path, use_images=False, composer='noname', title='unknown'): count = len(os.listdir(path)) if use_images: i_a.convert_images_to_textfile(count, path) measure_arrays = f_a.get_data_from_file() d_a.search_for_incorrect_measures(measure_arrays) key1 = (d_a.get_key(measure_arrays)) key.Key(key1) score_object = score.Score(key1, composer, title) bass_part_object = part.Part('bass') treble_part_object = part.Part('treble') previous_measures = [None, None] # 0: Left, 1: Right for index, measure in enumerate(measure_arrays): #print(str(index) + ': ' + str(len(measure))) if index == len(measure_arrays) - 1: tied_notes = [] else: tied_notes = d_a.analyze_for_ties(measure, measure_arrays[index + 1]) temp = d_a.analyze_pressed_keys(measure) bass_measure_part = temp[0] treble_measure_part = temp[1] temp = c_m.abc_both_hands(bass_measure_part, treble_measure_part, len(measure), tied_notes, previous_measures) bass_measure_object = temp[0] treble_measure_object = temp[1] bass_part_object.add(bass_measure_object) treble_part_object.add(treble_measure_object) previous_measures = [bass_measure_object, treble_measure_object] # 0: Left, 1: Right score_object.add([treble_part_object, bass_part_object]) return score_object
def __init__(self, screen_size=20, delay=200, box_width=20, human_player=True, food_value=200, moves_to_decrement=1, score_decrement=2, score_decrement_move=2, score_increment=2, initial_score=100, score_tracking=False, turn_decrement_factor=1): self.is_running = False self.__screen_size__ = screen_size self.__box_width__ = box_width self.__hit__ = False screen_width = screen_size * box_width pygame.init() self.clock = pygame.time.Clock() self.score_tracking = score_tracking self.score = score.Score(food_value=food_value, moves_to_decrement=moves_to_decrement, score_decrement=score_decrement, initial_score=initial_score, score_increment=score_increment, score_decrement_move=score_decrement_move, turn_decrement_factor=turn_decrement_factor) self.game_box = game_box.GameBox(screen_size) self.screen = pygame.display.set_mode([screen_width, screen_width]) self.walls_list = [] self.spawn_walls() self.snake = None self.food = None self.player = None self.human_player = human_player self.setup_game() self.__delay__ = delay self.is_running = True self.__snake_color__ = [0, 0, 0] self.__screen_color__ = [255, 255, 255] self.__food_color__ = [255, 0, 0] self.__wall_color__ = [50, 50, 50] # Size tracking self.total_size = 0 self.largest_snake = 0 self.average_size = 0 # Check if snake turned self.turned = False
def get_presence_results( idents: Set[int], sex: str, min_date: datetime.date, max_date: datetime.date, with_retired=False, ) -> List[PlayerResult]: """[min_date, max_date) is semiclose range :return list where date is latest for [min_date,...,max_date) """ present_pids = set() present_results = [] date_now = datetime.date.today() if not dba.initialized(): dba.open_connect() sql = """select games.DATE_G, games.RESULT_G, games.ID1_G, games.ID2_G from Tours_{0} AS tours, games_{0} AS games, Players_{0} AS fst_plr where games.ID_T_G = tours.ID_T and games.ID1_G = fst_plr.ID_P and (tours.NAME_T Not Like '%juniors%') and (fst_plr.NAME_P Not Like '%/%') """.format(sex) sql += dba.sql_dates_condition(min_date, max_date, dator="games.DATE_G") sql += " order by games.DATE_G desc;" with closing(dba.get_connect().cursor()) as cursor: for (match_dt, score_txt, fst_id, snd_id) in cursor.execute(sql): match_date = match_dt.date() if match_dt else None if not score_txt: continue # may be it is scheduled match date = match_date if date is None: log.error( f"empty date in {sex} pid1{fst_id} pid2 {snd_id} score:{score_txt}" ) continue if with_retired and not sc.Score(score_txt).retired: continue if not with_retired and fst_id in idents and fst_id not in present_pids: present_pids.add(fst_id) present_results.append( PlayerResult(id=fst_id, days_ago=(date_now - date).days)) if snd_id in idents and snd_id not in present_pids: present_pids.add(snd_id) present_results.append( PlayerResult(id=snd_id, days_ago=(date_now - date).days)) return present_results
def _initialize_results_sex(sex, max_rating, max_rating_dif, with_bo5=False, min_date=None, max_date=None): tmp_recov_dct = defaultdict(list) # date -> list of (plr_id, set2win) tmp_keep_dct = defaultdict(list) # date -> list of (plr_id, set2win) sql = """select tours.DATE_T, games.DATE_G, games.RESULT_G, games.ID1_G, games.ID2_G from Tours_{0} AS tours, games_{0} AS games, Players_{0} AS fst_plr where games.ID_T_G = tours.ID_T and games.ID1_G = fst_plr.ID_P and (tours.NAME_T Not Like '%juniors%') and (fst_plr.NAME_P Not Like '%/%')""".format(sex) sql += dba.sql_dates_condition(min_date, max_date) sql += " ;" with closing(dba.get_connect().cursor()) as cursor: for (tour_dt, match_dt, score_txt, fst_id, snd_id) in cursor.execute(sql): tdate = tour_dt.date() if tour_dt else None mdate = match_dt.date() if match_dt else None if not score_txt: continue scr = sc.Score(score_txt) sets_count = scr.sets_count(full=True) if sets_count < 2: continue date = mdate if mdate else tdate if date is None: continue recov, keep = _get_match_data(sex, date, fst_id, snd_id, scr, max_rating, max_rating_dif, with_bo5) if recov is not None: tmp_recov_dct[date].append((recov.player_id, recov.set2_win)) if keep is not None: tmp_keep_dct[date].append((keep.player_id, keep.set2_win)) recov_dates = list(tmp_recov_dct.keys()) recov_dates.sort(reverse=True) for date in recov_dates: recovery_dict[sex][date] = tmp_recov_dct[date] keep_dates = list(tmp_keep_dct.keys()) keep_dates.sort(reverse=True) for date in keep_dates: keep_dict[sex][date] = tmp_keep_dct[date]
def _initialize_results_sex(sex, min_date=None, max_date=None): tmp_dct = defaultdict(list) # date -> list of match_results sql = """select tours.DATE_T, games.DATE_G, games.RESULT_G, games.ID1_G, games.ID2_G from Tours_{0} AS tours, games_{0} AS games, Players_{0} AS fst_plr where games.ID_T_G = tours.ID_T and games.ID1_G = fst_plr.ID_P and (tours.NAME_T Not Like '%juniors%') and (fst_plr.NAME_P Not Like '%/%')""".format(sex) sql += dba.sql_dates_condition(min_date, max_date) sql += " ;" with closing(dba.get_connect().cursor()) as cursor: for (tour_dt, match_dt, score_txt, fst_id, snd_id) in cursor.execute(sql): tdate = tour_dt.date() if tour_dt else None mdate = match_dt.date() if match_dt else None if not score_txt: continue scr = sc.Score(score_txt) if scr.retired: continue sets_cnt = scr.sets_count(full=True) if sets_cnt not in (3, 5): continue if sets_cnt == 3: sets_sc = scr.sets_score() if sets_sc != (2, 1): continue indec_sc = scr[sets_cnt - 1] games_dif = indec_sc[0] - indec_sc[1] if games_dif <= 0: log.error( "strange decided score {} in {} 1id {} 2id {}".format( scr, sex, fst_id, snd_id)) continue date = mdate if mdate else tdate tmp_dct[date].append(MatchResult(fst_id, snd_id, games_dif)) dates = list(tmp_dct.keys()) dates.sort() for date in dates: results_dict[sex][date] = tmp_dct[date]
def __init__(self, width, height, fps): game_mouse.Game.__init__(self, "Pygame Starter", width, height, fps) pygame.font.init() self.font = pygame.font.SysFont('arial', 30, True) self.ball = ball.Ball(10, 10, (255, 255, 255), width, height) self.paddle = paddle.Paddle(60, 20, (255, 255, 255), width, height) self.brick = [ brick.Brick(60, 30, 575, 0, (255, 255, 255), width, height), brick.Brick(60, 30, 575, 62, (255, 255, 255), width, height), brick.Brick(60, 30, 575, 124, (255, 255, 255), width, height), brick.Brick(60, 30, 575, 186, (255, 255, 255), width, height), brick.Brick(60, 30, 575, 248, (255, 255, 255), width, height), brick.Brick(60, 30, 575, 310, (255, 255, 255), width, height), brick.Brick(60, 30, 575, 372, (255, 255, 255), width, height), brick.Brick(60, 30, 575, 434, (255, 255, 255), width, height) ] self.score = score.Score() return
def __init__(self): """Initialize class instance.""" self.screen = pygame.display.set_mode(Pong.WINSIZE) self.label = pygame.freetype.SysFont('Sans', 35) self.lw = wall.Wall(vector.Vector(0), pygame.Rect(-20, 0, 20, Pong.HEIGHT), Pong.BGCOLOR) self.rw = wall.Wall(vector.Vector(180), pygame.Rect(Pong.WIDTH, 0, 20, Pong.HEIGHT), Pong.BGCOLOR) self.tw = wall.Wall(vector.Vector(270), pygame.Rect(0, 0, Pong.WIDTH, 20), Pong.BGCOLOR) self.bw = wall.Wall(vector.Vector(90), pygame.Rect(0, Pong.HEIGHT - 20, Pong.WIDTH, 20), Pong.BGCOLOR) self.pl = wall.Player( vector.Vector(90), pygame.Rect(Pong.WIDTH / 2 - 80 / 2, Pong.HEIGHT - 20, 80, 20), Pong.PLCOLOR) self.en = wall.Player(vector.Vector(270), pygame.Rect(Pong.WIDTH / 2 - 80 / 2, 0, 80, 20), Pong.ENCOLOR) self.ba = wall.Ball( vector.Vector(270, 10), pygame.Rect(Pong.WIDTH / 2 - 20 / 2, Pong.HEIGHT / 2 - 20 / 2, 20, 20), Pong.BACOLOR) self.sc = score.Score() self.message = '' self.make_ready()
def __init__(self, width, height, fps): pygame.font.init() game_mouse.Game.__init__(self, "Flappy Bird", width, height, fps) self.state = 'Main Menu' self.main_menu = main_menu.Main_Menu(width, height) self.end_menu = end_menu.End_Menu(width, height) self.pause = pause_menu.Pause_Menu(width, height) self.barriers = barriers.Barriers(height, width) self.bird = bird.Bird(width, height) self.score = score.Score(width, height) self.scores_menu = displayscoresmenu.ScoresMenu(width, height) self.background = background.Background(height, width) self.music = { "state" : "", "songs" : ["sounds/palm-beach.wav", "sounds/chubby-cat.wav", "sounds/the-awakening.wav"], "current" : ""} self.instruction_menu = instruction_menu.InstructionMenu(width, height) self.bugs = [] self.bug = bug.Bug return
def test_close_previous(self): stat1 = HoldStat() stat1.close_previous(sc.Score("1-1"), prev_left_service=True, prev_left_wingame=True) # 1/1, 0/0 stat1.close_previous(sc.Score("2-1"), prev_left_service=False, prev_left_wingame=False) # 1/1, 1/1 stat1.close_previous(sc.Score("2-2"), prev_left_service=True, prev_left_wingame=False) # 1/2, 1/1 stat1.close_previous(sc.Score("2-3"), prev_left_service=False, prev_left_wingame=False) # 1/2, 2/2 stat1.close_previous(sc.Score("2-4"), prev_left_service=True, prev_left_wingame=True) # 2/3, 2/2 stat1.close_previous(sc.Score("6-6"), prev_left_service=True, prev_left_wingame=False) # skip tie res_pair = stat1.result_pair(setnum=1, as_float=False) self.assertEqual(res_pair, (WinLoss(2, 1), WinLoss(2, 0)))
#!/usr/bin/env python3 import pdb # from __future__ import division from random import uniform import score # TODO build class and functions, this is for testing # character level testing # s = score.Score('./data/en-char') # model = s.load_model('./models/model.en.char.pt') # word level testing # s = score.Score('./data/en-word') s = score.Score('./data/en-char') # model = s.load_model('./models/model.en.word.pt') model = s.load_model('./models/model.en.char.pt') lstmscore = lambda cand: s.score_sent(cand, model) # formatting def lstmify(sent): # characterize = lambda sent: ' '.join(' '.join(sent.hyp)[4:].replace(' ', '@').replace('</s>', '<eos>')) seq = sent.hyp # remove the <s>, that's already the LSTM's input seq = ' '.join(seq)[4:] seq = seq.replace('</s>', '<eos>') return seq def characterize(sent):
def _make(self, sex, match, completed_only): from tournament import Tournament if (not match.first_player or not match.second_player or not match.first_player.ident or not match.second_player.ident or not match.date): return tour_date_max = tt.past_monday_date(match.date) sql = """select Rounds.NAME_R, Courts.NAME_C, tours.ID_T, tours.NAME_T, tours.RANK_T, tours.DATE_T, tours.PRIZE_T, tours.COUNTRY_T, games.ID1_G, games.ID2_G, games.RESULT_G, games.DATE_G from Tours_{0} AS tours, Games_{0} AS games, Rounds, Courts where games.ID_T_G = tours.ID_T and Rounds.ID_R = games.ID_R_G and tours.ID_C_T = Courts.ID_C and tours.DATE_T < {1} and ((games.ID1_G = {2} and games.ID2_G = {3}) or (games.ID2_G = {2} and games.ID1_G = {3}) ) and (tours.NAME_T Not Like '%juniors%') ;""".format( sex, dba.msaccess_date(tour_date_max), match.first_player.ident, match.second_player.ident, ) with closing(dba.get_connect().cursor()) as cursor: for ( rnd_name, surf_name, tour_id, tour_name, tour_rank, tour_time, money, cou, p1st_id, p2nd_id, score_name, match_dtime, ) in cursor.execute(sql): score = sc.Score(score_name) if score.retired and completed_only: continue tour = Tournament( ident=tour_id, name=tour_name, sex=sex, surface=Surface(surf_name), rank=tour_rank, date=tour_time.date() if tour_time else None, money=money, cou=cou, ) if tour.level == "future": continue match_date = match_dtime.date( ) if match_dtime is not None else None if (p1st_id == match.first_player.ident and p2nd_id == match.second_player.ident): m = Match( match.first_player, match.second_player, score=score, rnd=Round(rnd_name), date=match_date, ) else: m = Match( match.second_player, match.first_player, score=score, rnd=Round(rnd_name), date=match_date, ) avgset = self._get_avgset(tour, m) self.tour_match_aset.append((tour, m, avgset)) self.tour_match_aset.sort(key=lambda i: i[0].date, reverse=True) self._remove_current_match(match.date)
def tours_generator( sex, todaymode=False, min_date=None, max_date=None, time_reverse=False, with_paired=False, with_mix=False, rnd_detailing=False, with_bets=False, with_stat=False, with_ratings=False, with_pers_det=False, ): from matchstat import get assert not (not with_paired and with_mix), "inconsistent with_paired with_mix" sql_builder = SqlBuilder( sex, todaymode, min_date=min_date, max_date=max_date, time_reverse=time_reverse, with_paired=with_paired, with_mix=with_mix, ) cur_tour = None for row in sql_builder.rows(): tour = Tournament( row.tour_id, row.tour_name, sex=sex, surface=tennis.Surface(row.surf_txt), rank=row.tour_rank, date=row.tour_dt.date() if row.tour_dt else None, money=row.tour_money, cou=row.tour_cou, ) rnd = tennis.Round(row.rnd_txt) scr = sc.Score(row.score_txt) if row.score_txt else None fst_player = tennis.Player( ident=row.fst_plr_id, name=row.fst_plr_name, cou=row.fst_plr_cou, birth_date=row.fst_plr_dt.date() if row.fst_plr_dt else None, ) snd_player = tennis.Player( ident=row.snd_plr_id, name=row.snd_plr_name, cou=row.snd_plr_cou, birth_date=row.snd_plr_dt.date() if row.snd_plr_dt else None, ) m = tennis.Match( fst_player, snd_player, scr, rnd, row.match_dt.date() if row.match_dt else None, ) if not m.paired(): if with_pers_det: m.read_pers_det(sex) if with_ratings: m.read_ratings(sex, tour.date) if with_bets: m.fill_offer(sex, tour.ident, tour.date, alter_bettor=False) if with_stat: m.stat = get( sex, tour.ident, rnd, fst_player.ident, snd_player.ident, tt.get_year_weeknum(tour.date), ) if cur_tour is not None and cur_tour.ident != tour.ident: if rnd_detailing: cur_tour.rounds_detailing() yield cur_tour cur_tour = tour elif cur_tour is None: cur_tour = tour cur_tour.matches_from_rnd[rnd].append(m) if cur_tour is not None: if rnd_detailing: cur_tour.rounds_detailing() yield cur_tour
if car.xcor() < -325: car.hideturtle() car.clear() screen_cars.remove(car) #Screen initialization screen = turtle.Screen() screen.setup(600, 600) screen.tracer(0) screen.colormode(255) screen.title("Turtle crossing game") #Classes initialization player = frog.Frog() scoreboard = score.Score() #Functions def exit_game(): screen.bye() turtle.done() #Listeners for executing the game screen.listen() screen.onkeypress(exit_game, "c") screen.onkeypress(player.move, "w") #Main loop stop = False