-
Notifications
You must be signed in to change notification settings - Fork 0
/
Piece.cpp
83 lines (64 loc) · 1.23 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
#include "Chess.h"
#include"Piece.h"
#include <iostream>
using namespace std;
Piece::Piece(bool c, int v) : color(c), value(v)
{
AllPiece.loadFromFile("images/figures.png");// To load the image of the piece
PieceImage.setTexture(AllPiece);
move = 0;
}
Piece::Piece(int v) : value(0) // For blank object
{
move = false;
}
Piece::Piece()
{
move = false;
}
Piece::~Piece()
{
}
bool Piece::isValid(int xfrom, int yfrom, int xto, int yto, Piece* b[8][8]) // For checking whether it is valid or invalid move
{
// If the destination is empty or it does not contain piece of same color(logic of exclusive OR gate)
if ((b[yto][xto]->value == 0) || (((!(b[yto][xto]->color)) && b[yfrom][xfrom]->color) || (b[yto][xto]->color && (!(b[yfrom][xfrom]->color)))))
{
move = true;
return true;
}
else
{
//cout << "\nIn base invalid funtion";
return false;
}
}
bool Piece::getColor()
{
return color;
}
int Piece::getValue()
{
return value;
}
int ExtractColor(int color)
{
{
if (color)
return 0;
else
return 1;
}
}
int Piece::getmove()
{
return move;
}
void Piece::decrementMove()
{
move--;
}
void Piece::incrementMove()
{
move++;
}