Exemplo n.º 1
0
    def test_inner_walls(self):
        # Create maze
        n_rows = 4
        n_cols = 7
        start = '2,0w'
        end = '0,3n'
        walls = ['2,3w', '2,4w', '2,5w']
        maze = Maze(n_rows, n_cols, start, end, walls)
        maze._apply_valid_move_constraint()  # Apply constraint to populate csp variables

        # Check to see that walls appear as variables in maze.csp
        for wall in walls:
            self.assertTrue(wall in maze.csp.variables)

        # Fix wall values
        maze._set_inner_walls()

        # Check to see that walls are fixed; they would no longer appear as variables
        for wall in walls:
            self.assertFalse(wall in maze.csp.variables)

        # Verify that walls are fixed to 0
        # circle_solution surrounds the inner walls, if walls are fixed to 1, solution will fail valid_move_constraint.
        # Since start and end locations have not been fixed, a circle is valid path
        circle_solution = {'2,2n': 1, '3,2n': 1, '3,3w': 1, '3,4w': 1, '3,5w': 1, '3,5n': 1, '2,5n': 1, '1,5w': 1,
                           '1,4w': 1, '1,3w': 1}
        fill_with_zeros(circle_solution, n_rows, n_cols)  # No ignore_list because we didn't fix start and end
        self.assertTrue(maze.csp.check(circle_solution))