-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboard.cpp
More file actions
85 lines (72 loc) · 1.6 KB
/
Copy pathboard.cpp
File metadata and controls
85 lines (72 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include "board.hpp"
Board::~Board() {
deleteBoard();
}
Board::Board(int N) {
this->N = N;
this->board = new char*[N];
for(int i = 0; i < N; i++) {
this->board[i] = new char[N];
}
initBoard();
}
int Board::getN() {
return this->N;
}
Board::Board(const Board& obj) {
if(this != &obj) {
this->board = new char*[N];
for(int i = 0; i < N; i++) {
this->board[i] = new char[N];
}
initBoard(obj.board);
}
}
void Board::clear() {
this->initBoard();
}
void Board::initBoard() {
for(int i = 0; i < this->N; i++) {
for(int j = 0; j < this->N; j++) {
this->board[i][j] = ' ';
}
}
}
void Board::initBoard(char** board) {
for(int i = 0; i < this->N; i++) {
for(int j = 0; j < this->N; j++) {
this->board[i][j] = board[i][j];
}
}
}
void Board::deleteBoard() {
for(int i = 0; i < N; i++) {
delete this->board[i];
}
delete this->board;
}
char** Board::getBoard() {
return this->board;
}
char Board::get(int row, int col) {
if(isValidRowCol(row,col))
return this->board[row][col];
return 0;
}
void Board::set(int row, int col, char c) {
if(isValidRowCol(row,col))
this->board[row][col] = c;
}
bool Board::isValidRowCol(int row, int col) {
return (row >= 0 && row < this->N && col >= 0 && col < this->N);
}
void Board::operator =(const Board& rhs) {
if(this != &rhs) {
/*
this->board = new char*[N];
for(int i = 0; i < N; i++) {
this->board[i] = new char[N];
}
*/
}
}