Changes between Version 5 and Version 6 of RecursiveMazeSolverExample
- Timestamp:
- 05/30/10 21:57:35 (14 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
RecursiveMazeSolverExample
v5 v6 45 45 import std.string; 46 46 47 /*48 * Created 7-Feb-2006;49 * Author: Jesse Phillips;50 */51 52 47 int main() { 53 48 Maze myMaze = new Maze(); 54 49 55 writefln( myMaze);50 writefln("%s", myMaze); 56 51 57 52 if(myMaze.solveMaze()) { 61 56 writefln("The maze could not be solved."); 62 57 63 writefln( myMaze);58 writefln("%s", myMaze); 64 59 65 60 return 0; 95 90 /// Prints the maze to the screen. 96 91 /// I will look for a Java's toString() equivalent 97 char[]toString()92 override string toString() 98 93 // Using Contracts (in{}out{}body{}) 99 94 in { 104 99 assert(maze); 105 100 }body { 106 char[]result = format("Maze Size: %dx%d\n", size[X], size[Y]);101 string result = format("Maze Size: %dx%d\n", size[X], size[Y]); 107 102 // change the array length to about 200 because I know it will be large 108 103 result ~= format("Starting Postion: (%d,%d)\n",start[X],start[Y]); 116 111 } 117 112 118 b itsolveMaze()113 bool solveMaze() 119 114 in { 120 115 assert(maze); 138 133 char[][] charSize = split(fileIn[line]); 139 134 140 // std.string.atoi() converts strings to int 141 result[X] = atoi(charSize[X]); 142 result[Y] = atoi(charSize[Y]); 135 version(D_Version2) { 136 result[X] = std.conv.to!int(charSize[X]); 137 result[Y] = std.conv.to!int(charSize[Y]); 138 } else { 139 // std.string.atoi() converts strings to int 140 result[X] = atoi(charSize[X]); 141 result[Y] = atoi(charSize[Y]); 142 } 143 143 144 144 return result; 148 148 /// fileIn was the string array created by std.file.read() 149 149 char[][] buildMaze() { 150 return fileIn[3.. length][0..length];150 return fileIn[3..$][0..$]; 151 151 } 152 152 153 153 /// Makes an attempt to move into x,y and continue to the exit 154 b ittraverseMaze(int x, int y) {154 bool traverseMaze(int x, int y) { 155 155 if(validMove(x, y)) 156 156 if(atEnd(x, y)) { 175 175 176 176 /// Checks to see if we are at the ending location 177 b itatEnd(int curX, int curY) {177 bool atEnd(int curX, int curY) { 178 178 return (curX == end[X] && curY == end[Y]); 179 179 } 180 180 181 181 /// Checks to see if we are in a wall, out of bounds, or somewhere we have been 182 b itvalidMove(int x, int y) {182 bool validMove(int x, int y) { 183 183 // Within the maze bounds? 184 184 if(y < 0 || x < 0 || y >= maze.length || x >= maze[y].length) 191 191 } 192 192 } 193 193 194 }}} 194 195 ==== output ====