Пример #1
0
    def add_option(self, section, name, option_type, default, alt_names,
                   *help):
        #print '    %s.%s = %s' % (section, name, default)
        if any(opts.has_key(name) for opts in self.modules.values()):
            print '# Warning: Duplicate definition for option', name
        self.__super.add_option(section, name, option_type, default, alt_names,
                                *help)

        if isinstance(alt_names, str) and len(alt_names) > 1:
            main_name = alt_names
        else:
            main_name = name

        type_name = option_type.__name__
        default_value = self.value_string(name, default)
        text = [
            '# %s (%s)' % (main_name, self.names.get(type_name, type_name))
        ]
        text.extend('# ' + line for line in help)
        text.append(';%s = %s' % (name, default_value))

        current_value = self.value_string(name, getattr(self, name))
        if current_value != default_value:
            text.append('%s = %s' % (name, current_value))
        self.modules[section][name] = text
Пример #2
0
 def convoy_note(convoyed, destination, routes, route_valid=bool):
     result = FAR
     if not (convoyed.exists() and convoyed.can_be_convoyed()): result = NSA
     elif not destination.exists(): result = CST
     elif destination.province.is_coastal():
         if any(route_valid(route) for route in routes): result = MBV
     #print 'convoy_note(%s, %s) => %s' % (convoyed, destination, result)
     return result
Пример #3
0
 def can_move_to(self, place):
     #print '\tQuery: %s -> %s' % (self, place)
     if isinstance(place, Coast):
         # Check whether it can move to any coastline
         return any(place.matches(prov) for prov in self.coast.borders_out)
     else:
         # Assume a Province or province token
         return place.key in [key[1] for key in self.coast.borders_out]
     return False
Пример #4
0
 def distance(self, coast, provs):
     ''' Returns the coast's distance from the nearest of the provinces,
         particularly for use in determining civil disorder retreats.
     '''#'''
     # Todo: Count army and fleet movements differently?
     result = 0
     rank = seen = [coast.province.key]
     while rank:
         if any(place in provs for place in rank): return result
         new_rank = []
         for here in rank:
             new_rank.extend([
                 key for key in self.spaces[here].borders_out
                 if key not in seen and key not in new_rank
             ])
         seen.extend(new_rank)
         rank = new_rank
         result += 1
     # Inaccessible island
     return Infinity
Пример #5
0
    def tokens(self):
        cats = defaultdict(list)
        for prov in sorted(self.borders):
            # Inland_non-SC = 0x50
            # Inland_SC = 0x51
            # Sea_non-SC = 0x52
            # Sea_SC = 0x53
            # Coastal_non-SC = 0x54
            # Coastal_SC = 0x55
            # Bicoastal_non-SC = 0x56
            # Bicoastal_SC = 0x57
            num = 0x5000
            keys = list(self.borders[prov])
            if len(keys) > 2:
                # Yes, we should probably look for coastline specs,
                # but this works for anything in the current variants.
                num += 0x0600
            elif AMY not in keys:
                num += 0x0200
            elif FLT in keys:
                num += 0x0400

            if any(prov in self.homes[power] for power in self.homes):
                num += 0x0100
            cats[num].append(prov)

        numbers = {}
        index = count()
        for cat in sorted(cats):
            for prov in cats[cat]:
                numbers[cat + index.next()] = prov

        for index, power in enumerate(sorted(self.homes)):
            if power != "UNO":
                numbers[0x4100 + index] = power

        return Representation(numbers, protocol.default_rep)
Пример #6
0
#----------------------------------
dict_en_es = {}
dict_es_en = {}
filenames_EN_ES = ["translator-files/en-es-en-Dic/src/main/resources/dic/verbs/en-es.xml",
                   "translator-files/en-es-en-Dic/src/main/resources/dic/en-es.xml"]
filenames_ES_EN = ["translator-files/en-es-en-Dic/src/main/resources/dic/verbs/es-en.xml",
                   "translator-files/en-es-en-Dic/src/main/resources/dic/es-en.xml"]

for filename in filenames_EN_ES:
    f.get_word_and_definition(filename, dict_en_es)
for filename in filenames_ES_EN:
    f.get_word_and_definition(filename, dict_es_en)

#compare two dict and add those missing to source
perhaps_extra = {}
f.any("en-es-top-92-verbs.txt", perhaps_extra)
f.compare_dict(dict_en_es, perhaps_extra)

perhaps_extra = {}
f.any("en-es-top-92-verbs.txt", perhaps_extra)
f.compare_dict(dict_es_en, perhaps_extra)
# to delete
for k, v in dict_en_es.items():
    print(k, ":", v)
#---------------------------------
# game creation TODO
#---------------------------------
# get expressions
    # could check if value is a string containing more that 2 words
    # that would mean it is a full sentence
    # could write that in a json file
Пример #7
0
 def __contains__(self, name):
     lower = name.lower()
     return any(lower == n.lower() for n in self)