Exemplo n.º 1
0
	def get_move_text(self,dir,movers,destposnicks,destpos):
		verb = random.choice(chatter.SYNS_FALL_TO if dir == 0 else chatter.SYNS_RISE_TO)
		verb = verb.format("" if len(movers) > 1 else "s")
		if len(destposnicks) > 1 and destposnicks != movers:
			destposnicks = sorted(set(destposnicks) - set(movers))
			extra = " ".join([" with",listtostr(destposnicks)])
		else: extra = ""
		fragment = " ".join([listtostr(sorted(movers)),verb,chatter.STRF_POS(destpos,bool(extra))])
		return "".join([fragment,extra]) + "!"
Exemplo n.º 2
0
 def generate(self, word, round_name, involved_letters, difficulty):
     num_letters = random.randint(1, 2)
     involved_letters = set(involved_letters)
     if round_name in [
             "blockbeginend", "blockend", "blockmiddle", "blockstart",
             "ordered", "onlyhas"
     ]:
         possible_letters = set(word) - involved_letters
     elif round_name in ["subanag"]:
         possible_letters = involved_letters
     elif round_name in ["boggle"]:
         possible_letters = involved_letters - set(["@"])
     else:
         possible_letters = None
     if possible_letters:
         letters = random.sample(
             possible_letters,
             num_letters) if num_letters < len(possible_letters) else list(
                 possible_letters)
         regex = re.compile("^.*(?:" + ".*".join(letters) + (
             "|" +
             ".*".join(reversed(letters)) if len(letters) > 1 else "") +
                            ").*$")
         str = STR_ANNOUNCE_MOD.format(
             listtostr(map(embolden, sorted(letters)), conj="and"))
     else:
         regex = re.compile("^.*$")
         str = ""
     return regex, str
Exemplo n.º 3
0
	def generate(self, word, words, difficulty):
		block_length = min(len(word),random.randint(4,6))
		block = [list(word)[i] for i in sorted(random.sample(xrange(len(list(word))),block_length))]
		regex = re.compile("^.*"+".*".join(block)+".*$")
		str = STR_ANNOUNCE.format(listtostr(map(embolden,block)))
		involved_letters = block
		return regex.match, str, involved_letters
Exemplo n.º 4
0
	def generate(self, word, words, difficulty):
		num_letters = random.randint(7,9)
		num_vowels = min(random.randint(3,5),int(round(num_letters/2)))
		letters = sorted(set(discrete_sample(constants.VOWEL_FREQS,num_vowels)+discrete_sample(constants.CONS_FREQS,num_letters-num_vowels)))
		#letters = sorted(map(lambda a: LETTERFREQS[a-1],list(set(random_partition(random.randint(1.5*26,3*26))))))
		regex = "^[^"+"".join(letters)+"]*$"
		str = STR_ANNOUNCE.format(listtostr(map(embolden,letters),conj="and"))
		involved_letters = letters
		return re.compile(regex).match, str, involved_letters
Exemplo n.º 5
0
 def generate(self, word, words, difficulty):
     block_length = min(len(word), random.randint(4, 6))
     block = [
         list(word)[i] for i in sorted(
             random.sample(xrange(len(list(word))), block_length))
     ]
     regex = re.compile("^.*" + ".*".join(block) + ".*$")
     str = STR_ANNOUNCE.format(listtostr(map(embolden, block)))
     involved_letters = block
     return regex.match, str, involved_letters
Exemplo n.º 6
0
	def final_scores(self):
		self.output(chatter.STR_GAME_OVER)
		chatters = [chatter.STRF_FIRST_POS,chatter.STRF_SECOND_POS,chatter.STRF_THIRD_POS]
		joint_chatters = [chatter.STRF_JOINT_FIRST_POS,chatter.STRF_JOINT_SECOND_POS,chatter.STRF_JOINT_THIRD_POS]
		new_merged = self.merge_data(self.newscores.iteritems(),pos=1)
		top_three = self.get_top_three(new_merged)
		if top_three:
			for n in range(len(top_three)):
				nicks = listtostr(top_three[n][0])
				pos = self.merged_pos(top_three[n][0][0],new_merged)
				if len(top_three[n][0]) > 1: chat = joint_chatters[pos]
				else: chat = chatters[pos]
				self.output(chat().format(nicks,self.newscores[top_three[n][0][0]]))
		else: self.output(chatter.STR_NO_SCORES)
Exemplo n.º 7
0
	def generate(self, word, round_name, involved_letters, difficulty):
		num_letters = random.randint(1,4)
		possible_letters = None
		if round_name in ["blockbeginend","blockend","blockmiddle","blockstart","ordered"]:
			possible_letters = ALPHABET - set(word)
		elif round_name in ["boggle"]:
			possible_letters = involved_letters - set(["@"])
		else: possible_letters = None
		if not possible_letters:
			regex = None
			str = ""
		else:
			# This picking ought to be done probabilistically according to letter frequency, but until tools.discrete_sample is rewritten this will have to do.
			letters = random.sample(possible_letters,num_letters)
			regex = re.compile("^[^"+"".join(letters)+"]*$")
			str = STR_ANNOUNCE_MOD.format(listtostr(map(embolden,sorted(letters)),conj="and"))
		return regex, str
Exemplo n.º 8
0
	def generate(self, word, round_name, involved_letters, difficulty):
		num_letters = random.randint(1,2)
		involved_letters = set(involved_letters)
		if round_name in ["blockbeginend","blockend","blockmiddle","blockstart","ordered","onlyhas"]:
			possible_letters = set(word) - involved_letters
		elif round_name in ["subanag"]:
			possible_letters = involved_letters
		elif round_name in ["boggle"]:
			possible_letters = involved_letters - set(["@"])
		else: possible_letters = None
		if possible_letters:
			letters = random.sample(possible_letters,num_letters) if num_letters < len(possible_letters) else list(possible_letters)
			regex = re.compile("^.*(?:"+".*".join(letters)+("|"+".*".join(reversed(letters)) if len(letters) > 1 else "")+").*$")
			str = STR_ANNOUNCE_MOD.format(listtostr(map(embolden,sorted(letters)),conj="and"))
		else:
			regex = re.compile("^.*$")
			str = ""
		return regex, str
Exemplo n.º 9
0
	def generate(self, word, words, difficulty):
		#num_letters = random.randint(5,8)
		#num_vowels = min(random.randint(2,3),int(round(num_letters/2.5)))
		#letters = discrete_sample(constants.VOWEL_FREQS,num_vowels)+discrete_sample(constants.CONS_FREQS,num_letters-num_vowels)
		word_letters = set(word)
		num_letters = min(len(word_letters),random.randint(5,8))
		letters = set(random.sample(word_letters,num_letters))
		# Ensure at least two vowels are available so that the chances of insolubility are extremely low.
		if len(letters & VOWELS) < 2:
			used_word_vowels = letters & VOWELS
			unused_vowels = VOWELS - used_word_vowels
			unused_word_vowels = unused_vowels & word_letters
			if len(unused_word_vowels) > 0: letters.add(random.choice(list(unused_word_vowels)))
			else: letters.add(random.choice(list(unused_vowels)))
		if "Q" in letters and "U" not in letters: letters.add("U")
		regex = re.compile("^["+"".join(letters)+"]*$")
		str = STR_ANNOUNCE.format(listtostr(map(embolden,sorted(letters)),conj="or"))
		involved_letters = "".join(letters)
		return regex.match, str, involved_letters
Exemplo n.º 10
0
 def generate(self, word, round_name, involved_letters, difficulty):
     num_letters = random.randint(1, 4)
     possible_letters = None
     if round_name in [
             "blockbeginend", "blockend", "blockmiddle", "blockstart",
             "ordered"
     ]:
         possible_letters = ALPHABET - set(word)
     elif round_name in ["boggle"]:
         possible_letters = involved_letters - set(["@"])
     else:
         possible_letters = None
     if not possible_letters:
         regex = None
         str = ""
     else:
         # This picking ought to be done probabilistically according to letter frequency, but until tools.discrete_sample is rewritten this will have to do.
         letters = random.sample(possible_letters, num_letters)
         regex = re.compile("^[^" + "".join(letters) + "]*$")
         str = STR_ANNOUNCE_MOD.format(
             listtostr(map(embolden, sorted(letters)), conj="and"))
     return regex, str
Exemplo n.º 11
0
 def generate(self, word, words, difficulty):
     #num_letters = random.randint(5,8)
     #num_vowels = min(random.randint(2,3),int(round(num_letters/2.5)))
     #letters = discrete_sample(constants.VOWEL_FREQS,num_vowels)+discrete_sample(constants.CONS_FREQS,num_letters-num_vowels)
     word_letters = set(word)
     num_letters = min(len(word_letters), random.randint(5, 8))
     letters = set(random.sample(word_letters, num_letters))
     # Ensure at least two vowels are available so that the chances of insolubility are extremely low.
     if len(letters & VOWELS) < 2:
         used_word_vowels = letters & VOWELS
         unused_vowels = VOWELS - used_word_vowels
         unused_word_vowels = unused_vowels & word_letters
         if len(unused_word_vowels) > 0:
             letters.add(random.choice(list(unused_word_vowels)))
         else:
             letters.add(random.choice(list(unused_vowels)))
     if "Q" in letters and "U" not in letters: letters.add("U")
     regex = re.compile("^[" + "".join(letters) + "]*$")
     str = STR_ANNOUNCE.format(
         listtostr(map(embolden, sorted(letters)), conj="or"))
     involved_letters = "".join(letters)
     return regex.match, str, involved_letters
Exemplo n.º 12
0
	def get_stay_text(self,movers,pos):
		verb = random.choice(chatter.SYNS_KEEP).format("" if len(movers) > 1 else "s")
		return " ".join([listtostr(sorted(movers)),verb,chatter.STRF_POS(pos,len(movers) > 1)]) + "."