[英] Chess

查看:54
本文介绍了棋的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

G''day


我正在写国际象棋程序。这是我的代码:


#include< stdio.h>

#include< stdlib.h>


bool isInCheck(int krow,int kcol,int qrow,int qcol)

{

double check;

double cal1;

double cal2;

cal1 = abs(krow-qrow);

cal2 = abs(kcol-qcol);

check =(krow = qrow)||(kcol = qcol); ||((krow-qrow))=(kcol-qcol));

返回0;
< br $>
}

int main(){

int score = 0;

//检查行检查

if(isInCheck(0,4,0,2)){

printf(" Correct horizo​​ntal\\\
);

得分++;

}

else {

printf(水平不正确);

}

//检查列是否支票

if(isInCheck(0,4,4,4)){

printf(" Correct diagonally\ n");

得分++;

}

else {

printf("不正确的垂直\ n) ;);

}

//检查对角线是否支票

if(isInCheck(0,4,3,1)){

printf(" Correct) diagonally \\\
;

得分++;

}

else {

printf("对角错误) \ n");

}

//检查King是否在检查中

if(!isInCheck(0,4,1) ,0)){

printf(正确无检查\ n);

得分++;

}

else {

printf(不正确,不检查\ n);

}


/ /输出分数

printf(" \ n");

printf("得分:%i %% \ n",得分* 100/4) ;


}


我的输出是:


水平不正确

垂直不正确

对角线不正确

正确无需支票


得分:25%


我试图简单地使用isInCheck函数。你们有没有

的建议。


谢谢


格雷格

G''day

I am writing a chess program. Here is my code:

#include <stdio.h>
#include <stdlib.h>

bool isInCheck (int krow, int kcol, int qrow, int qcol)
{
double check;
double cal1;
double cal2;
cal1 = abs(krow-qrow);
cal2 = abs(kcol-qcol);
check=(krow=qrow)||(kcol=qcol);||((krow-qrow))=(kcol-qcol));
return 0;

}
int main() {
int score = 0;
// Check row for check
if (isInCheck(0,4,0,2) ) {
printf("Correct horizontally\n");
score++;
}
else {
printf("Incorrect horizontally\n");
}
// Check column for check
if (isInCheck(0,4,4,4) ) {
printf("Correct diagonally\n");
score++;
}
else {
printf("Incorrect vertically\n");
}
// Check diagonal for check
if (isInCheck (0,4,3,1) ) {
printf("Correct diagonally\n");
score++;
}
else {
printf("Incorrect diagonally\n");
}
// Check that King is not in check
if (!isInCheck (0,4,1,0) ) {
printf("Correct for no check\n");
score++;
}
else {
printf("Incorrect for no check\n");
}

// Output Score
printf("\n");
printf("Score: %i%%\n", score*100/4);

}

My output is:

Incorrect horizontally
Incorrect vertically
Incorrect diagonally
Correct for no check

Score: 25%

I am trying to simply the isInCheck function. Would you guys have any
suggestions.

Thanks

Greg

推荐答案

Gregc。写道:

G''day

我正在写国际象棋程序。这是我的代码:

#include< stdio.h>
#include< stdlib.h>

bool isInCheck(int krow,int kcol, int qrow,int qcol)
{
双重检查;
双cal1;
双cal2;
cal1 = abs(krow-qrow);
cal2 = abs(kcol-qcol);
check =(krow = qrow)||(kcol = qcol); ||((krow-qrow))=(kcol-qcol));
返回0 ;


int main(){
int score = 0;
//检查行检查
if(isInCheck( 0,4,0,2)){
printf(水平纠正);
得分++;
}
其他{
printf(" ;水平不正确\ n");
}
//检查列是否检查
if(isInCheck(0,4,4,4)){
printf("正确对角地\ n);
得分++;
}
其他{
printf(不正确的垂直\ n);
}
//检查对角线是否检查
if(isInCheck(0,4,3,1)){
printf(" Correct diagonally\\\
));
得分++ ;
}
其他{
printf(对角线不正确);
}
//检查国王是否在检查中
if(!isInCheck(0,4,1,0)){
printf(" Correct for no check\\\
);
得分++;
}
else {
printf(不正确,不检查\ n);

//输出分数
printf(" \ n");
printf("得分:%i %% \ n",得分* 100/4);

}

我的输出是:

水平不正确
垂直不正确
对角线不正确
正确无需检查

分数:25%

我正在尝试简单来说就是isInCheck功能。
你们有什么建议。

G''day

I am writing a chess program. Here is my code:

#include <stdio.h>
#include <stdlib.h>

bool isInCheck (int krow, int kcol, int qrow, int qcol)
{
double check;
double cal1;
double cal2;
cal1 = abs(krow-qrow);
cal2 = abs(kcol-qcol);
check=(krow=qrow)||(kcol=qcol);||((krow-qrow))=(kcol-qcol));
return 0;

}

int main() {
int score = 0;
// Check row for check
if (isInCheck(0,4,0,2) ) {
printf("Correct horizontally\n");
score++;
}
else {
printf("Incorrect horizontally\n");
}
// Check column for check
if (isInCheck(0,4,4,4) ) {
printf("Correct diagonally\n");
score++;
}
else {
printf("Incorrect vertically\n");
}
// Check diagonal for check
if (isInCheck (0,4,3,1) ) {
printf("Correct diagonally\n");
score++;
}
else {
printf("Incorrect diagonally\n");
}
// Check that King is not in check
if (!isInCheck (0,4,1,0) ) {
printf("Correct for no check\n");
score++;
}
else {
printf("Incorrect for no check\n");
}

// Output Score
printf("\n");
printf("Score: %i%%\n", score*100/4);

}

My output is:

Incorrect horizontally
Incorrect vertically
Incorrect diagonally
Correct for no check

Score: 25%

I am trying to simply the isInCheck function.
Would you guys have any
suggestions.




/ * BEGIN new.c * /


#include< stdio.h>


int isInCheck(int krow,int kcol,int qrow,int qcol)

{

返回

krow == qrow

|| kcol == qcol

|| krow + kcol == qrow + qcol

|| krow - kcol == qrow - qcol;

}


int main(无效)

{

int score = 0;


if(isInCheck(0,4,0,2)){

puts("Correct horizo​​ntal);

++得分;

}否则{

put(水平不正确);

}

if(isInCheck(0,4,4,4)){

puts(对角线正确);

++得分;

} else {

puts(垂直不正确);

}

if(isInCheck(0) ,4,3,1)){

puts(对角线正确);

++得分;

}其他{

put(对角线不正确);

}

if(!isInCheck(0,4,1,0)){

put(正确无需支票);

++得分;

}否则{

puts( 不检查不正确);

}

printf(" \ nnnmin:%i %% \ n",得分* 100/4);

返回0;

}


/ * END new.c * /

-

pete



/* BEGIN new.c */

#include <stdio.h>

int isInCheck (int krow, int kcol, int qrow, int qcol)
{
return
krow == qrow
|| kcol == qcol
|| krow + kcol == qrow + qcol
|| krow - kcol == qrow - qcol;
}

int main(void)
{
int score = 0;

if (isInCheck(0,4,0,2)) {
puts("Correct horizontally");
++score;
} else {
puts("Incorrect horizontally");
}
if (isInCheck(0,4,4,4)) {
puts("Correct diagonally");
++score;
} else {
puts("Incorrect vertically");
}
if (isInCheck (0,4,3,1)) {
puts("Correct diagonally");
++score;
} else {
puts("Incorrect diagonally");
}
if (!isInCheck (0,4,1,0)) {
puts("Correct for no check");
++score;
} else {
puts("Incorrect for no check");
}
printf("\nScore: %i%%\n", score * 100 / 4);
return 0;
}

/* END new.c */
--
pete




Gregc。写道:

Gregc. wrote:
G''day

我正在写国际象棋程序。这是我的代码:

#include< stdio.h>
#include< stdlib.h>

bool isInCheck(int krow,int kcol, int qrow,int qcol)
{
双重检查;
双cal1;
双cal2;
cal1 = abs(krow-qrow);
cal2 = abs(kcol-qcol);
check =(krow = qrow)||(kcol = qcol); ||((krow-qrow))=(kcol-qcol));
返回0 ;

}



这有几个问题。


你基本上需要检查((krow == qrow)||(kcol == krow)),

水平或垂直检查,

或((krow + qrow)==( kcol + qcol))


或((kcol + krow)==(qcol + qrow))最后两个是对角线检查。

我''我确定你做出有效的条件陈述并不是超出你的要求



int main(){
int score = 0;
//检查行检查
if(isInCheck(0,4,0,2)){
printf(水平纠正\ n);
得分++;
}
其他{
printf("水平错误\ nn);;
}
//检查栏目是否检查
if(isInCheck(0,4,4,4)){
printf(" Correct diagonally\\\
));
得分++;
}
G''day

I am writing a chess program. Here is my code:

#include <stdio.h>
#include <stdlib.h>

bool isInCheck (int krow, int kcol, int qrow, int qcol)
{
double check;
double cal1;
double cal2;
cal1 = abs(krow-qrow);
cal2 = abs(kcol-qcol);
check=(krow=qrow)||(kcol=qcol);||((krow-qrow))=(kcol-qcol));
return 0;

}

There are several things wrong with this.

You basically need to check that ((krow == qrow ) || (kcol == krow)),
horizontal or verticle check,
or ((krow + qrow) == (kcol + qcol))

or ((kcol + krow) == (qcol + qrow)) the last two being diagonal check.
I''m sure it''s not beyond you to make an efficient condition statement
out of these.
int main() {
int score = 0;
// Check row for check
if (isInCheck(0,4,0,2) ) {
printf("Correct horizontally\n");
score++;
}
else {
printf("Incorrect horizontally\n");
}
// Check column for check
if (isInCheck(0,4,4,4) ) {
printf("Correct diagonally\n");
score++;
}




(0,4)和(4,4)不是对角线。尝试(0,4)和(4,0)。



(0,4) and (4,4) are not diagonal. Try (0,4) and (4,0).




Stephen Dedalus写道:

Stephen Dedalus wrote:
格雷格。写道:
G''day

我正在写国际象棋程序。这是我的代码:

#include< stdio.h>
#include< stdlib.h>

bool isInCheck(int krow,int kcol, int qrow,int qcol)
{
双重检查;
双cal1;
双cal2;
cal1 = abs(krow-qrow);
cal2 = abs(kcol-qcol);
check =(krow = qrow)||(kcol = qcol); ||((krow-qrow))=(kcol-qcol));
返回0 ;



这有几个问题。

你基本上需要检查((krow == qrow)||( kcol == krow)),
G''day

I am writing a chess program. Here is my code:

#include <stdio.h>
#include <stdlib.h>

bool isInCheck (int krow, int kcol, int qrow, int qcol)
{
double check;
double cal1;
double cal2;
cal1 = abs(krow-qrow);
cal2 = abs(kcol-qcol);
check=(krow=qrow)||(kcol=qcol);||((krow-qrow))=(kcol-qcol));
return 0;

}

There are several things wrong with this.

You basically need to check that ((krow == qrow ) || (kcol == krow)),




我的意思是((krow == qrow)||(kcol == qcol))这里。

水平或垂直检查,
或((krow + qrow)==(kcol + qcol))

或((kcol + krow)==(qcol + qrow))最后两个是对角线检查。

我确定你做出有效的条件陈述并不是超出你的意思。



I meant ((krow == qrow ) || (kcol == qcol)) here.
horizontal or verticle check,
or ((krow + qrow) == (kcol + qcol))

or ((kcol + krow) == (qcol + qrow)) the last two being diagonal check.
I''m sure it''s not beyond you to make an efficient condition statement
out of these.

int main(){
int score = 0;
//检查行以进行检查
if(isInCheck(0,4,0,2)){
printf(" Correct horizo​​ntal\\\
);
得分++;
}
其他{
printf(水平不正确);
}
//检查列是否检查
if(isInCheck(0,4) ,4,4)){
printf(" Correct diagonally\\\
);
得分++;
}
int main() {
int score = 0;
// Check row for check
if (isInCheck(0,4,0,2) ) {
printf("Correct horizontally\n");
score++;
}
else {
printf("Incorrect horizontally\n");
}
// Check column for check
if (isInCheck(0,4,4,4) ) {
printf("Correct diagonally\n");
score++;
}



(0,4 )和(4,4)不是对角线。尝试(0,4)和(4,0)。



(0,4) and (4,4) are not diagonal. Try (0,4) and (4,0).






这篇关于棋的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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