-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathposition.cpp
66 lines (58 loc) · 885 Bytes
/
position.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
#include "position.h"
Position::Position()
{
col = 'a';
row = 1;
}
Position::Position(char col, int row)
{
if (validPos(col, row))
{
this->col = col;
this->row = row;
} else
{
this->col = -1;
this->row = '\0';
}
}
Position::Position(char col, char row)
{
int setRow = row - '0';
if (validPos(col, setRow))
{
this->col = col;
this->row = setRow;
} else
{
this->col = '\0';
this->row = -1;
}
}
Position::Position(std::string pos)
{
if (validPos(pos))
{
this->col = pos[0];
this->row = pos[1] - '0';
} else
{
this->col = '\0';
this->row = -1;
}
}
bool Position::validPos(char col, int row)
{
if (col >= 'a' && col <= 'h' && row >= 1 && row <= 8)
{
return true;
} else
{
return false;
}
}
bool Position::validPos(std::string pos)
{
return validPos(pos[0], pos[1] - '0');
}
bool Position::isValid() { return validPos(col, row); }