Java Reference
In-Depth Information
LISTING 12.1
continued
The maze was successfully traversed!
7770110001111
3077707771001
0000707070300
7770777070333
7070000773003
7077777703333
7000000000000
7777777777777
The Maze class shown in Listing 12.2 uses a two-dimensional array of integers
to represent the maze. The goal is to move from the top-left corner (the entry
point) to the bottom-right corner (the exit point). Initially, a 1 indicates a clear
path and a 0 indicates a blocked path. As the maze is solved, these array elements
are changed to other values to indicate attempted paths and ultimately a success-
ful path through the maze if one exists.
LISTING 12.2
//********************************************************************
// Maze.java Author: Lewis/Loftus
//
// Represents a maze of characters. The goal is to get from the
// top left corner to the bottom right, following a path of 1s.
//********************************************************************
public class Maze
{
private final int TRIED = 3;
private final int PATH = 7;
private int [][] grid = { {1,1,1,0,1,1,0,0,0,1,1,1,1},
{1,0,1,1,1,0,1,1,1,1,0,0,1},
{0,0,0,0,1,0,1,0,1,0,1,0,0},
{1,1,1,0,1,1,1,0,1,0,1,1,1},
Search WWH ::




Custom Search