переопределение формального параметра 'board' - PullRequest
0 голосов
/ 15 апреля 2020

Я получаю эту ошибку, когда пытаюсь нарисовать доску, поэтому проблема в разделе void drawBoard, и я не уверен, как решить эту проблему, я пытался не включать векторную доску (getBoardSize (), 'е'); (функция), но если я включу векторную доску (boardSize, 'e'); он скажет неопознанный, а также я впервые пытаюсь использовать и понять uint.

#include <Windows.h>
#include <vector>
#include <iostream>

using namespace std;

typedef unsigned int uint;

enum uintType { none, frog, toad };


uint getBoardSize() {
uint value = 0;
// ask for board size
// read value from input
// as long as value if out of bounds (less than 3 or greater than 30), ask for a new value
return value;
}

uint getNumberOfUnits(uint size) {
uint value = 0;
// ask for board size
// read value from input
// as long as value if out of bounds (less than 1 or greater than (size-1/2), ask for a new value
return value;
}

void setup(uint size, uint number, vector<uintType>& board, vector<bool>& visible) {
board.resize(size, none);
visible.resize(size, false);
// add actual units to board
// determine initial visibility
}

void drawBoard(vector<uintType>& board, vector<bool>& visible) {
vector<char> board(getBoardSize(), 'e');
for (int i = 0; i < getBoardSize(); i++) {
    cout << board[i] << " ";
}
cout << endl;
}

// returns true if the player could move, false otherwise
bool handlePlayerTurn() {
// PLACE HOLDER, REPLACE
return true;
}

// returns true if the AI could move, false otherwise
bool handleRandomTurn() {
// PLACE HOLDER, REPLACE
return true;
}

// returns true if the player won, false if the AI won
bool mainLoop(vector<uintType>& board, vector<bool>& visible) {
while (true) {
    // - Draw the board
    drawBoard(board, visible);
    // - Handle player turn
    if (!handlePlayerTurn())
        return false;
    // - Handle AI / random turn
    if (!handleRandomTurn())
        return true;
}
}

void finalMessage(bool playerwon, vector<uintType>& board) {
// Some suitable output
}

int main() {
uint boardSize;
uint numberOfUnits;
vector<uintType> board;
vector<bool> visible;
// - Ask for board size
cout << "Enter the size of the board => ";
cin >> boardSize;
boardSize = getBoardSize();
// - Ask for number of units
numberOfUnits = getNumberOfUnits(boardSize);
// Setup the board:
setup(boardSize, numberOfUnits, board, visible);
// - Run the main loop :
bool playerwon = mainLoop(board, visible);
// - Give win / loss message
finalMessage(playerwon, board);
}

Ответы [ 2 ]

0 голосов
/ 15 апреля 2020
void drawBoard(vector<uintType>& board, vector<bool>& visible) {
    vector<char> board(getBoardSize(), 'e');
    // other stuff
}

Ваша локальная переменная board имеет то же имя, что и параметр board вашей функции. Используйте другое имя для вашей локальной переменной, и все готово!

0 голосов
/ 15 апреля 2020

В строке 36 вы скрываете параметр доска с локальной переменной с тем же именем

Удаляет имя первого параметра или удаляет эту локальную переменную, в зависимости от вашей цели

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...