maze.h
上传用户:sycq158
上传日期:2008-10-22
资源大小:15361k
文件大小:73k
- // Copyright: 胡小民,丁展 2002.5
- #ifndef _MAZE_H
- #define _MAZE_H
- #include "stdio.h"
- #include "stdlib.h"
- #include "iostream.h"
- #include "fstream.h"
- #include "mazeMake.h"
- #include "head.h"
- // tell others that this path cannot be accessed in fact it describe the new maze
- bool found=false;
- int step=0;
- class element;
- class Stack;
- class offsets;
- int Max(int x,int y ,int z,int w);
- void GenerateMaze();
- long SearchPath(Stack& _stack);
- void InitMark();
- void ShowMaze();
- void SimpleMaze();
- void SubAllocate(int count,Stack _stackarray[],int n,element position,
- int markall[CONST_MAZEX][CONST_MAZEY],bool mark[CONST_MAZEX][CONST_MAZEY],
- int pos[CONST_MAZEX][CONST_MAZEY],int &tag);
- void Allocate(Stack _stackarray[],int n,int type);
- void HumanSubAllocate(int count,Stack _stackarray[],int n,element position,
- int markall[CONST_MAZEX][CONST_MAZEY],bool mark[CONST_MAZEX][CONST_MAZEY],
- int pos[CONST_MAZEX][CONST_MAZEY],int &tag);
- bool Square1(int i,int j)
- {
- if(maze[i-1][j]&&maze[i][j-1]&&maze[i-1][j-1])
- return true;
- return false;
- }
- bool Square0(int i,int j)
- {
- if(!maze[i-1][j]&&!maze[i][j-1]&&!maze[i-1][j-1])
- return true;
- return false;
- }
- //----------------------------//
- class element
- {
- public:
- int row;
- int col;
- int dir;
- };
- bool EqualElement(const element a,const element b)
- {
- if(a.col==b.col&&a.row==b.row)
- return true;
- else
- return false;
- }
- class offsets
- {
- public:
- int vert;
- int horiz;
- public:
- void GetValue(int vert=0,int horiz=0)
- {
- this->vert=vert;
- this->horiz=horiz;
- }
- };
- //---------------------------//
- offsets move[4];
- class Stack
- {
- private:
- int top;
- element error;
- int count;
- public:
- element stack[MAX_STACK_SIZE];
- public:
- bool classmark[CONST_MAZEX][CONST_MAZEY];
- int method; // method是对走法的处理,顺时针,逆时针等等
- int sleep;
- public:
- Stack():top(-1)
- {
- this->InitMark();
- }
- void NewAntsCame()
- {
- this->InitMark();
- this->classmark[1][1]=true;
- ::markall[1][1]++;
- AddStack(1,1,1);
- row=1;
- col=1;
- dir=1;
- next_row=0;
- next_col=0;
- dir=0;
- count=0;
- pos[1][1]++;
- //------------------
- count++;
- position=DeleteStack();
- row=position.row;
- col=position.col;
- dir=position.dir;
- ::wild[1][1]=false;
- sleep=0;
- }
- void SetDir(int dir)
- {
- this->dir=dir;
- }
- void StackEmpty()
- {
- top=-1;
- }
- element DeleteStack()
- {
- if(top==-1)
- return error;
- else
- return stack[top--];
- }
- bool AddStack(const element & pa)
- {
- if(top==MAX_STACK_SIZE-1)
- return false;
- else
- {
- stack[++top]=pa;
- return true;
- }
- }
- bool AddStack(int row,int col,int dir)
- {
- if(top==MAX_STACK_SIZE-1)
- return false;
- else
- {
- top++;
- stack[top].row=row;
- stack[top].col=col;
- stack[top].dir=dir;
- return true;
- }
- }
- bool Empty()
- {
- if(top==-1)
- return true;
- else
- return false;
- }
- void InitMark();
- //
- private:
- int row,col,next_row,next_col,dir;
- element position;
- public:
- int SearchPathStepByStep(int markall[CONST_MAZEX][CONST_MAZEY],bool mark[CONST_MAZEX][CONST_MAZEY],int pos[CONST_MAZEX][CONST_MAZEY]);
- bool TestDir(int dir,int markall[CONST_MAZEX][CONST_MAZEY],bool mark[CONST_MAZEX][CONST_MAZEY],int pos[CONST_MAZEX][CONST_MAZEY]);
- bool TestDirection(int dir,int markall[CONST_MAZEX][CONST_MAZEY],bool mark[CONST_MAZEX][CONST_MAZEY],int pos[CONST_MAZEX][CONST_MAZEY]);
- bool HumanTestDirection(int dir,int markall[CONST_MAZEX][CONST_MAZEY],bool mark[CONST_MAZEX][CONST_MAZEY],int pos[CONST_MAZEX][CONST_MAZEY]);
- int HumanSearchPathStepByStep(int markall[CONST_MAZEX][CONST_MAZEY],bool mark[CONST_MAZEX][CONST_MAZEY],int pos[CONST_MAZEX][CONST_MAZEY]);
- int SearchPathStepByStepRandom();
- int GetLength()
- {
- return top;
- }
- element GetCurrentPosition()
- {
- element temp;
- temp.row=row;
- temp.col=col;
- temp.dir=0 ; // temp.dir=dir;
- return temp;
- }
- element GetLastPosition()
- {
- element temp;
- temp.row=next_row;
- temp.col=next_col;
- temp.dir=0;
- return temp;
- }
- ~Stack()
- {}
- };
- //--------------independent-------------------//
- void Stack::InitMark()
- {
- int i,j;
- for(i=0;i<CONST_MAZEX;i++)
- for(j=0;j<CONST_MAZEY;j++)
- {
- if(maze[i][j]==1)
- classmark[i][j]=true;
- else
- classmark[i][j]=false;
- }
- }
- // 1 2 4 8
- int Max(int x,int y ,int z,int w)
- {
- int max=x;
- int count=0;
- if(max<y)
- max=y;
- if(max<z)
- max=z;
- if(max<w)
- max=w;
- if(max==x)
- count|=1;
- if(max==y)
- count|=2;
- if(max==z)
- count|=4;
- if(max==w)
- count|=8;
- return count;
- }
- // if the direction is ok then i take it else i just be idle
- //hxm begin
- bool Stack::TestDir(int dir,int markall[CONST_MAZEX][CONST_MAZEY],bool mark[CONST_MAZEX][CONST_MAZEY],int pos[CONST_MAZEX][CONST_MAZEY])
- //hxm end
- {
- this->dir=dir;
- if(this->dir<0||this->dir>3)
- return false;
- next_row=row+move[dir].vert;
- next_col=col+move[dir].horiz;
- if(next_row==EXIT_ROW&&next_col==EXIT_COL)
- {
- found=true;
- ::mark[next_row][next_col]=true;
- ::markall[next_row][next_col]++;
-
- ::pos[next_row][next_col]++;
- ::pos[row][col]--;
- ::wild[next_row][next_col]=false;
- position.row=row;
- position.col=col;
- position.dir=--dir;
- AddStack(position);
- row=next_row;
- col=next_col;
- dir=3;
- AddStack(row,col,dir);
- count++;
- return true;
- }
- else
- // 墙 在栈里 别人设的墙
- if(!maze[next_row][next_col]&&!classmark[next_row][next_col]&&!mark[next_row][next_col])
- {
- classmark[next_row][next_col]=true;
- ::pos[row][col]--;
- ::pos[next_row][next_col]++;
- ::wild[next_row][next_col]=false;
- position.row=row;
- position.col=col;
- position.dir=++this->dir;
- AddStack(position);
- row=next_row;
- col=next_col;
- this->dir=0;
- count++;
- return true;
- }
- return false;
- }
- bool Stack::TestDirection(int dir,int markall[CONST_MAZEX][CONST_MAZEY],bool mark[CONST_MAZEX][CONST_MAZEY],int pos[CONST_MAZEX][CONST_MAZEY])
- {
- this->dir=dir;
- if(this->dir<0||this->dir>3)
- return false;
- int num=0;
- while(num<4)
- {
- this->dir=this->dir%4;
- next_row=row+move[this->dir].vert;
- next_col=col+move[this->dir].horiz;
- if(next_row==EXIT_ROW&&next_col==EXIT_COL)
- {
- found=true;
- classmark[next_row][next_col]=true;
- ::wild[next_row][next_col]=false;
-
- ::pos[next_row][next_col]++;
- ::pos[row][col]--;
- position.row=row;
- position.col=col;
- position.dir=--dir;
- AddStack(position);
- row=next_row;
- col=next_col;
- dir=3;
- AddStack(row,col,dir);
- count++;
- return true;
- }
- else
- if(!maze[next_row][next_col]&&!classmark[next_row][next_col]&&!mark[next_row][next_col])
- {
- classmark[next_row][next_col]=true;
- ::pos[row][col]--;
- ::pos[next_row][next_col]++;
- ::wild[next_row][next_col]=false;
-
- position.row=row;
- position.col=col;
- position.dir=++this->dir;
- AddStack(position);
- row=next_row;
- col=next_col;
- this->dir=0;
- count++;
- return true;
- }
- else
- {
- ++this->dir;
- num++;
- if(num==4)
- {
- ::mark[row][col]=true;// tell others donot take this way;
- count++;
- ::pos[row][col]--;
- ::markall[row][col]=UNACCESSABLE;
- position=DeleteStack();
- row=position.row;
- col=position.col;
- this->dir=position.dir;
- ::pos[row][col]++;
- return false;
- }
- }
- }
- return false;
- }
- bool Stack::HumanTestDirection(int dir,int markall[CONST_MAZEX][CONST_MAZEY],bool mark[CONST_MAZEX][CONST_MAZEY],int pos[CONST_MAZEX][CONST_MAZEY])
- {
- this->dir=dir;
- if(this->dir<0||this->dir>3)
- return false;
- int num=0;
- while(num<4)
- {
- this->dir=this->dir%4;
- next_row=row+move[this->dir].vert;
- next_col=col+move[this->dir].horiz;
- if(next_row==EXIT_ROW&&next_col==EXIT_COL)
- {
- found=true;
- classmark[next_row][next_col]=true;
- ::wild[next_row][next_col]=false;
-
- ::pos[next_row][next_col]++;
- ::pos[row][col]--;
- position.row=row;
- position.col=col;
- position.dir=--dir;
- AddStack(position);
- row=next_row;
- col=next_col;
- dir=3;
- AddStack(row,col,dir);
- count++;
- return true;
- }
- else
- if(!maze[next_row][next_col]&&!classmark[next_row][next_col]&&!mark[next_row][next_col])
- {
- classmark[next_row][next_col]=true;
- ::pos[row][col]--;
- ::pos[next_row][next_col]++;
- ::wild[next_row][next_col]=false;
-
- position.row=row;
- position.col=col;
- position.dir=++this->dir;
- AddStack(position);
- row=next_row;
- col=next_col;
- this->dir=0;
- count++;
- return true;
- }
- else
- {
- ++this->dir;
- num++;
- Stack temp;
- temp=*this;
- if(num==4)
- {
- ::mark[row][col]=true;// tell others donot take this way;
- count++;
- ::pos[row][col]--;
- ::markall[row][col]=UNACCESSABLE;
- position=DeleteStack();
- row=position.row;
- col=position.col;
- this->dir=position.dir;
- ::pos[row][col]++;
-
- int row1,col1,next_row1,next_col1;
- element position1;
- while(1)
- {
- int t=0;
- position1=temp.DeleteStack();
- row1=position1.row;
- col1=position1.col;
- temp.dir=position1.dir;
- while(t<4)
- {
- temp.dir=temp.dir%4;
- next_row1=row1+move[temp.dir].vert;
- next_col1=col1+move[temp.dir].horiz;
- if(!maze[next_row1][next_col1]&&!classmark[next_row1][next_col1]&&!mark[next_row1][next_col1])
- {
- return false;
- }
- temp.dir++;
- t++;
- }
- ::mark[row1][col1]=true;
- ::markall[row1][col1]=UNACCESSABLE;
- }
-
- return false;
- }
- }
- }
- return false;
- }
- int Stack::HumanSearchPathStepByStep(int markall[CONST_MAZEX][CONST_MAZEY],bool mark[CONST_MAZEX][CONST_MAZEY],int pos[CONST_MAZEX][CONST_MAZEY])
- {
- while(dir<4&&!found)
- {
- next_row=row+move[dir].vert;
- next_col=col+move[dir].horiz;
- if(next_row==EXIT_ROW&&next_col==EXIT_COL)
- {
- found=true;
- classmark[next_row][next_col]=true;
- ::wild[next_row][next_col]=false;
- ::pos[next_row][next_col]++;
- ::pos[row][col]--;
- position.row=row;
- position.col=col;
- position.dir=--dir;
- AddStack(position);
- row=next_row;
- col=next_col;
- dir=0;
- AddStack(row,col,dir);
- count++;
-
- }
- else
- {
- if(!maze[next_row][next_col]&&!classmark[next_row][next_col]&&!mark[next_row][next_col])
- {
- classmark[next_row][next_col]=true;
- ::pos[row][col]--;
- ::pos[next_row][next_col]++;
- ::wild[next_row][next_col]=false;
-
- position.row=row;
- position.col=col;
- position.dir=++dir;
- AddStack(position);
- row=next_row;
- col=next_col;
- dir=0;
- count++;
- return 0;
- }
- else
- {
- ++dir;
- if(dir==4)
- {
- if(!Empty()&&!found)
- {
- Stack temp;
- temp=*this;
- ::mark[row][col]=true;// tell others donot take this way;
- count++;
- ::pos[row][col]--;
- ::markall[row][col]=UNACCESSABLE;
- position=DeleteStack();
- row=position.row;
- col=position.col;
- dir=position.dir;
- ::pos[row][col]++;
-
- int row1,col1,next_row1,next_col1;
- element position1;
- while(1)
- {
- int t=0;
- position1=temp.DeleteStack();
- row1=position1.row;
- col1=position1.col;
- temp.dir=position1.dir;
- while(t<4)
- {
- temp.dir++;
- temp.dir=temp.dir%4;
- next_row1=row1+move[temp.dir].vert;
- next_col1=col1+move[temp.dir].horiz;
- if(!maze[next_row1][next_col1]&&!classmark[next_row1][next_col1]&&!mark[next_row1][next_col1])
- {
- return 0;
- }
- t++;
- }
- ::mark[row1][col1]=true;
- ::markall[row1][col1]=UNACCESSABLE;
- }
-
- return 0;
- }
- else
- return -1;
- }
- }
- }
- }
- if(found)
- {
- return count;
- }
- else
- {
- return 0;
- }
- }
- int Stack::SearchPathStepByStep(int markall[CONST_MAZEX][CONST_MAZEY],bool mark[CONST_MAZEX][CONST_MAZEY],int pos[CONST_MAZEX][CONST_MAZEY])
- {
- while(dir<4&&!found)
- {
- next_row=row+move[dir].vert;
- next_col=col+move[dir].horiz;
- if(next_row==EXIT_ROW&&next_col==EXIT_COL)
- {
- found=true;
- classmark[next_row][next_col]=true;
- ::wild[next_row][next_col]=false;
- ::pos[next_row][next_col]++;
- ::pos[row][col]--;
- position.row=row;
- position.col=col;
- position.dir=--dir;
- AddStack(position);
- row=next_row;
- col=next_col;
- dir=0;
- AddStack(row,col,dir);
- count++;
-
- }
- else
- {
- if(!maze[next_row][next_col]&&!classmark[next_row][next_col]&&!mark[next_row][next_col])
- {
- classmark[next_row][next_col]=true;
- ::pos[row][col]--;
- ::pos[next_row][next_col]++;
- ::wild[next_row][next_col]=false;
-
- position.row=row;
- position.col=col;
- position.dir=++dir;
- AddStack(position);
- row=next_row;
- col=next_col;
- dir=0;
- count++;
- return 0;
- }
- else
- {
- ++dir;
- if(dir==4)
- {
- if(!Empty()&&!found)
- {
- ::mark[row][col]=true;// tell others donot take this way;
- count++;
- ::pos[row][col]--;
- ::markall[row][col]=UNACCESSABLE;
- position=DeleteStack();
- row=position.row;
- col=position.col;
- dir=position.dir;
- ::pos[row][col]++;
- return 0;
- }
- else
- return -1;
- }
- }
- }
- }
- if(found)
- {
- return count;
- }
- else
- {
- return 0;
- }
- }
- int Stack::SearchPathStepByStepRandom()
- {
- int num=0;
- int method=rand()%2;
- dir=rand()%4;
- while(!found)
- {
- next_row=row+move[dir].vert;
- next_col=col+move[dir].horiz;
- if(next_row==EXIT_ROW&&next_col==EXIT_COL)
- {
- ::found=true;
- classmark[next_row][next_col]=true;
- ::pos[next_row][next_col]++;
- ::pos[row][col]--;
- position.row=row;
- position.col=col;
- position.dir=--dir;
- AddStack(position);
- row=next_row;
- col=next_col;
- dir=0;
- AddStack(row,col,dir);
- count++;
-
- }
- else
- {
- if(!maze[next_row][next_col]&&!classmark[next_row][next_col])
- {
- classmark[next_row][next_col]=true;
- ::pos[row][col]--;
- ::pos[next_row][next_col]++;
- position.row=row;
- position.col=col;
- position.dir=++dir;
- AddStack(position);
- row=next_row;
- col=next_col;
- dir=0;
- count++;
- return 0;
- }
- else
- {
- ++num;
- if(num==4)
- {
- if(!Empty()&&!found)
- {
- count++;
- ::pos[row][col]--;
- position=DeleteStack();
- row=position.row;
- col=position.col;
- dir=position.dir;
- ::pos[row][col]++;
- return 0;
- }
- else
- return -1;
- }
- }
- }
- if(method==0)
- dir=(++dir)%4;
- if(method==1)
- dir=((--dir)+4)%4;
- }
- if(found)
- {
- return count;
- }
- else
- {
- return 0;
- }
- }
- void SimpleMaze()
- {
- int i=1,j=1;
- maze[i][j]=0;
- int k;
- while(i!=EXIT_ROW||j!=EXIT_COL)
- {
- if(i==EXIT_ROW)
- {
- while(j!=EXIT_COL)
- maze[i][++j]=0;
- break;
- }
- if(j==EXIT_COL)
- {
- while(i!=EXIT_ROW)
- maze[++i][j]=0;
- break;
- }
- k=rand()%2;
- if(k==0)
- {
- i++;
- maze[i][j]=0;
- continue;
- }
- if(k==1)
- {
- j++;
- maze[i][j]=0;
- continue;
- }
- }
- }
- void GenerateMaze()
- {
- int i,j;
- int i1,j1;
- for(i=0;i<SIZEX_MAZE;i++)
- for(j=0;j<SIZEY_MAZE;j++)
- maze[i][j]=1;
- SimpleMaze();
- for(i=2;i<SIZEX_MAZE-2;i++)
- for(j=2;j<SIZEY_MAZE-2;j++)
- {
- if(Square1(i,j))
- {
- i1=i-rand()%2;
- j1=j-rand()%2;
- maze[i1][j1]=0;
- }
- }
- Stack _stack;
- if(SearchPath(_stack)==0)
- {
- SimpleMaze();
- }
- }
- void ShowMaze()
- {
- int i=0,j=0;
- for(i=1;i<SIZEX_MAZE-1;i++)
- {
- for(j=1;j<SIZEY_MAZE-1;j++)
- cout<<maze[i][j]<<" ";
- cout<<endl;
- }
- }
- void InitMark()
- {
- int i,j;
- for(i=0;i<CONST_MAZEX;i++)
- for(j=0;j<CONST_MAZEY;j++)
- {
- wild[i][j]=true;
- mark[i][j]=false;
- if(maze[i][j]==1)
- markall[i][j]=UNACCESSABLE;
- else
- markall[i][j]=0;
- pos[i][j]=0;
- }
- move[0].GetValue(-1,0);
- move[1].GetValue(0,1);
- move[2].GetValue(1,0);
- move[3].GetValue(0,-1);
- }
- long SearchPath(Stack & _stack)
- {
- int row,col,next_row,next_col,dir;
- long count=0;
- bool found=false;
- element position;
- InitMark();
- mark[1][1]=true;
- _stack.AddStack(1,1,1);
- while(!_stack.Empty()&&!found)
- {
- position=_stack.DeleteStack();
- row=position.row;
- col=position.col;
- dir=position.dir;
- while(dir<4&&!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;
- _stack.AddStack(position);
- row=next_row;
- col=next_col;
- dir=0;
- count++;
- }
- else
- ++dir;
- }
- }
- if(found)
- {
- return count;
- }
- else
- return 0;
- }
- void InitAll()
- {
- GenerateMaze();
- InitMark();
- }
- int Min(int x,int y ,int z,int w,bool xi,bool yi,bool zi,bool wi)
- {
- int m=x*y*z*w;
- int count;
- if(m==0)
- {
- count=0;
- if(x==0&&xi)
- count+=1;
- if(y==0&&yi)
- count+=2;
- if(z==0&&zi)
- count+=4;
- if(w==0&&wi)
- count+=8;
- return count;
- }
- return 0;
- // return 0 shows that it should do as priority and not the chance
- //如果这个时候有两个路口有人,一个路口没有人进去过,那么全塞到这个路口里面去
- }
- // hxm begin
- void SubAllocate(int count,Stack _stackarray[],int n,element position,int markall[CONST_MAZEX][CONST_MAZEY],bool mark[CONST_MAZEX][CONST_MAZEY],int pos[CONST_MAZEX][CONST_MAZEY],int &tag)
- // hxm end
- {
- int max,i;
- int num;
- int dir;
- int x=position.row;
- int y=position.col;
- int turn;
-
- switch(count)
- {
- case 1: // all go to (x-1,y)
- for(i=0;i<n;i++)
- {
- if(EqualElement(_stackarray[i].GetCurrentPosition(),position))
- {
-
- dir=0;
- if(tag==4)
- {
- _stackarray[i].TestDirection(dir,markall,mark,pos);
- tag=0;
- return ;
- }
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- max=markall[x+1][y];
- if(max<markall[x][y-1])
- { max=markall[x][y-1];}
- if(max<markall[x][y+1])
- { max=markall[x][y+1];}
- num=0;
- if(max==markall[x+1][y]) num+=2;
- if(max==markall[x][y-1]) num+=4;
- if(max==markall[x][y+1]) num+=8;
- tag++;
- SubAllocate(num,_stackarray,n,position,markall,mark,pos,tag);
- }
- }
- }
- break;
- case 2: // all go to (x+1,y)
- for(i=0;i<n;i++)
- {
- if(EqualElement(_stackarray[i].GetCurrentPosition(),position))
- {
- dir=2;
- if(tag==4)
- {
- _stackarray[i].TestDirection(dir,markall,mark,pos);
- tag=0;
- return ;
- }
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- max=markall[x-1][y];
- if(max<markall[x][y-1])
- { max=markall[x][y-1];}
- if(max<markall[x][y+1])
- { max=markall[x][y+1];}
- num=0;
- if(max==markall[x-1][y]) num+=1;
- if(max==markall[x][y-1]) num+=4;
- if(max==markall[x][y+1]) num+=8;
- tag++;
- SubAllocate(num,_stackarray,n,position,markall,mark,pos,tag);
- }
- }
- }
- break;
- case 3: // all to (x-1,y) and (x+1,y)
- turn=0;
- for(i=0;i<n;i++)
- {
- if(EqualElement(_stackarray[i].GetCurrentPosition(),position))
- {
- if(turn==0)
- {
- dir=0;
- if(tag==4)
- {
- _stackarray[i].TestDirection(dir,markall,mark,pos);
- tag=0;
- return ;
- }
- turn=1;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=2;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- turn=0;
- max=markall[x][y-1];
- if(max<markall[x][y+1])
- { max=markall[x][y+1];}
- num=0;
- if(max==markall[x][y-1]) num+=4;
- if(max==markall[x][y+1]) num+=8;
- tag++;
- SubAllocate(num,_stackarray,n,position,markall,mark,pos,tag);
- }
- }
- }
- else
- {
- dir=2;
- if(tag==4)
- {
- _stackarray[i].TestDirection(dir,markall,mark,pos);
- tag=0;
- return ;
- }
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=0;
- turn=0;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- turn=1;
- max=markall[x][y-1];
- if(max<markall[x][y+1])
- { max=markall[x][y+1] ;}
- num=0;
- if(max==markall[x][y-1]) num+=4;
- if(max==markall[x][y+1]) num+=8;
- tag++;
- SubAllocate(num,_stackarray,n,position,markall,mark,pos,tag);
- }
- }
- }
- }
- }
- break;
-
- case 4:
- // all go to (x,y-1)
- for(i=0;i<n;i++)
- {
- if(EqualElement(_stackarray[i].GetCurrentPosition(),position))
- {
- dir=3;
- if(tag==4)
- {
- _stackarray[i].TestDirection(dir,markall,mark,pos);
- tag=0;
- return ;
- }
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- max=markall[x-1][y];
- if(max<markall[x+1][y])
- { max=markall[x+1][y] ;}
- if(max<markall[x][y+1])
- { max=markall[x][y+1] ;}
- num=0;
- if(max==markall[x-1][y]) num+=1;
- if(max==markall[x+1][y]) num+=2;
- if(max==markall[x][y+1]) num+=8;
- tag++;
- SubAllocate(num,_stackarray,n,position,markall,mark,pos,tag);
- }
- }
- }
- break;
- case 5: // all go to (x-1,y) and (x,y-1)
- turn=0;
- for(i=0;i<n;i++)
- {
- if(EqualElement(_stackarray[i].GetCurrentPosition(),position))
- {
- if(turn==0)
- {
- dir=0;
- if(tag==4)
- {
- _stackarray[i].TestDirection(dir,markall,mark,pos);
- tag=0;
- return ;
- }
- turn=1;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=3;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- turn=0;
- max=markall[x+1][y];
- if(max<markall[x][y+1])
- { max=markall[x][y+1] ;}
- num=0;
- if(max==markall[x+1][y]) num+=2;
- if(max==markall[x][y+1]) num+=8;
- tag++;
- SubAllocate(num,_stackarray,n,position,markall,mark,pos,tag);
- }
- }
- }
- else
- {
- dir=3;
- if(tag==4)
- {
- _stackarray[i].TestDirection(dir,markall,mark,pos);
- tag=0;
- return ;
- }
- turn=0;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=0;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- turn=1;
- max=markall[x+1][y];
- if(max<markall[x][y+1])
- { max=markall[x][y+1] ;}
- num=0;
- if(max==markall[x+1][y]) num+=2;
- if(max==markall[x][y+1]) num+=8;
- tag++;
- SubAllocate(num,_stackarray,n,position,markall,mark,pos,tag);
- }
- }
- }
- }
- }
- break;
- case 6: // all go to (x+1,y) and (x,y-1)
- turn=0;
- for(i=0;i<n;i++)
- {
- if(EqualElement(_stackarray[i].GetCurrentPosition(),position))
- {
- if(turn==0)
- {
- turn=1;
- dir=2;
- if(tag==4)
- {
- _stackarray[i].TestDirection(dir,markall,mark,pos);
- tag=0;
- return ;
- }
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=3;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- turn=0;
- max=markall[x-1][y];
- if(max<markall[x][y+1])
- { max=markall[x][y+1] ;}
- num=0;
- if(max==markall[x-1][y]) num+=1;
- if(max==markall[x][y+1]) num+=8;
- tag++;
- SubAllocate(num,_stackarray,n,position,markall,mark,pos,tag);
- }
- }
- }
- else
- {
- dir=3;
- if(tag==4)
- {
- _stackarray[i].TestDirection(dir,markall,mark,pos);
- tag=0;
- return ;
- }
- turn=0;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=2;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- turn=1;
- max=markall[x-1][y];
- if(max<markall[x][y+1])
- { max=markall[x][y+1] ;}
- num=0;
- if(max==markall[x-1][y]) num+=1;
- if(max==markall[x][y+1]) num+=8;
- tag++;
- SubAllocate(num,_stackarray,n,position,markall,mark,pos,tag);
- }
- }
- }
- }
- }
- break;
- case 7:
- // all go to (x-1,y) and (x+1,y) and (x,y-1)
- turn=0;
- for(i=0;i<n;i++)
- {
- if(EqualElement(_stackarray[i].GetCurrentPosition(),position))
- {
- if(tag==4)
- {
- _stackarray[i].TestDirection(dir,markall,mark,pos);
- tag=0;
- return ;
- }
- switch(turn)
- {
- case 0:
- dir=0;
- turn=1;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=2;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=3;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- turn=0;
- dir=1;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=0;
- _stackarray[i].TestDirection(dir,markall,mark,pos);
-
- }
- }
- }
- }
- break;
- case 1:
- dir=2;
- turn=2;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=3;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=0;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- turn=1;
- dir=1;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=0;
- _stackarray[i].TestDirection(dir,markall,mark,pos);
-
- }
- }
- }
- }
- break;
- case 2:
- dir=3;
- turn=0;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=0;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=2;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- turn=2;
- dir=1;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=0;
- _stackarray[i].TestDirection(dir,markall,mark,pos);
-
- }
- }
- }
- }
- break;
- }
- }
- }
- break;
-
- case 8:
- // all go to (x,y+1)
- for(i=0;i<n;i++)
- {
- if(EqualElement(_stackarray[i].GetCurrentPosition(),position))
- {
- dir=1;
- if(tag==4)
- {
- _stackarray[i].TestDirection(dir,markall,mark,pos);
- tag=0;
- return ;
- }
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- max=markall[x-1][y];
- if(max<markall[x+1][y])
- { max=markall[x+1][y];}
- if(max<markall[x][y-1])
- { max=markall[x][y-1];}
- num=0;
- if(max==markall[x-1][y]) num+=1;
- if(max==markall[x+1][y]) num+=2;
- if(max==markall[x][y-1]) num+=4;
- tag++;
- SubAllocate(num,_stackarray,n,position,markall,mark,pos,tag);
-
- }
- }
- }
- break;
-
- case 9:
- // all go to (x-1,y) and (x,y+1)
- turn=0;
- for(i=0;i<n;i++)
- {
- if(EqualElement(_stackarray[i].GetCurrentPosition(),position))
- {
- dir=0;
- if(tag==4)
- {
- _stackarray[i].TestDirection(dir,markall,mark,pos);
- tag=0;
- return ;
- }
- if(turn==0)
- {
- turn=1;
- dir=0;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=1;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- turn=0;
- max=markall[x+1][y];
- if(max<markall[x][y-1])
- { max=markall[x][y-1] ;}
- num=0;
- if(max==markall[x+1][y]) num+=2;
- if(max==markall[x][y-1]) num+=4;
- tag++;
- SubAllocate(num,_stackarray,n,position,markall,mark,pos,tag);
- }
- }
- }
- else
- {
- dir=1;
- turn=0;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=0;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- turn=1;
- max=markall[x+1][y];
- if(max<markall[x][y-1])
- { max=markall[x][y-1];}
- num=0;
- if(max==markall[x+1][y]) num+=2;
- if(max==markall[x][y-1]) num+=4;
- tag++;
- SubAllocate(num,_stackarray,n,position,markall,mark,pos,tag);
- }
- }
- }
- }
- }
-
- break;
- case 10:
- // all go to (x+1,y) and (x,y+1)
- turn=0;
- for(i=0;i<n;i++)
- {
- if(EqualElement(_stackarray[i].GetCurrentPosition(),position))
- {
- dir=0;
- if(tag==4)
- {
- _stackarray[i].TestDirection(dir,markall,mark,pos);
- tag=0;
- return ;
- }
- if(turn==0)
- {
- turn=1;
- dir=2;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=1;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- turn=0;
- max=markall[x-1][y];
- if(max<markall[x][y-1])
- { max=markall[x][y-1] ;}
- num=0;
- if(max==markall[x-1][y]) num+=1;
- if(max==markall[x][y-1]) num+=4;
- tag++;
- SubAllocate(num,_stackarray,n,position,markall,mark,pos,tag);
- }
- }
- }
- else
- {
- dir=1;
- turn=0;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=0;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- turn=1;
- max=markall[x+1][y];
- if(max<markall[x][y-1])
- { max=markall[x][y-1] ;}
- num=0;
- if(max==markall[x+1][y]) num+=2;
- if(max==markall[x][y-1]) num+=4;
- tag++;
- SubAllocate(num,_stackarray,n,position,markall,mark,pos,tag);
- }
- }
- }
- }
- }
-
- break;
- case 11:
- // all go to (x-1,y) and (x+1,y) and (x,y+1)
- turn=0;
- for(i=0;i<n;i++)
- {
- if(EqualElement(_stackarray[i].GetCurrentPosition(),position))
- {
- dir=0;
- if(tag==4)
- {
- _stackarray[i].TestDirection(dir,markall,mark,pos);
- tag=0;
- return ;
- }
- switch(turn)
- {
- case 0:
- dir=0;
- turn=1;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=2;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=1;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- turn=0;
- dir=3;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=0;
- _stackarray[i].TestDirection(dir,markall,mark,pos);
-
- }
- }
- }
- }
- break;
- case 1:
- dir=2;
- turn=2;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=1;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=0;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- turn=1;
- dir=3;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=0;
- _stackarray[i].TestDirection(dir,markall,mark,pos);
-
- }
- }
- }
- }
- break;
- case 2:
- dir=1;
- turn=0;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=0;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=2;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- turn=2;
- dir=3;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=0;
- _stackarray[i].TestDirection(dir,markall,mark,pos);
-
- }
- }
- }
- }
- break;
- }
- }
- }
- break;
- case 12:
- // all go to (x,y-1) and (x,y+1)
- turn=0;
- for(i=0;i<n;i++)
- {
- if(EqualElement(_stackarray[i].GetCurrentPosition(),position))
- {
- dir=0;
- if(tag==4)
- {
- _stackarray[i].TestDirection(dir,markall,mark,pos);
- tag=0;
- return ;
- }
- if(turn==0)
- {
- turn=1;
- dir=3;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=1;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- turn=0;
- max=markall[x-1][y];
- if(max<markall[x+1][y])
- { max=markall[x+1][y] ;}
- num=0;
- if(max==markall[x-1][y]) num+=1;
- if(max==markall[x+1][y]) num+=2;
- tag++;
- SubAllocate(num,_stackarray,n,position,markall,mark,pos,tag);
- }
- }
- }
- else
- {
- dir=1;
- turn=0;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=3;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- turn=1;
- max=markall[x-1][y];
- if(max<markall[x+1][y])
- { max=markall[x+1][y] ;}
- num=0;
- if(max==markall[x-1][y]) num+=1;
- if(max==markall[x+1][y]) num+=2;
- tag++;
- SubAllocate(num,_stackarray,n,position,markall,mark,pos,tag);
- }
- }
- }
- }
- }
-
- break;
- case 13:
- // all go to (x-1,y) and (x,y-1) and (x,y+1)
- turn=0;
- for(i=0;i<n;i++)
- {
- if(EqualElement(_stackarray[i].GetCurrentPosition(),position))
- {
- dir=0;
- if(tag==4)
- {
- _stackarray[i].TestDirection(dir,markall,mark,pos);
- tag=0;
- return ;
- }
- switch(turn)
- {
- case 0:
- dir=0;
- turn=1;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=3;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=1;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- turn=0;
- dir=2;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=0;
- _stackarray[i].TestDirection(dir,markall,mark,pos);
-
- }
- }
- }
- }
- break;
- case 1:
- dir=3;
- turn=2;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=1;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=0;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- turn=1;
- dir=2;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=0;
- _stackarray[i].TestDirection(dir,markall,mark,pos);
-
- }
- }
- }
- }
- break;
- case 2:
- dir=1;
- turn=0;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=0;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=3;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- turn=2;
- dir=2;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=0;
- _stackarray[i].TestDirection(dir,markall,mark,pos);
-
- }
- }
- }
- }
- break;
- }
- }
- }
- break;
- case 14:
- // all go to (x+1,y) and (x,y-1) and (x,y+1)
- turn=0;
- for(i=0;i<n;i++)
- {
- if(EqualElement(_stackarray[i].GetCurrentPosition(),position))
- {
- dir=0;
- if(tag==4)
- {
- _stackarray[i].TestDirection(dir,markall,mark,pos);
- tag=0;
- return ;
- }
- switch(turn)
- {
- case 0:
- dir=2;
- turn=1;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=3;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=1;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- turn=0;
- dir=0;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=0;
- _stackarray[i].TestDirection(dir,markall,mark,pos);
-
- }
- }
- }
- }
- break;
- case 1:
- dir=3;
- turn=2;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=1;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=1;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- turn=1;
- dir=2;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=0;
- _stackarray[i].TestDirection(dir,markall,mark,pos);
-
- }
- }
- }
- }
- break;
- case 2:
- dir=1;
- turn=0;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=2;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=3;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- turn=2;
- dir=0;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=0;
- _stackarray[i].TestDirection(dir,markall,mark,pos);
-
- }
- }
- }
- }
- break;
-
- }
- }
- }
- break;
- case 15: // all go to (x-1,y) and (x+1,y) and (x,y-1) and (x,y+1)
- turn=0;
- for(i=0;i<n;i++)
- {
- if(EqualElement(_stackarray[i].GetCurrentPosition(),position))
- {
- dir=0;
- if(tag==4)
- {
- _stackarray[i].TestDirection(dir,markall,mark,pos);
- tag=0;
- return ;
- }
- switch(turn)
- {
- case 0:
- dir=0;
- _stackarray[i].TestDirection(dir,markall,mark,pos);
- turn=1;
- break;
- case 1:
- dir=1;
- _stackarray[i].TestDirection(dir,markall,mark,pos);
- turn=2;
- break;
- case 2:
- dir=2;
- _stackarray[i].TestDirection(dir,markall,mark,pos);
- turn=3;
- break;
- case 3:
- dir=3;
- _stackarray[i].TestDirection(dir,markall,mark,pos);
- turn=0;
- break;
- }
- }
- }
- break;
- default:
- break;
- }
- }
- void HumanSubAllocate(int count,Stack _stackarray[],int n,element position,int markall[CONST_MAZEX][CONST_MAZEY],bool mark[CONST_MAZEX][CONST_MAZEY],int pos[CONST_MAZEX][CONST_MAZEY],int &tag)
- // hxm end
- {
- int max,i;
- int num;
- int dir;
- int x=position.row;
- int y=position.col;
- int turn;
-
- switch(count)
- {
- case 1: // all go to (x-1,y)
- for(i=0;i<n;i++)
- {
- if(EqualElement(_stackarray[i].GetCurrentPosition(),position))
- {
-
- dir=0;
- if(tag==4)
- {
- _stackarray[i].HumanTestDirection(dir,markall,mark,pos);
- tag=0;
- return ;
- }
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- max=markall[x+1][y];
- if(max<markall[x][y-1])
- { max=markall[x][y-1];}
- if(max<markall[x][y+1])
- { max=markall[x][y+1];}
- num=0;
- if(max==markall[x+1][y]) num+=2;
- if(max==markall[x][y-1]) num+=4;
- if(max==markall[x][y+1]) num+=8;
- tag++;
- HumanSubAllocate(num,_stackarray,n,position,markall,mark,pos,tag);
- }
- }
- }
- break;
- case 2: // all go to (x+1,y)
- for(i=0;i<n;i++)
- {
- if(EqualElement(_stackarray[i].GetCurrentPosition(),position))
- {
- dir=2;
- if(tag==4)
- {
- _stackarray[i].HumanTestDirection(dir,markall,mark,pos);
- tag=0;
- return ;
- }
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- max=markall[x-1][y];
- if(max<markall[x][y-1])
- { max=markall[x][y-1];}
- if(max<markall[x][y+1])
- { max=markall[x][y+1];}
- num=0;
- if(max==markall[x-1][y]) num+=1;
- if(max==markall[x][y-1]) num+=4;
- if(max==markall[x][y+1]) num+=8;
- tag++;
- HumanSubAllocate(num,_stackarray,n,position,markall,mark,pos,tag);
- }
- }
- }
- break;
- case 3: // all to (x-1,y) and (x+1,y)
- turn=0;
- for(i=0;i<n;i++)
- {
- if(EqualElement(_stackarray[i].GetCurrentPosition(),position))
- {
- if(turn==0)
- {
- dir=0;
- if(tag==4)
- {
- _stackarray[i].HumanTestDirection(dir,markall,mark,pos);
- tag=0;
- return ;
- }
- turn=1;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=2;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- turn=0;
- max=markall[x][y-1];
- if(max<markall[x][y+1])
- { max=markall[x][y+1];}
- num=0;
- if(max==markall[x][y-1]) num+=4;
- if(max==markall[x][y+1]) num+=8;
- tag++;
- HumanSubAllocate(num,_stackarray,n,position,markall,mark,pos,tag);
- }
- }
- }
- else
- {
- dir=2;
- if(tag==4)
- {
- _stackarray[i].HumanTestDirection(dir,markall,mark,pos);
- tag=0;
- return ;
- }
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=0;
- turn=0;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- turn=1;
- max=markall[x][y-1];
- if(max<markall[x][y+1])
- { max=markall[x][y+1] ;}
- num=0;
- if(max==markall[x][y-1]) num+=4;
- if(max==markall[x][y+1]) num+=8;
- tag++;
- HumanSubAllocate(num,_stackarray,n,position,markall,mark,pos,tag);
- }
- }
- }
- }
- }
- break;
-
- case 4:
- // all go to (x,y-1)
- for(i=0;i<n;i++)
- {
- if(EqualElement(_stackarray[i].GetCurrentPosition(),position))
- {
- dir=3;
- if(tag==4)
- {
- _stackarray[i].HumanTestDirection(dir,markall,mark,pos);
- tag=0;
- return ;
- }
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- max=markall[x-1][y];
- if(max<markall[x+1][y])
- { max=markall[x+1][y] ;}
- if(max<markall[x][y+1])
- { max=markall[x][y+1] ;}
- num=0;
- if(max==markall[x-1][y]) num+=1;
- if(max==markall[x+1][y]) num+=2;
- if(max==markall[x][y+1]) num+=8;
- tag++;
- HumanSubAllocate(num,_stackarray,n,position,markall,mark,pos,tag);
- }
- }
- }
- break;
- case 5: // all go to (x-1,y) and (x,y-1)
- turn=0;
- for(i=0;i<n;i++)
- {
- if(EqualElement(_stackarray[i].GetCurrentPosition(),position))
- {
- if(turn==0)
- {
- dir=0;
- if(tag==4)
- {
- _stackarray[i].HumanTestDirection(dir,markall,mark,pos);
- tag=0;
- return ;
- }
- turn=1;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=3;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- turn=0;
- max=markall[x+1][y];
- if(max<markall[x][y+1])
- { max=markall[x][y+1] ;}
- num=0;
- if(max==markall[x+1][y]) num+=2;
- if(max==markall[x][y+1]) num+=8;
- tag++;
- HumanSubAllocate(num,_stackarray,n,position,markall,mark,pos,tag);
- }
- }
- }
- else
- {
- dir=3;
- if(tag==4)
- {
- _stackarray[i].HumanTestDirection(dir,markall,mark,pos);
- tag=0;
- return ;
- }
- turn=0;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=0;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- turn=1;
- max=markall[x+1][y];
- if(max<markall[x][y+1])
- { max=markall[x][y+1] ;}
- num=0;
- if(max==markall[x+1][y]) num+=2;
- if(max==markall[x][y+1]) num+=8;
- tag++;
- HumanSubAllocate(num,_stackarray,n,position,markall,mark,pos,tag);
- }
- }
- }
- }
- }
- break;
- case 6: // all go to (x+1,y) and (x,y-1)
- turn=0;
- for(i=0;i<n;i++)
- {
- if(EqualElement(_stackarray[i].GetCurrentPosition(),position))
- {
- if(turn==0)
- {
- turn=1;
- dir=2;
- if(tag==4)
- {
- _stackarray[i].HumanTestDirection(dir,markall,mark,pos);
- tag=0;
- return ;
- }
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=3;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- turn=0;
- max=markall[x-1][y];
- if(max<markall[x][y+1])
- { max=markall[x][y+1] ;}
- num=0;
- if(max==markall[x-1][y]) num+=1;
- if(max==markall[x][y+1]) num+=8;
- tag++;
- HumanSubAllocate(num,_stackarray,n,position,markall,mark,pos,tag);
- }
- }
- }
- else
- {
- dir=3;
- if(tag==4)
- {
- _stackarray[i].HumanTestDirection(dir,markall,mark,pos);
- tag=0;
- return ;
- }
- turn=0;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=2;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- turn=1;
- max=markall[x-1][y];
- if(max<markall[x][y+1])
- { max=markall[x][y+1] ;}
- num=0;
- if(max==markall[x-1][y]) num+=1;
- if(max==markall[x][y+1]) num+=8;
- tag++;
- HumanSubAllocate(num,_stackarray,n,position,markall,mark,pos,tag);
- }
- }
- }
- }
- }
- break;
- case 7:
- // all go to (x-1,y) and (x+1,y) and (x,y-1)
- turn=0;
- for(i=0;i<n;i++)
- {
- if(EqualElement(_stackarray[i].GetCurrentPosition(),position))
- {
- if(tag==4)
- {
- _stackarray[i].HumanTestDirection(dir,markall,mark,pos);
- tag=0;
- return ;
- }
- switch(turn)
- {
- case 0:
- dir=0;
- turn=1;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=2;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=3;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- turn=0;
- dir=1;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=0;
- _stackarray[i].HumanTestDirection(dir,markall,mark,pos);
-
- }
- }
- }
- }
- break;
- case 1:
- dir=2;
- turn=2;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=3;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=0;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- turn=1;
- dir=1;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=0;
- _stackarray[i].HumanTestDirection(dir,markall,mark,pos);
-
- }
- }
- }
- }
- break;
- case 2:
- dir=3;
- turn=0;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=0;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=2;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- turn=2;
- dir=1;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=0;
- _stackarray[i].HumanTestDirection(dir,markall,mark,pos);
-
- }
- }
- }
- }
- break;
- }
- }
- }
- break;
-
- case 8:
- // all go to (x,y+1)
- for(i=0;i<n;i++)
- {
- if(EqualElement(_stackarray[i].GetCurrentPosition(),position))
- {
- dir=1;
- if(tag==4)
- {
- _stackarray[i].HumanTestDirection(dir,markall,mark,pos);
- tag=0;
- return ;
- }
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- max=markall[x-1][y];
- if(max<markall[x+1][y])
- { max=markall[x+1][y];}
- if(max<markall[x][y-1])
- { max=markall[x][y-1];}
- num=0;
- if(max==markall[x-1][y]) num+=1;
- if(max==markall[x+1][y]) num+=2;
- if(max==markall[x][y-1]) num+=4;
- tag++;
- HumanSubAllocate(num,_stackarray,n,position,markall,mark,pos,tag);
-
- }
- }
- }
- break;
-
- case 9:
- // all go to (x-1,y) and (x,y+1)
- turn=0;
- for(i=0;i<n;i++)
- {
- if(EqualElement(_stackarray[i].GetCurrentPosition(),position))
- {
- dir=0;
- if(tag==4)
- {
- _stackarray[i].HumanTestDirection(dir,markall,mark,pos);
- tag=0;
- return ;
- }
- if(turn==0)
- {
- turn=1;
- dir=0;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=1;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- turn=0;
- max=markall[x+1][y];
- if(max<markall[x][y-1])
- { max=markall[x][y-1] ;}
- num=0;
- if(max==markall[x+1][y]) num+=2;
- if(max==markall[x][y-1]) num+=4;
- tag++;
- HumanSubAllocate(num,_stackarray,n,position,markall,mark,pos,tag);
- }
- }
- }
- else
- {
- dir=1;
- turn=0;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=0;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- turn=1;
- max=markall[x+1][y];
- if(max<markall[x][y-1])
- { max=markall[x][y-1];}
- num=0;
- if(max==markall[x+1][y]) num+=2;
- if(max==markall[x][y-1]) num+=4;
- tag++;
- HumanSubAllocate(num,_stackarray,n,position,markall,mark,pos,tag);
- }
- }
- }
- }
- }
-
- break;
- case 10:
- // all go to (x+1,y) and (x,y+1)
- turn=0;
- for(i=0;i<n;i++)
- {
- if(EqualElement(_stackarray[i].GetCurrentPosition(),position))
- {
- dir=0;
- if(tag==4)
- {
- _stackarray[i].HumanTestDirection(dir,markall,mark,pos);
- tag=0;
- return ;
- }
- if(turn==0)
- {
- turn=1;
- dir=2;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=1;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- turn=0;
- max=markall[x-1][y];
- if(max<markall[x][y-1])
- { max=markall[x][y-1] ;}
- num=0;
- if(max==markall[x-1][y]) num+=1;
- if(max==markall[x][y-1]) num+=4;
- tag++;
- HumanSubAllocate(num,_stackarray,n,position,markall,mark,pos,tag);
- }
- }
- }
- else
- {
- dir=1;
- turn=0;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=0;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- turn=1;
- max=markall[x+1][y];
- if(max<markall[x][y-1])
- { max=markall[x][y-1] ;}
- num=0;
- if(max==markall[x+1][y]) num+=2;
- if(max==markall[x][y-1]) num+=4;
- tag++;
- HumanSubAllocate(num,_stackarray,n,position,markall,mark,pos,tag);
- }
- }
- }
- }
- }
-
- break;
- case 11:
- // all go to (x-1,y) and (x+1,y) and (x,y+1)
- turn=0;
- for(i=0;i<n;i++)
- {
- if(EqualElement(_stackarray[i].GetCurrentPosition(),position))
- {
- dir=0;
- if(tag==4)
- {
- _stackarray[i].HumanTestDirection(dir,markall,mark,pos);
- tag=0;
- return ;
- }
- switch(turn)
- {
- case 0:
- dir=0;
- turn=1;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=2;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=1;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- turn=0;
- dir=3;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=0;
- _stackarray[i].HumanTestDirection(dir,markall,mark,pos);
-
- }
- }
- }
- }
- break;
- case 1:
- dir=2;
- turn=2;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=1;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=0;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- turn=1;
- dir=3;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=0;
- _stackarray[i].HumanTestDirection(dir,markall,mark,pos);
-
- }
- }
- }
- }
- break;
- case 2:
- dir=1;
- turn=0;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=0;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=2;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- turn=2;
- dir=3;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=0;
- _stackarray[i].HumanTestDirection(dir,markall,mark,pos);
-
- }
- }
- }
- }
- break;
- }
- }
- }
- break;
- case 12:
- // all go to (x,y-1) and (x,y+1)
- turn=0;
- for(i=0;i<n;i++)
- {
- if(EqualElement(_stackarray[i].GetCurrentPosition(),position))
- {
- dir=0;
- if(tag==4)
- {
- _stackarray[i].HumanTestDirection(dir,markall,mark,pos);
- tag=0;
- return ;
- }
- if(turn==0)
- {
- turn=1;
- dir=3;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=1;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- turn=0;
- max=markall[x-1][y];
- if(max<markall[x+1][y])
- { max=markall[x+1][y] ;}
- num=0;
- if(max==markall[x-1][y]) num+=1;
- if(max==markall[x+1][y]) num+=2;
- tag++;
- HumanSubAllocate(num,_stackarray,n,position,markall,mark,pos,tag);
- }
- }
- }
- else
- {
- dir=1;
- turn=0;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=3;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- turn=1;
- max=markall[x-1][y];
- if(max<markall[x+1][y])
- { max=markall[x+1][y] ;}
- num=0;
- if(max==markall[x-1][y]) num+=1;
- if(max==markall[x+1][y]) num+=2;
- tag++;
- HumanSubAllocate(num,_stackarray,n,position,markall,mark,pos,tag);
- }
- }
- }
- }
- }
-
- break;
- case 13:
- // all go to (x-1,y) and (x,y-1) and (x,y+1)
- turn=0;
- for(i=0;i<n;i++)
- {
- if(EqualElement(_stackarray[i].GetCurrentPosition(),position))
- {
- dir=0;
- if(tag==4)
- {
- _stackarray[i].HumanTestDirection(dir,markall,mark,pos);
- tag=0;
- return ;
- }
- switch(turn)
- {
- case 0:
- dir=0;
- turn=1;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=3;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=1;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- turn=0;
- dir=2;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=0;
- _stackarray[i].HumanTestDirection(dir,markall,mark,pos);
-
- }
- }
- }
- }
- break;
- case 1:
- dir=3;
- turn=2;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=1;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=0;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- turn=1;
- dir=2;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=0;
- _stackarray[i].HumanTestDirection(dir,markall,mark,pos);
-
- }
- }
- }
- }
- break;
- case 2:
- dir=1;
- turn=0;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=0;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=3;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- turn=2;
- dir=2;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=0;
- _stackarray[i].HumanTestDirection(dir,markall,mark,pos);
-
- }
- }
- }
- }
- break;
- }
- }
- }
- break;
- case 14:
- // all go to (x+1,y) and (x,y-1) and (x,y+1)
- turn=0;
- for(i=0;i<n;i++)
- {
- if(EqualElement(_stackarray[i].GetCurrentPosition(),position))
- {
- dir=0;
- if(tag==4)
- {
- _stackarray[i].HumanTestDirection(dir,markall,mark,pos);
- tag=0;
- return ;
- }
- switch(turn)
- {
- case 0:
- dir=2;
- turn=1;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=3;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=1;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- turn=0;
- dir=0;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=0;
- _stackarray[i].HumanTestDirection(dir,markall,mark,pos);
-
- }
- }
- }
- }
- break;
- case 1:
- dir=3;
- turn=2;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=1;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=1;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- turn=1;
- dir=2;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=0;
- _stackarray[i].HumanTestDirection(dir,markall,mark,pos);
-
- }
- }
- }
- }
- break;
- case 2:
- dir=1;
- turn=0;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=2;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=3;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- turn=2;
- dir=0;
- if(_stackarray[i].TestDir(dir,markall,mark,pos)==false)
- {
- dir=0;
- _stackarray[i].HumanTestDirection(dir,markall,mark,pos);
-
- }
- }
- }
- }
- break;
-
- }
- }
- }
- break;
- case 15: // all go to (x-1,y) and (x+1,y) and (x,y-1) and (x,y+1)
- turn=0;
- for(i=0;i<n;i++)
- {
- if(EqualElement(_stackarray[i].GetCurrentPosition(),position))
- {
- dir=0;
- if(tag==4)
- {
- _stackarray[i].HumanTestDirection(dir,markall,mark,pos);
- tag=0;
- return ;
- }
- switch(turn)
- {
- case 0:
- dir=0;
- _stackarray[i].HumanTestDirection(dir,markall,mark,pos);
- turn=1;
- break;
- case 1:
- dir=1;
- _stackarray[i].HumanTestDirection(dir,markall,mark,pos);
- turn=2;
- break;
- case 2:
- dir=2;
- _stackarray[i].HumanTestDirection(dir,markall,mark,pos);
- turn=3;
- break;
- case 3:
- dir=3;
- _stackarray[i].HumanTestDirection(dir,markall,mark,pos);
- turn=0;
- break;
- }
- }
- }
- break;
- default:
- break;
- }
- }
- void Allocate(Stack _stackarray[],int n,int type)
- {
- int x,y;
- int count=0;
- int i=0;
- int dir=0;
- element position;
- int turn=0;
- int length=0;
- int countnum=0;
- bool once=true;
- int maze[CONST_MAZEX][CONST_MAZEY];
- int markall[CONST_MAZEX][CONST_MAZEY]; // record the num of ants of go into the path
- bool mark[CONST_MAZEX][CONST_MAZEY]; // record that some path is not accessable
- int pos[CONST_MAZEX][CONST_MAZEY]; // record all objects position at the same time
- bool wild[CONST_MAZEX][CONST_MAZEY];
- Stack newStack[CONST_ANT_NUM];
- ::step++;
- for(i=0;i<n;i++)
- newStack[i]=_stackarray[i];
- for(i=0;i<CONST_MAZEX;i++)
- for(int j=0;j<CONST_MAZEY;j++)
- {
- maze[i][j]=::maze[i][j];
- markall[i][j]=::markall[i][j];
- mark[i][j]=::mark[i][j];
- pos[i][j]=::pos[i][j];
- wild[i][j]=::wild[i][j];
- }
- for(x=1;x<SIZEX_MAZE-1;x++)
- for(y=1;y<SIZEY_MAZE-1;y++)
- {
- if(pos[x][y]<=0)
- continue;
- else
- {
- position.row=x;
- position.col=y;
- position.dir=1;
-
- count=Min(markall[x-1][y],markall[x+1][y],markall[x][y-1],markall[x][y+1],wild[x-1][y],
- wild[x+1][y],wild[x][y-1],wild[x][y+1]);
-
- if(count!=0)
- {
- switch(count)
- {
- case 1:
- case 2:
- case 4:
- case 8:
- {
- for(i=0;i<n;i++)
- {
- if(EqualElement(_stackarray[i].GetCurrentPosition(),position))
- {
- if(count==1)
- dir=0; //all go to (x-1,y)
- else if(count==2)
- dir=2; // all go to(x+1,y)
- else if(count==4)
- dir=3; // all to to (x,y-1)
- else if(count==8)
- dir=1; // all go to (x,y+1)
- newStack[i].SetDir(dir);
- newStack[i].SearchPathStepByStep(markall,mark,pos);
- }
- }
- break;
- }
- case 3:
- case 5:
- case 6:
- {
- turn=0;
- for(i=0;i<n;i++)
- {
- if(EqualElement(_stackarray[i].GetCurrentPosition(),position))
- {
- if(turn==0)
- {
- if(count== 3 || count ==5)
- dir=0;
- else if(count==6) // all go to (x+1,y) and (x,y-1)
- dir=2;
- newStack[i].SetDir(dir);
- newStack[i].SearchPathStepByStep(markall,mark,pos);
- turn=1;
- }
- else
- {
- if(count==3)
- dir=2; // all to (x-1,y) and (x+1,y)
- else if(count==5 || count==6)
- dir=3; // all go to (x-1,y) and (x,y-1)
- newStack[i].SetDir(dir);
- newStack[i].SearchPathStepByStep(markall,mark,pos);
- turn=0;
- }
- // //if((++countnum)==n) return;
- }
- }
- break;
- }
- case 7:
- case 11:
- case 13:
- case 14:
- {
- // 7: all go to (x-1,y) and (x+1,y) and (x,y-1)
- // 11: all go to (x-1,y) and (x+1,y) and (x,y+1)
- // 13: all go to (x-1,y) and (x,y-1) and (x,y+1)
- // 14: all go to (x+1,y) and (x,y-1) and (x,y+1)
- turn=0;
- for(i=0;i<n;i++)
- {
- if(EqualElement(_stackarray[i].GetCurrentPosition(),position))
- {
- switch(turn)
- {
- case 0:
- if(count==7 || count ==11 || count==13)
- dir=0;
- else
- dir=2;
- newStack[i].SetDir(dir);
- newStack[i].SearchPathStepByStep(markall,mark,pos);
- turn=1;
- break;
- case 1:
- if(count==7 || count==11)
- dir=2;
- else
- dir=3;
- newStack[i].SetDir(dir);
- newStack[i].SearchPathStepByStep(markall,mark,pos);
- turn=2;
- break;
- case 2:
- if(count==7)
- dir=3;
- else
- dir=1;
- newStack[i].SetDir(dir);
- newStack[i].SearchPathStepByStep(markall,mark,pos);
- turn=0;
- break;
- }
- }
- }
- break;
- }
-
- case 9: // all go to (x-1,y) and (x,y+1)
- case 10: // all go to (x+1,y) and (x,y+1)
- case 12: // all go to (x,y-1) and (x,y+1)
- {
- turn=0;
- for(i=0;i<n;i++)
- {
- if(EqualElement(_stackarray[i].GetCurrentPosition(),position))
- {
- switch(turn)
- {
- case 0:
- if(count==9)
- dir=0;
- else if(count==10)
- dir=2;
- else if(count==12)
- dir=3;
- newStack[i].SetDir(dir);
- newStack[i].SearchPathStepByStep(markall,mark,pos);
- turn=1;
- break;
- case 1:
- dir=1;
- newStack[i].SetDir(dir);
- newStack[i].SearchPathStepByStep(markall,mark,pos);
- turn=0;
- break;
- }
- }
- }
- break;
- }
- case 15:
- {
- cout<<"error in allocate"<<endl;
- exit(0);
- }
- default:
- break;
-
- }
- }
- else
- {
- // count the max priority
-
- count=Max(markall[x-1][y],markall[x+1][y],markall[x][y-1],markall[x][y+1]);
- int tag=0;
- if(type==HUMAN)
- HumanSubAllocate(count,newStack,n,position,::markall,mark,pos,tag);
- else
- SubAllocate(count,newStack,n,position,::markall,mark,pos,tag);
- }
-
- }
- }
- for(i=0;i<n;i++)
- _stackarray[i]=newStack[i];
- }
- #endif