class Test: def __init__(self, dic): self.itms = list([(i, dic[i]) for i in dic]) random.shuffle(self.itms) self.cur_idx = 0 self.queque = [i for i in range(len(self.itms))] self.len = len(self.queque) self.hint = None self.speaker = Speaker() def get_quest(self, idx): return self.itms[idx][1] def get_ans(self, idx): return self.itms[idx][0] def sayAnswer(self): self.speaker.say(self.get_ans(self.cur_idx)) def ask(self): if len(self.queque)>0: self.cur_idx = self.queque[0] del self.queque[0] return self.get_quest(self.cur_idx) else: return None def get_hint(self): if self.hint == None: idx = 0 else: idx = None self.hint = hint(self.get_ans(self.cur_idx), self.hint, idx) return self.hint def is_right_ans(self, ans): if self.get_ans(self.cur_idx) == ans: self.hint = False return True else: if len(self.queque)>0: if self.queque[-1]!=self.cur_idx: self.queque.append(self.cur_idx) else: self.queque.append(self.cur_idx) return False
class Norensama(object): def __init__(self): self._speaker = Speaker() self._ifttt = Ifttt({"api_key": config.IFTTT_APIKEY}) self._status = StatusManager() self._actions = [ Yureyure(self._speaker), Hello(self._speaker), Joke(self._speaker), TimeSignal(self._speaker), ] self._blow_actions = [ # よわい Soyosoyo(self._speaker), # 横揺れ Yurayura(self._speaker), # 波 Byubyu(self._speaker) ] self._blow_action_index = 1 def select_blow_action(self, data={}): acc = data.get("accelerometer") if acc is None: return print(acc.acc_x, acc.acc_y, acc.acc_z) acc_x = abs(acc.acc_x) if acc_x > .5: self._blow_action_index = 2 elif acc_x > .2: self._blow_action_index = 1 else: self._blow_action_index = 0 def main(self): print("main") status_thread = threading.Thread(target=self._status.update) status_thread.daemon = True status_thread.start() self.select_blow_action() selected_time = time.time() while True: data = self._status.get_data() # 10分に一回、ゆれの音を決める if time.time() - selected_time > 60.: self.select_blow_action(data) # その音で、IFTTT # 揺れに合わせて、ゆらゆら言っている start = time.time() while time.time() - start < 6.: # 風のまね self._blow_actions[self._blow_action_index].run(data) # 強制起動もここでやる # RT、フォロー、された場合は、ここでいう if random.random() > .9: # TODO ちょっとこのファイルが再生時間長いので、カットする self._speaker.say("iphone") time.sleep(3.) print("search action") # このタイミングで、反応があると、ちがうこともいう runable_action = [x for x in self._actions if x.check(data)] if runable_action: start = time.time() idx = int(random.random() * len(runable_action)) message = runable_action[idx].run({}) # 1時間発言していないキーワードだったら、IFTTT print(time.time() - start) time.sleep(1.)
sv.start() while not sv.started: pass print "Scrabble vision started. Ready." print "Starting speaker..." voice = Speaker() voice.start() PICKLE_FILENAME = "game.state" if len(sys.argv) == 2: filename = sys.argv[1] (scoreboard, game_board) = pickle.load( open(filename, "rb") ) print "Game recovered from file" voice.say("Resuming game!") else: #Find out our players player_count = int(ask("How many players?")) player_list = [] for i in range(1, player_count+1): x = ask("What is Player %d's name?"% i) player_list.append(x.strip()) game_board = Board() scoreboard = Scoreboard(player_list) voice.say("Starting game!") #Create scorebox