You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
158 lines
3.5 KiB
158 lines
3.5 KiB
import random, time, brathuhn
|
|
DICE = [['A','A','A','F','R', 'S']]
|
|
DICE.append(['A','A','E','E','E','E'])
|
|
DICE.append(['A','A','F','I','R','S'])
|
|
DICE.append(['A','D','E','N','N','N'])
|
|
DICE.append(['A','E','E','E','E','M'])
|
|
|
|
DICE.append(['A','E','E','G','M','U'])
|
|
DICE.append(['A','E','G','M','N','N'])
|
|
DICE.append(['A','F','I','R','S','Y'])
|
|
DICE.append(['B','J','K','Qu','X','Z'])
|
|
DICE.append(['C','C','E','N','S','T'])
|
|
|
|
DICE.append(['C','E','I','I','L','T'])
|
|
DICE.append(['C','E','I','P','S','T'])
|
|
DICE.append(['C','E','I','L','P','T'])
|
|
DICE.append(['D','D','H','N','O','T'])
|
|
DICE.append(['D','H','H','L','O','R'])
|
|
|
|
DICE.append(['D','H','L','N','O','R'])
|
|
DICE.append(['D','H','L','N','O','R'])
|
|
DICE.append(['E','I','I','I','T','T'])
|
|
DICE.append(['E','M','O','T','T','T'])
|
|
DICE.append(['E','N','S','S','S','U'])
|
|
|
|
DICE.append(['F','I','P','R','S','Y'])
|
|
DICE.append(['G','O','R','R','V','W'])
|
|
DICE.append(['I','P','R','R','R','Y'])
|
|
DICE.append(['N','O','O','T','U','W'])
|
|
DICE.append(['O','O','O','T','T','U'])
|
|
|
|
bog_kern = [[-1,-1], [-1, 0], [-1, 1],
|
|
[ 0,-1] , [ 0, 1],
|
|
[ 1,-1], [ 1, 0], [ 1,-1]]
|
|
|
|
bog_current = "asdf";
|
|
|
|
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])
|
|
else:
|
|
brathuhn.sendMsg(brathuhn.ROOM,"Usage: !boggle",'groupchat')
|
|
brathuhn.addCommand("boggle","Usage: !boggle",boggle)
|
|
|
|
|
|
|
|
|
|
def bog_ans(msg, args):
|
|
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')
|
|
brathuhn.addCommand("bog_ans","Usage: !bog_ans ans1 ans2 ...",bog_ans)
|
|
|
|
|
|
def bog_verify(msgs, bog):
|
|
|
|
ret = [];
|
|
|
|
# TODO migrate to creation of bog_current
|
|
bog_pad = [[""]*7]
|
|
for i in range(5):
|
|
t = [""];
|
|
t.extend(bog[i])
|
|
t.append("")
|
|
bog_pad.append(t)
|
|
bog_pad.append([""]*7)
|
|
|
|
|
|
for m in msgs:
|
|
|
|
# loop through bog, if first letter == m[0] then checkmachine
|
|
pos_r = pos_l = -1;
|
|
|
|
for r in bog:
|
|
pos_r += 1
|
|
pos_l = -1
|
|
for l in r:
|
|
pos_l += 1
|
|
if bog[pos_r][pos_l] == m[0]:
|
|
|
|
|
|
r = check_valid(m[1:], bog_pad, [[pos_r+1,pos_l+1]]);
|
|
if(r == 1):
|
|
ret.append(m)
|
|
return list(set(ret))
|
|
|
|
|
|
def check_valid(m, bog, path):
|
|
|
|
# check path, no letters must be used twice
|
|
# pass path along, always use last position in path as
|
|
# pos, but check if new match exists in pos
|
|
c = m[0]
|
|
pos = path[-1:][0]
|
|
r = 0
|
|
for k in bog_kern:
|
|
if (bog[pos[0]+k[0]][pos[1]+k[1]] == c) and ([pos[0]+k[0],pos[1]+k[1]] not in path):
|
|
|
|
if(len(m) == 1):
|
|
r = 1
|
|
else:
|
|
cpath = path
|
|
cpath.append([pos[0]+k[0],pos[1]+k[1]])
|
|
r = check_valid(m[1:], bog, cpath)
|
|
if r == 1:
|
|
break
|
|
return r
|
|
|
|
def bog_count(words):
|
|
count = 0;
|
|
|
|
for w in words:
|
|
l = len(w)
|
|
if l < 3:
|
|
continue;
|
|
elif l < 5:
|
|
count += 1
|
|
elif l < 6:
|
|
count += 2
|
|
elif l < 7:
|
|
count += 3
|
|
elif l < 8:
|
|
count += 5
|
|
elif l >= 8:
|
|
count += 11
|
|
|
|
return count |