#include
#include
#include
#include
#include
using std::cout;
using std::ifstream;
using std::istringstream;
using std::string;
using std::vector;
enum class State {kEmpty, kObstacle};
vector ParseLine(string line) {
istringstream sline(line);
int n;
char c;
vector row;
while (sline >> n >> c && c == ',') {
if (n == 0) {
row.push_back(State::kEmpty);
} else {
row.push_back(State::kObstacle);
}
}
return row;
}
vector> ReadBoardFile(string path) {
ifstream myfile (path);
vector> board{};
if (myfile) {
string line;
while (getline(myfile, line)) {
vector row = ParseLine(line);
board.push_back(row);
}
}
return board;
}
string CellString(State cell) {
switch(cell) {
case State::kObstacle: return "â°ï¸ ";
default: return "0 ";
}
}
void PrintBoard(const vector> board) {
for (int i = 0; i < board.size(); i++) {
for (int j = 0; j < board[i].size(); j++) {
cout << CellString(board[i][j]);
}
cout << "\n";
}
}
int main() {
auto board = ReadBoardFile("1.board");
PrintBoard(board);
}