How to use no_target method in yandex-tank

Best Python code snippet using yandex-tank

main.py

Source:main.py Github

copy

Full Screen

1"""2COMP30024 Artificial Intelligence, Semester 1, 20213Project Part A: Searching4This script contains the entry point to the program (the code in5`__main__.py` calls `main()`). Your solution starts here!6"""7# haoyu: how to run this program8# python -m search search/ + "file name";9# eg :python -m search search/test1.json10import sys11import json12# If you want to separate your code into separate files, put them13# inside the `search` directory (like this one and `util.py`) and14# then import from them like this:15from search.util import print_board, print_slide, print_swing16from search.datastructure import *17from search.SearchingAlgorithm import *18import time19import random20def main():21 start = time.time()22 try:23 with open(sys.argv[1]) as file:24 data = json.load(file)25 except IndexError:26 print("usage: python3 -m search path/to/input.json", file=sys.stderr)27 sys.exit(1)28 # TODO:29 # Find and print a solution to the board configuration described30 # by `data`.31 # Why not start by trying to print this configuration out using the32 # `print_board` helper function? (See the `util.py` source code for33 # usage information).34 game = Board()35 #stage136 Upper = []37 Blocks = []38 Lower = [] 39 board_dict ={40 }41 for i in data['upper']:42 board_dict[tuple((i[1],i[2]))] = i[0]43 Upper.append((MyNode(i[0],"upper",tuple((i[1],i[2])),game))) 44 for i in data['lower']:45 board_dict[tuple((i[1],i[2]))] = i[0]46 Lower.append((MyNode(i[0],"lower",tuple((i[1],i[2])),game))) 47 for i in data['block']: 48 board_dict[tuple((i[1],i[2]))] = 'b'49 Blocks.append((MyNode("b","block",tuple((i[1],i[2])),game)))50 #move dict for the next move:51 move_dic = {52 }53 no_targets = []54 turn = 155 #print_board(board_dict)56 while(len(Lower)>0):57 p = 058 s = 059 r = 060 for lower_token in Lower:61 if(lower_token.role == 'p'):62 s+=163 elif(lower_token.role == 'r'):64 p+=165 elif(lower_token.role == 's'):66 r+=167 for current_card in Upper:68 nextpoint = RunDFSOnCards(current_card, game, turn)69 if nextpoint is not None:70 move_dic[current_card] = nextpoint71 else:72 if current_card in move_dic.keys():73 move_dic.pop(current_card)74 no_targets.append(current_card)75 continue76 77 #if two tokens are move to the same location, we run random for either of them:78 move_key = [key for key in move_dic.keys()]79 move_value = [move_dic[key] for key in move_key]80 same_spot = []81 original_surrounding = []82 for i in range(len(move_key)):83 for j in range(i,len(move_key)):84 if (i != j ) and move_dic[move_key[i]] == move_dic[move_key[j]] and (move_key[i].role != move_key[j].role):85 same_spot.append(move_key[i])86 same_spot.append(move_key[j]) 87 for spot in same_spot:88 available = []89 for near in game.grid[spot.getx()][spot.gety()].surrounding:90 if(len(near.cards) > 0):91 if(near.cards[0].side == 'block'):92 continue93 if(HasEnemy(near.cards) and spot.ResistanceOpponentRole() == near.cards[0].role):94 continue 95 available.append(near.coordinate)96 else:97 available.append(near.coordinate)98 original_surrounding.append(available)99 possible_combination = []100 if(len(same_spot) == 2):101 possible_combination = [(a,b) for a in original_surrounding[0] for b in original_surrounding[1] if a !=b]102 elif(len(same_spot) ==3):103 possible_combination = [(a,b,c) for a in original_surrounding[0] for b in original_surrounding[1] for c in original_surrounding[2] if (a !=b and b!= c and c != a)]104 comibination_len = len(possible_combination)105 if(comibination_len > 0):106 randn = random.randint(0,comibination_len-1)107 move_dic[same_spot[0]] = possible_combination[randn][0]108 move_dic[same_spot[1]] = possible_combination[randn][1]109 if(len(same_spot)==3):110 move_dic[same_spot[2]]= possible_combination[randn][2]111 #if BFS cant find a target, move randomly112 for no_target in no_targets:113 # random move114 acceptable_list = []115 existing_key = [key for key in move_dic.keys()]116 existing_value =[move_dic[key] for key in existing_key]117 suicide_list = []118 for spot in game.grid[no_target.getx()][no_target.gety()].surrounding:119 if(len(spot.cards) > 0):120 if(spot.cards[0].role == 'block'):121 continue122 if(HasEnemy(spot.cards) and no_target.ResistanceOpponentRole() == spot.cards[0].role):123 suicide_list.append(spot.coordinate)124 continue 125 else:126 acceptable_list.append(spot.coordinate)127 128 if((len(suicide_list) > 0) and ((no_target.role == 'p' and p == 0) or (no_target.role == 's' and s ==0) or (no_target.role == 'r' and r == 0))):129 move_dic[no_target] = suicide_list [0]130 no_targets.remove(no_target)131 continue132 133 chooseable = list(set(acceptable_list) - set(existing_value)) 134 if len(chooseable) > 0:135 n = random.randint(0,len(chooseable)-1)136 move_dic[no_target] = chooseable[n]137 no_targets.remove(no_target)138 continue139 else:140 print(len(acceptable_list))141 if len(acceptable_list) > 0:142 g = random.randint(0,len(acceptable_list)-1)143 move_dic[no_target] = acceptable_list[g]144 no_targets.remove(no_target)145 elif len(suicide_list) > 0:146 move_dic[no_target] = suicide_list[0]147 no_targets.remove(no_target) 148 continue149 for key in move_dic.keys():150 printMove(turn,key,move_dic[key])151 key.Move(move_dic[key],game)152 153 for key in list(move_dic.keys()):154 if key not in list(move_dic.keys()):155 continue156 settlement(move_dic[key],game,Upper,Lower,move_dic)157 turn+=1158 ...

Full Screen

Full Screen

high_striker.py

Source:high_striker.py Github

copy

Full Screen

1from psychopy import visual, core, event2import random3class HighStriker(object):4 def __init__(self, win, top_coords: tuple, bottom_coords: tuple, target_radius=20, slider_radius=10):5 self.window = win6 self.top_coords = top_coords7 self.bottom_coords = bottom_coords8 self.line = visual.ShapeStim( win=win, lineColor='black', vertices=(bottom_coords, top_coords), units='pix')9 self.target = visual.Circle(10 win=win,11 units="pix",12 radius=target_radius,13 # fillColor=[1, 0, 0],14 lineColor='red'15 )16 self.target.pos = top_coords17 self.slider = visual.Circle(18 win=win,19 units="pix",20 radius=slider_radius,21 fillColor=[1, 1, 1],22 lineColor=[1, 1, 1]23 )24 self.slider.pos = bottom_coords25 self.slider_travel_time = .726 self.timestep = 1/6027 def draw(self, no_target=False):28 if no_target:29 self.line.draw()30 self.slider.draw()31 else:32 self.line.draw()33 self.target.draw()34 self.slider.draw()35 36 def randomize_target(self):37 lower_bound = int(self.bottom_coords[1] + (self.top_coords[1] - self.bottom_coords[1])/3)38 y_pos = random.randrange(lower_bound, self.top_coords[1])39 self.target.pos = (0, y_pos )40 return y_pos41 def slide_up(self, to_slide: int, auto_draw=[], no_target=False):42 initial_pos = self.slider.pos[1]43 clock = core.Clock()44 while clock.getTime() < self.slider_travel_time:45 core.wait(self.timestep)46 progress = (clock.getTime()/self.slider_travel_time)*to_slide47 self.slider.pos = (0, initial_pos + progress)48 self.draw(no_target=no_target)49 for e in auto_draw:50 if e:51 e.draw()52 self.window.flip()53 def reset_slider(self):54 self.slider.pos = self.bottom_coords...

Full Screen

Full Screen

exercise1_dijkstra_v2.py

Source:exercise1_dijkstra_v2.py Github

copy

Full Screen

1from scipy.sparse import csr_matrix2from scipy.sparse.csgraph import dijkstra3import pandas as pd4# setup inicial5NO_TARGET = 26# carrega dados7df = pd.read_csv("exercise1.csv")8# ajusta estrutura de dados para o algoritmo9lista_distancias = df.to_numpy().tolist()10# gera matriz esparsa11grafo = csr_matrix(lista_distancias)12# aplica algoritmo de Dijkstra13# indices = NO_TARGET - 1 porque começa em 014distancias = dijkstra(csgraph=grafo, directed=False, indices=NO_TARGET - 1)15# output16print(17 f"Menores distâncias do nó {NO_TARGET} em relação aos demais são descritas a seguir:"18)19for i, dist in enumerate(distancias, 1):20 if i == NO_TARGET:21 continue...

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