-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpiece.cpp
55 lines (45 loc) · 1005 Bytes
/
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
#include "piece.h"
Piece::Piece(QString _pos, enum Color _color, QString _name, char _type, QObject *parent) : QObject(parent)
{
currentPosition = _pos;
pngName = _name;
type = _type;
color = _color;
}
char Piece::getType() const
{
return type;
}
Color Piece::getColor() const
{
return color;
}
QString Piece::getName() const
{
return pngName;
}
QString Piece::getCurrentPosition() const
{
return currentPosition;
}
void Piece::setCurrentPosition(const QString &value)
{
currentPosition = value;
}
int Piece::convertMoveToIndex(QString move){
char letter = move.at(0).toLatin1();
char number = move.at(1).toLatin1();
int col = (int)letter - 65;
int row = (int)number - 49;
int arrRow = 7-row;
int index = arrRow*8+col;
return index;
}
QString Piece::convertIndexToMove(int index){
char col = (index % 8)+65;
char row = (7-(index / 8))+49;
QString output = "";
output += col;
output += row;
return output;
}