def generate(self, word, round_name, involved_letters, difficulty): if round_name == "subanag": if len(set(involved_letters)) < len( involved_letters): # We have dupes! maxpos = int(round(len(involved_letters) / 1.5)) twodupes = [sorted(random.sample(range(maxpos), 2))] else: twodupes = None elif round_name == "onlyhas": r = random.randint(0, max(int(round(len(word) / 1.5)), 3)) s = r + random.randint(1, 2) twodupes = [[r, s]] elif round_name in [ "blockbeginend", "blockend", "blockmiddle", "blockstart", "exclude", "onlyhas", "ordered", "boggle" ]: # Find all letters that occur at least twice within the word, logging only their first and second appearances. twodupes = [ y[0:2] for y in [[i for i in range(len(word)) if word[i] == x] for x in set(word)] if len(y) > 1 ] else: twodupes = None if twodupes: # Purely random choice often forces players to seek extraordinarily long words, so we minimize the forced word length. dupe = min(twodupes, key=max) regex = re.compile("".join([ "^", "." * dupe[0], "(.)", "." * (dupe[1] - dupe[0] - 1), r"\1" ])) str = STR_ANNOUNCE_MOD.format(embolden(ORDINALS[dupe[0]]), embolden(ORDINALS[dupe[1]])) else: regex = None str = "" return regex, str
def generate(self, word, words, difficulty): anag = "".join(random.sample(word,len(word))) hintamount = max(int(round(len(word)/4)),1) r = random.randint(0,hintamount) hint = word[:r]+"*"*(len(word)-hintamount)+(word[-1*(hintamount-r):] if r != hintamount else "") str = STR_ANNOUNCE.format(embolden(anag),embolden(hint)) involved_letters = word return self.anag_regex(word).match, str, involved_letters
def generate(self, word, words, difficulty): block_length = min(len(word) - 1, random.randint(3, 6)) left_length = random.randint(1, block_length - 1) right_length = block_length - left_length block = (word[0:left_length], word[-1 * right_length:]) regex = re.compile("^" + block[0] + ".*" + block[1] + "$") str = STR_ANNOUNCE.format(embolden(block[0]), embolden(block[1])) involved_letters = block[0] + block[1] return regex.match, str, involved_letters
def submit_word(self, word, nick): if nick not in self.newscores: self.newscores[nick] = 0 #Mark the submitter as having submitted a word (for scoring purposes). word = re.sub('[^a-zA-Z]','',word).upper() if re.match('NESS(?:ES)?$',word): self.output(chatter.NO_NESSES.format(nick)) elif word in self.best_words: if len(self.best_words) > 1: maxmsg = chatter.STR_GOT_MAX.format(nick,len(self.best_words),embolden(word),self.scored_words[word]) else: maxmsg = chatter.STR_GOT_MAX_UNIQUE.format(nick,embolden(word),self.scored_words[word]) self.output(maxmsg) self.define_word(word) self.end_timer.cancel() bonus = self.handle_streak(nick) self.add_score(nick,self.scored_words[word]+bonus) self.comment_score(nick) self.new_round() elif word in self.possible_words: score = self.scored_words[word] if score > self.winningword_score: if self.winningword_score == 0: msg = chatter.STRF_GOOD_WORD().format(word,score) if self.time_left() < self.reset_time: self.reset_end_timer() msg += " " + chatter.STR_TIME_RESET.format(self.reset_time) else: msg += " " + self.time_warning() elif nick == self.winningnick: msg = chatter.STRF_BEAT_SELF().format(word,score) + " " + self.time_warning() else: msg = chatter.STRF_BEAT_OTHER().format(word,score,self.winningnick,self.winningword,self.winningword_score) + " " + self.time_warning() self.winningword = word self.winningword_score = score self.winningnick = nick else: if word == self.winningword: msg = chatter.STR_NO_BEAT_SELF.format(nick) else: poss = "your" if nick == self.winningnick else (self.winningnick + "'s") msg = chatter.STRF_NO_BEAT_OTHER().format(word,score,poss,self.winningword,self.winningword_score) + " " + self.time_warning() self.output(msg) elif cfg.DYNAMIC_HINTS and self.round_name in ["anag","defn"]: newindices = set([i for i in range(min(len(word),len(self.answord))) if word[i] == self.answord[i]]) allindices = newindices | self.hint_indices if (newindices - self.hint_indices): self.hint_indices = allindices partial = "".join([self.answord[i] if i in sorted(allindices) else "?" for i in range(len(self.answord))]) self.output(chatter.STRF_ANAG_HINT().format(partial))
def generate(self, word, words, difficulty): block_length = min(len(word),random.randint(3,4)) pos = random.randint(0,len(word)-block_length) block = word[pos:pos+block_length] regex = re.compile("^.*"+block+".*$") str = STR_ANNOUNCE.format(embolden(block)) involved_letters = block return regex.match, str, involved_letters
def generate(self, word, words, difficulty): block_length = min(len(word), random.randint(4, 5)) pos = len(word) - block_length block = word[pos:pos + block_length] regex = re.compile("^.*" + block + "$") str = STR_ANNOUNCE.format(embolden(block)) involved_letters = block return regex.match, str, involved_letters
def generate(self, word, words, difficulty): r = random.randint(0,len(self.wn_words)) wnword, defn = self.wn_words[r].upper(), self.wn_defs[r] hintamount = max(int(round(len(wnword)/4)),1) s = random.randint(0,hintamount) hint = wnword[:s]+"*"*(len(wnword)-hintamount)+(wnword[-1*(hintamount-s):] if s != hintamount else "") str = STR_ANNOUNCE.format(defn,embolden(hint)) involved_letters = wnword regex = re.compile("".join(["^",wnword,"$"])) return regex.match, str, involved_letters
def generate(self, word, words, difficulty): num_letters = random.randint(8, 13) num_vowels = min(random.randint(3, 5), int(round(num_letters / 2.5))) letters = discrete_sample(constants.VOWEL_FREQS, num_vowels) + discrete_sample( constants.CONS_FREQS, num_letters - num_vowels ) random.shuffle(letters) str = STR_ANNOUNCE.format(embolden("".join(letters))) involved_letters = letters return self.subanag_regex(letters).match, str, involved_letters
def generate(self, word, words, difficulty): num_letters = random.randint(8, 13) num_vowels = min(random.randint(3, 5), int(round(num_letters / 2.5))) letters = discrete_sample( constants.VOWEL_FREQS, num_vowels) + discrete_sample( constants.CONS_FREQS, num_letters - num_vowels) random.shuffle(letters) str = STR_ANNOUNCE.format(embolden("".join(letters))) involved_letters = letters return self.subanag_regex(letters).match, str, involved_letters
def generate(self, word, round_name, involved_letters, difficulty): if round_name in ["blockbeginend","blockend","blockmiddle","blockstart","exclude","onlyhas","ordered","boggle"]: if round_name == "onlyhas": max_repeats = random.randint(2,3) elif round_name == "exclude": max_repeats = random.randint(1,3) else: max_repeats = random.randint(1,2) regex = re.compile("^(?:([A-Za-z])(?!"+r".*\1"*max_repeats+"))*$") str = STR_ANNOUNCE_MOD.format(embolden(NUM_TIMES[max_repeats])) else: regex = None str = "" return regex, str
def generate(self, word, round_name, involved_letters, difficulty): if round_name == "subanag": if len(set(involved_letters)) < len(involved_letters): # We have dupes! maxpos = int(round(len(involved_letters)/1.5)) twodupes = [sorted(random.sample(range(maxpos),2))] else: twodupes = None elif round_name == "onlyhas": r = random.randint(0,max(int(round(len(word)/1.5)),3)) s = r + random.randint(1,2) twodupes = [[r,s]] elif round_name in ["blockbeginend","blockend","blockmiddle","blockstart","exclude","onlyhas","ordered","boggle"]: # Find all letters that occur at least twice within the word, logging only their first and second appearances. twodupes = [y[0:2] for y in [[i for i in range(len(word)) if word[i] == x] for x in set(word)] if len(y) > 1] else: twodupes = None if twodupes: # Purely random choice often forces players to seek extraordinarily long words, so we minimize the forced word length. dupe = min(twodupes, key=max) regex = re.compile("".join(["^","."*dupe[0],"(.)","."*(dupe[1] - dupe[0] - 1),r"\1"])) str = STR_ANNOUNCE_MOD.format(embolden(ORDINALS[dupe[0]]),embolden(ORDINALS[dupe[1]])) else: regex = None str = "" return regex, str
def generate(self, word, round_name, involved_letters, difficulty): if round_name in [ "blockbeginend", "blockend", "blockmiddle", "blockstart", "exclude", "onlyhas", "ordered", "boggle" ]: if round_name == "onlyhas": max_repeats = random.randint(2, 3) elif round_name == "exclude": max_repeats = random.randint(1, 3) else: max_repeats = random.randint(1, 2) regex = re.compile("^(?:([A-Za-z])(?!" + r".*\1" * max_repeats + "))*$") str = STR_ANNOUNCE_MOD.format(embolden(NUM_TIMES[max_repeats])) else: regex = None str = "" return regex, str
import re import random from constants import ALPHABET from formatting import embolden, listtostr STR_ANNOUNCE_MOD = "Your word must " + embolden("exclude") + " {}!" class modifiergenerator(): def __init__(self): pass 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)
import re import random from constants import ALPHABET from formatting import embolden, listtostr STR_ANNOUNCE_MOD = "Your word must "+embolden("exclude")+" {}!" class modifiergenerator(): def __init__(self): pass 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
import re import random from constants import ORDINALS from formatting import embolden STR_ANNOUNCE_MOD = "The {} and {} letters must be "+embolden("the same")+"!" class modifiergenerator(): def __init__(self): pass def generate(self, word, round_name, involved_letters, difficulty): if round_name == "subanag": if len(set(involved_letters)) < len(involved_letters): # We have dupes! maxpos = int(round(len(involved_letters)/1.5)) twodupes = [sorted(random.sample(range(maxpos),2))] else: twodupes = None elif round_name == "onlyhas": r = random.randint(0,max(int(round(len(word)/1.5)),3)) s = r + random.randint(1,2) twodupes = [[r,s]] elif round_name in ["blockbeginend","blockend","blockmiddle","blockstart","exclude","onlyhas","ordered","boggle"]: # Find all letters that occur at least twice within the word, logging only their first and second appearances. twodupes = [y[0:2] for y in [[i for i in range(len(word)) if word[i] == x] for x in set(word)] if len(y) > 1] else: twodupes = None if twodupes: # Purely random choice often forces players to seek extraordinarily long words, so we minimize the forced word length. dupe = min(twodupes, key=max) regex = re.compile("".join(["^","."*dupe[0],"(.)","."*(dupe[1] - dupe[0] - 1),r"\1"])) str = STR_ANNOUNCE_MOD.format(embolden(ORDINALS[dupe[0]]),embolden(ORDINALS[dupe[1]]))
import re import random from formatting import embolden, listtostr STR_ANNOUNCE_MOD = "Your word " + embolden("must include") + " {}!" class modifiergenerator(): def __init__(self): pass 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)
import re import random from constants import NUM_TIMES from formatting import embolden STR_ANNOUNCE_MOD = "You " + embolden( "must not") + " use any letter " + embolden("more than") + " {}!" class modifiergenerator(): def __init__(self): pass def generate(self, word, round_name, involved_letters, difficulty): if round_name in [ "blockbeginend", "blockend", "blockmiddle", "blockstart", "exclude", "onlyhas", "ordered", "boggle" ]: if round_name == "onlyhas": max_repeats = random.randint(2, 3) elif round_name == "exclude": max_repeats = random.randint(1, 3) else: max_repeats = random.randint(1, 2) regex = re.compile("^(?:([A-Za-z])(?!" + r".*\1" * max_repeats + "))*$") str = STR_ANNOUNCE_MOD.format(embolden(NUM_TIMES[max_repeats])) else: regex = None str = "" return regex, str
import re import random from constants import NUM_TIMES from formatting import embolden STR_ANNOUNCE_MOD = "You "+embolden("must not")+" use any letter "+embolden("more than")+" {}!" class modifiergenerator(): def __init__(self): pass def generate(self, word, round_name, involved_letters, difficulty): if round_name in ["blockbeginend","blockend","blockmiddle","blockstart","exclude","onlyhas","ordered","boggle"]: if round_name == "onlyhas": max_repeats = random.randint(2,3) elif round_name == "exclude": max_repeats = random.randint(1,3) else: max_repeats = random.randint(1,2) regex = re.compile("^(?:([A-Za-z])(?!"+r".*\1"*max_repeats+"))*$") str = STR_ANNOUNCE_MOD.format(embolden(NUM_TIMES[max_repeats])) else: regex = None str = "" return regex, str
def format_grid(self, grid): return [embolden(" ".join(g).replace("@", "Qu")) for g in grid]
import re import random from formatting import embolden, listtostr STR_ANNOUNCE_MOD = "Your word "+embolden("must include")+" {}!" class modifiergenerator(): def __init__(self): pass 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
def format_grid(self, grid): return [embolden(" ".join(g).replace("@","Qu")) for g in grid]
import re import random from constants import ORDINALS from formatting import embolden STR_ANNOUNCE_MOD = "The {} and {} letters must be " + embolden( "the same") + "!" class modifiergenerator(): def __init__(self): pass def generate(self, word, round_name, involved_letters, difficulty): if round_name == "subanag": if len(set(involved_letters)) < len( involved_letters): # We have dupes! maxpos = int(round(len(involved_letters) / 1.5)) twodupes = [sorted(random.sample(range(maxpos), 2))] else: twodupes = None elif round_name == "onlyhas": r = random.randint(0, max(int(round(len(word) / 1.5)), 3)) s = r + random.randint(1, 2) twodupes = [[r, s]] elif round_name in [ "blockbeginend", "blockend", "blockmiddle", "blockstart", "exclude", "onlyhas", "ordered", "boggle" ]: # Find all letters that occur at least twice within the word, logging only their first and second appearances.