十五周——中国象棋棋盘

来源:互联网 发布:网络括扑结构图 编辑:程序博客网 时间:2024/05/16 17:02
/** Copyright (c) 2013, 烟台大学计算机学院* All rights reserved.* 作    者:申玉迪* 完成日期:2013 年 12 月 9 日* 版 本 号:v1.0* 输入描述: 无* 问题描述:中国象棋棋盘*/#include <iostream>#include <ctime>#include <cstdlib>using namespace std;void setdata(int a[8][8]);void out(int a[8][8]);void mine(int a[8][8],int x, int y);int main(){    int a[8][8],x,y;    setdata(a);    out(a);    cout<<"输入一个位置:";    cin>>x>>y;    mine(a,x,y);    return 0;}void setdata(int a[8][8]){    int i,j;    srand(time(NULL));//需要用当前时间作“种子”,以便每次运行取得的序列不同    for(i=0; i<8; i++)        for(j=0; j<8; j++)            a[i][j]=rand()%50+1;    return;}void out(int a[8][8]){    int i,j;    for(i=0; i<8; i++)    {        cout<<"第"<<i+1<<"行:";        for(j=0; j<8; j++)        {            cout<<a[i][j]<<" ";        }        cout<<endl;    }}void mine(int a[8][8],int x, int y){    cout<<"这个数是:"<<a[x][y]<<endl;    if(a[x-1][y]<=25)    {        if(x-2>=0&&y-1>=0&&y+1<8)        {            cout<<"("<<x-2<<","<<y-1<<","<<a[x-2][y-1]<<")"<<endl;            cout<<"("<<x-2<<","<<y+1<<","<<a[x-2][y+1]<<")"<<endl;        }    }    if(a[x][y-1]<=25)    {        if(x-1>=0&&y-2>=0&&x+1<8)        {            cout<<"("<<x-1<<","<<y-2<<","<<a[x-1][y-2]<<")"<<endl;            cout<<"("<<x+1<<","<<y-2<<","<<a[x+1][y-2]<<")"<<endl;        }    }    if(a[x+1][y]<=25)    {        if(x+2<8&&y-1>=0&&y+1<8)        {            cout<<"("<<x+2<<","<<y-1<<","<<a[x+2][y-1]<<")"<<endl;            cout<<"("<<x+2<<","<<y+1<<","<<a[x+2][y+1]<<")"<<endl;        }    }    if(a[x][y+1]<=25)    {        if(x-1>=0&&y+2<8&&x+1<8)        {            cout<<"("<<x+1<<","<<y+2<<","<<a[x+1][y+2]<<")"<<endl;            cout<<"("<<x-1<<","<<y+2<<","<<a[x-1][y+2]<<")"<<endl;        }    }}


 

 

只想到这样写,简单的算法没想出来,找了好久都没有找到可以参考的,求大神指导

原创粉丝点击