コード例 #1
0
    def test_ctor(self):
        """Make sure that the constructor values are getting properly set."""
        manager = MazeManager()

        self.assertEqual(manager.get_maze_count(), 0)
        self.assertEqual(manager.get_mazes(), [])
        self.assertEqual(manager.quiet_mode, False)
コード例 #2
0
    def test_check_matching_id(self):
        """Check that check_matching_id is functioning properly"""

        manager = MazeManager()
        manager.add_maze(8, 8, 1)
        manager.add_maze(8, 8, 1)
        result = [manager.check_matching_id(1)]
        self.assertEqual(len(result), 1)
コード例 #3
0
    def test_get_maze(self):
        """Test the get_maze function"""
        manager = MazeManager()

        self.assertEqual(manager.get_maze(0), None)
        self.assertEqual(manager.get_mazes(), [])
        maze1 = manager.add_maze(6, 6)
        self.assertEqual(maze1.id, 0)
コード例 #4
0
    def test_add_new(self):
        """Test adding mazes by passing maze specs into add_maze"""
        manager = MazeManager()

        maze1 = manager.add_maze(6, 6)
        self.assertEqual(maze1.id, 0)
        self.assertEqual(manager.get_mazes().__len__(), 1)
        self.assertEqual(manager.get_maze_count(), 1)

        maze2 = manager.add_maze(3, 3, 1)
        self.assertEqual(maze2.id, 1)
        self.assertEqual(manager.get_mazes().__len__(), 2)
        self.assertEqual(manager.get_maze_count(), 2)
コード例 #5
0
    def test_get_mazes(self):
        """Tests that get_mazes is returning all mazes"""
        manager = MazeManager()

        self.assertEqual(manager.get_maze(0), None)
        self.assertEqual(manager.get_mazes(), [])
        manager.add_maze(6, 6)
        manager.add_maze(6, 6)
        mazes = manager.get_mazes()
        self.assertAlmostEqual(mazes.__len__(), 2)
コード例 #6
0
    def test_get_maze_count(self):
        """Tests the get_maze_number function"""
        manager = MazeManager()

        self.assertEqual(manager.get_maze_count(), 0)
        maze1 = Maze(2, 2)
        manager.add_existing_maze(maze1)
        self.assertEqual(manager.get_maze_count(), 1)
コード例 #7
0
 def test_set_quiet_mode(self):
     manager = MazeManager()
     self.assertEqual(manager.quiet_mode, False)
     manager.set_quiet_mode(True)
     self.assertEqual(manager.quiet_mode, True)
コード例 #8
0
 def test_set_filename(self):
     """Tests that the filename is getting set"""
     manager = MazeManager()
     filename = "myFile"
     manager.set_filename(filename)
     self.assertEqual(filename, manager.media_name)
コード例 #9
0
    def test_add_existing(self):
        """Test adding mazes by passing already existing Maze objects in"""
        manager = MazeManager()

        maze1 = Maze(2, 2)
        self.assertEqual(maze1.id, 0)
        manager.add_existing_maze(maze1)

        self.assertEqual(manager.get_mazes().__len__(), 1)
        self.assertEqual(manager.get_maze_count(), 1)
        self.assertIsNotNone(manager.get_maze(maze1.id))
        self.assertEqual(manager.get_maze(maze1.id).id, maze1.id)

        maze2 = Maze(3, 3, 1)
        self.assertEqual(maze2.id, 1)
        manager.add_existing_maze(maze2)

        self.assertEqual(manager.get_mazes().__len__(), 2)
        self.assertEqual(manager.get_maze_count(), 2)
        self.assertIsNotNone(manager.get_maze(maze2.id))
        self.assertEqual(manager.get_maze(maze2.id).id, maze2.id)
コード例 #10
0
from __future__ import absolute_import
from src.maze_manager import MazeManager

if __name__ == "__main__":

    # Create the manager
    manager = MazeManager()

    # Add a 10x10 maze to the manager
    maze = manager.add_maze(10, 10)

    # Solve the maze using the Bi Directional algorithm
    manager.solve_maze(maze.id, "BiDirectional", "fancy")

    # Display the maze
    manager.show_maze(maze.id)

    # Show how the maze was generated
    manager.show_generation_animation(maze.id)

    # Show how the maze was solved
    manager.show_solution_animation(maze.id)

    # Display the maze with the solution overlaid
    manager.show_solution(maze.id)
コード例 #11
0
from __future__ import absolute_import
from src.maze_manager import MazeManager

if __name__ == "__main__":

    # Create the manager
    manager = MazeManager()

    # Add a 10x10 maze to the manager
    maze = manager.add_maze(10, 10)

    # Solve the maze using the Breadth First algorithm
    manager.solve_maze(maze.id, "DepthFirstBacktracker")

    # Display the maze
    manager.show_maze(maze.id)

    # Show how the maze was generated
    manager.show_generation_animation(maze.id)

    # Show how the maze was solved
    manager.show_solution_animation(maze.id)

    # Display the maze with the solution overlaid
    manager.show_solution(maze.id)
コード例 #12
0
from __future__ import absolute_import
from src.maze_manager import MazeManager
from src.maze import Maze


if __name__ == "__main__":

    # create a maze manager to handle all operations
    manager = MazeManager()

    # now create a maze using the binary tree method
    maze_using_btree = Maze(10, 10, algorithm="bin_tree")

    # add this maze to the maze manager
    maze_using_btree = manager.add_existing_maze(maze_using_btree)

    # show the maze
    manager.show_maze(maze_using_btree.id)

    # show how the maze was generated
    manager.show_generation_animation(maze_using_btree.id)
コード例 #13
0
from __future__ import absolute_import
from src.maze_manager import MazeManager
from src.maze import Maze


if __name__ == "__main__":

    # The easiest way to use the library is through the Manager class. It acts as the glue between
    # The visualization, solver, and maze classes. Mazes inside the manager have unique ids that we use
    # to specify particular mazes.
    manager = MazeManager()

    # We can add mazes to the manager two different ways.
    # The first way, we specify the maze dimensions. The maze that is created gets returned back to you.
    maze = manager.add_maze(10, 10)

    # The second way is by creating a maze, and then adding it to the manager. Doing this will require you to add
    # from src.maze import Maze
    # to your imports. Because the ids need to be unique, the manager will ensure this happens. It may change the
    # id of the maze that was passed in, so we assign it to the return value to make sure we're using the updated maze.
    maze2 = Maze(10, 10)
    maze2 = manager.add_existing_maze(maze2)

    # by default when creating a maze, depth first search is used.
    # to generate maze using binary tree method,
    maze_binTree = Maze(10, 10, algorithm = "bin_tree")
    maze_binTree = manager.add_existing_maze(maze_binTree)

    # We can disable showing any output from the solver by entering quiet mode
    # manager.set_quiet_mode(True)
コード例 #14
0
from __future__ import absolute_import
from src.maze_manager import MazeManager

if __name__ == "__main__":

    # Create the manager
    manager = MazeManager()

    # Add a 10x10 maze to the manager
    maze = manager.add_maze(10, 10)

    # Solve the maze using the Depth First Backtracker algorithm
    manager.solve_maze(maze.id, "BreadthFirst")

    # Display the maze
    manager.show_maze(maze.id)

    # Show how the maze was generated
    manager.show_generation_animation(maze.id)

    # Show how the maze was solved
    manager.show_solution_animation(maze.id)

    # Display the maze with the solution overlaid
    manager.show_solution(maze.id)