Hi newbie there,this is code for chess game(just started) ,i want to convert the input in characters to integers via getMove function i have tried to made but its not working..
output is "invalid input" every time
#include <iostream>
using namespace std;
void printBoard(char board[][8],int row,int col);
void getMove(int arr[],char sr,int sc,char dr,int dc);
bool validMove(int a[],int n);
void main (){
char sr,dr;
int sc,dc;
int n=4;
cout <<"Enter source coordinates :" ;
cin >> sr;
cin >> sc;
cout <<"Enter destination coordinates :" ;
cin >> dr;
cin >> dc;
int move[4]={sr,sc,dr,dc};
int row=8;int col=8;
sr=toupper(sr);//capitalize char coordinates
dr=toupper(dr);
getMove( move, sr, sc, dr, dc);
bool valid =validMove( move,n);
if(valid == false){
cout << "Invalid input!";
}
cout << endl;cout << endl;
char board[8][8];
printBoard(board,row,col);
}
void printBoard(char board[][8],int row,int col){
for(int i=0;i<8;i++){
for(int j=0;j<8;j++){
if (i==1 ){
board[i][j]='P';
cout << " " << board[i][j] << '|' << " ";
}else if (i==6 ){
board[i][j]='p' ;
cout << " " << board[i][j] << '|' << " ";
}else if (i==0 && j==0 || i==0 && j==7 ){//Rook
board[i][j]='R' ;
cout << " " << board[i][j] << '|' << " ";
}else if (i==7 && j==0 || i==7 && j==7 ){//rook
board[i][j]='r' ;
cout << " " << board[i][j] << '|' << " ";
}else if (i==0 && j==1 || i==0 && j==6 ){//Night
board[i][j]='N' ;
cout << " " << board[i][j] << '|' << " ";
}else if (i==7 && j==1 || i==7 && j==6 ){//night
board[i][j]='n' ;
cout << " " << board[i][j] << '|' << " ";
}else if (i==0 && j==2 || i==0 && j==5 ){//Bishop
board[i][j]='B' ;
cout << " " << board[i][j] << '|' << " ";
}else if (i==7 && j==2 || i==7 && j==5 ){//bishop
board[i][j]='b' ;
cout << " " << board[i][j] << '|' << " ";
}else if (i==0 && j==3 ){ //Queen
board[i][j]='Q' ;
cout << " " << board[i][j] << '|' << " ";
}else if (i==7 && j==3 ){ //queen
board[i][j]='q' ;
cout << " " << board[i][j] << '|' << " ";
}else if (i==0 && j==4 ){ //King
board[i][j]='K' ;
cout << " " << board[i][j] << '|' << " ";
}else if (i==7 && j==4 ){ //king
board[i][j]='k' ;
cout << " " << board[i][j] << '|' << " ";
}else{
board[i][j]= ' ';
cout << " " << board[i][j] << "|" << " ";
board[0][1]= 'R';
}
}
cout << endl ;
cout << "_______________________________";
cout << endl ;
}
}
void getMove(int arr[],char sr,int sc,char dr,int dc){
arr[0]=sr-65;//get ascii of rows
arr[1]=sc-1;//get index started from 0
arr[2]=dr-65;
arr[3]=dc-1;
}
bool validMove(int a[],int n){
n=4;
if(a[0] != 0 ||a[0] != 1 ||a[0] != 2 ||a[0] != 3 ||a[0] != 4 ||a[0] != 5 ||a[0] != 6 ||a[0] != 7 ){
return false;
}else if(a[2] != 0 ||a[2] != 1 ||a[2] != 2 ||a[2] != 3 ||a[2] != 4 ||a[2] != 5 ||a[2] != 6 ||a[2] != 7 ){
return false;
}else if(a[1] != 0 ||a[1] != 1 ||a[1] != 2 ||a[1] != 3 ||a[1] != 4 ||a[1] != 5 ||a[1] != 6 ||a[1] != 7 ){
return false;
}else if(a[3] != 0 ||a[3] != 1 ||a[3] != 2 ||a[3] != 3 ||a[3] != 4 ||a[3] != 5 ||a[3] != 6 ||a[3] != 7 ){
return false;
}else {
return true;}
}