|
|
|
|
@ -33,50 +33,101 @@ bog_kern = [[-1,-1], [-1, 0], [-1, 1], |
|
|
|
|
[ 0,-1] , [ 0, 1], |
|
|
|
|
[ 1,-1], [ 1, 0], [ 1, 1]] |
|
|
|
|
|
|
|
|
|
bog_current = None; |
|
|
|
|
bog_current = None |
|
|
|
|
answers = {} |
|
|
|
|
|
|
|
|
|
def timesup(a): |
|
|
|
|
brathuhn.sendMsg(brathuhn.ROOM,"Time's up!",'groupchat') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def boggle(msg,args): |
|
|
|
|
if len(args)==1: |
|
|
|
|
global bog_current |
|
|
|
|
mymsg = "" |
|
|
|
|
random.shuffle(DICE) |
|
|
|
|
i = 0 |
|
|
|
|
|
|
|
|
|
bog_current = []; |
|
|
|
|
j = -1; |
|
|
|
|
for d in DICE: |
|
|
|
|
if i % 5 == 0: |
|
|
|
|
bog_current.append([]) |
|
|
|
|
j = j+1 |
|
|
|
|
mymsg += "\n" |
|
|
|
|
i+=1 |
|
|
|
|
c = d[random.randint(0,5)] |
|
|
|
|
bog_current[j].append(c); |
|
|
|
|
mymsg += "%3s" % ( c ) |
|
|
|
|
brathuhn.sendMonoMsg(brathuhn.ROOM,mymsg,'groupchat') |
|
|
|
|
brathuhn.sendMsg(brathuhn.ROOM,"you have 3 minutes",'groupchat') |
|
|
|
|
brathuhn.callAt(timesup, time.time()+60*3, [1]) |
|
|
|
|
if len(args)==2 and args[1]=="start": |
|
|
|
|
boggle_start(msg,args) |
|
|
|
|
elif len(args)==2 and args[1]=="count": |
|
|
|
|
boggle_count(msg,args) |
|
|
|
|
else: |
|
|
|
|
brathuhn.sendMsg(brathuhn.ROOM,"Usage: !boggle",'groupchat') |
|
|
|
|
brathuhn.addCommand("boggle","Play Boggle! Usage: !boggle",boggle) |
|
|
|
|
brathuhn.sendMsg(brathuhn.ROOM,"Usage: !boggle start|count",'groupchat') |
|
|
|
|
|
|
|
|
|
def boggle_start(msg,args): |
|
|
|
|
global bog_current |
|
|
|
|
global answers |
|
|
|
|
answers = {} |
|
|
|
|
mymsg = "" |
|
|
|
|
random.shuffle(DICE) |
|
|
|
|
i = 0 |
|
|
|
|
|
|
|
|
|
bog_current = []; |
|
|
|
|
j = -1; |
|
|
|
|
for d in DICE: |
|
|
|
|
if i % 5 == 0: |
|
|
|
|
bog_current.append([]) |
|
|
|
|
j = j+1 |
|
|
|
|
mymsg += "\n" |
|
|
|
|
i+=1 |
|
|
|
|
c = d[random.randint(0,5)] |
|
|
|
|
bog_current[j].append(c); |
|
|
|
|
mymsg += "%3s" % ( c ) |
|
|
|
|
brathuhn.sendMonoMsg(brathuhn.ROOM,mymsg,'groupchat') |
|
|
|
|
brathuhn.sendMsg(brathuhn.ROOM,"you have 3 minutes",'groupchat') |
|
|
|
|
brathuhn.callAt(timesup, time.time()+60*3, [1]) |
|
|
|
|
|
|
|
|
|
def boggle_count(msg,args): |
|
|
|
|
global answers |
|
|
|
|
# remove double words |
|
|
|
|
removed = {} |
|
|
|
|
for k in answers: |
|
|
|
|
if k not in removed: |
|
|
|
|
removed[k] = [] |
|
|
|
|
ans = answers[k] |
|
|
|
|
|
|
|
|
|
for word in ans: |
|
|
|
|
for k_others in answers: |
|
|
|
|
if k_others==k: |
|
|
|
|
continue |
|
|
|
|
ans_o = answers[k_others] |
|
|
|
|
if word in ans_o: |
|
|
|
|
if not word in removed[k]: |
|
|
|
|
removed[k].append(word) |
|
|
|
|
if k_others in removed: |
|
|
|
|
removed[k_others].append(word), k_others |
|
|
|
|
else: |
|
|
|
|
removed[k_others] = [word] |
|
|
|
|
ans_o.remove(word) |
|
|
|
|
for word in removed[k]: |
|
|
|
|
if word in ans: |
|
|
|
|
ans.remove(word) |
|
|
|
|
# count the points |
|
|
|
|
for k in answers: |
|
|
|
|
ans = answers[k] |
|
|
|
|
valid = bog_verify(ans, bog_current) |
|
|
|
|
invalid = list(set(ans)-set(valid)) |
|
|
|
|
|
|
|
|
|
count = count_points(valid) |
|
|
|
|
user = k |
|
|
|
|
strinv = "" |
|
|
|
|
strval = "" |
|
|
|
|
strdoub = "" |
|
|
|
|
if len(invalid) != 0: |
|
|
|
|
strinv = "; invalid: {0}".format(invalid) |
|
|
|
|
if len(valid) != 0: |
|
|
|
|
strval = "; valid: {0}".format(valid) |
|
|
|
|
if len(removed[k]) != 0: |
|
|
|
|
strdoub = "; doubles: {0}".format(removed[k]) |
|
|
|
|
brathuhn.sendMsg(brathuhn.ROOM,"{0}: {1} pts{2}{3}{4}".format(user, count, strinv,strval,strdoub),'groupchat') |
|
|
|
|
# reset answers |
|
|
|
|
answers = {} |
|
|
|
|
|
|
|
|
|
brathuhn.addCommand("boggle","Play Boggle! Usage: !boggle start|count",boggle) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def bog_ans(msg, args): |
|
|
|
|
global answers |
|
|
|
|
answer = [w.strip().upper() for w in args[1:]] |
|
|
|
|
|
|
|
|
|
valid = bog_verify(answer, bog_current) |
|
|
|
|
invalid = list(set(answer)-set(valid)) |
|
|
|
|
|
|
|
|
|
count = bog_count(valid) |
|
|
|
|
user = msg.getFrom().getResource() |
|
|
|
|
strinv = "" |
|
|
|
|
if len(invalid) != 0: |
|
|
|
|
strinv = "; invalid: {0}".format(invalid) |
|
|
|
|
brathuhn.sendMsg(brathuhn.ROOM,"{0}: {1} pts{2}".format(user, count, strinv),'groupchat') |
|
|
|
|
answers[user]=answer |
|
|
|
|
brathuhn.sendMsg(brathuhn.ROOM, user+": ACK!",'groupchat') |
|
|
|
|
|
|
|
|
|
brathuhn.addCommand("ba","=boggle answer; Usage: !ba ans1 ans2 ...",bog_ans) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -150,7 +201,7 @@ def check_valid(m, bog, path): |
|
|
|
|
|
|
|
|
|
return False |
|
|
|
|
|
|
|
|
|
def bog_count(words): |
|
|
|
|
def count_points(words): |
|
|
|
|
count = 0; |
|
|
|
|
|
|
|
|
|
for w in words: |
|
|
|
|
|