C/C++の宿題を片付けます 88代目
■ このスレッドは過去ログ倉庫に格納されています
0462デフォルトの名無しさん
2007/05/31(木) 13:40:43#include<stdio.h>
#include<memory.h>
#define DLIMIT 12
#define XSIZE 8
#define YSIZE 8
int gboard[XSIZE*YSIZE];int gxpos[DLIMIT];int gypos[DLIMIT];int i;
void knight_move(int x,int y,int depth){
if(depth > DLIMIT ){memset( gboard , 0 , sizeof( gboard ) );return;}
if(gboard[x*YSIZE+y] ){memset( gboard , 0 , sizeof( gboard ) );return;}
if(x < 0 ){ return; }if(x >= XSIZE ){ return; }if(y < 0 ){ return; }if(y >= YSIZE ){ return; }
gxpos[depth]=x;gypos[depth]=y;gboard[x*YSIZE+y] = true;
if(x==7 && y==7){for(i=0;i<=depth;i++){printf("(%d,%d)",gxpos[i],gypos[i]);}printf("GOAL\n");memset( gboard , 0 , sizeof( gboard ) );return;}
knight_move(x+1,y+2,depth+1);knight_move(x+2,y+1,depth+1);knight_move(x+2,y-1,depth+1);knight_move(x+1,y-2,depth+1);
knight_move(x-1,y-2,depth+1);knight_move(x-2,y-1,depth+1);knight_move(x-2,y+1,depth+1);knight_move(x-1,y+2,depth+1);}
int main(){memset( gboard , 0 , sizeof( gboard ) );knight_move(0,0,0);}
BCCで動くかシラネ
あってるかもシラネw
■ このスレッドは過去ログ倉庫に格納されています