|
迷宫求解的过程演示(9) AnsiString tempStr=Mark; tempStr=tempStr.SubString(1,5); if(tempStr!=SMark) { ShowMessage("该文件不是迷宫数据文件"); throw(0); } int tRow,tCol; int tEdition; fscanf(in, " %d ", &tEdition); fscanf(in, " %d %d ", &tRow,&tCol); LabyrinthCol=tCol; LabyrinthRow=tRow; SetMemory(); int tState; for(int k=0;k<LabyrinthRow*LabyrinthCol;k++) { if(feof(in)) { ShowMessage("文件被破坏!!!"); throw(0); } fscanf(in, " %d ", &tState); LabyrinthData[k]=tState; } FileName=tFileName; IsChange=false; } __finally { fclose(in); } } catch(...) { return false; } }
bool CLabyrinth::GetNewPoint(int Direction,int &tRow,int &tCol,int &tState) { int OldCol=tCol; int OldRow=tRow; switch(Direction) { case 1: tCol=tCol;tRow=tRow-1;break; case 2: tCol=tCol+1;tRow=tRow;break; case 3: tCol=tCol;tRow=tRow+1;break; case 4: tCol=tCol-1;tRow=tRow;break; default :return false; } tState=GetState(tRow+1,tCol+1); if((tState==STATE_PASStState==STATE_END)&&AlreadPassList->IndexOf(Format("X:%dY:%d",ARRAYOFCONST((OldCol+1,OldRow+1))))<0)//发现了新的结点 return true; return false; } void CLabyrinth::FindResult(TPoint *tStartPoint) {
|