早就开发了一个旋转程序
- #include<cstdio>
- #include<cstring>
- char a[4000]="x";
- char b[4000]="x";
- char minb[4000]="x";
- int sz=19; //19
- char t[3]="";
- char fn[100]="";
- int main(int argc, char* argv[])
- {
- FILE *fi,*fo;
- fi=fopen(argv[1],"rb");
- int c=fread(a,sizeof(char),3999,fi);
- memcpy(minb,a,c);
- fclose(fi);
- char x,y,x2,y2;
- for(int r=1; r<=7; r++) //find the minimal
- {
- int j=0; //b pos
- for(int i=0; i<c; i++)
- {
- if(a[i]==';' && (a[i+1]=='B'|| a[i+1]=='W') && a[i+2]=='[')
- {
- x=a[i+3],y=a[i+4];
- memcpy(b+j,a+i,3),j+=3;
- t[0]=x,t[1]=y;
- switch(r)
- {
- case 1: //up-down
- x2=x,y2=sz-(y-'a')+'a'-1; //ok
- break;
- case 2: //left-right
- x2=sz-(x-'a')+'a'-1,y2=y; //ok
- break;
- case 3: //rotate a-clock 90
- x2=y,y2=sz-(x-'a')+'a'-1;
- break;
- case 4: //rotate a-clock 180
- x2=sz-(x-'a')+'a'-1,y2=sz-(y-'a')+'a'-1;
- break;
- case 5: //rotate clock 90
- x2=sz-(y-'a')+'a'-1,y2=x;
- break;
- case 6: //rotate by line 135
- x2=y,y2=x;
- break;
- case 7: //rotate by line 45
- x2=sz-(y-'a')+'a'-1,y2=sz-(x-'a')+'a'-1;
- break;
- }
- if(t[0]<'t')
- t[0]=x2,t[1]=y2;
- memcpy(b+j,t,2),j+=2;
- i+=5;
- //memcpy(b+j,a+i,1),j+=1;
- }
- //else
- memcpy(b+j,a+i,1),j+=1;
- }
- if(strcmp(b,minb)<0)
- memcpy(minb,b,c);
- }
- sprintf(fn,"%s_min.sgf",argv[1]);
- fo=fopen(fn,"wb");
- fwrite(minb,sizeof(char),c,fo);
- fclose(fo);
- printf("%d\n",c);
- }
复制代码 |