-
Notifications
You must be signed in to change notification settings - Fork 1
/
Move.cpp
101 lines (88 loc) · 2.46 KB
/
Move.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
97
98
99
100
101
#include "Move.h"
#include "Utility.h"
#include <iostream>
#include <string>
using namespace std;
Move::Move(vector<MicroMove> moveSeq)
{
this->moveSeq = moveSeq;
}
Move::Move()
{
}
Move::Move(string move, int boardSize)
{
Utility util;
vector<string> explodedMove = util.splitString(move);
if (explodedMove.size() % 3 != 0)
{
cerr << "Error in input move format. Not a multiple of 3";
}
char type;
vector<pair<int, int>> moveInfo;
for (int i = 0; i < explodedMove.size(); i += 3)
{
pair<int, int> pos = make_pair(stoi(explodedMove[i + 1]), stoi(explodedMove[i + 2]));
// Convert the pos into rectangular format
pos = util.polarToArray(pos, boardSize);
// Extract and fill the move type
if (explodedMove[i] == "P")
{
// Place this ring
type = 'P';
moveInfo.push_back(pos);
// Push the micromove and clear moveInfo
moveSeq.push_back(MicroMove(type, moveInfo));
moveInfo.clear();
}
else if (explodedMove[i] == "S")
{
// Select a ring
type = 'M';
// Push into the moveInfo
moveInfo.push_back(pos);
}
else if (explodedMove[i] == "M")
{
// Move the selected ring
type = 'M';
moveInfo.push_back(pos);
// Push the micromove and clear moveInfo
moveSeq.push_back(MicroMove(type, moveInfo));
moveInfo.clear();
}
else if (explodedMove[i] == "RS")
{
// Remove a row
type = 'R';
moveInfo.push_back(pos);
}
else if (explodedMove[i] == "RE")
{
// Remove row end
type = 'R';
moveInfo.push_back(pos);
// Push the micromove and clear moveInfo
moveSeq.push_back(MicroMove(type, moveInfo));
moveInfo.clear();
}
else if (explodedMove[i] == "X")
{
// Remove a ring
type = 'X';
moveInfo.push_back(pos);
// Push the micromove and clear moveInfo
moveSeq.push_back(MicroMove(type, moveInfo));
moveInfo.clear();
}
}
}
string Move::cartesianToPolarString(int boardSize)
{
string result = "";
for (int i = 0; i < moveSeq.size(); i++)
{
result += moveSeq[i].cartesianToPolarString(boardSize);
}
return result;
}