def __init__(self, filename): self.filename = filename self.make_window() self.map = Map() self.map.load(self.filename) self.aa = True self.markings = True
def test_robot_does_not_moves_out_of_bounds_if_there_is_a_scent_at_its_location( ): map = Map(10, 10) map.add_scent(10, 10) robot = Robot(10, 10, 'N', map) robot.perform_instruction('F') assert robot.x == 10 assert robot.y == 10 assert not robot.is_lost
def propagate_method(self): self.state_label.configure(text="Generating Map") self.master.update() # Récupération des données sélectionnées self.data = { "width": int(self.im_width.get()), "height": int(self.im_height.get()), "seed_number": int(self.seed_number.get()), "blur": int(self.blur.get()), "generation_seed": int(self.generation_seed.get()) } seed(self.data["generation_seed"]) map_propagate_method = Map(self.data) # Envoi des données self.map = map_propagate_method.start() # Création de la carte self.state_label.configure(text="New Map Generated") self.var.set(randint(0, 1000)) # Génère une nouvelle seed aléatoire
def get_map_info(row): link = row.xpath('./a') if len(link) > 0: href = link[0].xpath('./@href')[0] return Map( name=sanitize(link[0].text_content()), link=href, region='null' ).dict()
def main(): running = True map_list = load_maps() maps = [Map(*read_grid(level)) for level in map_list] while running: # os.system('cls') print('Debugging Console') print('==================') print('1) View maps') command = input('> ') command_handler(command)
def setUp(self): self.map_1 = Map([[0, 1]]) self.v_1 = [[1, 0]] # The second map self.map_2 = Map([[1, 0, 1], [0, 0, 1]]) self.v_2 = [[1, 1, 0], [0, 0, 0]] # The third map self.map_3 = Map([[1, 0, 1, 1], [1, 0, 1, 1], [0, 0, 0, 1], [1, 0, 1, 0]]) self.v_3 = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
class Gui(object): def __init__(self, filename): self.filename = filename self.make_window() self.map = Map() self.map.load(self.filename) self.aa = True self.markings = True def make_window(self): self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window.set_title("Series Of Tubes") # create all the basic widgets. self.vbox = gtk.VBox() self.menubar = gtk.MenuBar() self.create_map_menu() self.renderer = Renderer(self) self.vbox.pack_start(self.menubar, expand=False) self.vbox.pack_start(self.renderer, expand=True) # exit the app on window close self.window.connect("delete_event", self.quit) self.window.add(self.vbox) self.window.show_all() def create_map_menu(self): "Makes the 'map' menu." menu = gtk.Menu() main_item = gtk.MenuItem("Map") self.aa_item = gtk.MenuItem("Antialiasing Off") self.aa_item.connect("activate", self.aa_toggle) menu.append(self.aa_item) self.markings_item = gtk.MenuItem("Markings Off") self.markings_item.connect("activate", self.markings_toggle) menu.append(self.markings_item) save_item = gtk.MenuItem("Reload") save_item.connect("activate", self.reload) menu.append(save_item) save_item = gtk.MenuItem("Save") save_item.connect("activate", self.save) menu.append(save_item) quit_item = gtk.MenuItem("Quit") quit_item.connect("activate", self.quit) menu.append(quit_item) main_item.set_submenu(menu) self.menubar.append(main_item) def aa_toggle(self, *args): "Callback to turn antialiasing on and off." self.aa = not self.aa if self.aa: self.aa_item.get_child().set_text("Antialiasing Off") else: self.aa_item.get_child().set_text("Antialiasing On") self.renderer.queue_draw() def markings_toggle(self, *args): "Callback to turn markings on and off." self.markings = not self.markings if self.markings: self.markings_item.get_child().set_text("Markings Off") else: self.markings_item.get_child().set_text("Markings On") self.renderer.queue_draw() def reload(self, *args, **kwds): self.map.load(self.filename) self.renderer.queue_draw() def save(self, *args, **kwds): self.map.save_offsets(self.filename) def quit(self, *args, **kwds): "Exit the app when the main window is closed." gtk.main_quit() return False def main(self): gtk.main()
def default_map(): return Map(10, 10)
class DFSTest(unittest.TestCase): def setUp(self): self.map_1 = Map([[0, 1]]) self.v_1 = [[1, 0]] # The second map self.map_2 = Map([[1, 0, 1], [0, 0, 1]]) self.v_2 = [[1, 1, 0], [0, 0, 0]] # The third map self.map_3 = Map([[1, 0, 1, 1], [1, 0, 1, 1], [0, 0, 0, 1], [1, 0, 1, 0]]) self.v_3 = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]] def tearDown(self): self.v_2 = [[1, 1, 0], [0, 0, 0]] self.v_3 = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]] def test_map(self): # Check if the map sizes are calculated correctly self.assertEqual(self.map_1.X, 2) self.assertEqual(self.map_1.Y, 1) self.assertEqual(self.map_2.X, 3) def test_validity(self): # Check if the cell lies outside the map self.assertFalse(self.map_1.is_valid(x=2, y=0, visited=self.v_1)) self.assertFalse(self.map_2.is_valid(1, 2, self.v_2)) # Check if the cell has been visited self.assertFalse(self.map_1.is_valid(0, 0, self.v_1)) self.assertFalse(self.map_2.is_valid(0, 0, self.v_2)) # Check if the cell lies on water self.assertFalse(self.map_2.is_valid(1, 1, self.v_2)) # Check if the cell is a part of an island and has not yet been visited self.assertTrue(self.map_1.is_valid(1, 0, self.v_1)) self.assertTrue(self.map_2.is_valid(2, 1, self.v_2)) def test_dfs(self): # Check if the DFS correctly marks the visited cells self.map_2.dfs(2, 0, self.v_2) self.assertEqual(self.v_2, [[1, 1, 1], [0, 0, 1]]) self.map_3.dfs(3, 0, self.v_3) self.assertEqual( self.v_3, [[0, 0, 1, 1], [0, 0, 1, 1], [0, 0, 0, 1], [0, 0, 1, 0]]) def test_island_count(self): self.assertEqual(self.map_1.count_islands(), 1) self.assertEqual(self.map_2.count_islands(), 2) self.assertEqual(self.map_3.count_islands(), 3)