How to use get_state method in localstack

Best Python code snippet using localstack_python

v4.py

Source:v4.py Github

copy

Full Screen

...40 agent4 = DQN_agent(env.agent_state_count*env.agents, env.num_actions, env.ROWS, env.COLUMNS) #init of agent41 42 rec_moves_to = [43 {44 env.get_state([3,3]):1,45 env.get_state([3,4]):1,46 env.get_state([4,4]):4,47 env.get_state([5,4]):4,48 env.get_state([5,5]):1,49 env.get_state([5,6]):1,50 env.get_state([5,7]):1,51 env.get_state([4,7]):3,52 env.get_state([4,8]):153 },54 {55 env.get_state([5,3]):1,56 env.get_state([4,3]):3,57 env.get_state([3,3]):3,58 env.get_state([2,3]):3,59 env.get_state([2,4]):1,60 env.get_state([2,5]):1,61 env.get_state([2,6]):1,62 env.get_state([2,7]):1,63 env.get_state([2,8]):164 },65 {66 env.get_state([7,3]):1,67 env.get_state([7,4]):1,68 env.get_state([6,4]):3,69 env.get_state([6,5]):1,70 env.get_state([6,6]):1,71 env.get_state([6,7]):172 },73 {74 env.get_state([9,3]):1,75 env.get_state([9,4]):1,76 env.get_state([9,5]):1,77 env.get_state([9,6]):1,78 env.get_state([9,7]):1,79 env.get_state([8,7]):3,80 env.get_state([7,7]):3,81 env.get_state([7,8]):1,82 }83 ]84 rec_moves_from = [85 {86 env.get_state([4,8]):2,87 env.get_state([4,7]):2,88 env.get_state([5,7]):4,89 env.get_state([5,6]):2,90 env.get_state([5,5]):2,91 env.get_state([5,4]):2,92 env.get_state([4,4]):3,93 env.get_state([3,4]):3,94 env.get_state([3,3]):295 },96 {97 env.get_state([2,8]):2,98 env.get_state([2,7]):2,99 env.get_state([2,6]):2,100 env.get_state([2,5]):2,101 env.get_state([2,4]):2,102 env.get_state([2,3]):2,103 env.get_state([3,3]):4,104 env.get_state([4,3]):4,105 env.get_state([5,3]):4106 },107 {108 env.get_state([6,7]):2,109 env.get_state([6,6]):2,110 env.get_state([6,5]):2,111 env.get_state([6,4]):2,112 env.get_state([7,4]):4,113 env.get_state([7,3]):2114 },115 {116 env.get_state([7,8]):2,117 env.get_state([7,7]):2,118 env.get_state([8,7]):4,119 env.get_state([9,7]):4,120 env.get_state([9,6]):2,121 env.get_state([9,5]):2,122 env.get_state([9,4]):2,123 env.get_state([9,3]):2 124 }125 ]126 print(rec_moves_to)127 128 agentos = [agent,agent2,agent3,agent4]129 rewards_all_episodes = [0,0,0,0] # only for human metrics130 rewards_current_episode = [0,0,0,0] # only for human metrics131 num_of_success = 0132 num_packages = 0133 moving_average_20a = deque(maxlen=400) # only for human metrics134 moving_average_20b = deque(maxlen=400) # only for human metrics135 moving_average_20c = deque(maxlen=400) # only for human metrics136 moving_average_20d = deque(maxlen=400) # only for human metrics137 successes_last_100 = deque(maxlen=100)138 rock = False139 packages_total = []140 file_count = 0141 for episode in range(NUM_EPISODES):142 143 if len(packages_total) % 700 == 0:144 with open('LOGGED_v4,'+str(file_count)+'.csv', mode='w') as the_file:145 writer = csv.writer(the_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)146 for the_file_elements in range(len(packages_total)):147 writer.writerow([the_file_elements,packages_total[the_file_elements]])148 file_count += 1149 150 done = False151 rewards_current_episode = [0,0,0,0]152 if num_packages > 80:153 for ag in agentos:154 ag.epsilon_min = 0.01155 num_packages = 0156 #environment setup 157 state = env.reset(randomised_position=False) # resets environment for new simulation158 if sum(successes_last_100) > 60:159 agent.epsilon_min = 0160 #iteration process161 for step in range (1,MAX_EPISODE_STEPS):162 #let agent make action suggestions163 action_list = []164 for i in range(env.agents):165 action_list.append(agentos[i].act(state[i]))166 if (episode > 40000): # to see what is going on (simulation)167 if not rock: 168 input("rock and roll!")169 rock = True170 os.system('clear')171 print("\033[1;41m" + "simulation run: {}".format(episode) + "\033[1;m")172 #print(f"state_space_size already visited: {agent.visited_memory}")173 print("state:{}".format(state))174 print("delivered packages: {}".format(num_packages))175 #print("most recent reward: {}".format(rewards_all_episodes[-1]))176 env.show()177 time.sleep(0.3)178 event_list = env.sim_step(action_list)179 180 181 for i in range(env.agents):182 rewards_current_episode[i] += event_list[i][1]183 if env.current_state[i][2] == 0 and env.get_state(env.current_state[i]) in rec_moves_to[i]:184 if rec_moves_to[i][env.get_state(env.current_state[i])] == action_list[i]:185 rewards_current_episode[i] += CORRECT_MOVE_REWARD186 elif env.current_state[i][2] == 1 and env.get_state(env.current_state[i]) in rec_moves_from[i]:187 if rec_moves_from[i][env.get_state(env.current_state[i])] == action_list[i]:188 rewards_current_episode[i] += CORRECT_MOVE_REWARD189 done = True if event_list[i][2] else done190 if done == True:191 moving_average_20a.append(rewards_current_episode[0])192 moving_average_20b.append(rewards_current_episode[1])193 moving_average_20c.append(rewards_current_episode[2])194 moving_average_20d.append(rewards_current_episode[3])195 196 for i in range(env.agents):197 if event_list[i][1] == 5:198 num_packages += 1199 200 201 successes_last_100.append(0)...

Full Screen

Full Screen

board.py

Source:board.py Github

copy

Full Screen

...28 table = []29 i = 030 while i < 3:31 row = []32 row.append(self.table[i][0].get_state())33 row.append(self.table[i][1].get_state())34 row.append(self.table[i][2].get_state())35 table.append(row)36 i = i + 137 return table38 def change_turn(self):39 if self.turn == 'X':40 self.turn = 'O'41 else:42 self.turn = 'X'43 def make_turn(self,t):44 self.turn = t45 def find_winner(self):46 row = 047 col = 048 winner = 'null'49 while row < 3:50 if self.equals3(self.table[row][0].get_state(), self.table[row][1].get_state(), self.table[row][2].get_state()):51 winner = self.table[row][0].get_state()52 row = row + 153 while col < 3:54 if self.equals3(self.table[0][col].get_state(), self.table[1][col].get_state(), self.table[2][col].get_state()):55 winner = self.table[0][col].get_state()56 col = col + 157 if self.equals3(self.table[0][0].get_state(), self.table[1][1].get_state(), self.table[2][2].get_state()):58 winner = self.table[0][0].get_state()59 if self.equals3(self.table[2][0].get_state(), self.table[1][1].get_state(), self.table[0][2].get_state()):60 winner = self.table[2][0].get_state()61 62 filled = self.is_filled()63 if filled == True and winner == 'null':64 winner = 'Tie'65 66 return winner67 68 def is_empty(self, row, col):69 if self.table[row][col].get_state() == ' ':70 return True71 return False72 73 def is_filled(self):74 for i in range(3):75 for j in range(3):76 if self.table[i][j].get_state() == ' ':77 return False78 return True79 80 def update_cell(self, row, col):81 if self.is_empty(row,col):82 turn = self.get_turn()83 if turn == 'X':84 self.table[row][col].make_X()85 self.change_turn()86 else:87 self.table[row][col].make_O()88 self.change_turn()89 def AIMove(self):90 best_x = 091 best_y = 092 bestScore = -100093 if self.is_filled() == False:94 for i in range(3):95 for j in range(3):96 if self.table[i][j].get_state() == ' ':97 self.table[i][j].make_O()98 self.set_turn('X')99 score = self.minimax(True)100 self.table[i][j].initialize()101 if score > bestScore:102 bestScore = score103 best_x = i104 best_y = j105 self.table[best_x][best_y].make_O()106 self.set_turn('X')107 108 def minimax(self,isHuman):109 result = self.find_winner()110 if result == 'X':111 return -1112 if result == 'O':113 return 1114 if result == 'Tie':115 return 0116 if isHuman:117 bestScore = 1000118 for i in range(3):119 for j in range(3):120 if self.table[i][j].get_state() == ' ':121 self.table[i][j].make_X()122 self.set_turn('O')123 score = self.minimax(False)124 self.table[i][j].initialize()125 bestScore = min(score, bestScore)126 return bestScore127 else:128 bestScore = -1000129 for i in range(3):130 for j in range(3):131 if self.table[i][j].get_state() == ' ':132 self.table[i][j].make_O()133 self.set_turn('X')134 score = self.minimax(True)135 self.table[i][j].initialize()136 bestScore = max(score, bestScore)...

Full Screen

Full Screen

test_server_condenser_api.py

Source:test_server_condenser_api.py Github

copy

Full Screen

...3from worth.server.condenser_api.get_state import get_state4from worth.server.condenser_api.tags import get_trending_tags5from worth.server.condenser_api.call import call6@pytest.mark.asyncio7async def test_get_state():8 ret = await get_state('/trending')9 assert 'discussion_idx' in ret10 assert await get_state('trending')11 assert await get_state('promoted')12 assert await get_state('created')13 assert await get_state('hot')14 assert await get_state('@xeroc')15 assert await get_state('@xeroc/feed')16 assert await get_state('@xeroc/comments')17 assert await get_state('@xeroc/recent-replies')18 assert await get_state('worth/@xeroc/python-worth-v0-1-1')19 assert await get_state('worth/@xeroc/re-dercoco-re-xeroc-python-worth-v0-1-1-20160802t073430189z')20 assert await get_state('trending/blockchain')21 assert await get_state('tags')22 with pytest.raises(AssertionError):23 await get_state('trending/blockchain/xxx')24 with pytest.raises(AssertionError):25 await get_state('tags/xxx')26 with pytest.raises(Exception):27 await get_state('witnesses')28@pytest.mark.asyncio29async def test_call():30 assert await call('condenser_api',31 'get_followers',32 ['xeroc', '', 'blog', 10])33 assert await call('condenser_api',34 'get_discussions_by_blog',35 [{"tag": "xeroc",36 "start_author": "",37 "start_permlink": "",38 "limit": 10}])39@pytest.mark.asyncio40async def test_get_trending_tags():41 full = await get_trending_tags()...

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 localstack 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