#ifndef DIRECTION_H_42BDAFB9 #define DIRECTION_H_42BDAFB9 #include #include #include using coord = std::tuple; enum class Direction { up, down, left, right }; inline Direction directionFromString(std::string_view str) { if (str == "up") return Direction::up; if (str == "right") return Direction::right; if (str == "down") return Direction::down; if (str == "left") return Direction::left; throw std::invalid_argument("Invalid direction: " + std::string(str)); } inline coord coordInDirection(int x, int y, Direction dir) { switch (dir) { case Direction::up: return {x, y-1}; case Direction::down: return {x, y+1}; case Direction::left: return {x-1, y}; case Direction::right: return {x+1, y}; } } #endif /* end of include guard: DIRECTION_H_42BDAFB9 */