Я работаю над очень простой консольной игрой в шахматы, и я продолжаю получать ошибки и не знаю почему.Вот часть моего кода:
string board[8][8] = {
"BR", "BKn", "BB", "BQ", "BKi", "BB", "BKn", "BR",
"BP", "BP", "BP", "BP", "BP", "BP", "BP", "BP",
"0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0", "0",
"WP", "WP", "WP", "WP", "WP", "WP", "WP", "WP",
"WR", "WKn", "WB", "WKi", "WQ", "WB", "WKn", "WR"
};
void setBoard(string piece, string side, int where1, int where2) {
if (side == "white") {
if (piece == "rook") {
board[where1, where2] = "WR"; //All lines like this get an error
}
else if (piece == "knight") {
board[where1, where2] = "WKn";
}
else if (piece == "bishop") {
board[where1, where2] = "WB";
}
else if (piece == "king") {
board[where1, where2] = "WKi";
}
else if (piece == "queen") {
board[where1, where2] = "WQ";
}
else if (piece == "pawn") {
board[where1, where2] = "WP";
}
}
else if (side == "black") {
if (piece == "rook") {
board[where1, where2] = "BR";
}
else if (piece == "knight") {
board[where1, where2] = "Bkn";
}
else if (piece == "bishop") {
board[where1, where2] = "BB";
}
else if (piece == "king") {
board[where1, where2] = "BKi";
}
else if (piece == "queen") {
board[where1, where2] = "BQ";
}
else if (piece == "pawn") {
board[where1, where2] = "BP";
}
}
}
void play(string where) {
bool second = false;
char first = where[0];
int x = conv1(first);
int sec = where[1];
sec -= 48;
int y = conv2(sec);
if (x == 69 || y == 69) {
cout << "Error: Not a valid space. Make sure the letter is capitalized." << endl;
chess();
}
else {
if (board[x][y] != "0") {
if (second == false) {
string piece = getPiece(board[x][y]);
cout << "Where do you want to move the piece " << piece << " ?" << endl;
string input; cin >> input;
play(input);
}
else if (second == true) {
string piece = getPiece(board[x][y]);
cout << "Are you sure you want move the piece " << piece << " to the space " << where << " ?" << endl << "Yes(1) \nNo(2)" << endl;
int choice; cin >> choice;
if (choice == 1) {
string side = getSide(board[x][y]);
setBoard(piece, side, x, y);
}
else chess();
}
}
else cout << "Error: There is no piece on space " << where << " ." << endl;
}
}
Это дает мне эту ошибку:
Ошибка 1 ошибка C2440: '=': невозможно преобразовать из 'const char [3]'to' std :: string [8] '
Я не знаю, что не так с моим кодом, может кто-нибудь сказать мне, что происходит.Кроме того, я могу без проблем изменить значение платы в функции воспроизведения, просто когда я пытаюсь сделать это там, это злится на меня.