From 4d22b81b5a574658e2590b77d71e3c692cfd4457 Mon Sep 17 00:00:00 2001 From: Vincent Le Gallic Date: Sat, 26 May 2012 14:56:03 +0200 Subject: [PATCH] =?utf8?q?Programmation=20adapt=C3=A9e=20=C3=A0=20Salesman?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- Salesman.py | 55 +++++++++++++++++++++-------------------------------- 1 file changed, 22 insertions(+), 33 deletions(-) diff --git a/Salesman.py b/Salesman.py index 523d960..d437e87 100755 --- a/Salesman.py +++ b/Salesman.py @@ -149,40 +149,30 @@ class Deconnaisseur(ircbot.SingleServerIRCBot): else: ok="refuse" if ok=="do_it": - enigme,indice,answer=self.get_enigme() + enigme,answer=self.get_enigme() log(self.serveur,channel,u"$Énigme$".encode("utf8"),("%s | %s"%(enigme, answer)).encode("utf8")) serv.privmsg(channel,enigme.encode("utf8")) token=time.time() - self.play_status[channel]=[1,enigme,indice,answer_reg,answer,token] - serv.execute_delayed(random.randrange(ttrig*3,ttrig*5),self.give_indice,(serv,channel,token)) + self.play_status[channel]=[1,enigme,answer,token] + # ce bot n'a pas d'indices + serv.execute_delayed(random.randrange(ttrig*7,ttrig*10),self.give_answer,(serv,channel,token)) elif ok=="refuse": raise RefuseError - def give_indice(self,serv,channel,token): - if self.play_status[channel][0]==1: - if token==None: - # c'est donc que l'indice a été demandé - if self.play_status[channel][-1]+config_time_incompressible_clue pays ou pays -> capitale + enigme,answer=random.choice([[capitale,pays],[pays,capitale]]) # on incrémente la choisie played[id_choisi]+=1 # on enregistre le played_file f=open(played_file,"w") f.write("\n".join(["%-3s : %s"%(k,v) for k,v in played.items()])) f.close() - return enigme.decode("utf8"),indice.decode("utf8"),answer_reg.decode("utf8"),answer.decode("utf8") + return map(lambda x:x.decode("utf8"), [enigme,answer]) def pourmoi(self, serv, message): pseudo=self.nick @@ -359,7 +351,7 @@ class Deconnaisseur(ircbot.SingleServerIRCBot): elif cmd in ["states","status"]: if auteur in self.overops: for k in self.play_status.keys(): - serv.privmsg(auteur,(u"%s : %s"%(k,"; ".join([unicode(i) for i in self.play_status[k]]))).encode("utf8") ) + serv.privmsg(auteur,(u"%s : %s"%(k," | ".join([unicode(i) for i in self.play_status[k]]))).encode("utf8") ) elif cmd=="say": if auteur in self.overops and len(message)>2: serv.privmsg(message[1]," ".join(message[2:])) @@ -497,7 +489,7 @@ class Deconnaisseur(ircbot.SingleServerIRCBot): serv.privmsg(canal,"%s: coucou"%(auteur)) if cmd in ["ping"] and not canal in self.quiet_channels: serv.privmsg(canal,"%s: pong"%(auteur)) - if cmd in ["déconnaissance","deconnaissance","énigme","enigme","encore"]: + if cmd in ["ville","capitale","pays","énigme","enigme","encore"]: if canal in self.play_channels: if self.play_status.get(canal,[-1])[0]==0: try: @@ -519,8 +511,6 @@ class Deconnaisseur(ircbot.SingleServerIRCBot): # trie par pseudo scores.sort(lambda x,y:cmp(x[0].lower(),y[0].lower())) serv.privmsg(auteur,"Scores by pseudo : "+" ; ".join(["%s %s"%(i[0],i[1]) for i in scores])) - if cmd=="indice" and canal in self.play_channels: - self.give_indice(serv,canal,None) if is_tag(message) and not canal in self.quiet_channels: if auteur in self.ops: action=random.choice(config_tag_actions) @@ -535,10 +525,9 @@ class Deconnaisseur(ircbot.SingleServerIRCBot): else: tryother=True if tryother: - if self.play_status.get(canal,[-1])[0] in [1,2]: - answer_regexp=self.play_status[canal][3] - answer=self.play_status[canal][4] - if reussi(message.decode("utf8"),answer,answer_regexp,auteur): + if self.play_status.get(canal,[-1])[0]==1: + answer=self.play_status[canal][2] + if reussi(message.decode("utf8"),answer,auteur): serv.privmsg(canal,(u"%s: bravo ! (C'était %s)"%(auteur,answer)).encode("utf8")) log(self.serveur,canal,auteur+"$win",message) self.add_score(auteur,1) @@ -599,7 +588,7 @@ class Deconnaisseur(ircbot.SingleServerIRCBot): if __name__=="__main__": import sys if len(sys.argv)==1: - print "Usage : deconnaisseur.py [--debug]" + print "Usage : Salesman.py [--debug]" exit(1) serveur=sys.argv[1] if "debug" in sys.argv or "--debug" in sys.argv: @@ -613,5 +602,5 @@ if __name__=="__main__": except KeyError: print "Server Unknown : %s"%(serveur) exit(404) - deco=Deconnaisseur(serveur,debug) - deco.start() + salesman=Salesman(serveur,debug) + salesman.start() -- 2.39.2