本文整理汇总了Python中lib.game.Game.is_valid_command方法的典型用法代码示例。如果您正苦于以下问题:Python Game.is_valid_command方法的具体用法?Python Game.is_valid_command怎么用?Python Game.is_valid_command使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lib.game.Game
的用法示例。
在下文中一共展示了Game.is_valid_command方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from lib.game import Game [as 别名]
# 或者: from lib.game.Game import is_valid_command [as 别名]
#.........这里部分代码省略.........
if time.time()-timetaken<self.botConfig['checktime']: #don't check more frequently than once every 0.1
self.queueStatus="Sleeping"
time.sleep(self.botConfig['checktime'])
self.queueStatus="Running Command"
vote=self.topVote() #running the command after votetime seconds
if vote:
self.lastPushed=vote
words=vote.split("+") #input-time check should have already made sure it's a valid command
for y in words:
try:
self.game.push_button(y)
except:
time.sleep(0.01) #this is just to fill this catch block. It's bad, yes.
time.sleep(.15)
self.clearVote()
self.update_message(0)
else: #this is Anarchy
self.queueStatus="Pushing buttons"
self.update_message(0)
comList,userList=self.curQueue.getCom()
self.lastButton=comList
timetaken=time.time()
index=0;
for button in comList:
username=userList[index]
index +=1
words=button.split("+") #input-time check should have already made sure it's a valid command
for y in words:
if y in self.config['throttled_buttons']:
if time.time() - throttle_timers[y] < self.config['throttled_buttons'][y]:
continue
throttle_timers[y] = time.time()
try: #Just in case of weird edge case
self.game.push_button(y)
except:
time.sleep(0.01) #this is just to fill this catch block. It's bad, yes.
time.sleep(.05) #Anarchy is a bit more jumpy than Democracy
userLength=self.commandDisplayLength-len(button)-2
printusername=username
if len(username)>userLength:
printusername=username[0:userLength-3]+'...'
self.update_message_buffer(printusername+': '+button)
if time.time()-timetaken<self.botConfig['checktime']: #don't check more frequently than once every 0.1
self.queueStatus="Sleeping"
time.sleep(self.botConfig['checktime'])
def addVote(self,vote):
if vote in self.voteCount:
self.voteCount[vote]=self.voteCount[vote]+1
else:
self.voteCount[vote]=1
def topVote(self): #Gets top vote, applying rng to choose among ties
top=[k for k,v in self.voteItems if v == max(self.voteCount.values())]
if not top:
return None
return random.choice(top)
def sortVote(self):
sortedItems=sorted(self.voteItems,key=lambda tup: tup[1], reverse=True) #sort using the values, biggest to smallest
return sortedItems
def clearVote(self):
self.voteCount.clear()
def run(self):
#print("New Version!")
throttle_timers = {button:0 for button in config['throttled_buttons'].keys()}
t=threading.Thread(target=self.commandQueue, args=())
t.daemon=True
t.start()
while True: #For threadsafeness see discussion at the top of this file
#print(self.queueStatus)
#print(self.lastButton)
#print(self.curQueue.getStatus())
#print("Checking for new messages")
new_messages = self.irc.recv_messages(1024)
if not new_messages:
continue
for message in new_messages:
button = message['message'].lower()
username = message['username'].lower()
words = button.split(" ") #basic input cleanup
button=words[0]
#Anarchy/Democracy vote
if button=='democracy':
self.daQueue.addVote(1) #No update to try to make this as fast as possible
elif button=='anarchy':
self.daQueue.addVote(0)
if not self.game.is_valid_command(button):
continue
#print("Adding command")
self.curQueue.addCom([button,username])