《骑士游戏设计》由会员分享,可在线阅读,更多相关《骑士游戏设计(6页珍藏版)》请在金锄头文库上搜索。
1、/*qishi */#include #include struct memoryint sence88 ; int board88 ; int mem8 ; int last ; mem64 ;int h8=2,1,-1,-2,-2,-1,1,2 ;int v8=-1,-2,-2,-1,1,2,2,1 ;int board88=0 ;int sence88=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、2,3,4,4,4,4,3,2 ;int row, col,hty=0 ;int comeon(void) ;void goback(void) ;int findmin(int) ;void savemem(int) ;void altsence(void) ;void print() ;void printmem(int) ;/* PREPARE */void prepare(void)int i, j, ha8,va8 ; for(i=0; i64; i+) memi.last=-1 ; for(j=0; j8; j+) memi.memj=0 ; printf(Input Begin
3、Point :n) ; scanf(%d%d,row,col) ; boardrowcol=1 ; for(i=0; i=0 & hai=0 & vaivai- ; savemem(0) ; /*print(hty) ; */ hty+ ;/* COMEON! */int comeon(void)int i, ha8, va8, b8=9,9,9,9,9,9,9,9, info=0 ; for(i=0; i=0 & hai=0 & vaivai=0 & memhty.memi!=1 ) bi=sencehaivai ; i=findmin(b) ; if( bi!=9 ) ; row=hai
4、; col=vai ; boardhaivai=1 ; altsence() ; savemem(i) ; /*printmem(hty) ; */ hty+ ; info=1 ; return (info) ;/* GOBACK */void goback(void)int i,j ; hty-; boardrowcol=0 ; row = row - hmemhty.last ; col = col - vmemhty.last ; memhty.memmemhty+1.last = 1 ; for(i=0; i8; i+) for(j=0; j8; j+) senceij=memhty.
5、senceij ;/* PRINT */void print(void)int i; for(i=0; i64; i+) clrscr(); printmem(i) ; getchar() ; /* PRINTMEM */void printmem(int ht)int i, j; printf(No.%d Step;n,ht) ; for(i=0; i8; i+) for(j=0; j8; j+) if( memht.boardij=0) printf(O ) ; else printf(H ) ; printf(n) ; /* ALTSENCE */void altsence(void)i
6、nt i, ha8, va8 ; for(i=0; i=0 & hai=0 & vaivai- ; /* SAVEMEM */void savemem(int lt)int i,j ; memhty.last=lt ; for(i=0; i8; i+) for(j=0; j8; j+) memhty.senceij = senceij ; memhty.boardij = boardij ; /* FINDMIN */int findmin(int c8)int i,j=0 ; for(i=0; i8; i+) if( ci cj ) j=i ; return (j) ;/* MAIN */m
7、ain()int i; prepare() ; i=comeon(); while( hty64 ) if(i) i=comeon() ; else goback() ; i=1; print(); /* 8 queen */#include int col8 , temp=0 ;void qu(int n) int pan(int) ; void pri(void) ; int t; if(n=0) t=4 ; else t=8 ; for(coln=0; colnt; coln+ ) if(pan(n) continue ; if (n!=7) qu(n+1); else pri() ;
8、void pri(void)int i, j;for (i=0; i8; i+) for (j=0; j8; j+) if( coli=j ) printf(Q ) ; else printf(X ) ; printf(n) ; temp+ ;printf(n%dn,temp) ;getchar();int pan(int t) int i,n=0 ; for(i=0; it; i+) if (coli=colt) n=1; break; if( (colt+t) = (coli+i) ) n=1; break; if( (colt-t) = (coli-i) ) n=1; break; return(n);main() printf(n) ; qu(0); printf(%dEndn,temp) ; /