private List<ICoordinates> ListOfVisible(int i, int j) { CCoordinatesLen cur = new CCoordinatesLen(); CCoordinatesLen co = new CCoordinatesLen(); co.X1=i; co.Y1=j; cur.Copy(co); cur.Len = 0; CCoordinatesLen co1=new CCoordinatesLen(); co1.Copy(co); co1.Len=0; List<ICoordinates> ret = new List<ICoordinates>(); List<CCoordinatesLen> forWithWall = new List<CCoordinatesLen>(); List<ICoordinates> allied=new List<ICoordinates>(); Stack<CCoordinatesLen> stack1 = new Stack<CCoordinatesLen>(); Stack<CCoordinatesLen> stack2 = new Stack<CCoordinatesLen>(); Stack<CCoordinatesLen> swap=null; ICoordinates temp = new CCoordinatesLen(); CCoordinatesLen forPush=new CCoordinatesLen(); ret.Add(co1); bool [,]gone=new bool[maxX+1,maxY+1]; stack1.Push(cur); gone[cur.X1, cur.Y1] = true; for(int y=0;y<VisibleRadius;y++) { while(stack1.Count!=0) { cur=new CCoordinatesLen(); cur.Copy(stack1.Pop()); temp.Copy(cur); allied=AlliedNodes(temp); foreach (ICoordinates x in allied) { if(!gone[x.X1,x.Y1] && !(map[x.X1,x.Y1]==TypesOfField.WALL)) { forPush=new CCoordinatesLen(); forPush.Copy(x); forPush.Len=y+1; stack2.Push(forPush); gone[x.X1,x.Y1]=true; } } } foreach( CCoordinatesLen x in stack2) { cur=new CCoordinatesLen(); cur.Copy(x); cur.Len=x.Len; forWithWall.Add(cur); } swap=stack2; stack2=stack1; stack1=swap; } //bool found=false; List<CCoordinatesLen> forWithOutWall = ListOfRadiusLen(co,VisibleRadius); // так. теперь сравниваем. и добавляем. foreach (CCoordinatesLen x in forWithOutWall) { if ((FINDEQUALNUMLEN(forWithWall, x) != -1) && (forWithWall[FINDEQUALNUMLEN(forWithWall, x)].Len == /* >=*/ x.Len)) { ret.Add(x); } } return ret; }
private List<CCoordinatesLen> ListOfRadiusLen(ICoordinates co, int Radius) { CCoordinatesLen cur=new CCoordinatesLen(); CCoordinatesLen co1=new CCoordinatesLen(); cur.Copy(co); co1.Copy(co); co1.Len=0; List<CCoordinatesLen> ret=new List<CCoordinatesLen>(); List<ICoordinates> allied=new List<ICoordinates>(); Stack<CCoordinatesLen> stack1 = new Stack<CCoordinatesLen>(); Stack<CCoordinatesLen> stack2 = new Stack<CCoordinatesLen>(); Stack<CCoordinatesLen> swap=null; ICoordinates temp = new CCoordinatesLen(); CCoordinatesLen forPush=new CCoordinatesLen(); ret.Add(co1); bool [,]gone=new bool[maxX+1,maxY+1]; stack1.Push(cur); gone[cur.X1, cur.Y1] = true; for(int y=0;y<Radius;y++) { while(stack1.Count!=0) { cur=new CCoordinatesLen(); cur.Copy(stack1.Pop()); temp.Copy(cur); allied=AlliedNodes(temp); foreach (ICoordinates x in allied) { if(!gone[x.X1,x.Y1]) { forPush=new CCoordinatesLen(); forPush.Copy(x); forPush.Len=y+1; stack2.Push(forPush); gone[x.X1,x.Y1]=true; } } } foreach( CCoordinatesLen x in stack2) { cur=new CCoordinatesLen(); cur.Copy(x); cur.Len=x.Len; ret.Add(cur); } swap=stack2; stack2=stack1; stack1=swap; } return ret; }