-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.cpp
More file actions
46 lines (41 loc) · 1.45 KB
/
Copy pathUtils.cpp
File metadata and controls
46 lines (41 loc) · 1.45 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
/*
** EPITECH PROJECT, 2021
** ChessTrainer
** File description:
** TODO: CHANGE DESCRIPTION.
*/
#include <sstream>
#include <regex>
#include <iostream>
#include "Utils.hpp"
std::vector<std::string> ChessTrainer::Utils::splitString(const std::string& rawInput,
char delim) {
std::string buff;
std::stringstream ss(rawInput);
std::vector<std::string> tokens;
while (std::getline(ss, buff, delim))
tokens.push_back(buff);
return tokens;
}
std::vector<std::string> ChessTrainer::Utils::splitStringBySpace(const std::string& rawInput) {
const std::regex ws_re("\\s+");
std::vector<std::string> vector;
for (auto begin = std::sregex_token_iterator(rawInput.begin(),
rawInput.end(),
ws_re,
-1),
end = std::sregex_token_iterator(); begin != end; ++begin) {
vector.emplace_back(*begin);
}
for (auto v = vector.begin(); v != vector.end(); ++v)
if (v->empty())
vector.erase(v);
return vector;
}
int ChessTrainer::Utils::generateBoardIdxFromCoord(int x, int y) {
if (x > Utils::BoardSize || y > Utils::BoardSize)
throw std::out_of_range("x or y out of range");
bool negative = x < 0 || y < 0;
const int idx = abs(x) + (abs(y) - 1) * 8;
return negative ? -idx : idx;
}