Turbo-C
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
터보-C 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
Lua 게시판
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C/C++ Q/A
[2617] 미로 알고리즘인데, 에러가 3군데 있는데, 도저히 못찾겠네요..부탁드립니다.
김장훈 [firstkelly] 1127 읽음    2003-05-14 21:31
#include<stdio.h>
#include<stdlib.h>


#define MAX_STACK 100
#define FALSE 0
#define TRUE 1


typedef struct{
    short int row;
    short int col;
    short int dir;
    }elements;

elements stack[MAX_STACK];
int top;

typedef struct{
    short int vert;
    short int horiz;
    }offsets;
offsets move[8];

int EXIT_COL, EXIT_ROW;
int **maze;
int mark[MAX_STACK][MAX_STACK];


void clear();
void Input_Direct();
void delet(int *top);
void add(int *top, elements item);
void path();


void main()
{
    int i, j;
       int max_col, max_row;
    EXIT_COL = 8;
    EXIT_ROW = 8;
    max_col = EXIT_COL + 2;
       max_row = EXIT_ROW + 2;
    maze = (int **)calloc(max_col, sizeof(int *));
    for( i= 0 ; i < max_col ; i++)
    maze[i] = (int *)calloc(max_row, sizeof(int));
   
    int maze[10][10] =
        { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
          1, 0, 1, 1, 0, 0, 1, 1, 1, 1,
          1, 1, 0, 0, 1, 1, 1, 1, 1, 1,
          1, 1, 1, 0, 1, 1, 1, 0, 0, 1,
          1, 0, 0, 0, 0, 1, 0, 1, 1, 1,
          1, 0, 1, 1, 0, 1, 1, 1, 1, 1,
          1, 0, 1, 1, 0, 0, 0, 0, 1, 1,
          1, 1, 1, 0, 0, 1, 1, 0, 1, 1,
          1, 1, 0, 0, 1, 1, 1, 0, 0, 1,
          1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };

    for( i = 0 ; i < max_col ; i++)
    {
        for( j = 0 ; j < max_row ; j++)
        {
            mark[i][j] = 0 ;
        }
    }

    Input_Direct();
    clear();
    path();
}


void Input_Direct()
{
    move[0].vert=-1; move[0].horiz=0;
    move[1].vert=-1; move[1].horiz=1;
    move[2].vert=0; move[2].horiz=1;
    move[3].vert=1; move[3].horiz=1;
    move[4].vert=1; move[4].horiz=0;
    move[5].vert=1; move[5].horiz=-1;
    move[6].vert=0; move[6].horiz=-1;
    move[7].vert=-1; move[7].horiz=-1;
}


void clear()
{
    int i = 0;
    for( i = 0 ; i < MAX_STACK ; i++)
    *top[i] = NULL;
}


void push(int top, elements item)
{
    top++;
    stack[top] = item;
}



void pop(int top)
{      top--;
    return stack[top];
}

   


void path(void)
{
int i, row, col, next_row, next_col, dir, found=FALSE;
elements position;
mark[1][1]=1; top=0;
stack[0].row=1; stack[0].col=1; stack[0].dir=1;

while(top>-1 && !found){
    position = pop(*top);
    row = position.row;
    col = position.col;
    dir = position.dir;

    while(dir<8 && !found){
    next_row = row + move[dir].vert;
    next_col = col + move[dir].horiz;

    if(next_row==EXIT_ROW && next_col==EXIT_COL)
    found = TRUE;
    else if(!maze[next_row][next_col] && !mark[next_row][next_col])
    {
       mark[next_row][next_col] =1;
    position.row = row; position.col = col; position.dir = ++dir;
    add(&top, position);
    row = next_row; col = next_col; dir = 0;
    }
    else ++dir;
    }
    }

if(found){
    printf("THE PATH IS : \n");
    printf("ROW    COL\n");
    for(i = 0 ; i <= top ; i++)
        printf("%2d %5d\n", stack[i].row, stack[i].col);

    printf("%2d %5d\n", row, col);
    printf("%2d %5d\n", EXIT_ROW, EXIT_COL);
}
else printf("THIS MAZE IS BLOCKED PATH\n");
}

+ -

관련 글 리스트
2617 미로 알고리즘인데, 에러가 3군데 있는데, 도저히 못찾겠네요..부탁드립니다. 김장훈 1127 2003/05/14
4058     Re:미로 알고리즘인데, 에러가 3군데 있는데, 도저히 못찾겠네요..부탁드립니다. 임문환.실업자 1053 2003/05/14
4057     Re:미로 알고리즘인데, 에러가 3군데 있는데, 도저히 못찾겠네요..부탁드립니다. 임문환.실업자 1025 2003/05/14
4056     Re:미로 알고리즘인데, 에러가 3군데 있는데, 도저히 못찾겠네요..부탁드립니다. 임문환.실업자 997 2003/05/14
2619     Re:미로 알고리즘인데, 에러가 3군데 있는데, 도저히 못찾겠네요..부탁드립니다. 실업자 1148 2003/05/14
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.