def answerResponse(self, title, answer): id = self.puzzle_id_hash[deformatter.df_string(title)] dfed_answer = deformatter.df_string(answer) if (dfed_answer in self.solutions_per_puzzle[id]): return 1 elif (dfed_answer in self.partials_per_puzzle[id]): return 0 else: return -1
def getScore(self, teamname): teamname = deformatter.df_string(teamname) if teamname in self.solves_by_team: score = 0 # set funciton removes duplicates, though I think duplicate will never get added for puzzle in set(self.solves_by_team[teamname]): score += self.puzzles.getPoints(puzzle) return score else: return 0
def getFormatted(self, input, isSafe=True): if self.isTeam(input): df = deformatter.df_string(input) formatted = self.teamnames[df] normal = re.search('^[A-Z0-9\\\/\.\^\$\*\+\?\[\]\(\)\|'\ ',<>{}!@#%&_=`~ :;"]+$', formatted, re.IGNORECASE) # if the formatted team name is normal, or you don't about safety, then return formatted teamname if normal or not isSafe: return formatted else: return input else: return input
def addTeam(self, input): # is team already listed? df = deformatter.df_string(input) if (not self.isTeam(input)) and len(df) > 0: # add to team hash self.teamnames[df] = input # add on to team textfile tempfile = open(self.filename, "a+") tempfile.write("%s:%s\r\n" % (df, input)) tempfile.close() return True else: return False
def __init__(self, filename, puzzles): self.puzzles = puzzles self.filename = filename for p in puzzles.proper_title_by_puzzle: p = puzzles.proper_title_by_puzzle[p] p = deformatter.df_string(p) self.solves_by_puzzle[p] = 0 # print( self.solves_by_puzzle ) tempfile = open(filename, 'r') f = tempfile.readlines() tempfile.close() line_no = 1 puzzle_id = 1 for line in f: # print(line, end = '') temp = re.search( '([A-Z0-9]+):'\ '([A-Z0-9]+)'\ '\((-?[0-9]+(, -?[0-9]+){8})\)', line, re.IGNORECASE) if temp: # any acceptable titles should point to the same number ID # we will trust any teamname that exist in the savefile teamname = temp.group(1) puzzle = temp.group(2) time = temp.group(3).split(', ') time = tuple(map(int, time)) self.solvetime_by_team[teamname] = time result = self.addSolve(teamname, puzzle, time, False) else: print( "solves_class.property\tError on savefiles/puzzles.txt line " + str(line_no)) # print('') line_no += 1
def updateScoreboard(self, team): team = deformatter.df_string(team) # if team is in scoreboard, then delete team from scoreboard if (team in [x[2] for x in self.scoreboard]): self.scoreboard = [x for x in self.scoreboard if team not in x] # find first team with solvetime = self.solvetime_by_team[team] score = self.score_by_team[team] index = 0 ## THIS IS WHERE I STOPPED WORKING ## GETTING A LIST INDEX OUT OF RANGE ERROR while index < len(self.scoreboard) and (\ self.scoreboard[index][0] > score or \ (self.scoreboard[index][0] == score and \ self.scoreboard[index][1] < solvetime)): index += 1 self.scoreboard.insert(index, (score, solvetime, team))
def addSolve(self, teamname, puzzle, time, write_to_file=True): teamname = deformatter.df_string(teamname) puzzle = self.puzzles.getProperDeformatted(puzzle) # if not previously solved if not self.isSolved(teamname, puzzle) and self.puzzles.isPuzzle(puzzle): # if team is not on the board if (teamname not in self.solves_by_team): self.solves_by_team[teamname] = [] self.solvetime_by_team[teamname] = tuple( (0, 0, 0, 0, 0, 0, 0, 0, 0)) self.score_by_team[teamname] = 0 # print( ">>>"+teamname+"<<<" ) self.solves_by_team[teamname].append(puzzle) # print( time ) # print (time.__class__.__name__) # print( self.solvetime_by_team[teamname] ) if time > self.solvetime_by_team[teamname]: self.solvetime_by_team[teamname] = time self.score_by_team[teamname] += self.puzzles.getPoints(puzzle) self.solves_by_puzzle[puzzle] += 1 # print( "}"+teamname+"{" ) self.updateScoreboard(teamname) # add on to team textfile if write_to_file: tempfile = open(self.filename, "a+") tempfile.write("\r\n%s:%s%s" % (teamname, puzzle, str(time))) tempfile.close() # update timer # self.timer = max(self.timer, time+1) return True return False
def isTeam(self, input): df = deformatter.df_string(input) return df in self.teamnames
def getProperDeformatted(self, title): temp = self.getProperTitle(title) return deformatter.df_string(temp)
def getProperAnswer(self, title): id = self.puzzle_id_hash[deformatter.df_string(title)] return self.proper_answer_by_puzzle[id]
def getPoints(self, title): id = self.puzzle_id_hash[deformatter.df_string(title)] return self.points_per_puzzle[id]
def isPuzzle(self, title): dfed = deformatter.df_string(title) return dfed in self.puzzle_id_hash
def isSolved(self, teamname, puzzle): teamname = deformatter.df_string(teamname) puzzle = self.puzzles.getProperDeformatted(puzzle) return (teamname in self.solves_by_team) \ and (puzzle in self.solves_by_team[teamname])
import email, email.utils import imaplib import re import os import locale import time import itertools # email types subject lines team_registration = "Puzzlehunt Team Registration" answer_submission = "Puzzlehunt Answer Submission" ask_for_help = "Ask For Help" admin_command = "Admin Command" # enforce deformatting team_registration = deformatter.df_string(team_registration) answer_submission = deformatter.df_string(answer_submission) ask_for_help = deformatter.df_string(ask_for_help) admin_command = deformatter.df_string(admin_command) admin_emails = [ "*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**" ] # load save files teams = teams_class.Teams('savefiles/savefile_teams.txt') puzzles = puzzles_class.Puzzles('savefiles/savefile_puzzles.txt') solves = solves_class.Solves('savefiles/savefile_solves.txt', puzzles) emails = emails_class.Emails('savefiles/savefile_emails.txt')