forked from mahdisn76/UIAI2017_cpp_client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboard.cpp
91 lines (79 loc) · 1.63 KB
/
board.cpp
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
86
87
88
89
90
91
#include "board.h"
#include<iostream>
using namespace std;
Board::Board() //this constructor has bug high potential!!!
{
cells = new Cell*[8];
for(int i=0;i<8;i++)
cells[i]= new Cell[3]();
}
void Board::set_cell(int x, int y, char c)
{
cells[x][y].set_checker(x,y,c);
}
void Board::update(string s)
{
mycells.clear();
oppcells.clear();
emptycells.clear();
for(int i=0;i<8;i++)
{
for(int j=0;j<3;j++)
{
cells[i][j].pos->x=i;
cells[i][j].pos->y=j;
cells[i][j].checker=nullptr;
if(s[0]!='e')
{
cells[i][j].checker = new Checker(i,j,s[0]);
if(s[0]=='m')
mycells.push_back(&cells[i][j]);
else
oppcells.push_back(&cells[i][j]);
}
else
{
emptycells.push_back(&cells[i][j]);
}
if(s.length()>=2)
s=s.substr(2);
}
}
}
Board::~Board()
{
for(int i=0;i<8;i++)
{
delete[] cells[i];
cells[i] = nullptr;
}
delete cells;
cells = nullptr;
mycells.clear();
oppcells.clear();
emptycells.clear();
}
Cell** Board::get_cells()
{
return cells;
}
Cell& Board::get_cell(Pos p)
{
return cells[p.getx()][p.gety()];
}
Cell& Board::get_cell(const int x, const int y)
{
return cells[x][y];
}
vector<Cell*>& Board::get_myCells() //must test!
{
return mycells;
}
vector<Cell*>& Board::get_oppCells() //must test!
{
return oppcells;
}
vector<Cell*>& Board::get_emptyCells() //must test!
{
return emptycells;
}