-
Notifications
You must be signed in to change notification settings - Fork 0
/
pawn.cpp
81 lines (65 loc) · 1.63 KB
/
pawn.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
#include "pawn.h"
//Pawn::Pawn(QObject *parent) :
// QObject(parent)
//{
//}
Pawn::Pawn() : Bead()
{
this->id = 3;
}
Pawn::Pawn(int c)
{
this->id = 3;
this->setBeadColor(c);
}
//bool Pawn::ControlBead(Board &cboard, BoardPosition &bp)
//{
// BoardPosition * f = cboard.FindPos(bp);
// return (!f->IsFull()) | ((f->IsFull() & f->getBead()->getBeadColor())
// != (bp.getBead()->getBeadColor()));
//}
QList<BoardPosition> Pawn::NextChoices(BoardPosition &CurPos)
{
// CurPos is finded from board... //
QList<BoardPosition> np;
BoardPosition b,c;
if(CurPos.getBead()->getBeadColor() == BLACK)
{
b = CurPos.IncreaseRow(1);
c = CurPos.IncreaseRow(2);
}
else
{
b = CurPos.DecreaseRow(1);
c = CurPos.DecreaseRow(2);
}
np.push_back(b);
if(CurPos.getRow() == 2 || CurPos.getRow() == 7)
{
np.push_back(c);
}
return np;
}
bool Pawn::Check(BoardPosition &kingpos, BoardPosition &curpos)
{
BoardPosition a(curpos),b(curpos);
if(this->getBeadColor() == BLACK)
{
a = a.IncreaseRow(1).IncreaseCol(1);
b = b.IncreaseRow(1).DecreaseCol(1);
}
else
{
a = a.DecreaseRow(1).IncreaseCol(1);
b = b.DecreaseRow(1).DecreaseCol(1);
}
return (a == kingpos) | (b == kingpos);
}
void Pawn::DeletePoses(QList<BoardPosition> &N, BoardPosition *nextchoice, BoardPosition *current)
{
BoardPosition removed;
removed.setRow(nextchoice->getRow());
removed.setColumn(nextchoice->getColumn());
N.removeOne(removed);
// N.removeOne(choosed);
}