def test_complete(self): s1 = Section(None) sections = [s1] s2 = Section(None) sections2 = [s2] t = territory.Territory(sections) t2 = territory.Territory(sections2) t.combine(s1, t2, s2) self.assertEqual(t.is_complete(), True) self.assertEqual(len(t.sections_open), 2)
def __init__(self, name, filename): self.name = name with open(filename) as csvfile: readCSV = csv.reader(csvfile, delimiter=',') next(readCSV) i = 0 for row in readCSV: name, subtype, adjacent, owner = row[0], row[1], row[2], row[3] supplyCentre = True if row[4] == 'y' else False self.territories.append( t.Territory(name, subtype, adjacent, owner, supplyCentre)) i += 1 if i == 3: break for territory in self.territories: print(territory)
def init(game_size): max_cols, max_rows = game_size[0], game_size[1] tmp_list = [2] + [3] * 2 + [4] * 2 + [5] * 2 + [6] * 2 + [7] * 2 + [ 8 ] * 2 + [9] * 2 + [10] * 2 + [11] * 2 + [12] tmp_list = tmp_list * 3 token_numbers.extend(tmp_list) # 生成Grids - 最外圈为地图边界 for x in range(max_cols + 2): grids.append([]) # 边界地块也要生成出来 for y in range(max_rows + 2): random_resource = 0 tmp_token_number = -1 if x != 0 and x != max_cols + 1 and y != 0 and y != max_rows + 1: random_resource = random.randint(1, 4) random_index = random.randint(0, len(token_numbers) - 1) tmp_token_number = token_numbers.pop(random_index) grids[x].append( territory.Territory(x, y, random_resource, tmp_token_number)) # 生成 Corners for x in range(max_cols): for y in range(max_rows): self_grid = get_grid([x + 1, y + 1]) adj_index = map_.get_territories_index_of_adjacents(x + 1, y + 1) adjcents = [get_grid(element) for element in adj_index] try_add_to_list(city.City([adjcents[0], adjcents[1], self_grid])) try_add_to_list(city.City([adjcents[1], adjcents[2], self_grid])) try_add_to_list(city.City([adjcents[2], adjcents[3], self_grid])) try_add_to_list(city.City([adjcents[3], adjcents[4], self_grid])) try_add_to_list(city.City([adjcents[4], adjcents[5], self_grid])) try_add_to_list(city.City([adjcents[5], adjcents[0], self_grid])) # 生成 Player players.append(player.Player()) return True
def main(): territory.Territory.import_csv("malopolska.csv") new_territory = territory.Territory() new_territory.create_objects() while True: ui.handle_menu("main") options = ui.get_inputs([""], "Your choice") if options[0] == "1": ui.print_table([new_territory.count_entities()], [ "Województwo", "Powiaty", "Gminy miejskie", "Gminy wiejskie", "Gminy miejsko-wiejskie", "Obszary wiejskie", "Miasta", "Miasta na prawach powiatu", "Delegatury" ], "Statistics", False) elif options[0] == "2": ui.print_table([new_territory.cities_with_longest_names()], ["First city", "Second city", "Third city"], "3 cities with longest names") elif options[0] == "3": ui.print_table( [[new_territory.counties_with_largest_communities()]], ["County's name"], "County with the largest number of communities") elif options[0] == "4": ui.print_table(new_territory.locations_with_several_categories(), ["Locations name", "Number of categories"], "Locations, that belong to more than one category") elif options[0] == "5": options = ui.get_inputs(["Type search string: "], "Advanced search") output = new_territory.advanced_search(options[0]) if not output: ui.print_error_message("No matches found.") continue ui.print_table(output, ["Name", "Type"], "Matches found:") elif options[0] == "0": break else: ui.print_error_message("No such option available.")
def test_init(self): sections = [Section(None), Section(None), Section(None)] t = territory.Territory(sections) self.assertEqual(t.is_complete(), False) self.assertEqual(len(t.sections_open), 3)