Untitled

 avatar
unknown
c_cpp
2 years ago
1.6 kB
4
Indexable
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdlib.h>
 
int conv(char x){
 
  //int y; // not needed, just return n;
  int n = 0;
  char sld[8] = {'a','b','c','d','e','f','g','h'};
 
  while(n<8){
	if(sld[n] == x)
	return n;
	n++;
  }
}
 
 
int main(){
 
	char col;
	int row;
	bool end = false;
 
	// int pawn[1][2] = {{0,0}}; 
	// try this instead might be easier to understand 
	pawn_row = 0;
	pawn_col = 0;
while(end == false){	
	// might need to be [8][8]
	char board[8][9] ={	
	"OXOXOXOX",
	"XOXOXOXO",
	"OXOXOXOX",
	"XOXOXOXO",
	"OXOXOXOX",
	"XOXOXOXO",
	"OXOXOXOX",
	"XOXOXOXO"		
	};
 
	// not sure what this intended to do
	// looks like maybe you are trying to set the board position for the pawn 
	// if that's the case you can skip the loops 
	// and just try:
	// board[pawn_row][pawn_col] = '1';
	for(int a = 0; a!=1;a++){
     for(int b = 0; b!=2;b++){
	 board[pawn[a][b]][pawn[a][b]] = '1';}
	                     }
 
	// seems like this prints the board
	// you might need another for loop to print each character in the board
	for(int i = 0; i < 8; i++){
	if(i!=7){
	printf("%d%s\n",8-i,board[i][9]);
	}
	else{printf(" abcdefgh\n");}
	                 }
 
	bool valid = false;
	while(!valid){
	printf("Enter Coordinates\n");
	scanf(" %c%d",&col,&row);
	if(col == 'x'){end = true; valid = true;}
	else if(row>9||row<0||'a'>col||col>'h'){
	printf("Invalid move\n");	
	}
	else{valid = true;}
           	}
			
	pawn_row = 8-row;
	pawn_col = conv(col);
    //pawn[0][0] = 8-row;
	//pawn[0][1] = conv(col);
}  
   return 0;
}
Editor is loading...