-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotation.cpp
More file actions
122 lines (100 loc) · 2.46 KB
/
notation.cpp
File metadata and controls
122 lines (100 loc) · 2.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
//
// Created by austi on 12/9/2017.
//
#include "notation.h"
std::string notation::teams[TEAM_COUNT] = { "yellow", "red", "green", "blue" };
char notation::team_chars[TEAM_COUNT] = { 'y', 'r', 'g', 'b' };
notation::notation()
{
}
roll notation::fromStr(std::string rollStr)
{
int num1 = rollStr[0] - 48;
int num2 = rollStr[2] - 48;
return roll(num1, num2);
}
int notation::fromStr(std::string sq, int perspective)
{
if (sq[0] == 'h')
{
if (sq.length() < 3)
{
return -1;
}
int value = std::stoi(sq.substr(2));
return 47 + value;
}
else
{
//Find team char
for (int t = 0; t < TEAM_COUNT; t++)
{
if (sq[0] == team_chars[t])
{
int yellow_value = 12 * t;
int value = std::stoi(sq.substr(1)) - 1; //Indexed at 1
int64 m = 0;
magic_set(m, value);
return magic_getMsb(magic_getRot48(m, t, perspective));
}
}
}
return -1;
}
std::string notation::toStr(int sq, int perspective)
{
assert(perspective >= 0 && perspective < TEAM_COUNT);
std::string str = std::string();
if (sq >= 48)
{
str.append("h");
str.push_back(team_chars[perspective]);
int quadValue = (sq % 12) + 1;
str.append(std::to_string(quadValue));
}
else
{
int64 m = 0;
magic_set(m, sq);
int64 rot = magic_getRot48(m, perspective, 0);
int val = magic_getMsb(rot);
int quadIndex = val / 12;
str.push_back(team_chars[quadIndex]);
int quadValue = (val % 12) + 1;
str.append(std::to_string(quadValue));
}
return str;
}
std::string notation::toStr(int64 move)
{
if (move == NONE)
{
return "NONE";
}
std::string str = std::string();
str.append(toStr(move_getFirst(move)));
if (move_isTwoStep(move))
{
str.append(", ");
str.append(toStr(move_getSecond(move)));
}
return str;
}
std::string notation::toStr(int32 move)
{
int team = pseudomove_getTeam(move);
int from = pseudomove_getFrom(move);
int to = pseudomove_getTo(move);
std::string str = std::string();
if (!pseudomove_isTakeout(move))
{
str.append(toStr(from, team));
}
str.append(toStr(to, team));
return str;
}
std::string notation::toStr(int team)
{
assert(team >= 0 && team < TEAM_COUNT);
return teams[team];
}