Re: pathing.

new topic     » goto parent     » topic index » view thread      » older message » newer message

This is a multi-part message in MIME format.

------=_NextPart_000_00A5_01C24B23.578A86B0
	charset="iso-8859-2"

I wrote this program which solves maze:

--// maze.ex
--// example of problem:
--// 
--// sequence maze = {
--// {5,5,5,5,5,5,5,5,5,5,5,5},
--// {5,0,0,0,0,0,0,0,0,0,0,5},
--// {5,0,0,0,0,5,0,0,0,0,0,5},
--// {5,1,0,0,0,5,0,0,0,0,0,5},
--// {5,0,0,0,0,5,0,0,0,9,0,5},
--// {5,5,5,5,5,5,5,5,5,5,5,5}}
--// 
--// How do I find a path to go from the 1 to the 9,
--// avoiding all non-5 elements? 
--// (assume that there is only 1 1 and only 1 9,
--// and their locations are known 
--// in advance)





without warning

include get.e





--// @@@@@@@@@@
--// @@@@@@@@@@ Constants, variables and types.
--// @@@@@@@@@@

constant false = 0, true = 1

constant X = 1, Y = 2

constant
    TOP_RIGHT = 1,
    RIGHT = 2,
    BOTTOM_RIGHT = 3,
    BOTTOM = 4,
    BOTTOM_LEFT = 5,
    LEFT = 6,
    TOP_LEFT = 7,
    TOP = 8

constant ALL_DIRECTIONS = {
    --// TOP_RIGHT,
    RIGHT,
    --// BOTTOM_RIGHT,
    BOTTOM,
    --// BOTTOM_LEFT,
    LEFT,
    --// TOP_LEFT,
    TOP}

--// For each member in 'ALL_DIRECTIONS':
--// into which direction we need to go to get neighouring point.
constant ALL_DIRECTIONS_GOWAY = {
    { 1, -1},    --// TOP_RIGHT
    { 1,  0},    --// RIGHT
    { 1,  1},    --// BOTTOM_RIGHT
    { 0,  1},    --// BOTTOM
    {-1,  1},    --// BOTTOM_LEFT
    {-1,  0},    --// LEFT
    {-1, -1},    --// TOP_LEFT
    { 0, -1}     --// TOP
}

type DIRECTION (integer i)
    return find (i, ALL_DIRECTIONS)
end type

--// Path is sequence with points.
type PATH (sequence path)
    for i = 1 to length (path) do
        if not sequence (path [i])
        and length (path [i]) != 2
        and not integer (path [i] [1])
        and not integer (path [i] [2]) then
            return false
        end if
    end for
    return true
end type





--// @@@@@@@@@@
--// @@@@@@@@@@ Main routines of this program.
--// @@@@@@@@@@

--// Gets one neighbouring point.
--// Return sequence with these members:
--// 1. true if point exists there
--// 2. point value
--// 3. neighbour x and y, sequence
function get_neighbour (sequence maze, integer x, integer y,
    DIRECTION direction)
    integer neighbour_x, neighbour_y
    neighbour_x = x + ALL_DIRECTIONS_GOWAY [direction] [X]
    neighbour_y = y + ALL_DIRECTIONS_GOWAY [direction] [Y]
    if neighbour_x < 1
    or neighbour_x > length (maze [1])
    or neighbour_y < 1
    or neighbour_y > length (maze) then
        return {false}
    else
        return {
            true,
            maze [neighbour_y] [neighbour_x],
            {neighbour_x, neighbour_y}
            }
    end if
end function

--// Returns solved path or {} if it couldn't be found.
function solve_maze (sequence maze, integer start_x, integer start_y)
    --// Points which need to have members looked.
    --// Each member has this format:
    --// 1. point x
    --// 2. point y
    --// 3. last direction into which neighbour point
    --//    of this point was looked at,
    --//    index of this direction is saved,
    --//    where in ALL_DIRECTIONS is it.
    --// 4. Current path which led us to this point.
    sequence to_do_points
    sequence one_to_do_point
    integer cur_x, cur_y
    integer neighbour_value
    sequence neighbour_result
    DIRECTION cur_direction
    sequence neighbour_position
    integer i
    PATH cur_path
    to_do_points = {}
    cur_x = start_x
    cur_y = start_y
    cur_path = {{cur_x, cur_y}}
    --// Try to get first neighbour point of current point
    --// which has value right for path.
    i = 1
    while 1 do
        if i > length (ALL_DIRECTIONS) then
            --// We've looked all neighbouring points
            --// and none were good. Try to get next to-do path.
            if length (to_do_points) > 0 then
            --// There are some todo points.
                one_to_do_point = to_do_points [length (to_do_points)]
                cur_x = one_to_do_point [1]
                cur_y = one_to_do_point [2]
                i = one_to_do_point [3] + 1
                cur_path = one_to_do_point [4]
                --// Remove this to-do point from sequence
                --// of to-do points.
                to_do_points = to_do_points [1 ..
                    length (to_do_points) - 1]
            else
            --// no more todo points. We've examined all maze and
            --// solution was not got.
                return {}
            end if
        end if
        cur_direction = ALL_DIRECTIONS [i]
        neighbour_result = get_neighbour (maze, cur_x,
            cur_y, cur_direction)
        if neighbour_result [1] = true then
            neighbour_value = neighbour_result [2]
            if neighbour_value = 5 then
            --// This neighbour point will now become part
           --// of our path.
                neighbour_position = neighbour_result [3]
                if find (neighbour_position, cur_path) = 0 then
                --// This point is not yet part of our path. Good.
                    --// Save to-do path unless this is last direction:
                    if cur_direction != ALL_DIRECTIONS
                        [length (ALL_DIRECTIONS)] then
                    --// This is not last direction in sequence
                    --// of all directions
                    --// so for this point not all
                    --// neighbours were looked yet
                    --// and we need to save this to
                    --// to-do sequence.
                        to_do_points = append (to_do_points, 
                            {
                                cur_x,
                                cur_y,
                                i,
                                cur_path
                            })
                    end if
                    cur_x = neighbour_position [1]
                    cur_y = neighbour_position [2]
                    cur_path = append (cur_path, {cur_x, cur_y})
                    i = 0 --// will advance to 1 at end of this loop
                end if
            elsif neighbour_value = 9 then
            --// This is goal point. We've found the solution we
            --// were looking!
                neighbour_position = neighbour_result [3]
                cur_path = append (cur_path, neighbour_position)
                return cur_path 
            end if
        end if
        i += 1
    end while
    --// I don't see how can we get here.
    return {}
end function





--// @@@@@@@@@@
--// @@@@@@@@@@ Maze drawing routines.
--// @@@@@@@@@@

--// Draws maze onto console screen.
procedure draw_maze (sequence maze)
    sequence maze_line
    integer maze_point_value
    for y = 1 to length (maze) do
        maze_line = maze [y]
        for x = 1 to length (maze_line) do
            maze_point_value = maze_line [x]
            if maze_point_value = 1
            or maze_point_value = 9 then
                puts (1, sprintf ("%d", maze_point_value))
            elsif maze_point_value = 0 then
                puts (1, ' ')
            elsif maze_point_value = 5 then
                puts (1, "#")
            end if
        end for
        puts (1, "\n")
    end for
end procedure

--// Draws one path of maze onto console screen.
procedure draw_maze_path (sequence maze, PATH path)
    sequence maze_line
    integer maze_point_value
    for y = 1 to length (maze) do
        maze_line = maze [y]
        for x = 1 to length (maze_line) do
            if find ({x, y}, path) then
                maze_point_value = maze_line [x]
                if maze_point_value = 1
                or maze_point_value = 9 then
                    puts (1, sprintf ("%d", maze_point_value))
                elsif maze_point_value = 0 then
                    puts (1, ' ')
                elsif maze_point_value = 5 then
                    puts (1, "#")
                end if
            else
                puts (1, " ")
            end if
        end for
        puts (1, "\n")
    end for
end procedure




--// @@@@@@@@@@
--// @@@@@@@@@@ Test.
--// @@@@@@@@@@

constant MAZE_LIST = {
--// 1 2 3 4 5 6 7 8 9 0 1 2
    {
    {5,5,5,5,5,5,5,5,5,5,5,5}, --// 1
    {5,0,0,0,0,0,0,0,0,0,0,5}, --// 2
    {5,0,0,0,0,5,0,0,0,0,0,5}, --// 3
    {5,1,0,0,0,5,0,0,0,0,0,5}, --// 4
    {5,0,0,0,0,5,0,0,0,9,0,5}, --// 5
    {5,5,5,5,5,5,5,5,5,5,5,5}  --// 6
    },
--// 1 2 3 4 5 6 7 8 9 0 1 2
    {
    {5,5,5,5,5,5,5,5,5,5,5,5}, --// 1
    {5,0,0,0,0,0,0,0,0,0,0,5}, --// 2
    {5,0,0,0,0,5,9,0,0,0,0,5}, --// 3
    {5,1,0,0,0,5,0,0,0,0,0,5}, --// 4
    {5,0,0,0,0,5,0,0,0,0,0,5}, --// 5
    {5,5,5,5,5,5,5,5,5,5,5,5}  --// 6
    },
--// --// 1 2 3 4 5 6 7 8 9 0 1 2
    {
    {5,5,5,5,5,0,5,5,5,5,5,5}, --// 1
    {5,0,0,0,0,0,9,0,0,0,0,5}, --// 2
    {5,0,0,0,0,5,0,0,0,0,0,5}, --// 3
    {5,1,0,0,0,5,0,0,0,0,0,5}, --// 4
    {5,0,0,0,0,5,0,0,0,0,0,5}, --// 5
    {5,5,5,5,5,5,5,5,5,5,5,5}  --// 6
    },
--// 1 2 3 4 5 6 7 8 9 0 1 2
    {
    {0,0,0,0,0,0,0,0,0,0,0,0}, --// 1
    {0,0,0,0,0,0,0,0,0,0,0,0}, --// 2
    {0,0,0,0,0,0,0,0,0,0,0,0}, --// 3
    {0,1,5,5,5,5,5,0,0,0,0,0}, --// 4
    {0,0,0,0,0,0,0,0,0,0,0,0}, --// 5
    {0,0,0,0,0,0,0,0,0,0,0,0}  --// 6
    },
--// 1 2 3 4 5 6 7 8 9 0 1 2
    {
    {0,0,0,0,0,0,5,5,5,0,0,0}, --// 1
    {0,0,0,0,5,5,5,0,0,0,5,0}, --// 2
    {0,0,5,5,5,0,5,0,0,0,5,0}, --// 3
    {0,1,5,0,5,0,0,0,0,0,5,0}, --// 4
    {0,5,0,0,5,0,0,0,0,0,5,0}, --// 5
    {0,5,5,9,5,5,5,5,5,5,5,0}  --// 6
    },
--// 1 2 3 4 5 6 7 8 9 0 1 2
    {
    {0,0,0,0,0,0,0,0,0,0,0,0}, --// 1
    {0,5,5,5,0,0,0,0,0,0,0,0}, --// 2
    {0,5,0,5,0,0,0,0,0,0,0,0}, --// 3
    {0,1,0,5,0,0,0,0,0,0,0,0}, --// 4
    {0,5,5,5,0,0,0,0,0,0,0,0}, --// 5
    {0,0,0,0,0,0,0,0,0,0,0,0}  --// 6
    },
--// 1 2 3 4 5 6 7 8 9 0 1 2
    {
    {0,0,0,0,0,0,0,0,0,0,9,5}, --// 1
    {0,0,0,5,5,5,5,0,5,0,0,5}, --// 2
    {0,0,0,5,0,0,5,0,5,0,0,5}, --// 3
    {0,1,0,5,0,0,5,5,5,5,0,5}, --// 4
    {0,5,5,5,0,0,5,0,0,5,5,5}, --// 5
    {0,0,0,0,0,5,5,0,5,5,0,5}  --// 6
    },
--// 1 2 3 4 5 6 7 8 9 0 1 2
    {
    {0,0,0,0,0,0,0,0,0,0,0,0}, --// 1
    {0,0,0,0,0,0,0,0,0,0,0,0}, --// 2
    {0,0,9,0,0,0,0,0,0,0,0,0}, --// 3
    {0,1,5,0,0,0,0,0,0,0,0,0}, --// 4
    {0,0,5,0,0,0,0,0,0,0,0,0}, --// 5
    {0,0,0,0,0,0,0,0,0,0,0,0}  --// 6
    },
--// 1 2 3 4 5 6 7 8 9 0 1 2
    {
    {0,0,5,0,5,0,5,0,0,9,5,5}, --// 1
    {0,0,5,5,5,5,5,0,0,0,0,5}, --// 2
    {0,0,0,0,0,5,5,5,5,5,0,5}, --// 3
    {0,1,5,5,5,5,0,0,0,0,0,5}, --// 4
    {0,0,0,0,0,5,0,5,0,5,5,5}, --// 5
    {5,5,5,5,5,5,5,5,5,5,0,5}  --// 6
    }
    }
sequence maze
sequence solution_path
integer key
for i = 1 to length (MAZE_LIST) do
    maze = MAZE_LIST [i]
    puts (1, repeat ('=', 50))
    puts (1, "\nMaze:\n")
    draw_maze (maze)
    --// solution_path = solve_maze (maze, 2, 4)
    solution_path = solve_maze (maze, 2, 4)
    puts (1, "\n\nSolution:\n")
    if length (solution_path) then
        draw_maze_path (maze, solution_path)
        --// puts (1, "\nSolution points are: ")
        --// ? solution_path
    else
        puts (1, "No solution exists for this maze.\n")
    end if
    if i != length (MAZE_LIST) then
        puts (1, "\nPress escape to exit, enter to solve next maze "
            & sprintf ("(%d mazes left)", length (MAZE_LIST) - i)
            &  "...\n")
        key = wait_key ()
        if key = 27 then
            abort (0)
        end if
        puts (1, "\n\n")
    end if
end for
puts (1, "\nDone. Press any key to exit...\n")
if wait_key () then end if


------=_NextPart_000_00A5_01C24B23.578A86B0
Content-Type: application/octet-stream;
	name="maze.ex"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="maze.ex"

--// maze.ex
--// example of problem:
--// 
--// sequence maze = {
--// {5,5,5,5,5,5,5,5,5,5,5,5},
--// {5,0,0,0,0,0,0,0,0,0,0,5},
--// {5,0,0,0,0,5,0,0,0,0,0,5},
--// {5,1,0,0,0,5,0,0,0,0,0,5},
--// {5,0,0,0,0,5,0,0,0,9,0,5},
--// {5,5,5,5,5,5,5,5,5,5,5,5}}
--// 
--// How do I find a path to go from the 1 to the 9,
--// avoiding all non-5 elements? 
--// (assume that there is only 1 1 and only 1 9,
--// and their locations are known 
--// in advance)





without warning

include get.e





--// @@@@@@@@@@
--// @@@@@@@@@@ Constants, variables and types.
--// @@@@@@@@@@

constant false = 0, true = 1

constant X = 1, Y = 2

constant
    TOP_RIGHT = 1,
    RIGHT = 2,
    BOTTOM_RIGHT = 3,
    BOTTOM = 4,
    BOTTOM_LEFT = 5,
    LEFT = 6,
    TOP_LEFT = 7,
    TOP = 8

constant ALL_DIRECTIONS = {
    --// TOP_RIGHT,
    RIGHT,
    --// BOTTOM_RIGHT,
    BOTTOM,
    --// BOTTOM_LEFT,
    LEFT,
    --// TOP_LEFT,
    TOP}

--// For each member in 'ALL_DIRECTIONS':
--// into which direction we need to go to get neighouring point.
constant ALL_DIRECTIONS_GOWAY = {
    { 1, -1},    --// TOP_RIGHT
    { 1,  0},    --// RIGHT
    { 1,  1},    --// BOTTOM_RIGHT
    { 0,  1},    --// BOTTOM
    {-1,  1},    --// BOTTOM_LEFT
    {-1,  0},    --// LEFT
    {-1, -1},    --// TOP_LEFT
    { 0, -1}     --// TOP
}

type DIRECTION (integer i)
    return find (i, ALL_DIRECTIONS)
end type

--// Path is sequence with points.
type PATH (sequence path)
    for i = 1 to length (path) do
        if not sequence (path [i])
        and length (path [i]) != 2
        and not integer (path [i] [1])
        and not integer (path [i] [2]) then
            return false
        end if
    end for
    return true
end type





--// @@@@@@@@@@
--// @@@@@@@@@@ Main routines of this program.
--// @@@@@@@@@@

--// Gets one neighbouring point.
--// Return sequence with these members:
--// 1. true if point exists there
--// 2. point value
--// 3. neighbour x and y, sequence
function get_neighbour (sequence maze, integer x, integer y,
    DIRECTION direction)
    integer neighbour_x, neighbour_y
    neighbour_x = x + ALL_DIRECTIONS_GOWAY [direction] [X]
    neighbour_y = y + ALL_DIRECTIONS_GOWAY [direction] [Y]
    if neighbour_x < 1
    or neighbour_x > length (maze [1])
    or neighbour_y < 1
    or neighbour_y > length (maze) then
        return {false}
    else
        return {
            true,
            maze [neighbour_y] [neighbour_x],
            {neighbour_x, neighbour_y}
            }
    end if
end function

--// Returns solved path or {} if it couldn't be found.
function solve_maze (sequence maze, integer start_x, integer start_y)
    --// Points which need to have members looked.
    --// Each member has this format:
    --// 1. point x
    --// 2. point y
    --// 3. last direction into which neighbour point
    --//    of this point was looked at,
    --//    index of this direction is saved,
    --//    where in ALL_DIRECTIONS is it.
    --// 4. Current path which led us to this point.
    sequence to_do_points
    sequence one_to_do_point
    integer cur_x, cur_y
    integer neighbour_value
    sequence neighbour_result
    DIRECTION cur_direction
    sequence neighbour_position
    integer i
    PATH cur_path
    to_do_points = {}
    cur_x = start_x
    cur_y = start_y
    cur_path = {{cur_x, cur_y}}
    --// Try to get first neighbour point of current point
    --// which has value right for path.
    i = 1
    while 1 do
        if i > length (ALL_DIRECTIONS) then
            --// We've looked all neighbouring points
            --// and none were good. Try to get next to-do path.
            if length (to_do_points) > 0 then
            --// There are some todo points.
                one_to_do_point = to_do_points [length (to_do_points)]
                cur_x = one_to_do_point [1]
                cur_y = one_to_do_point [2]
                i = one_to_do_point [3] + 1
                cur_path = one_to_do_point [4]
                --// Remove this to-do point from sequence
                --// of to-do points.
                to_do_points = to_do_points [1 ..
                    length (to_do_points) - 1]
            else
            --// no more todo points. We've examined all maze and
            --// solution was not got.
                return {}
            end if
        end if
        cur_direction = ALL_DIRECTIONS [i]
        neighbour_result = get_neighbour (maze, cur_x,
            cur_y, cur_direction)
        if neighbour_result [1] = true then
            neighbour_value = neighbour_result [2]
            if neighbour_value = 5 then
            --// This neighbour point will now become part
           --// of our path.
                neighbour_position = neighbour_result [3]
                if find (neighbour_position, cur_path) = 0 then
                --// This point is not yet part of our path. Good.
                    --// Save to-do path unless this is last direction:
                    if cur_direction != ALL_DIRECTIONS
                        [length (ALL_DIRECTIONS)] then
                    --// This is not last direction in sequence
                    --// of all directions
                    --// so for this point not all
                    --// neighbours were looked yet
                    --// and we need to save this to
                    --// to-do sequence.
                        to_do_points = append (to_do_points, 
                            {
                                cur_x,
                                cur_y,
                                i,
                                cur_path
                            })
                    end if
                    cur_x = neighbour_position [1]
                    cur_y = neighbour_position [2]
                    cur_path = append (cur_path, {cur_x, cur_y})
                    i = 0 --// will advance to 1 at end of this loop
                end if
            elsif neighbour_value = 9 then
            --// This is goal point. We've found the solution we
            --// were looking!
                neighbour_position = neighbour_result [3]
                cur_path = append (cur_path, neighbour_position)
                return cur_path 
            end if
        end if
        i += 1
    end while
    --// I don't see how can we get here.
    return {}
end function





--// @@@@@@@@@@
--// @@@@@@@@@@ Maze drawing routines.
--// @@@@@@@@@@

--// Draws maze onto console screen.
procedure draw_maze (sequence maze)
    sequence maze_line
    integer maze_point_value
    for y = 1 to length (maze) do
        maze_line = maze [y]
        for x = 1 to length (maze_line) do
            maze_point_value = maze_line [x]
            if maze_point_value = 1
            or maze_point_value = 9 then
                puts (1, sprintf ("%d", maze_point_value))
            elsif maze_point_value = 0 then
                puts (1, ' ')
            elsif maze_point_value = 5 then
                puts (1, "#")
            end if
        end for
        puts (1, "\n")
    end for
end procedure

--// Draws one path of maze onto console screen.
procedure draw_maze_path (sequence maze, PATH path)
    sequence maze_line
    integer maze_point_value
    for y = 1 to length (maze) do
        maze_line = maze [y]
        for x = 1 to length (maze_line) do
            if find ({x, y}, path) then
                maze_point_value = maze_line [x]
                if maze_point_value = 1
                or maze_point_value = 9 then
                    puts (1, sprintf ("%d", maze_point_value))
                elsif maze_point_value = 0 then
                    puts (1, ' ')
                elsif maze_point_value = 5 then
                    puts (1, "#")
                end if
            else
                puts (1, " ")
            end if
        end for
        puts (1, "\n")
    end for
end procedure




--// @@@@@@@@@@
--// @@@@@@@@@@ Test.
--// @@@@@@@@@@

constant MAZE_LIST = {
--// 1 2 3 4 5 6 7 8 9 0 1 2
    {
    {5,5,5,5,5,5,5,5,5,5,5,5}, --// 1
    {5,0,0,0,0,0,0,0,0,0,0,5}, --// 2
    {5,0,0,0,0,5,0,0,0,0,0,5}, --// 3
    {5,1,0,0,0,5,0,0,0,0,0,5}, --// 4
    {5,0,0,0,0,5,0,0,0,9,0,5}, --// 5
    {5,5,5,5,5,5,5,5,5,5,5,5}  --// 6
    },
--// 1 2 3 4 5 6 7 8 9 0 1 2
    {
    {5,5,5,5,5,5,5,5,5,5,5,5}, --// 1
    {5,0,0,0,0,0,0,0,0,0,0,5}, --// 2
    {5,0,0,0,0,5,9,0,0,0,0,5}, --// 3
    {5,1,0,0,0,5,0,0,0,0,0,5}, --// 4
    {5,0,0,0,0,5,0,0,0,0,0,5}, --// 5
    {5,5,5,5,5,5,5,5,5,5,5,5}  --// 6
    },
--// --// 1 2 3 4 5 6 7 8 9 0 1 2
    {
    {5,5,5,5,5,0,5,5,5,5,5,5}, --// 1
    {5,0,0,0,0,0,9,0,0,0,0,5}, --// 2
    {5,0,0,0,0,5,0,0,0,0,0,5}, --// 3
    {5,1,0,0,0,5,0,0,0,0,0,5}, --// 4
    {5,0,0,0,0,5,0,0,0,0,0,5}, --// 5
    {5,5,5,5,5,5,5,5,5,5,5,5}  --// 6
    },
--// 1 2 3 4 5 6 7 8 9 0 1 2
    {
    {0,0,0,0,0,0,0,0,0,0,0,0}, --// 1
    {0,0,0,0,0,0,0,0,0,0,0,0}, --// 2
    {0,0,0,0,0,0,0,0,0,0,0,0}, --// 3
    {0,1,5,5,5,5,5,0,0,0,0,0}, --// 4
    {0,0,0,0,0,0,0,0,0,0,0,0}, --// 5
    {0,0,0,0,0,0,0,0,0,0,0,0}  --// 6
    },
--// 1 2 3 4 5 6 7 8 9 0 1 2
    {
    {0,0,0,0,0,0,5,5,5,0,0,0}, --// 1
    {0,0,0,0,5,5,5,0,0,0,5,0}, --// 2
    {0,0,5,5,5,0,5,0,0,0,5,0}, --// 3
    {0,1,5,0,5,0,0,0,0,0,5,0}, --// 4
    {0,5,0,0,5,0,0,0,0,0,5,0}, --// 5
    {0,5,5,9,5,5,5,5,5,5,5,0}  --// 6
    },
--// 1 2 3 4 5 6 7 8 9 0 1 2
    {
    {0,0,0,0,0,0,0,0,0,0,0,0}, --// 1
    {0,5,5,5,0,0,0,0,0,0,0,0}, --// 2
    {0,5,0,5,0,0,0,0,0,0,0,0}, --// 3
    {0,1,0,5,0,0,0,0,0,0,0,0}, --// 4
    {0,5,5,5,0,0,0,0,0,0,0,0}, --// 5
    {0,0,0,0,0,0,0,0,0,0,0,0}  --// 6
    },
--// 1 2 3 4 5 6 7 8 9 0 1 2
    {
    {0,0,0,0,0,0,0,0,0,0,9,5}, --// 1
    {0,0,0,5,5,5,5,0,5,0,0,5}, --// 2
    {0,0,0,5,0,0,5,0,5,0,0,5}, --// 3
    {0,1,0,5,0,0,5,5,5,5,0,5}, --// 4
    {0,5,5,5,0,0,5,0,0,5,5,5}, --// 5
    {0,0,0,0,0,5,5,0,5,5,0,5}  --// 6
    },
--// 1 2 3 4 5 6 7 8 9 0 1 2
    {
    {0,0,0,0,0,0,0,0,0,0,0,0}, --// 1
    {0,0,0,0,0,0,0,0,0,0,0,0}, --// 2
    {0,0,9,0,0,0,0,0,0,0,0,0}, --// 3
    {0,1,5,0,0,0,0,0,0,0,0,0}, --// 4
    {0,0,5,0,0,0,0,0,0,0,0,0}, --// 5
    {0,0,0,0,0,0,0,0,0,0,0,0}  --// 6
    },
--// 1 2 3 4 5 6 7 8 9 0 1 2
    {
    {0,0,5,0,5,0,5,0,0,9,5,5}, --// 1
    {0,0,5,5,5,5,5,0,0,0,0,5}, --// 2
    {0,0,0,0,0,5,5,5,5,5,0,5}, --// 3
    {0,1,5,5,5,5,0,0,0,0,0,5}, --// 4
    {0,0,0,0,0,5,0,5,0,5,5,5}, --// 5
    {5,5,5,5,5,5,5,5,5,5,0,5}  --// 6
    }
    }
sequence maze
sequence solution_path
integer key
for i = 1 to length (MAZE_LIST) do
    maze = MAZE_LIST [i]
    puts (1, repeat ('=', 50))
    puts (1, "\nMaze:\n")
    draw_maze (maze)
    --// solution_path = solve_maze (maze, 2, 4)
    solution_path = solve_maze (maze, 2, 4)
    puts (1, "\n\nSolution:\n")
    if length (solution_path) then
        draw_maze_path (maze, solution_path)
        --// puts (1, "\nSolution points are: ")
        --// ? solution_path
    else
        puts (1, "No solution exists for this maze.\n")
    end if
    if i != length (MAZE_LIST) then
        puts (1, "\nPress escape to exit, enter to solve next maze "
            & sprintf ("(%d mazes left)", length (MAZE_LIST) - i)
            &  "...\n")
        key = wait_key ()
        if key = 27 then
            abort (0)
        end if
        puts (1, "\n\n")
    end if
end for
puts (1, "\nDone. Press any key to exit...\n")
if wait_key () then end if
------=_NextPart_000_00A5_01C24B23.578A86B0--

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu