[공학 프로그래밍]maze.c스택과 큐를 이용한 최단거리 8방향 검색
- 최초 등록일
- 2006.04.14
- 최종 저작일
- 2006.04
- 6페이지/ C언어
- 가격 1,000원
소개글
#미로찾기#
1.스택과 큐를 사용
2.8방향 검색
3.최단거리 확보
4.최단거리 draw
목차
없음
본문내용
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <windows.h>
//스택 사이즈
#define MAX_STACK_SIZE 500
#define FALSE 0
#define TRUE 1
//비트 연산을 통한 미로를 그리기
#define UP 1
#define RIGHT 2
#define DOWN 4
#define LEFT 8
//미로 배열 사이즈
#define MAZE_SIZE 19
//양쪽 벽을 제외한 사이즈
#define EXIT_COL 17
#define EXIT_ROW 17
typedef struct
{
int row;
int col;
int dir;
}element;
element stack[MAX_STACK_SIZE];
element queue[MAX_STACK_SIZE];
typedef struct
{
int vert;
int horiz;
}offsets;
//미로 그려지는 함수
void draw_Maze(int m[MAZE_SIZE][MAZE_SIZE]);
//좌표 함수
void gotoxy(int x, int y);
//경로스캔 함수
void path_scan();
//최단 거리
void path_sort();
element queue_pop();
void queue_add(short_cut);
element sort_pop();
void sort_add(short_element);
int front, rear;
int top = -1;
offsets move[8] = {{-1,1},{1,1},{1,-1},{-1,-1},{-1,0},{0,1},{1,0},{0,-1}}; //정방향부터 Scan
element position;
draw_Maze(maze);
gotoxy(20,2);
puts("********생쥐 시뮬레이션*********");
gotoxy(20,5);
puts("**********ENTER PUSH**********");
while(getchar() != `\n`)
;
gotoxy(0,1);
puts("STRAT");
path_scan();
while(top > 0) {
position = sort_pop();
Sleep(50);
gotoxy(position.col, position.row);
puts("▩");
}
gotoxy(position.col+1, position.row+1);
puts("EXIT");
gotoxy(20,7);
puts("**********SORTEST PATH**********");
puts("");
puts("");
gotoxy(position.col+1, position.row+5);
puts("");
참고 자료
c로 배우는 알고리즘