def good_droid_turn(droid, G, warriors): print("Good droid at {} attempting its turn".format(droid.get_location())) if not (droid.get_is_alive()): print("GOOD AGENT IS DESTROYED!") # TODO: droid falls over return end_turn_and_print(G, False, warriors) goals = find_good_droid_goals(G, droid.get_location()) path = None for goal in goals: droid_in_goal = False for w in warriors: if goal == w.get_location(): droid_in_goal = True break if not droid_in_goal: print('good droid attempted goal: ' + str(goal)) ## UPDATE DROID POSITION path = find_path(droid.get_location(), goal, G) if path: break if not path: print("NO PATH FOR GOOD DROID") ##GAME SHOULD NOT END IF 2 GOOD DROIDS return end_turn_and_print(G, False, warriors) path = get_path(droid, path) if not debug_mode: follow_path(droid, path) ## UPDATE GRID STATE #v1 = path[0] #v2 = path[-1] #G[v1[0]][v1[1]] = False #G[v2[0]][v2[1]] = True #agent_pos = path[1] update_grid_state(G, path) check_for_EMP(droid) ## POST UPDATE ACTIONS droid_location = droid.get_location() if droid_location[0] > len(G) - 2: #if droid in goal: print("YOU WON") if not debug_mode: droid.droid_client.animate(3, 0) # chirping Sound # TODO: headspin return end_turn_and_print(G, True, warriors) else: dist, bad_droid = get_nearest_opponent(droid.get_location(), droid, warriors) if 1 < dist < 2: if droid.EMPs > 0: launch_EMP(droid, bad_droid) return end_turn_and_print(G, False, warriors)
def bad_droid_turn(droid, G, warriors): print("Bad droid at {} attempting its turn".format(droid.get_location())) # Skip Droid's Turn if not droid.get_is_active(): print('droid is inactive') droid.set_is_active(True) return end_turn_and_print(G, False, warriors) if random.random() <= airstrike_call_prob: print('Bad droid at {} called air strike'.format(droid.get_location())) if call_airstrike(warriors): return end_turn_and_print( G, True, warriors ) ## this means the airstrike killed the last living good_agent ## UPDATE DROID POSITION dist, closest_droid = get_nearest_opponent(droid.get_location(), droid, warriors) # TODO: UPDATE LOGIC FOR SETTING DROID GOAL bad_droid_goal = find_bad_droid_goal(G, droid, closest_droid.get_location()) path = find_path(droid.get_location(), bad_droid_goal, G) print('path is:' + str(path)) path = get_path(droid, path) if not path: print("NO PATH FOR BAD DROID" ) ##GAME SHOULD NOT END IF WE HAVE 2 BAD DROIDS return end_turn_and_print(G, False, warriors) if not debug_mode: follow_path(droid, path) ## UPDATE GRID STATE #v1 = path[0] #v2 = path[-1] #G[v1[0]][v1[1]] = False #G[v2[0]][v2[1]] = True #enemy_pos = path[1] update_grid_state(G, path) # TODO: POST UPDATE ACTIONS return end_turn_and_print(G, False, warriors)
def move_agent(self, agent_name, path): """Move agent_name by path of size 2""" print("move {0}: {1}".format(agent_name, path)) x, y = path[0] new_x, new_y = path[1] # Update grid states # Update agent's position self.update_agent_position(agent_name, (new_x, new_y)) # Update grid so that old position (x,y) is now available for move into # while new position is not available into self.update_neighbors((x, y), (new_x, new_y)) # Physically move robot if not self.debug: maneuver.follow_path( droid_client=self.get_agent_droidclient(agent_name), path=[(x, y), (new_x, new_y)])
# ║ ║ ║ ║ # ☐ ══☐ ☐ ══☐ # ║ ║ ║ # ☑ ☐ ══☐ ☒ # enemy1_bound = (5, 6) # enemy2 = (4, 4) # enemy2_bound = (3, 4) while True: # AGENT path = find_path(agent_pos, goal, G) maneuver.follow_path(droid, path[0:2]) print(path) v1 = path[0] v2 = path[1] G[v1[0]][v1[1]] = False G[v2[0]][v2[1]] = True agent_pos = path[1] print_graph(G) # BAD DROID 1 i = 1 while True: enemy_goal = agent_pos + (i, 0)
from client import DroidClient droid = DroidClient() droid.connect_to_R2D2() droid.animate(10) droid.set_stance(2) # transition to bipod from maneuver import follow_path path = [(0,0), (0,1), (1,1), (1,2), (2,2), (2,3), (3,3), (3,0), (0,0)] follow_path(droid, path, 0x88, scale_dist=0.5) droid.turn(0) droid.sleep() droid.quit()
import time from client import DroidClient import courses from a_star import A_star import maneuver # connect to Sphero droid = DroidClient() droid.connect_to_R2D2() # get course, find path G = courses.grid_1 start = (0, 0) goal = (3, 0) path = A_star(G, start, goal) # ☑ =start node, ☒ =goal node # ☐ ══☐ ☐ ══☐ # ║ ║ ║ ║ # ☐ ☐ ══☐ ☐ # ║ ║ ║ ║ # ☐ ══☐ ☐ ══☐ # ║ ║ ║ # ☑ ☐ ══☐ ☒ # traverse path speed = 0x88 # half speed maneuver.follow_path(droid, path, speed, dist_constant=0.75) droid.animate(10) droid.quit()