我怎么能用一个用户给出的尺寸的棋盘。 [英] How can I man a chess board with a size that given from the user.

查看:68
本文介绍了我怎么能用一个用户给出的尺寸的棋盘。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好程序员!

你今天好吗?



i总是喜欢玩代码并做出任何想法:D。

但不幸的是我找不到功能/代码可以让我做以下事情:

制作一个棋盘,它的大小应由用户给出,我必须为每一个动作设置目的地,所以如果国际象棋板尺寸等于10;我应该有100个国际象棋棋盘(10 * 10),但我找不到允许我从用户那里取整数并将其设置为棋盘大小的代码,同时我将制作国际象棋棋盘块编号与用户给出的尺寸完美配合!



对不起我糟糕的英语,如果你们帮助我,我会很高兴的。 ^^



祝福!

Hello programmers!
How are you today ?

i always like to play with codes and make whatever get on my mind :D.
but unfortunately i couldn't find the function/code that can make me do the following:
make a chess board, and the size of it should be given by the user, and i have to set a destination for each single move, so if the chess board size is equal to 10; i should've 100 chess block(10*10), but i couldn't find the code that allow me to take an integer from the user and set it as a chess board size in the same time that i will make the chess board block number working perfect with the size that has been given by the user!

i'am sorry for my awful English, i'd be pleased if you guys helped me. ^^

Best wishes!

推荐答案

好的,我再次抱歉我的英语不好,我的意思是我怎么能*制作一个尺寸由用户给出的棋盘。



无论如何这是我试过的:

void getdata()

{

int m;

int v;



srand(time(0));

m = rand()%(n * n)+1 ;;

v = m-1;

if(m == 1)

{

x = m;

y = m;

}

否则如果(m == 2)

{

x = mv;
$ b $通过= M + v;

}

否则如果(m == 3)

{

x = mv;
$ b $通过= M + v;

}

否则如果(m == 4)

{

x = mv;
$ b $通过= M + v;

}

否则if(m == 5)

{

x = mv;
$ b $通过= M + v;

}

否则if(m == 6)

{

x = mv;
$ b $通过= M + v;

}

否则如果(m == 7)

{

x = mv;
$ b $通过= M + v;

}

否则如果(m == 8)

{

x = mv;
$ b $通过= M + v;

}

否则如果(m == 9)

{

x = mv;
$ b $通过= M + v;

}

否则if(m == 10)

{

x = mv;
$ b $通过= M + v;

}



if(m == 11)

{

x = m-v + 1;

y = m;

}

else if(m == 12)

{

x = m-v + 1;

y = m + v;

}

否则if(m == 13)

{

x = m-v + 1;

y = m + v;

}

否则如果(m == 14)

{

x = m-v + 1;

y = m + v;

}

否则如果(m == 15)

{

x = m-v + 1;

y = m + v;

}

否则如果(m == 16)

{

x = m-v + 1;

y = m + v;

}

否则如果(m == 17)

{

x = m-v + 1;

y = m + v;

}

否则如果(m == 18)

{

x = m-v + 1;

y = m + v;

}

否则if(m == 19)

{

x = m-v + 1;

y = m + v;

}

否则if(m == 20)

{

x = 2;
$ b $通过= 10;

}

if(m == 21)

{

x = 3;
$ b $通过= 1;

}

否则if(m == 22)

{

x = 3;
$ b $通过= 2;

}

否则如果(m == 23)

{

x = 3;
$ b $通过= 3;

}

否则if(m == 24)

{

x = 3;
$ b $通过= 4;

}

否则if(m == 25)

{

x = 3;
$ b $通过= 5;

}

否则如果(m == 26)

{

x = 3;
$ b $通过= 6;

}

否则如果(m == 27)

{

x = 3;
$ b $通过= 7;

}

否则如果(m == 28)

{

x = 3;
$ b $通过= 8;

}

否则if(m == 29)

{

x = 3;
$ b $通过= 9;

}

否则如果(m == 30)

{

x = 3;
$ b $通过= 10;

}

if(m == 31)

{

x = 4;
$ b $通过= 1;

}

否则如果(m == 32)

{

x = 4;
$ b $通过= 2;

}

否则如果(m == 33)

{

x = 4;
$ b $通过= 3;

}

否则if(m == 34)

{

x = 4;
$ b $通过= 4;

}

否则如果(m == 35)

{

x = 4;
$ b $通过= 5;

}

否则如果(m == 36)

{

x = 4;
$ b $通过= 6;

}

否则如果(m == 37)

{

x = 4;
$ b $通过= 7;

}

否则如果(m == 38)

{

x = 4;
$ b $通过= 8;

}

否则如果(m == 39)

{

x = 4;
$ b $通过= 9;

}

否则如果(m == 40)

{

x = 4;
$ b $通过= 10;

}

int main()

{

int n;

cout< ;<输入matrex大小<< endl;

cin>> n;

int a [n];

int b [n];

}



如你所知,如果我知道国际象棋棋盘的大小,我可以知道x和y的最大长度,并获得每个(x,y)的数据(m)。

但是我无法想出能够得到我(x,y)的代码而不管(m)尺寸:(。

如你所见,我试图提出(m)和(v)这将使(x)和(y)不能超过棋盘尺寸(这是由用户给出的),但是当我尝试了这个时,当我必须从(x)的下一行开始时,我卡住了。



i希望你们有这个想法:)感谢快速回复!
Okay, i'am sorry again for my bad English, i mean "How can I *Make a chess board with a size that given by the user".

anyway this is what i've tried :
void getdata()
{
int m;
int v;

srand(time(0));
m=rand()%(n*n)+1;;
v=m-1;
if (m==1)
{
x=m;
y=m;
}
else if (m==2)
{
x=m-v;
y=m+v;
}
else if (m==3)
{
x=m-v;
y=m+v;
}
else if (m==4)
{
x=m-v;
y=m+v;
}
else if (m==5)
{
x=m-v;
y=m+v;
}
else if (m==6)
{
x=m-v;
y=m+v;
}
else if (m==7)
{
x=m-v;
y=m+v;
}
else if (m==8)
{
x=m-v;
y=m+v;
}
else if (m==9)
{
x=m-v;
y=m+v;
}
else if (m==10)
{
x=m-v;
y=m+v;
}

if (m==11)
{
x=m-v+1;
y=m;
}
else if (m==12)
{
x=m-v+1;
y=m+v;
}
else if (m==13)
{
x=m-v+1;
y=m+v;
}
else if (m==14)
{
x=m-v+1;
y=m+v;
}
else if (m==15)
{
x=m-v+1;
y=m+v;
}
else if (m==16)
{
x=m-v+1;
y=m+v;
}
else if (m==17)
{
x=m-v+1;
y=m+v;
}
else if (m==18)
{
x=m-v+1;
y=m+v;
}
else if (m==19)
{
x=m-v+1;
y=m+v;
}
else if (m==20)
{
x=2;
y=10;
}
if (m==21)
{
x=3;
y=1;
}
else if (m==22)
{
x=3;
y=2;
}
else if (m==23)
{
x=3;
y=3;
}
else if (m==24)
{
x=3;
y=4;
}
else if (m==25)
{
x=3;
y=5;
}
else if (m==26)
{
x=3;
y=6;
}
else if (m==27)
{
x=3;
y=7;
}
else if (m==28)
{
x=3;
y=8;
}
else if (m==29)
{
x=3;
y=9;
}
else if (m==30)
{
x=3;
y=10;
}
if (m==31)
{
x=4;
y=1;
}
else if (m==32)
{
x=4;
y=2;
}
else if (m==33)
{
x=4;
y=3;
}
else if (m==34)
{
x=4;
y=4;
}
else if (m==35)
{
x=4;
y=5;
}
else if (m==36)
{
x=4;
y=6;
}
else if (m==37)
{
x=4;
y=7;
}
else if (m==38)
{
x=4;
y=8;
}
else if (m==39)
{
x=4;
y=9;
}
else if (m==40)
{
x=4;
y=10;
}
int main()
{
int n;
cout<<"enter matrex size"<<endl;
cin>>n;
int a[n];
int b[n];
}

as you guys see, if i know the size of the chess board, i can know the max length of x and y, and get data(m) for each (x,y).
but i couldn't come up with a code that will get me (x,y) regardless of (m) size :(.
as you see, i tried to come up with (m) and (v) which will make the (x) and (y) cant go past the chess board size (which is given by the user), but when i tried that, i stuck when i reach the point when i have to start with the next line of (x).

i hope you guys got the idea :) thanks for the fast reply too !


我刚来了另一个想法,不确定它是否正常工作。

它应该是这样的:

int x = 1;

int y = 1;

int m,n;



while(y< = n){

for(int i = 1; i< n + 1; i ++){>

m = x,y;

y ++;

m ++;

}

x ++; / *这是我重置y值的地方,从第二行开始,即x = 2 * /

y = 1;

}
I just came with another idea, not sure if its working or not.
it should be like this :
int x=1;
int y=1;
int m,n;

while (y<=n){
for(int i=1;i<n+1;i++){>
m = x,y;
y++;
m++;
}
x++; /* this is where i reset the value of y, and start with the 2nd line which is x=2 */
y=1;
}


这篇关于我怎么能用一个用户给出的尺寸的棋盘。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆