The Code-Bin
Links
Home
Add your code!
All Listings
About
Latest Entry
Featured Scripts
Author's Website
Latest Entries
FFMPEG Thumbnail Scr...
PHP, 0.8KB
Jul. 29, 10:24pm
John
Z80 Assembler, 190 bytes
Feb. 17, 3:36am
John
Z80 Assembler, 176 bytes
Sep. 13, 2:19am
John
Z80 Assembler, 77 bytes
Sep. 13, 2:18am
John
Z80 Assembler, 209 bytes
Sep. 13, 2:17am
Stupid structures
Posted by: MD | October 23, 2009 @ 10:06pm
C++ Code
[
Download
]
#include <iostream> #include <fstream> #include <windows.h> using namespace std; struct direction { int xD; int yD; }; direction Up, Do, Le, Ri; Up.xD = 0; Up.yD = -1; Do.xD = 0; Do.yD = 1; Le.xD = -1; Le.yD = 0; Ri.xD = 1; Ri.yD = 0; char maze[100][100]; char solvedMaze[100][100]; void clearMaze(char maze[][100]); void readMaze(char maze[][100], int &rows, int &columns, string filename) // Reads the maze from the text file with the name passed to the function { ifstream inputMaze; inputMaze.open(filename.c_str()); inputMaze >> rows >> columns; string templine; int temprow, tempcolumn; temprow = 0; getline(inputMaze, templine); // Clears the end line character from the maze clearMaze(maze); while(!inputMaze.eof()) { getline(inputMaze, templine); for(tempcolumn=0; tempcolumn < columns; tempcolumn++) { maze[temprow][tempcolumn] = templine[tempcolumn]; } temprow++; } inputMaze.close(); } void clearMaze(char maze[][100]) // Sets every character in the maze to a wall // Extra walls outside of the maze will not effect the solving of the maze // Since we are given the dimensions of the maze, it will not affect the output // of the maze, either. { int i, j; for(i=0; i<100; i++) { for(j=0; j<100; j++) { maze[i][j] = '*'; } } } void displayMaze(char maze[][100], int rows, int columns) // Displays the maze { for(int i = 0; i < rows; i++) { for(int j = 0; j < columns; j++) { cout << maze[i][j]; } cout << endl; } } void makeMove(char maze[][100], direction direct, int &X, int &Y) { // I will finish this later >.> } void solveMaze(char maze[][100], int rows, int columns) { int X, Y; X = 1; Y = 1; direction currentDirection = Ri; // We start at (1,1), or maze[1][1] // // We wish to get to (columns - 1, rows - 1), or maze[rows-1][columns-1] while(X != (columns - 1) && Y != (rows - 1)) { makeMove(maze, currentDirection, X, Y); } } int main() { int rows, columns; string firstline, filename; filename = "maze1.txt"; readMaze(maze, rows, columns, filename); displayMaze(maze, rows, columns); char cc; cin >> cc; return 0; }
Syntax Highlighting
[
Open in new window
]
Author Comments
none
Rating
4.49 / 8
79 Votes
http://codebin.yi.org/430
page generated in 0.00 seconds