I am new to C.
I am trying to make sure that the rows and column adjacent to the row and column the user input are blocked( being populated by an 'X' behind the UI so a move can not be made there. This is to stay out of the line of the queens moves. Is my for loop correct? how can I display the 'X' to make sure that these spaces are being populated?
Thanks,
Code:
#include <stdio.h>
#include <ctype.h>
#define SIZE 8 /* Size of board*/
/* function prototype */
void display(char board[] [SIZE]);
int valid_moves(char board[] [SIZE], int moves[] [SIZE], char player);
int main()
{
char board [SIZE] [SIZE] ={ 0 }; /* The board*/
int moves[SIZE] [SIZE] ={0}; /* valid moves */
int row = 0;
int col = 0;
char queenie = 'Q'; /* user selection*/
int y =0; /* column number*/
int x =0; /* row number*/
char player = 'Q';
/* empty all the squares */
for(row = 0; row < SIZE; row++)
for(col = 0; col < SIZE; col++)
board[row] [col] = ' ';
/*fflush(stdin); /*flush the buffer: keyboard--stdin*/
printf("please enter the row numer 0-7 and column number 0-7 to place the queen:");
scanf("%d %d", &x,&y);
board[x][y]='Q';
for(x=x; x-1==0 && x+1==7; x++)
{
x='X';
printf("board mark",board[x][y]);
}
for(x= x; x-1==0 && x+1==7; x--)
{
x='X';
}
for(y= y; y-1==0&&y+1==7; y++)
{
y='X';
}
for(y= y; y-1==0&&y+1==7; y--)
{
y='X';
}
if(x<0 && y<0 || x>SIZE && y>SIZE)
{
printf(" That is an invalid entry!\n");
}
display(board);
}
/* display board funtion definition*/
void display(char board[] [SIZE])
{
int row = 0; /* row index */
int col = 0; /* col index */
char col_label = 'a'; /* column label */
printf("\n "); /*start top line */
for(col = 0; col<SIZE; col++)
printf(" %c", col_label+col); /* display the top line*/
printf("\n"); /*end of top line*/
/*display the intermediate rows*/
for(row = 0; row < SIZE; row++)
{
printf(" +");
for(col = 0; col<SIZE; col++)
printf("---+");
printf("\n%2d|",row + 1);
for(col = 0; col< SIZE; col++)
printf(" %c |", board[row][col]); /* display counters in row*/
printf("\n");
}
printf(" +"); /*start the bottom line*/
for(col = 0; col<SIZE ; col++)
printf("---+"); /*display the bottom line*/
printf("\n"); /* end bottom line*/
}