How to use render_screen method in yandex-tank

Best Python code snippet using yandex-tank

main.py

Source:main.py Github

copy

Full Screen

...44score = 045pattern = []46time_delay = 50047running = True48def render_screen(g=green, r=red, y=yellow, b=blue):49 screen.fill(black)50 score_txt = font.render('Счёт: ' + str(score), True, white)51 screen.blit(score_txt, (450, 50))52 pygame.draw.rect(screen, g, pygame.Rect(50, 150, 250, 250))53 pygame.draw.rect(screen, r, pygame.Rect(300, 150, 250, 250))54 pygame.draw.rect(screen, y, pygame.Rect(50, 400, 250, 250))55 pygame.draw.rect(screen, b, pygame.Rect(300, 400, 250, 250))56 pygame.display.update()57def show_pattern():58 time_delay = 500 - 100 * int(len(pattern) / 5)59 if time_delay <= 100:60 time_delay = 10061 render_screen()62 pygame.time.delay(1000)63 for x in pattern:64 for event in pygame.event.get():65 if event.type == pygame.QUIT:66 quit_game()67 if x == 1:68 # ЗЕЛЁНЫЙ69 render_screen(g=light_green)70 green_sound.play()71 pygame.time.delay(time_delay)72 render_screen()73 green_sound.stop()74 elif x == 2:75 # КРАСНЫЙ76 render_screen(r=light_red)77 red_sound.play()78 pygame.time.delay(time_delay)79 render_screen()80 red_sound.stop()81 elif x == 3:82 # ЖЁЛТЫЙ83 render_screen(y=light_yellow)84 yellow_sound.play()85 pygame.time.delay(time_delay)86 render_screen()87 yellow_sound.stop()88 elif x == 4:89 # СИНИЙ90 render_screen(b=light_blue)91 blue_sound.play()92 pygame.time.delay(time_delay)93 render_screen()94 blue_sound.stop()95 pygame.time.delay(time_delay)96def new_pattern():97 global score98 score = len(pattern)99 pattern.append(random.randint(1, 4))100def check_pattern(player_pattern):101 if player_pattern != pattern[:len(player_pattern)]:102 lose_screen()103def click_listen():104 turn_time = time.time()105 player_pattern = []106 while time.time() <= turn_time + 3 and len(player_pattern) < len(pattern):107 for event in pygame.event.get():108 if event.type == pygame.QUIT:109 quit_game()110 if event.type == pygame.MOUSEBUTTONUP and event.button == 1:111 pos = pygame.mouse.get_pos()112 x = pos[0]113 y = pos[1]114 if 50 < x < 300 and 150 < y < 400:115 render_screen(g=light_green)116 green_sound.play()117 pygame.time.delay(time_delay)118 green_sound.stop()119 render_screen()120 player_pattern.append(1)121 check_pattern(player_pattern)122 turn_time = time.time()123 elif 300 < x < 550 and 150 < y < 400:124 render_screen(r=light_red)125 red_sound.play()126 pygame.time.delay(time_delay)127 red_sound.stop()128 render_screen()129 player_pattern.append(2)130 check_pattern(player_pattern)131 turn_time = time.time()132 elif 50 < x < 300 and 400 < y < 650:133 render_screen(y=light_yellow)134 yellow_sound.play()135 pygame.time.delay(time_delay)136 yellow_sound.stop()137 render_screen()138 player_pattern.append(3)139 check_pattern(player_pattern)140 turn_time = time.time()141 elif 300 < x < 550 and 400 < y < 650:142 render_screen(b=light_blue)143 blue_sound.play()144 pygame.time.delay(time_delay)145 blue_sound.stop()146 render_screen()147 player_pattern.append(4)148 check_pattern(player_pattern)149 turn_time = time.time()150 if not time.time() <= turn_time + 3:151 lose_screen()152def quit_game():153 running = False154 pygame.display.quit()155 pygame.quit()156 sys.exit()157def lose_screen():158 lose_sound.play()159 global score160 screen.fill(black)...

Full Screen

Full Screen

replay_game_session.py

Source:replay_game_session.py Github

copy

Full Screen

1import json2import time3import cv24import os5import argparse6import gym7import gym_super_mario_bros8argument_parser = argparse.ArgumentParser(description="A script used to replay the game session.")9argument_parser.add_argument("-i", "--input-path", type=str, default=None)10argument_parser.add_argument("-o", "--output-path", type=str, default= None)11argument_parser.add_argument("-r", "--render-screen", type=bool, default=True)12_STAGE_ORDER = [13 (1, 1),14 (1, 2),15 (1, 3),16 (2, 2),17 (1, 4),18 (3, 1),19 (4, 1),20 (2, 1),21 (2, 3),22 (2, 4),23 (3, 2),24 (3, 3),25 (3, 4),26 (4, 2)27]28def make_next_stage(world, stage, num):29 if num < len(_STAGE_ORDER):30 world = _STAGE_ORDER[num][0]31 stage = _STAGE_ORDER[num][1]32 else:33 if stage >= 4:34 stage = 135 if world >= 8:36 world = 137 else:38 world += 139 else:40 stage += 141 return world, stage, "SuperMarioBros-%s-%s-v0" % (str(world), str(stage))42def replay_game_from_actions(session_path, output_path=None, render_screen=False):43 if output_path is not None and not os.path.exists(output_path):44 os.makedirs(output_path)45 with open(session_path) as json_file:46 data = json.load(json_file)47 first_world = "SuperMarioBros-1-1-v0"48 env = gym_super_mario_bros.make(first_world)49 next_state = env.reset()50 world = 151 stage = 152 stage_num = 053 finish = True54 frame_number = 155 steps = 056 for action in data["obs"]:57 58 if render_screen:59 env.render()60 61 next_state, reward, done, info = env.step(action)62 steps += 163 if output_path is not None:64 cvt_state = cv2.cvtColor(next_state, cv2.COLOR_BGR2RGB)65 cv2.imwrite(os.path.join(output_path, "game_%s.png" % frame_number), cvt_state)66 is_first = True67 frame_number += 168 69 if info["flag_get"]:70 finish = True71 if done:72 done = False73 end = time.time()74 75 if finish or steps >= 16000:76 stage_num += 177 world, stage, new_world = make_next_stage(world, stage, stage_num)78 env.close()79 env = gym_super_mario_bros.make(new_world)80 finish = False81 steps = 082 next_state = env.reset()83if __name__ == "__main__":84 args = argument_parser.parse_args()85 input_path = args.input_path86 render_screen = args.render_screen87 output_path = args.output_path88 if input_path is None:89 raise Exception("Please provide the path to a game session!")90 replay_game_from_actions(91 session_path=input_path,92 output_path=output_path,93 render_screen=render_screen...

Full Screen

Full Screen

day_13_2019.py

Source:day_13_2019.py Github

copy

Full Screen

1import time2from typing import List, Any, Tuple3from collections import defaultdict4from util.helpers import solution_timer5from util.input_helper import read_entire_input6from util.console import console7from util.shared import sgn8from year_2019.intcode import IntCode, parse9display = False10data = read_entire_input(2019,13)11def render(screen, score):12 tiles = {0:" ",1:f'[white]{chr(9608)}', 2:"[green]#", 3: "-", 4: "[red]O"}13 xmin = min(i[0] for i in screen.keys())14 xmax = max(i[0] for i in screen.keys())15 ymin = min(i[1] for i in screen.keys())16 ymax = max(i[1] for i in screen.keys())17 image = '\n'.join(''.join(tiles[screen[(i,j)]] for i in range(xmin, xmax+1)) for j in range(ymin, ymax+1))18 return image+'\n'+"-"*20 + f'{score:05d}' + "-"*2019@solution_timer(2019,13,1)20def part_one(data: List[str]):21 instructions = parse(data)22 game = IntCode(instructions)23 screen = {}24 while not game.halted:25 x, y, tile = game.run([]), game.run([]), game.run([])26 screen[(x,y)] = tile27 if display:28 console.print(render(screen, 0))29 return sum(1 for _, tile in screen.items() if tile == 2)30@solution_timer(2019,13,2)31def part_two(data: List[str]):32 render_screen = False33 instructions = parse(data)34 instructions[0] = 235 game = IntCode(instructions)36 screen = {}37 inputs = []38 while not game.halted:39 x = game.run(inputs)40 y = game.run(inputs)41 tile = game.run(inputs)42 if (x,y) == (-1,0):43 score = tile44 else:45 screen[(x,y)] = tile46 # if (x,y) == 47 ball = [position for position, tile in screen.items() if tile == 4]48 paddle = [position for position, tile in screen.items() if tile == 3]49 if ball and paddle:50 inputs = [sgn(ball[0][0]-paddle[0][0])]51 # if tile == 4:52 # render_screen = True53 if display and render_screen:54 console.print("\33[2J")55 console.print(render(screen, score))56 # print(f"score: {score}")57 render_screen = False58 #time.sleep(0.05)59 i = input()60 return score61if __name__ == "__main__":62 data = read_entire_input(2019,13)63 part_one(data)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run yandex-tank automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful