Permalink
Browse files

updated readme

  • Loading branch information...
1 parent 46982f3 commit 7235b04e57dfa03f7f17777278468d5d0cbaf66d @liweinan committed Mar 24, 2013
View
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="AntConfiguration">
+ <defaultAnt bundledAnt="true" />
+ </component>
+</project>
+
@@ -0,0 +1,13 @@
+<component name="libraryTable">
+ <library name="Maven: junit:junit:4.10">
+ <CLASSES>
+ <root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.10/junit-4.10.jar!/" />
+ </CLASSES>
+ <JAVADOC>
+ <root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.10/junit-4.10-javadoc.jar!/" />
+ </JAVADOC>
+ <SOURCES>
+ <root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.10/junit-4.10-sources.jar!/" />
+ </SOURCES>
+ </library>
+</component>
@@ -0,0 +1,13 @@
+<component name="libraryTable">
+ <library name="Maven: org.hamcrest:hamcrest-core:1.1">
+ <CLASSES>
+ <root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.1/hamcrest-core-1.1.jar!/" />
+ </CLASSES>
+ <JAVADOC>
+ <root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.1/hamcrest-core-1.1-javadoc.jar!/" />
+ </JAVADOC>
+ <SOURCES>
+ <root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.1/hamcrest-core-1.1-sources.jar!/" />
+ </SOURCES>
+ </library>
+</component>
View
@@ -1,4 +1,27 @@
-mazejava
-========
+# Maze Java
+
+A maze game written in java for fun.
+
+## Usage
+
+Create a 5x5 maze:
+
+ Maze maze = MazeFactory.createMaze(5, 5);
+
+Print it:
+
+ maze.print();
+
+ +---+---+---+---+---+
+ > | | |
+ +---+ + + + +
+ | | | | |
+ + + + +---+ +
+ | | | | |
+ + + +---+---+ +
+ | | | |
+ + +---+ + + +
+ | | V |
+ +---+---+---+---+ +
+
-MazeJava
View
38 pom.xml
@@ -1,25 +1,19 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
- <groupId>io</groupId>
- <artifactId>maze</artifactId>
- <version>1.0-SNAPSHOT</version>
- <packaging>jar</packaging>
+ <groupId>mazejava</groupId>
+ <artifactId>mazejava</artifactId>
+ <version>1.0-SNAPSHOT</version>
- <name>maze</name>
- <url>http://maven.apache.org</url>
+ <dependencies>
- <properties>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- </properties>
-
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>3.8.1</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
-</project>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.10</version>
+ </dependency>
+ </dependencies>
+</project>
@@ -18,7 +18,7 @@
private CellState in, out;
private CellState[][] cells;
private int m, n;
- private LinkedList<CellState> histories = new LinkedList<CellState>();
+ private Stack<CellState> histories = new Stack<CellState>();
private int visited_cnt = 0;
public Maze(int m, int n) {
@@ -48,7 +48,7 @@ public void generate() {
histories.push(currentCell);
visited_cnt++;
- System.out.println("LEGEND: C- CANDIDATE, D- DECISION, R- RESULT, F- FALLBACK");
+ System.out.println("LEGEND: C- CANDIDATE, D- DECISION, R- RESULT, G- GO BACK");
while (histories.size() > 0 && visited_cnt < m*n) {
while (currentCell != null) {
@@ -59,7 +59,7 @@ public void generate() {
}
}
currentCell = histories.pop();
- System.out.println("F- x:" + currentCell.getX() + " y:" + currentCell.getY());
+ System.out.println("(G- x:" + currentCell.getX() + " y:" + currentCell.getY() + ")");
}
}
@@ -183,17 +183,27 @@ public void print() {
for (int y = 0; y < n; y++) {
Queue<String> parts = new LinkedList<String>();
-
for (int x = 0; x < m; x++) {
+
CellState cell = cells[x][y];
String part = new String(token);
+ if (x==0 && y==0) { // in
+ part = part.replaceAll(" \\|", " > |");
+ }
+
+ if (x==m-1 && y==n-1) { //out
+ part = part.replaceAll(" \\|", " V |");
+ }
+
+
if (cell.getSouthDoor().isOpened()) {
part = part.replaceAll("\\-", " ");
}
if (cell.getEastDoor().isOpened()) {
part = part.replaceAll("\\|", " ");
}
+
parts.offer(part);
}
@@ -13,7 +13,7 @@
public class PlayMaze {
public static final void main(String[] args) {
- Maze maze = MazeFactory.createMaze(60, 60);
+ Maze maze = MazeFactory.createMaze(5, 5);
maze.print();
}
}

0 comments on commit 7235b04

Please sign in to comment.