Giter VIP home page Giter VIP logo

maze's Introduction

Maze

使用DFS实现字符迷宫,提供默认和自定义迷宫大小。

Code

int migong::get(node start,node end)//求迷宫路径
{
	//入口 出口不通
	if(arr[1][1]==1||arr[end.x][end.y]==1)
	{
		return 0;
	}
	stack <node> s;
	node curpos;
	curpos=start;
	int curstep=1;
	do{
		if(arr[curpos.x][curpos.y]==0)//是通路
		{
			arr[curpos.x][curpos.y]=curstep;//足迹
			curpos.direction=0;//方向
			s.push(curpos);
			curstep++;
			if(curpos.x==end.x&&curpos.y==end.y)
				return 1;
			curpos=getnext(curpos,curpos.direction);
		}
		else//不是通路
		{
			if(!s.empty())
			{
				curpos=s.top();
				s.pop();
				curstep--;
				while(curpos.direction==3&&!s.empty())
				{
					arr[curpos.x][curpos.y]=-1;
					curpos=s.top();
					s.pop();
					curstep--;
				}
				if(curpos.direction<3)
				{
					curpos.direction++;
					s.push(curpos);
					curstep++;
					curpos=getnext(curpos,curpos.direction);
				}}}
	}while (!s.empty());
	return 2;//无法到达终点
}  

Screenshots

ChangeLog

ChangeLog

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.