-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMove.cpp
More file actions
78 lines (66 loc) · 1.46 KB
/
Move.cpp
File metadata and controls
78 lines (66 loc) · 1.46 KB
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
#include "Move.h"
Move::Move()
{
}
Move::Move(const Move & move)
{
this->seq = move.seq;
}
Move::Move(const vector<Position> seq)
{
this->seq = seq;
}
Move::Move(const string & input)
{
int len = input.length();
if (input == "-1"){
return;
}
string delimiter = "-";
vector<string> points = split(input,delimiter);
for (int i = 0; i<points.size();++i)
{
string point = points[i];
string result;
for (int j = 1; j<point.length()-1;++j)
{
result += point[j];
}
vector<string> xy = split(result,",");
int x = stoi(xy[0]);
int y = stoi(xy[1]);
Position coordinate{x,y};
seq.push_back(coordinate);
}
}
vector<string> Move::split(string input,const string delimiter){
vector<string> result;
size_t pos = 0;
string token;
while ((pos = input.find(delimiter)) != string::npos) {
token = input.substr(0, pos);
result.push_back(token);
input.erase(0, pos + delimiter.length());
}
result.push_back(input);
return result;
}
string Move::toString()
{
string result;
for (int i = 0;i<seq.size();++i)
{
result += "("+to_string(seq[i][0])+","+to_string(seq[i][1])+")";
if (i != seq.size()-1)
{
result += "-";
}
}
return result;
}
bool Move::isCapture()
{
if (this->seq.size()>2)
return true;
return abs(seq[0][0]-seq[1][0]) > 1;
}