-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cell.cs
95 lines (91 loc) · 2.48 KB
/
Cell.cs
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
92
93
94
95
using System.Drawing;
namespace CheckersSolver
{
public class Cell
{
public bool empty;
public bool white;
public Cell[] Neighbours = new Cell[4];
public int X { get; private set; }
public int Y { get; private set; }
public int index { get; private set; }
public Cell(int X, int Y, int index)
{
this.X = X;
this.Y = Y;
this.index = index;
empty = true;
white = true;
}
//DEEP COPY CONSTRUCTOR
public Cell(Cell originalToDeepCopy)
{
index = originalToDeepCopy.index;
X = originalToDeepCopy.X;
Y = originalToDeepCopy.Y;
empty = originalToDeepCopy.empty;
white = originalToDeepCopy.white;
Neighbours = (Cell[])originalToDeepCopy.Neighbours.Clone();
}
public void NextState()
{
if (empty)
{
empty = false;
white = true;
return;
}
else if (white)
{
white = false;
return;
}
else
{
empty = true;
return;
}
}
public Cell GetNeighbour(Direction direction)
{
return Neighbours[(int)direction];
}
public bool MovePossible(bool left)
{
Cell neighbour =
Neighbours[(int)CellMath.DirectionFromColorAndSide(white, left)];
if (neighbour == null)
return false;
if (neighbour.empty)
return true;
else
return false;
}
public bool CapturePossible(bool left)
{
Cell neighbour =
Neighbours[(int)CellMath.DirectionFromColorAndSide(white, left)];
if (neighbour == null)
{ return false; }
Cell neighboursNeighbour =
neighbour.Neighbours[(int)CellMath.DirectionFromColorAndSide(white, left)];
if (neighboursNeighbour == null)
{ return false; }
if (neighbour.empty == false && neighbour.white != white && neighboursNeighbour.empty)
{
return true;
}
else
{
return false;
}
}
}
public enum Direction
{
NW,
NE,
SE,
SW
}
}