From 56a93b0fa41455a56c7104cdf5e6a0958cbfc5f7 Mon Sep 17 00:00:00 2001 From: royus <> Date: Mon, 27 Aug 2018 23:08:32 +0900 Subject: [PATCH] not done --- source/solver.c | 281 +++++++++++++++++++++++++----------------------- 1 file changed, 148 insertions(+), 133 deletions(-) diff --git a/source/solver.c b/source/solver.c index ba77daa..e1edab2 100644 --- a/source/solver.c +++ b/source/solver.c @@ -1,7 +1,7 @@ /* solver.c */ -/* Last Change: 2018/08/26 (Sun) 23:31:34. */ +/* Last Change: 2018/08/27 (Mon) 23:01:56. */ -#define MAX_ATTEMPS 100000 +#define MAX_ATTEMPS 10000 #include #include @@ -16,6 +16,9 @@ int connected[8*72*72/2+1]={}; //connected[0]=(number of connected lines) int depth,height,width; int goalx,goaly,goalz; int lines; +int dx[6]={-1,0,0,1,0,0}; +int dy[6]={0,-1,0,0,1,0}; +int dz[6]={0,0,-1,0,0,1}; //z,y,x void read(void){ //read problem @@ -73,129 +76,132 @@ void read(void){ //read problem return; } -int randline(void){ //return random line number - return rand()%lines+1; -} - -void shuffle(int array[],int start,int end){ - int i,j,t; - if(end==start) - return; - for(i=start;i0&&avail[nowz][nowy][nowx-1]>=2) - isbranch++; - if(nowy>0&&avail[nowz][nowy-1][nowx]>=2) - isbranch++; - if(nowz>0&&avail[nowz-1][nowy][nowx]>=2) - isbranch++; - if(nowx=2) - isbranch++; - if(nowy=2) - isbranch++; - if(nowz=2) - isbranch++; - if(isbranch>0){ - avail[nowz][nowy][nowx]=1; - return 0; - } - if(avail[nowz][nowy][nowx]==1) - avail[nowz][nowy][nowx]=2; - int i,src=0; +int available(int z,int y, int x){ //return 1 when (nowx,nowy,nowz) can be connected to goal + int i,src=0,contd,isbranch; + int history[8*72*72],index=0; + int nowx=x,nowy=y,nowz=z; int searchorder[6]; //x+-,y+-,z+- /* for(i=0;i<6;i++) */ - /* searchorder[i]=-1; */ - if(nowx>goalx){ - searchorder[src]=0; - src++; - }else - searchorder[5+src]=0; - if(nowy>goaly){ - searchorder[src]=1; - src++; - }else - searchorder[4+src]=1; - if(nowz>goalz){ - searchorder[src]=2; - src++; - }else - searchorder[3+src]=2; - if(nowx0&&available(nowx-1,nowy,nowz,0)) - return 1; - break; - case 1: - if(nowy>0&&available(nowx,nowy-1,nowz,0)) - return 1; - break; - case 2: - if(nowz>0&&available(nowx,nowy,nowz-1,0)) - return 1; - break; - case 3: - if(nowx=width||nowy>=height||nowz>=depth){ + printf("error %d %d %d\n",nowx,nowy,nowz); + /* printf("%d, %d\n",index,history[index]); */ + /* printf("%d %d %d\n",dx[history[index]],dy[history[index]],dz[history[index]]); */ + return 0; + } + if(avail[nowz][nowy][nowx]==-1){ //goal + return 1; } - if(avail[nowz][nowy][nowx]==2) - avail[nowz][nowy][nowx]=1; + isbranch=-1; + if(nowx>0&&avail[nowz][nowy][nowx-1]>=2) + isbranch++; + if(nowy>0&&avail[nowz][nowy-1][nowx]>=2) + isbranch++; + if(nowz>0&&avail[nowz-1][nowy][nowx]>=2) + isbranch++; + if(nowx=2) + isbranch++; + if(nowy=2) + isbranch++; + if(nowz=2) + isbranch++; + if(isbranch>0&&index){ + avail[nowz][nowy][nowx]=0; + index--; + if(nowx-dx[history[index]]<0||nowy-dy[history[index]]<0||nowz-dx[history[index]]<0||nowx-dz[history[index]]>=width||nowy-dy[history[index]]>=height||nowz-dz[history[index]]>=depth){ + /* printf("something wrong\n"); */ + }else{ + nowx-=dx[history[index]]; + nowy-=dy[history[index]]; + nowz-=dz[history[index]]; + avail[nowz][nowy][nowx]=1; + printf("%d %d %d -\n",nowx,nowy,nowz); + /* return 0;//goback */ + continue; + } + } + if(avail[nowz][nowy][nowx]==1) + avail[nowz][nowy][nowx]=2; + if(nowx>goalx){ + searchorder[src]=0; + src++; + }else + searchorder[5+src]=0; + if(nowy>goaly){ + searchorder[src]=1; + src++; + }else + searchorder[4+src]=1; + if(nowz>goalz){ + searchorder[src]=2; + src++; + }else + searchorder[3+src]=2; + if(nowx=width||nowy+dy[searchorder[i]]>=height||nowz+dz[searchorder[i]]>=depth) + continue; + if(avail[nowz+dz[searchorder[i]]][nowy+dy[searchorder[i]]][nowx+dx[searchorder[i]]]==1){ + contd=0; + nowx+=dx[searchorder[i]]; + nowy+=dy[searchorder[i]]; + nowz+=dz[searchorder[i]]; + /* printf("%d %d %d\n",dx[searchorder[i]],dy[searchorder[i]],dz[searchorder[i]]); */ + printf("%d %d %d +\n",nowx,nowy,nowz); + history[index]=searchorder[i]; + /* printf("%d\n",index); */ + index++; + } + } + if(avail[nowz][nowy][nowx]==3||index==0) + return 0; + if(contd&&index){ + avail[nowz][nowy][nowx]=0; + index--; + if(nowx-dx[history[index]]<0||nowy-dy[history[index]]<0||nowz-dx[history[index]]<0||nowx-dz[history[index]]>=width||nowy-dy[history[index]]>=height||nowz-dz[history[index]]>=depth){ + /* printf("something wrong\n"); */ + }else{ + nowx-=dx[history[index]]; + nowy-=dy[history[index]]; + nowz-=dz[history[index]]; + avail[nowz][nowy][nowx]=1; + printf("%d %d %d -\n",nowx,nowy,nowz); + /* printf("%d %d %d\n",dx[history[index]],dy[history[index]],dz[history[index]]); */ + continue; + } + } + } return 0; } @@ -228,7 +234,7 @@ int connectable(int linea,int lineb){ //return 1 if linea can be connected when printf("Error: Line %d\n",linea); return 0; } - return available(startx,starty,startz,1); + return available(startz,starty,startx); } void connect(int line){ //connect line @@ -256,9 +262,9 @@ void delete(int line){ //delete line } int solve(void){ //return 1 when solved, 0 when cannot - int i,j,linea,lineb; + int i,linea,lineb[10000]; for(i=0;i