资源描述:
《骑士游戏设计.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、/******************************qishi*****************************/#include#includestructmemory{intsence[8][8];intboard[8][8];intmem[8];intlast;}mem[64];inth[8]={2,1,-1,-2,-2,-1,1,2};intv[8]={-1,-2,-2,-1,1,2,2,1};intboard[8][8]={0};intsence[8][8]=
2、{{2,3,4,4,4,4,3,2},{3,4,6,6,6,6,4,3},{4,6,8,8,8,8,6,4},{4,6,8,8,8,8,6,4},{4,6,8,8,8,8,6,4},{4,6,8,8,8,8,6,4},{3,4,6,6,6,6,4,3},{2,3,4,4,4,4,3,2}};introw,col,hty=0;intcomeon(void);voidgoback(void);intfindmin(int[]);voidsavemem(int);voidaltsence(void);voidprint();vo
3、idprintmem(int);/*PREPARE*/voidprepare(void){inti,j,ha[8],va[8];for(i=0;i<64;i++){mem[i].last=-1;for(j=0;j<8;j++)mem[i].mem[j]=0;}printf("InputBeginPoint:");scanf("%d%d",row,col);board[row][col]=1;for(i=0;i<8;i++){ha[i]=row+h[i];va[i]=col+v[i];if(ha[i]>=0&&ha[i]
4、<=7&&va[i]>=0&&va[i]<=7)sence[ha[i>[va[i>--;}savemem(0);/*print(hty);*/hty++;}/*COMEON!!*/intcomeon(void){inti,ha[8],va[8],b[8]={9,9,9,9,9,9,9,9},info=0;for(i=0;i<8;i++){ha[i]=row+h[i];va[i]=col+v[i];if(ha[i]>=0&&ha[i]<=7&&va[i]>=0&&va[i]<=7)if(board[ha[i>[va[i>==
5、0&&mem[hty].mem[i]!=1)b[i]=sence[ha[i>[va[i>;}i=findmin(b);if(b[i]!=9);{row=ha[i];col=va[i];board[ha[i>[va[i>=1;altsence();savemem(i);/*printmem(hty);*/hty++;info=1;}return(info);}/*GOBACK~~*/voidgoback(void){inti,j;hty--;board[row][col]=0;row=row-h[mem[hty].last]
6、;col=col-v[mem[hty].last];mem[hty].mem[mem[hty+1].last]=1;for(i=0;i<8;i++)for(j=0;j<8;j++)sence[i][j]=mem[hty].sence[i][j];}/*PRINT*/voidprint(void){inti;for(i=0;i<64;i++){clrscr();printmem(i);getchar();}}/*PRINTMEM*/voidprintmem(intht){inti,j;printf("No.%dStep;
7、",ht);for(i=0;i<8;i++){for(j=0;j<8;j++)if(mem[ht].board[i][j]==0)printf("O");elseprintf("H");printf("");}}/*ALTSENCE*/voidaltsence(void){inti,ha[8],va[8];for(i=0;i<8;i++){ha[i]=row+h[i];va[i]=col+v[i];if(ha[i]>=0&&ha[i]<=7&&va[i]>=0&&va[i]<=7)sence[ha[i>[va[i>--
8、;}}/*SAVEMEM*/voidsavemem(intlt){inti,j;mem[hty].last=lt;for(i=0;i<8;i++)for(j=0;j<8;j++){mem[hty].sence[i][j]=sence[i][j];mem[hty].board[i][j]=board[i]