-
Notifications
You must be signed in to change notification settings - Fork 1
/
Board.java
91 lines (80 loc) · 2.09 KB
/
Board.java
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
import java.util.ArrayList;
/**
* Created by Alireza on 5/10/2017.
*/
public class Board {
private ArrayList < ArrayList <Cell> > cells;
private ArrayList<Cell> mycells;
private ArrayList<Cell> oppcells;
private ArrayList<Cell> emptycells;
public Board()
{
cells = new ArrayList<ArrayList<Cell>>();
mycells = new ArrayList<Cell>();
oppcells = new ArrayList<Cell>();
emptycells = new ArrayList<Cell>();
for(int i=0;i<8;i++)
{
ArrayList<Cell> tmp = new ArrayList<Cell>();
tmp.clear();
for(int j=0;j<3;j++)
{
tmp.add(new Cell(i,j,'e'));
}
cells.add(tmp);
}
}
public void update(String s)
{
mycells.clear();
oppcells.clear();
emptycells.clear();
for(int i=0;i<8;i++)
{
for(int j=0;j<3;j++)
{
cells.get(i).get(j).set_checker(null);
if(s.charAt(0)!='e')
{
cells.get(i).get(j).set_checker(new Checker(i,j,s.charAt(0)));
if(s.charAt(0)=='m')
mycells.add(cells.get(i).get(j));
else
oppcells.add(cells.get(i).get(j));
}
else
emptycells.add(cells.get(i).get(j));
if(s.length()>=2)
s=s.substring(2);
}
}
}
public Cell get_cell(Pos p)
{
return cells.get(p.getX()).get(p.getY());
}
public void set_cell(int x, int y, char c)
{
cells.get(x).get(y).set_checker(x,y,c);
}
public Cell get_cell(int x , int y)
{
return cells.get(x).get(y);
}
public ArrayList <ArrayList <Cell> > get_cells()
{
return cells;
}
public ArrayList <Cell> get_myCells()
{
return mycells;
}
public ArrayList<Cell> get_oppCells()
{
return oppcells;
}
public ArrayList<Cell> get_emptyCells()
{
return emptycells;
}
}