-
Notifications
You must be signed in to change notification settings - Fork 0
/
piece.cpp
96 lines (79 loc) · 1.9 KB
/
piece.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
#include <iostream>
#include "piece.h"
using namespace std;
void Piece::setMoved()
{
if(hasMoved == false)
hasMoved = true;
return;
}
std::string Piece::printSide()
{
if(side == Black)
return "Black";
else
return "White";
}
bool Piece::diagonalCheck(int originRow, int originColumn, int destinationRow, int destinationColumn)
{
//4 directions
int row = originRow, column = originColumn;
while(true)//(row != destinationRow && column != destinationColumn)
{
if(row < destinationRow)
row++;
else
row--;
if(column < destinationColumn)
column++;
else
column--;
if(row == destinationRow && column == destinationColumn)
return true;
if(!(board_->isPositionEmpty(row, column)))
return false;
}
}
bool Piece::straightCheck(int originRow, int originColumn, int destinationRow, int destinationColumn)
{
if(originRow == destinationRow)//If on same row
{
if(destinationColumn > originColumn)
{
for(int i = originColumn + 1; i < destinationColumn; i++)
{
if(!(board_->isPositionEmpty(originRow, i)))
return false;
}
}
if(destinationColumn < originColumn)
{
for(int i = originColumn - 1; i > destinationColumn; i--)
{
if(!(board_->isPositionEmpty(originRow, i)))
return false;
}
}
}
/////////////////////////////////////////////////////////////////////////////
if(originColumn == destinationColumn)//If on same column
{
if(destinationRow > originRow)
{
for(int i = originRow + 1; i < destinationRow; i++)
{
if(!(board_->isPositionEmpty(i, originColumn)))
return false;
}
}
if(destinationRow < originRow)
{
for(int i = originRow - 1; i > destinationRow; i--)
{
if(!(board_->isPositionEmpty(i, originColumn)))
return false;
}
}
}
return true;
}