예제 #1
0
    def __init__(self,
                 token,
                 working_dir,
                 rating=None,
                 start_command=['./start.sh', '-p', '{port}'],
                 output_dir='./output/',
                 stdout='./{timestamp}-stdout.txt',
                 stderr='./{timestamp}-stderr.txt',
                 message_file='./current_rating.txt',
                 rating_message="Your current rating is: {rating}",
                 rank_message="You are ranked {rank} out of {total}",
                 process_owner=None):
        self.token = token
        self.working_dir = working_dir
        if rating is not None:
            self.rating = elo.RATING_CLASS(rating)
        else:
            self.init_rating()
        self.start_command = start_command
        self.output_dir = path_rel_to_dir(output_dir, self.working_dir)
        self.stdout = path_rel_to_dir(stdout, self.output_dir)
        self.stderr = path_rel_to_dir(stderr, self.output_dir)
        self.message_file = path_rel_to_dir(message_file, self.output_dir)
        self.rating_message = rating_message
        self.rank_message = rank_message
        self.process_owner = process_owner \
            if process_owner is not None \
            else self.token

        if not os.path.exists(self.output_dir):
            os.mkdir(self.output_dir)
예제 #2
0
 def clean_line(iterable):
     li = list(iterable)
     if len(li) != 1 and len(li) != 2:
         raise ValueError(
             "A ratings file should only contain lines with one or two "
             "values, got {}".format(li))
     if len(li) == 2:
         try:
             li[1] = elo.RATING_CLASS(li[1])
         except ValueError as error:
             raise ValueError(
                 "The second value of a rating line should be "
                 "interpretable as {}. I received the following error "
                 "while casting:\n\t{}".format(elo.RATING_CLASS.__name__,
                                               error))
     return li
예제 #3
0
 def set_ratings(self, iterable):
     tokens = set()
     for line in iterable:
         token = line[0]
         if token in tokens:
             raise ValueError(
                 "A token may only be specified once. Token: {}".format(
                     token))
         tokens.add(token)
         if len(line) > 2:
             raise ValueError(
                 "No extra information next to a token and the desired "
                 "rating should be specified: {}".format(line))
         if len(line) == 2:
             if token in self.player_map:
                 self.player_map[token].rating = elo.RATING_CLASS(line[1])
             elif not self.ignore_unknown_players:
                 raise ValueError(
                     "Rating specified for unknown player: {}".format(
                         token))
예제 #4
0
    def __init__(self, token, working_dir, rating=None,
                 start_command=['./start.sh', '-p', '3001'],
                 output_dir='./output/',
                 stdout='./{timestamp}-stdout.txt',
                 stderr='./{timestamp}-stderr.txt',
                 process_owner=None):
        self.token = token
        self.working_dir = working_dir
        self.start_command = start_command
        self.stdout = stdout
        self.stderr = stderr
        self.process_owner = process_owner \
            if process_owner is not None \
            else self.token

        self.output_dir = output_dir if os.path.isabs(output_dir) \
            else os.path.join(self.working_dir, output_dir)
        if not os.path.exists(self.output_dir):
            os.mkdir(self.output_dir)
        if rating is not None:
            self.rating = elo.RATING_CLASS(rating)
        else:
            self.init_rating()
예제 #5
0
 def init_rating(self):
     self.rating = elo.RATING_CLASS(elo.INITIAL)