-
Notifications
You must be signed in to change notification settings - Fork 0
/
rook.cpp
118 lines (90 loc) · 2.15 KB
/
rook.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include "rook.h"
//Rook::Rook(QObject *parent) :
// QObject(parent)
//{
//}
Rook::Rook()
{
this->id = 5;
}
Rook::Rook(int c)
{
this->id = 5;
this->setBeadColor(c);
}
QList<BoardPosition> Rook::NextChoices(BoardPosition &CurPos)
{
QList<BoardPosition> np;
bool AEmpty = true,BEmpty = true;
BoardPosition b(CurPos),a(CurPos);
for(int r = 1; r < 9 ; r++)
{
a = a.IncreaseCol(1);
if(a.InRange() )
{
np.push_back(a);
}
// AEmpty = !cboard.FindPos(a)->IsFull();
b = b.DecreaseCol(1);
if(b.InRange())
{
np.push_back(b);
}
// BEmpty = !cboard.FindPos(b)->IsFull();
}
AEmpty = true;
BEmpty = true;
a = CurPos;
b = CurPos;
for(int j = 1 ; j < 9 ; j++)
{
a = a.IncreaseRow(1);
b = b.DecreaseRow(1);
if(a.InRange())
{
np.push_back(a);
}
// AEmpty = !cboard.FindPos(a)->IsFull();
if(b.InRange())
{
np.push_back(b);
}
// BEmpty = !cboard.FindPos(b)->IsFull();
}
return np;
}
bool Rook::Check(BoardPosition &kingpos, BoardPosition &curpos)
{
return (curpos.getColumn() == kingpos.getColumn())
| (curpos.getRow() == kingpos.getRow());
}
void Rook::DeletePoses(QList<BoardPosition> &N, BoardPosition *nextchoice, BoardPosition *current)
{
BoardPosition temp;
QPair<int,int> result;
int div = 1;
temp.setRow(nextchoice->getRow());
temp.setColumn(nextchoice->getColumn());
result.first = (nextchoice->getRow() - current->getRow());
result.second = nextchoice->getColumn() - current->getColumn();
if(result.first != 0)
{
div = abs(result.first);
}
else if(result.second != 0)
{
div = abs(result.second);
}
result.first = result.first / div;
result.second = result.second / div;
if(current->getBead()->getBeadColor() == nextchoice->getBead()->getBeadColor())
{
N.removeOne(temp);
}
temp = temp + result;
while(temp.InRange())
{
N.removeOne(temp);
temp = temp + result;
}
}