미로찾기(mase) C소스
- 최초 등록일
- 2009.03.15
- 최종 저작일
- 2008.04
- 압축파일
- 가격 2,000원
소개글
미로찾기(mase)를 C로 구현한 소스입니다.
**실행순서
1.파일의 압축을 풀니다.
2.stack.c 파일을 컴파일 합니다.
3.mase.c 파일을 컴파일 합니다.
4.실행합니다.
미로는 mase.dat파일에 짜여져 있습니다. 이 파일을 열어 미로를 수정할 수 있습니다.
가로,세로 10칸씩이고, 숫자1은 벽, 숫자0은 통로, `S`는 시작점 `D`는 도착점 입니다.
실행하시면 미로에서 지나쳤으나 막혀서 돌아간 길은 `X`로
성공적으로 찾은 길은 `+`로 표시됩니다.
컴파일 실행환경
윈도우/MS Visual Studio
본문내용
#include <stdio.h>
#include <stdlib.h>
#include "stacksADT.h"
//MAPPOINT구조체 선언
typedef struct
{
int branch; //branch여부(0:no 1:yes)
int xPoint; //x축 좌표
int yPoint; //y축 좌표
} MAPPOINT;
int main()
{
int i=0,j=0;
int numOfRoute=0; //route의 수
int toBxPoint=-100,toByPoint=-100; //bottom 좌표
int toRxPoint=-100,toRyPoint=-100; //right 좌표
int toTxPoint=-100,toTyPoint=-100; //top 좌표
int toLxPoint=-100,toLyPoint=-100; //left 좌표
char mase[10][11];
FILE *fp;
STACK* stack;
MAPPOINT* mapPoint; //mapPoint를 MAPPOINT형으로 선언
stack=createStack();
if((fp=fopen("mase.dat", "r")) == NULL) {
puts("file open error: Cannot find mase.dat");
exit(0);
}
for(i=0; i<10; i++) fscanf(fp, "%s", mase[i]);
//S(시작점)찾은후 push
for(i=0; i<10; i++)
{
if(mase[i][0]==`S`) //시작점을 찾았을 경우
{
mapPoint = (MAPPOINT* ) malloc(sizeof( MAPPOINT)); //동적메모리 할당
mapPoint->xPoint=0; //x축 좌표
mapPoint->yPoint=i; //y축 좌표
mapPoint->branch=0; //branch여부(0:no 1:yes)
pushStack(stack,mapPoint); //push mapPoint
}
}
압축파일 내 파일목록
mase.c
mase.dat
stacks.c
stacksADT.h
참고 자료
없음