def hand_hit(self, hand): """waits for a hit from the specified hand""" if self.hand_down(hand): wait_for(self.hand_up, (hand, )) wait_for(self.hand_down, (hand, )) return self.coords[hand][X]
def hand_slide(self, hand, hit_location): x = self.coords[hand][X] wait_for(self.joint_moved_x, (x, hand, hit_location)) if self.hand_up(hand): return False return self.coords[hand][X]
def hand_hit(self, hand): """waits for a hit from the specified hand""" if self.hand_down(hand): wait_for(self.hand_up, (hand,)) wait_for(self.hand_down, (hand,)) return self.coords[hand][X]
def __init__(self, name, room): self.score = 0 self.room = room self.name = name self.thread = None self.thread2 = None self.id = "" self.key_downs = [] self.pos = {'x':-200.0, 'y':0.0} self.team = "" self.browser = webdriver.Chrome() self.browser.get(room.roomLink) ut.wait_for(self.user_name_enter) ut.wait_for(self.getId)
def _run_hand(self, hand): instrument = None while self.playing: inst_class, inst_kwargs = self.hand_instruments[hand] self._change_pitches(hand) x = wait_for(kinect.hand_hit, (hand,)) if not self.playing: # we waited a while, so have to check again return hit_location = x pitches = self._hand_pitches(x, hand) velocity = self._calc_velocity(hand, slide=False) if instrument is not None: instrument.stop() instrument = inst_class(pitches, velocity, **inst_kwargs) instrument.start() while x: new_pitches = self._hand_pitches(x, hand) if new_pitches != pitches: pitches = new_pitches velocity = self._calc_velocity(hand, slide=True) instrument = instrument.slide(pitches, velocity) x = kinect.hand_slide(hand, hit_location) hit_location = None instrument.stop()
def _run_hand(self, hand): instrument = None while self.playing: inst_class, inst_kwargs = self.hand_instruments[hand] self._change_pitches(hand) x = wait_for(kinect.hand_hit, (hand, )) if not self.playing: #we waited a while, so have to check again return hit_location = x pitches = self._hand_pitches(x, hand) velocity = self._calc_velocity(hand, slide=False) if instrument is not None: instrument.stop() instrument = inst_class(pitches, velocity, **inst_kwargs) instrument.start() while (x): new_pitches = self._hand_pitches(x, hand) if new_pitches != pitches: pitches = new_pitches velocity = self._calc_velocity(hand, slide=True) instrument = instrument.slide(pitches, velocity) x = kinect.hand_slide(hand, hit_location) hit_location = None instrument.stop()
def __init__(self,name,token,number_of_bots): self.press_time = {'short_press':0.005, 'long_press':0.1} self.possible_keys = ['X','S','D','A','W'] self.possible_actions = [[ch, self.press_time['long_press']] for ch in self.possible_keys] self.roomLink = '' self.browser = webdriver.Chrome() self.browser.get('https://html5.haxball.com/headless') ut.wait_for(self.start_room, token) ut.wait_for(self.get_room_link) self.bots = [] self.curr_screen = -1 self.time = 0 self.cancel_future_calls = None self.steps = 0 self.maxsteps = 64 self.ball_pos = {'x':0.0, 'y':0.0} for i in range(number_of_bots): pname = "P"+str(i) self.bots.append(Player(pname,self))