Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

미로찾기/상욱&인수: Difference between revisions

From ZeroWiki
imported>Unknown
No edit summary
 
(Repair batch-0005 pages from live compare)
 
Line 3: Line 3:
   
   
  public class MazeBoard {
  public class MazeBoard {
  public int boardMatrix[][];
  public int boardMatrix[][];
  public static int WALL = 0;
  public static int WALL = 0;
  public static int PATH = 1;
  public static int PATH = 1;
Line 9: Line 9:
  public static int BLOCK = 3;
  public static int BLOCK = 3;
   
   
  public MazeBoard(int boardMatrix[][]) {
  public MazeBoard(int boardMatrix[][]) {
  int x = boardMatrix[0].length;
  int x = boardMatrix[0].length;
  int y = boardMatrix.length;
  int y = boardMatrix.length;
  this.boardMatrix = new int[y+2][x+2];
  this.boardMatrix = new int[y+2][x+2];
  for(int i = 0 ; i < x ; ++i)
  for(int i = 0 ; i < x ; ++i)
  for(int j = 0 ; j < y ; ++j)
  for(int j = 0 ; j < y ; ++j)
  this.boardMatrix[j+1][i+1] = boardMatrix[j][i];
  this.boardMatrix[j+1][i+1] = boardMatrix[j][i];
  }
  }
  public boolean isEndPoint(Point point) {
  public boolean isEndPoint(Point point) {
Line 25: Line 25:
  }
  }
  public int getBoardSymbol(Point pt) {
  public int getBoardSymbol(Point pt) {
  return boardMatrix[pt.y][pt.x];
  return boardMatrix[pt.y][pt.x];
  }
  }
  }
  }
Line 42: Line 42:
  public static final int N = 3;
  public static final int N = 3;
   
   
  public static final Point directionTable[] =
  public static final Point directionTable[] =
  { new Point(1, 0), new Point(0, 1), new Point(-1, 0), new Point(0, -1)};
  { new Point(1, 0), new Point(0, 1), new Point(-1, 0), new Point(0, -1)};
   
   
Line 54: Line 54:
  Point curPoint = new Point( getLastPoint() );
  Point curPoint = new Point( getLastPoint() );
  if ( isValidMove(curPoint,i) ) {
  if ( isValidMove(curPoint,i) ) {
  curPoint.x += directionTable[i].x;
  curPoint.x += directionTable[i].x;
  curPoint.y += directionTable[i].y;
  curPoint.y += directionTable[i].y;
  tracedPath.add( new Point(curPoint) );
  tracedPath.add( new Point(curPoint) );
  return;
  return;
Line 63: Line 63:
  }
  }
  public boolean isValidMove(Point curPoint, int nth) {
  public boolean isValidMove(Point curPoint, int nth) {
  Point nextPt = new Point( curPoint.x + directionTable[nth].x,  
  Point nextPt = new Point( curPoint.x + directionTable[nth].x,  
  curPoint.y + directionTable[nth].y );
  curPoint.y + directionTable[nth].y );
  Point prevPt = (Point) tracedPath.elementAt(tracedPath.size() - 2);  
  Point prevPt = (Point) tracedPath.elementAt(tracedPath.size() - 2);  
  return board.isOpened(nextPt) && getDirection(nextPt)!= getDirection(prevPt);
  return board.isOpened(nextPt) && getDirection(nextPt)!= getDirection(prevPt);
Line 87: Line 87:
  public void backToPrev() {
  public void backToPrev() {
  Point pt = new Point(getLastPoint());
  Point pt = new Point(getLastPoint());
  board.boardMatrix[pt.y][pt.x] = MazeBoard.BLOCK;
  board.boardMatrix[pt.y][pt.x] = MazeBoard.BLOCK;
  tracedPath.remove( tracedPath.size()-1 );  
  tracedPath.remove( tracedPath.size()-1 );  
  }
  }
Line 101: Line 101:
  final int X = 3;
  final int X = 3;
  final int Y = 3;
  final int Y = 3;
  int mazeBoard[][] = { {1,1,0}, {0,1,0}, {0,1,2} };
  int mazeBoard[][] = { {1,1,0}, {0,1,0}, {0,1,2} };
  MazeBoard mb = new MazeBoard(mazeBoard);
  MazeBoard mb = new MazeBoard(mazeBoard);
  Player player = new Player(0,0,mb);
  Player player = new Player(0,0,mb);
Line 109: Line 109:
  }
  }
  public void testCreation() {
  public void testCreation() {
  int expected[][] = { {0,0,0,0,0}, {0,1,1,0,0}, {0,0,1,0,0},
  int expected[][] = { {0,0,0,0,0}, {0,1,1,0,0}, {0,0,1,0,0},
  {0,0,1,2,0}, {0,0,0,0,0} };
  {0,0,1,2,0}, {0,0,0,0,0} };
  for(int i = 0 ; i < X+2 ; ++i)  
  for(int i = 0 ; i < X+2 ; ++i)  
  for(int j = 0 ; j < Y+2 ; ++j)  
  for(int j = 0 ; j < Y+2 ; ++j)  
  assertEquals(expected[j][i], mb.boardMatrix[j][i]);
  assertEquals(expected[j][i], mb.boardMatrix[j][i]);
  }
  }
  public void testMovement() {
  public void testMovement() {
  Point expectedPoint[] = { new Point(2,1), new Point(2,2),
  Point expectedPoint[] = { new Point(2,1), new Point(2,2),
  new Point(2,3), new Point(3,3) };
  new Point(2,3), new Point(3,3) };
  for(int i = 0 ; i < 4 ; ++i) {
  for(int i = 0 ; i < 4 ; ++i) {
  player.move();
  player.move();
  assertEquals( expectedPoint[i], player.getLastPoint() );
  assertEquals( expectedPoint[i], player.getLastPoint() );
  }
  }
  }
  }
  public void testMovement2() {
  public void testMovement2() {
  Vector expected = new Vector();
  Vector expected = new Vector();
  Point pt[] = {new Point(0,0), new Point(1,1), new Point(2,1),
  Point pt[] = {new Point(0,0), new Point(1,1), new Point(2,1),
  new Point(2,2), new Point(2,3), new Point(3,3)};
  new Point(2,2), new Point(2,3), new Point(3,3)};
  for(int i = 0 ; i < pt.length ; ++i)
  for(int i = 0 ; i < pt.length ; ++i)
  expected.add(pt[i]);
  expected.add(pt[i]);
  player.traverseMaze();
  player.traverseMaze();
  assertEquals( expected, player.tracedPath );
  assertEquals( expected, player.tracedPath );
Line 141: Line 141:
  player.traverseMaze();
  player.traverseMaze();
  Point point = player.getLastPoint();
  Point point = player.getLastPoint();
  assertEquals(2, mb.boardMatrix[point.y][point.x]);
  assertEquals(2, mb.boardMatrix[point.y][point.x]);
  }
  }
  }
  }
Line 150: Line 150:
   
   
  public class ComplexMazeTestCase extends TestCase {
  public class ComplexMazeTestCase extends TestCase {
  int complexMatrix[][] = {{1,1,1,0},{0,0,1,0},{1,1,1,1},{2,0,0,0}};
  int complexMatrix[][] = {{1,1,1,0},{0,0,1,0},{1,1,1,1},{2,0,0,0}};
  MazeBoard mb = new MazeBoard(complexMatrix);
  MazeBoard mb = new MazeBoard(complexMatrix);
  Player player = new Player(0,0,mb);
  Player player = new Player(0,0,mb);
Line 163: Line 163:
 
 
  public void testAll() {
  public void testAll() {
  Point expected[] = {new Point(0,0), new Point(1,1), new Point(2,1),
  Point expected[] = {new Point(0,0), new Point(1,1), new Point(2,1),
  new Point(3,1), new Point(3,2), new Point(3,3),
  new Point(3,1), new Point(3,2), new Point(3,3),
  new Point(2,3), new Point(1,3), new Point(1,4)};  
  new Point(2,3), new Point(1,3), new Point(1,4)};  
  player.traverseMaze();
  player.traverseMaze();
  for(int i = 0 ; i < expected.length ; i++)
  for(int i = 0 ; i < expected.length ; i++)
  assertEquals(expected[i], (Point) player.tracedPath.get(i));
  assertEquals(expected[i], (Point) player.tracedPath.get(i));
  }
  }
   
   
  public void testAcceptance1() {
  public void testAcceptance1() {
  int matrix[][] = { {1,1,0,0,0,0},
  int matrix[][] = { {1,1,0,0,0,0},
  {0,1,1,1,1,0},
  {0,1,1,1,1,0},
  {0,0,0,0,1,0},
  {0,0,0,0,1,0},
Line 183: Line 183:
  }
  }
  public void testAcceptance2() {
  public void testAcceptance2() {
  int matrix[][] = {{1,1,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0},
  int matrix[][] = {{1,1,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0},
  {0,1,1,1,1,0,0,1,0,0,0,0,0,1,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0},
  {0,1,1,1,1,0,0,1,0,0,0,0,0,1,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0},
  {0,0,0,0,1,1,1,1,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,1,1,1,0,0,0,0},
  {0,0,0,0,1,1,1,1,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,1,1,1,0,0,0,0},
Line 217: Line 217:
   
   
  public class MazeFrame extends JApplet {
  public class MazeFrame extends JApplet {
  JButton mazeUnit[][] = new JButton[20][30];
  JButton mazeUnit[][] = new JButton[20][30];
  MazeBoard maze;
  MazeBoard maze;
  Player player;
  Player player;
  public void init() {
  public void init() {
  int matrix[][] = {{1,1,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0},
  int matrix[][] = {{1,1,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0},
  {0,1,1,1,1,0,0,1,0,0,0,0,0,1,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0},
  {0,1,1,1,1,0,0,1,0,0,0,0,0,1,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0},
  {0,0,0,0,1,1,1,1,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,1,1,1,0,0,0,0},
  {0,0,0,0,1,1,1,1,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,1,1,1,0,0,0,0},
Line 248: Line 248:
  for(int i = 0 ; i < 20 ; ++i) {
  for(int i = 0 ; i < 20 ; ++i) {
  for(int j = 0 ; j < 30 ; ++j) {
  for(int j = 0 ; j < 30 ; ++j) {
  mazeUnit[i][j] = new JButton();
  mazeUnit[i][j] = new JButton();
 
 
  int boardSymbol = maze.getBoardSymbol(new Point(j+1,i+1));  
  int boardSymbol = maze.getBoardSymbol(new Point(j+1,i+1));  
  if( boardSymbol == MazeBoard.WALL )  
  if( boardSymbol == MazeBoard.WALL )  
  mazeUnit[i][j].setBackground(Color.BLACK);  
  mazeUnit[i][j].setBackground(Color.BLACK);  
  else if( boardSymbol == MazeBoard.PATH ||
  else if( boardSymbol == MazeBoard.PATH ||
  boardSymbol == MazeBoard.BLOCK )
  boardSymbol == MazeBoard.BLOCK )
  mazeUnit[i][j].setBackground(Color.WHITE);
  mazeUnit[i][j].setBackground(Color.WHITE);
  getContentPane().add(mazeUnit[i][j]);
  getContentPane().add(mazeUnit[i][j]);
  }
  }
  }
  }
Line 267: Line 267:
  for(int i = 1 ; i < player.tracedPath.size() ; ++i) {
  for(int i = 1 ; i < player.tracedPath.size() ; ++i) {
  Point pt = (Point)player.tracedPath.get(i);
  Point pt = (Point)player.tracedPath.get(i);
  mazeUnit[pt.y-1][pt.x-1].setBackground(Color.RED);
  mazeUnit[pt.y-1][pt.x-1].setBackground(Color.RED);
  }
  }
  }
  }
 
 
  }
  }

Latest revision as of 00:44, 27 March 2026

MazeBoard.java

import java.awt.Point;

public class MazeBoard {
	public int boardMatrix[][];
	public static int WALL = 0;
	public static int PATH = 1;
	public static int END = 2;
	public static int BLOCK = 3;

	public MazeBoard(int boardMatrix[][]) {
		int x = boardMatrix[0].length;
		int y = boardMatrix.length;
		this.boardMatrix = new int[y+2][x+2];
		for(int i = 0 ; i < x ; ++i)
			for(int j = 0 ; j < y ; ++j)
				this.boardMatrix[j+1][i+1] = boardMatrix[j][i];
	}
	public boolean isEndPoint(Point point) {
		return getBoardSymbol(point) == END;
	}
	public boolean isOpened(Point pt) {
		return getBoardSymbol(pt) != MazeBoard.WALL &&
				getBoardSymbol(pt) != MazeBoard.BLOCK;		
	}
	public int getBoardSymbol(Point pt) {
		return boardMatrix[pt.y][pt.x];
	}
}

Player.java

import java.awt.Point;
import java.util.Vector;

public class Player {
	public Vector tracedPath = new Vector();
	public MazeBoard board;

	public static final int E = 0;
	public static final int S = 1;
	public static final int W = 2;
	public static final int N = 3;

	public static final Point directionTable[] =
		{ new Point(1, 0), new Point(0, 1), new Point(-1, 0), new Point(0, -1)};

	public Player(int x, int y, MazeBoard board) {
		tracedPath.add(new Point(0,0));
		tracedPath.add(new Point(x + 1, y + 1));
		this.board = board;		
	}
	public void move() {
		for (int i = 0; i < 4; ++i) {
			Point curPoint = new Point( getLastPoint() );
			if ( isValidMove(curPoint,i) ) {
				curPoint.x += directionTable[i].x;
				curPoint.y += directionTable[i].y;
				tracedPath.add( new Point(curPoint) );
				return;
			}
		}
		backToPrev();
	}
	public boolean isValidMove(Point curPoint, int nth) {
		Point nextPt = new Point( curPoint.x + directionTable[nth].x, 
							curPoint.y + directionTable[nth].y );
		Point prevPt = (Point) tracedPath.elementAt(tracedPath.size() - 2); 
		return board.isOpened(nextPt) && getDirection(nextPt)!= getDirection(prevPt);
	}
	public int getDirection(Point point) {
		Point curPoint = new Point(getLastPoint());
		if (point.x > curPoint.x)
			return E;
		if (point.x < curPoint.x)
			return W;
		if (point.y > curPoint.y)
			return S;
		return N;
	}
	public Point getLastPoint() {
		return (Point)tracedPath.get(tracedPath.size() - 1);
	}
	public void traverseMaze() {
		while( !board.isEndPoint( getLastPoint() ) )
			move();
	}
	public void backToPrev() {
		Point pt = new Point(getLastPoint());
		board.boardMatrix[pt.y][pt.x] = MazeBoard.BLOCK;
		tracedPath.remove( tracedPath.size()-1 );				 
	}
}

MazeTestCase

import java.awt.Point;
import java.util.Vector;

import junit.framework.TestCase;

public class MazeTestCase extends TestCase {
	final int X = 3;
	final int Y = 3;
	int mazeBoard[][] = { {1,1,0}, {0,1,0}, {0,1,2} };	
	MazeBoard mb = new MazeBoard(mazeBoard);
	Player player = new Player(0,0,mb);
	
	public MazeTestCase(String title) {
		super(title);
	}
	public void testCreation() {
		int expected[][] = { {0,0,0,0,0}, {0,1,1,0,0}, {0,0,1,0,0},
							{0,0,1,2,0}, {0,0,0,0,0} };
		for(int i = 0 ; i < X+2 ; ++i) 
			for(int j = 0 ; j < Y+2 ; ++j) 
				assertEquals(expected[j][i], mb.boardMatrix[j][i]);
	}
	public void testMovement() {
		Point expectedPoint[] = { new Point(2,1), new Point(2,2),
								new Point(2,3), new Point(3,3) };
		for(int i = 0 ; i < 4 ; ++i) {
			player.move();
			assertEquals( expectedPoint[i], player.getLastPoint() );						
		}
	}
	public void testMovement2() {
		Vector expected = new Vector();
		Point pt[] = {new Point(0,0), new Point(1,1), new Point(2,1),
					 new Point(2,2), new Point(2,3), new Point(3,3)};
		for(int i = 0 ; i < pt.length ; ++i)
			expected.add(pt[i]);			
		player.traverseMaze();
		assertEquals( expected, player.tracedPath );
	}
	public void testJudge() {
		Point point = new Point(2,1);
		assertEquals(Player.E, player.getDirection(point));
		point.setLocation(1,2);
		assertEquals(Player.S, player.getDirection(point));
	}	
	public void testEnd() {
		player.traverseMaze();
		Point point = player.getLastPoint();
		assertEquals(2, mb.boardMatrix[point.y][point.x]);		
	}	
}

ComplexMazeTestCase

import java.awt.Point;
import junit.framework.TestCase;

public class ComplexMazeTestCase extends TestCase {
	int complexMatrix[][] = {{1,1,1,0},{0,0,1,0},{1,1,1,1},{2,0,0,0}};
	MazeBoard mb = new MazeBoard(complexMatrix);
	Player player = new Player(0,0,mb);
	
	public void testBlocked() {
		for(int i = 0 ; i < 5 ; ++i)
			player.move();				
		player.backToPrev();
		assertEquals(MazeBoard.BLOCK, mb.getBoardSymbol(new Point(4,3)));
		assertEquals(new Point(3,3), player.getLastPoint());
	}
	
	public void testAll() {
		Point expected[] = {new Point(0,0), new Point(1,1), new Point(2,1),
						new Point(3,1), new Point(3,2), new Point(3,3),
						new Point(2,3), new Point(1,3), new Point(1,4)}; 
		player.traverseMaze();
		for(int i = 0 ; i < expected.length ; i++)
			assertEquals(expected[i], (Point) player.tracedPath.get(i));
	}

	public void testAcceptance1() {
		int matrix[][] = {	 {1,1,0,0,0,0},
							{0,1,1,1,1,0},
							{0,0,0,0,1,0},
							{0,0,0,0,2,0} };						
		MazeBoard maze = new MazeBoard(matrix);
		Player p = new Player(0,0,maze);
		p.traverseMaze();

		assertEquals(new Point(5,4), p.getLastPoint());
	}	
	public void testAcceptance2() {
		int matrix[][] = {{1,1,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0},
							{0,1,1,1,1,0,0,1,0,0,0,0,0,1,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0},
							{0,0,0,0,1,1,1,1,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,1,1,1,0,0,0,0},
							{0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0},
							{0,0,1,1,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
							{0,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,0,0},
							{1,1,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0},
							{1,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0},
							{1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0},
							{1,1,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0},
							{1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0},
							{1,0,0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0},
							{1,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0},
							{0,1,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0},
							{1,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0},
							{0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1,1,1,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,0,0,0,0,0,0,0,0,0,0,0,0},
							{0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0},
							{0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,1,1,1,0,0,0},
							{0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,1,1,1,2}};						
		MazeBoard maze = new MazeBoard(matrix);
		Player p = new Player(0,0,maze);
		p.traverseMaze();

		assertEquals(new Point(30,20), p.getLastPoint());
	}
}

MazeFrame.java

import java.awt.*;

import javax.swing.*;

public class MazeFrame extends JApplet {
	JButton mazeUnit[][] = new JButton[20][30];
	MazeBoard maze;
	Player player;	
	public void init() {
		int matrix[][] = {{1,1,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0},
							{0,1,1,1,1,0,0,1,0,0,0,0,0,1,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0},
							{0,0,0,0,1,1,1,1,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,1,1,1,0,0,0,0},
							{0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0},
							{0,0,1,1,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
							{0,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,0,0},
							{1,1,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0},
							{1,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0},
							{1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0},
							{1,1,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0},
							{1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0},
							{1,0,0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0},
							{1,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0},
							{0,1,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0},
							{1,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0},
							{0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1,1,1,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,0,0,0,0,0,0,0,0,0,0,0,0},
							{0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0},
							{0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,1,1,1,0,0,0},
							{0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,1,1,1,2}};						
		maze = new MazeBoard(matrix);
		player = new Player(0,0,maze);
		player.traverseMaze();

		getContentPane().setLayout(new GridLayout(20,30));
		for(int i = 0 ; i < 20 ; ++i) {
			for(int j = 0 ; j < 30 ; ++j) {
				mazeUnit[i][j] = new JButton();
				
				int boardSymbol = maze.getBoardSymbol(new Point(j+1,i+1)); 
				if( boardSymbol == MazeBoard.WALL ) 
					mazeUnit[i][j].setBackground(Color.BLACK);	 
				else if( boardSymbol == MazeBoard.PATH ||
					boardSymbol == MazeBoard.BLOCK )			
					mazeUnit[i][j].setBackground(Color.WHITE);	
				getContentPane().add(mazeUnit[i][j]);
			}
		}
		setSize(600,600);
		setVisible(true);
		
		traverse();
	}
	public void traverse() {
		for(int i = 1 ; i < player.tracedPath.size() ; ++i) {
			Point pt = (Point)player.tracedPath.get(i);
			mazeUnit[pt.y-1][pt.x-1].setBackground(Color.RED);
		}
	}
	
}