G
Gregc.
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
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