好玩的独立钻石跳棋!!!!!!!!!!!紧急啊

qiangqiang1112 2002-05-29 04:01:17
就是一个十字型的棋盘(例如,在9x9的方盘的四个角上各去掉3x3的部分),布满了棋子,只有一个空的(现在,规定它位于棋盘的中心)
棋子行进的规则是 棋子只能横向或者纵向行进,而且一颗棋子要想移动,必须跳过另一个棋子,那么被跳过的这个棋子将被去掉
例如1、2、3号位置中,1.和2号上有棋子,那么1号棋子就跳到了3号,而2号棋子将被去掉
......
诸如此类的走法
能否找到一个有效算法,能使最后棋盘上只剩下一个棋子????
...全文
221 24 打赏 收藏 转发到动态 举报
写回复
用AI写文章
24 条回复
切换为时间正序
请发表友善的回复…
发表回复
qiangqiang1112 2002-06-07
  • 打赏
  • 举报
回复
哦…………………………!!!!!!!!!!!!!!!!!!!!!!
我看到了,明白了!!!!!!!!
可是: kensta() 大哥,你的程序怎么和exe不同呢,是不是我还要自己编译那几个文件啊
qiangqiang1112 2002-06-07
  • 打赏
  • 举报
回复
你们的action()函数是干什么的啊
好象没说明啊
imagex 2002-06-06
  • 打赏
  • 举报
回复
改进了前面某位的代码,如下:
int tableai[TABLESIZE][TABLESIZE];
int findn=0;
struct {
int x,y;
int d,res;
}history[TABLESIZE*TABLESIZE-16];
int steps=0;

void move(int x,int y,int d){
tableai[x][y]=NONE_NAIL;
switch(d){
case LEFT:tableai[x-1][y]=NONE_NAIL;tableai[x-2][y]=NAIL;break;
case RIGHT:tableai[x+1][y]=NONE_NAIL;tableai[x+2][y]=NAIL;break;
case UP:tableai[x][y-1]=NONE_NAIL;tableai[x][y-2]=NAIL;break;
case DOWN:tableai[x][y+1]=NONE_NAIL;tableai[x][y+2]=NAIL;break;
}
history[steps].x=x;
history[steps].y=y;
history[steps].d=d;
steps++;
}
void demove(int x,int y,int d){
tableai[x][y]=NAIL;
switch(d){
case LEFT:tableai[x-1][y]=NAIL;tableai[x-2][y]=NONE_NAIL;break;
case RIGHT:tableai[x+1][y]=NAIL;tableai[x+2][y]=NONE_NAIL;break;
case UP:tableai[x][y-1]=NAIL;tableai[x][y-2]=NONE_NAIL;break;
case DOWN:tableai[x][y+1]=NAIL;tableai[x][y+2]=NONE_NAIL;break;
}
steps--;
}

void showmove(){
int i;
int t[TABLESIZE][TABLESIZE];
redraw();
for(i=0;i<TABLESIZE*TABLESIZE;i++)t[0][i]=table[0][i];
for(i=0;i<steps;i++){
delay(1000);
action(history[i].x,history[i].y);
switch(history[i].d){
case LEFT:action(history[i].x-2,history[i].y);break;
case RIGHT:action(history[i].x+2,history[i].y);break;
case UP:action(history[i].x,history[i].y-2);break;
case DOWN:action(history[i].x,history[i].y+2);break;
}
}
for(i=0;i<TABLESIZE*TABLESIZE;i++)table[0][i]=t[0][i];
getch();
}
int teststep(int x,int y,int d){
int i,j=0,k=0;
switch(d){
case LEFT:if(x>1&&tableai[x-1][y]==NAIL&&tableai[x-2][y]==NONE_NAIL)j=1;break;
case RIGHT:if(x<TABLESIZE-2&&tableai[x+1][y]==NAIL&&tableai[x+2][y]==NONE_NAIL)j=1;break;
case UP: if(y>1&&tableai[x][y-1]==NAIL&&tableai[x][y-2]==NONE_NAIL)j=1;break;
case DOWN:if(y<TABLESIZE-2&&tableai[x][y+1]==NAIL&&tableai[x][y+2]==NONE_NAIL)j=1;break;
}
if(!j)return 0;
move(x,y,d);
for(i=0;i<TABLESIZE;i++)
for(j=0;j<TABLESIZE;j++)
if(tableai[i][j]==NAIL){
k=teststep(i,j,UP)+
teststep(i,j,DOWN)+
teststep(i,j,LEFT)+
teststep(i,j,RIGHT);
}
if(steps==(TABLESIZE*TABLESIZE-18))
//printf("%d ",++findn);
{showmove();}
demove(x,y,d);
return k;
}
void franchai(){
int i,j;
steps=TABLESIZE*TABLESIZE-17;
for(i=0;i<TABLESIZE;i++)
for(j=0;j<TABLESIZE;j++){
tableai[i][j]=table[i][j];
if(tableai[i][j]==NAIL)steps--;
}
teststep(TABLESIZE/2-2,TABLESIZE/2,RIGHT);
}
这个更快了
kensta 2002-06-06
  • 打赏
  • 举报
回复
应该是因为解法太多了吧,我试着显示找到的解法数量,几分钟内找到了15xxx多个,被我中断了。
kensta 2002-06-05
  • 打赏
  • 举报
回复
这个算法可以用在7*7的格子上,速度上可以了(奇快不超过1秒就有解)
int tableai[TABLESIZE][TABLESIZE];
int findn=0;
struct {
int x,y;
int d,res;
}history[TABLESIZE*TABLESIZE-16];
int steps=0;

void move(int x,int y,int d){
tableai[x][y]=NONE_NAIL;
switch(d){
case LEFT:tableai[x-1][y]=NONE_NAIL;tableai[x-2][y]=NAIL;break;
case RIGHT:tableai[x+1][y]=NONE_NAIL;tableai[x+2][y]=NAIL;break;
case UP:tableai[x][y-1]=NONE_NAIL;tableai[x][y-2]=NAIL;break;
case DOWN:tableai[x][y+1]=NONE_NAIL;tableai[x][y+2]=NAIL;break;
}
history[steps].x=x;
history[steps].y=y;
history[steps].d=d;
steps++;
}
void demove(int x,int y,int d){
tableai[x][y]=NAIL;
switch(d){
case LEFT:tableai[x-1][y]=NAIL;tableai[x-2][y]=NONE_NAIL;break;
case RIGHT:tableai[x+1][y]=NAIL;tableai[x+2][y]=NONE_NAIL;break;
case UP:tableai[x][y-1]=NAIL;tableai[x][y-2]=NONE_NAIL;break;
case DOWN:tableai[x][y+1]=NAIL;tableai[x][y+2]=NONE_NAIL;break;
}
steps--;
}

void showmove(){
int i;
int t[TABLESIZE][TABLESIZE];
redraw();
for(i=0;i<TABLESIZE*TABLESIZE;i++)t[0][i]=table[0][i];
for(i=0;i<steps;i++){
delay(1000);
action(history[i].x,history[i].y);
switch(history[i].d){
case LEFT:action(history[i].x-2,history[i].y);break;
case RIGHT:action(history[i].x+2,history[i].y);break;
case UP:action(history[i].x,history[i].y-2);break;
case DOWN:action(history[i].x,history[i].y+2);break;
}
}
for(i=0;i<TABLESIZE*TABLESIZE;i++)table[0][i]=t[0][i];
getch();
}
int teststep(int x,int y,int d){
int i,j=0,k=0;
switch(d){
case LEFT:if(x>1&&tableai[x-1][y]==NAIL&&tableai[x-2][y]==NONE_NAIL)j=1;break;
case RIGHT:if(x<TABLESIZE-2&&tableai[x+1][y]==NAIL&&tableai[x+2][y]==NONE_NAIL)j=1;break;
case UP: if(y>1&&tableai[x][y-1]==NAIL&&tableai[x][y-2]==NONE_NAIL)j=1;break;
case DOWN:if(y<TABLESIZE-2&&tableai[x][y+1]==NAIL&&tableai[x][y+2]==NONE_NAIL)j=1;break;
}
if(!j)return 0;
move(x,y,d);
for(i=0;i<TABLESIZE;i++)
for(j=0;j<TABLESIZE;j++)
if(tableai[i][j]==NAIL){
k=teststep(i,j,UP)+
teststep(i,j,DOWN)+
teststep(i,j,LEFT)+
teststep(i,j,RIGHT);
}
if(steps==(TABLESIZE*TABLESIZE-18))
//printf("%d ",++findn);
{showmove();}
demove(x,y,d);
return k;
}
void franchai(){
int i,j;
steps=TABLESIZE*TABLESIZE-17;
for(i=0;i<TABLESIZE;i++)
for(j=0;j<TABLESIZE;j++){
tableai[i][j]=table[i][j];
if(tableai[i][j]==NAIL)steps--;
}
teststep(TABLESIZE/2-2,TABLESIZE/2,RIGHT);
}
FranklinBHU 2002-06-05
  • 打赏
  • 举报
回复
我玩过这个游戏,可没想过算法。
qiangqiang1112 2002-06-03
  • 打赏
  • 举报
回复
kensta() 大哥
如果把最大深度都判断完了的时间复杂度是多少阿
您的 游戏能不能让我看看阿
谢谢了
qiangqiang_1112@163.com
lbl20020123 2002-06-03
  • 打赏
  • 举报
回复
gz
goodsong 2002-06-02
  • 打赏
  • 举报
回复
关注
java悠悠 2002-06-02
  • 打赏
  • 举报
回复
关注,
kensta 2002-06-02
  • 打赏
  • 举报
回复
我认为,每次都只有一部分棋子可动,并且他们只能在四个方向上跳出
对所有棋子的可动的步进行下一步的计算,不过这样可能太多了。

如果可以找到一种方法,判断出死路的状态,(可能是孤立的子的数量和距离的关系)那么就可以减少判断的开销。

如果用树来表示,
struct node{
int x,y;
node *up,*dn,*lf,*rt;
};
建立一个四叉树,其最大深度为:7*7-2*2*4-2
然后判断某个节点的最大深度加该节点的深度是否达到最大深度。

这还是没有避免大量的计算,可能机器还算不完。

如果能在一个局部找出失败的必然状态,幸许还有可能吧。
游戏已经编好了,ai算法还在思考中。
qiangqiang1112 2002-06-01
  • 打赏
  • 举报
回复
那怎么样的数据结构才能说合理呢
我现在是没什么头绪了
killjoy 2002-06-01
  • 打赏
  • 举报
回复
我在想想呀!
wulj99 2002-06-01
  • 打赏
  • 举报
回复
不容易哦
killjoy 2002-05-31
  • 打赏
  • 举报
回复
我的一点思路:1。每跳一次少一个点,那么最快的完成方法的跳动次数应该与点数相同。
2。每跳一次,就会出现两个连续的空格。
3。点的特点:根据周围邻居的数量来划分:2,3,4。
4。任何一个点周围必须要有一个点,也就是说必须要有一个邻居,否则这个点将为不可跳。
5。一个点可跳的条件是它的十字上两个点的距离上有空点。
Kusk 2002-05-31
  • 打赏
  • 举报
回复
用广度优先就可以,只要数据结构合理是没有问题的。
Zig 2002-05-31
  • 打赏
  • 举报
回复
显然搜索,只要机器速度够快。
qiangqiang1112 2002-05-31
  • 打赏
  • 举报
回复
然后呢
killjoy 2002-05-30
  • 打赏
  • 举报
回复
我对你问题感兴趣,可是你没有说清楚9X9是指的是方格还是点呀!如果方便你画张图给我,另外1,2,3代表什么呢?位置?具体是什么样的位置呢?
kensta 2002-05-30
  • 打赏
  • 举报
回复
感兴趣,我试试?
加载更多回复(4)

33,009

社区成员

发帖
与我相关
我的任务
社区描述
数据结构与算法相关内容讨论专区
社区管理员
  • 数据结构与算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧