13 std::string validation_string{
"^[a-i](?:10|[1-9])$"};
14 std::regex validation_pattern(validation_string);
15 if (!std::regex_match(
value_, validation_pattern)) {
17 "String '" +
value_ +
"' does not match the regex pattern '" +
18 validation_string +
"'"
24 char algebraic_column = (char)(game_board_space.
file +
'a');
25 auto algebraic_row = std::to_string(10 - game_board_space.
rank);
26 value_ = algebraic_column + algebraic_row;
30 char algebraic_column =
value_[0];
31 auto file = algebraic_column -
'a';
32 auto algebraic_row =
value_.substr(1);
33 auto rank = 10 - std::stoi(algebraic_row);
53 const std::vector<AlgebraicBoardSpace> &algebraic_board_spaces
55 if (algebraic_board_spaces.size() < 2) {
58 return AlgebraicMove{algebraic_board_spaces.at(0), algebraic_board_spaces.at(1)};
62 if (tokens.size() != 2) {
85const std::string
GetInput(std::istream &input_stream) {
86 std::string user_input;
87 std::getline(input_stream, user_input);
92const std::string
Trim(
const std::string &str) {
97 auto start = std::find_if_not(str.begin(), str.end(), ::isspace);
98 auto end = std::find_if_not(str.rbegin(), str.rend(), ::isspace).base();
100 return std::string(start, end);
103const std::vector<std::string>
Tokenize(
const std::string &input) {
104 std::vector<std::string> tokens;
106 std::stringstream stream(input);
109 while (std::getline(stream, segment,
',')) {
110 auto trimmed_segment =
Trim(segment);
111 tokens.emplace_back(trimmed_segment);
118 for (
auto &token : tokens) {
120 std::cerr <<
"Token '" + token +
"' is not a valid algebraic board space."
126 if (tokens.size() != 2) {
127 std::cerr <<
"AlgebraicMove consists of exactly 2 board spaces, but "
128 << tokens.size() <<
" values provided" << std::endl;
135 std::regex pattern(
"^[a-i](?:10|[1-9])$");
136 return std::regex_match(algebraic_space, pattern);
Constants, typedefs, and simple structs used by gameboard::GameBoard.
bool operator==(const AlgebraicBoardSpace &other) const
gameboard::BoardSpace ToGameBoardSpace()
const std::string value()
AlgebraicBoardSpace(const std::string &value)
static const AlgebraicMove Create(const std::vector< AlgebraicBoardSpace > &algebraic_board_spaces)
const AlgebraicBoardSpace end()
const AlgebraicBoardSpace start()
AlgebraicMove(const AlgebraicBoardSpace &start, const AlgebraicBoardSpace &end)
AlgebraicBoardSpace start_
const gameboard::Move ToGameBoardMove()
bool IsValidAlgebraicBoardSpace(const std::string &algebraic_space)
bool IsValidAlgebraicMove(const std::vector< std::string > &tokens)
const std::string Trim(const std::string &str)
const std::string GetInput(std::istream &input_stream)
const std::vector< std::string > Tokenize(const std::string &input)
A pair of coordinate (rank, and file) with properties determined by comparison with values of gameboa...
A gameboard::BoardSpace pair (start and end).
gameboard::BoardSpace end
gameboard::BoardSpace start