From 8713d03831226dcd559c6a1e2b1c7b0d7c660bac Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Wed, 16 Mar 2022 11:53:46 -0400 Subject: added signs (which can't be read yet) --- src/direction.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/direction.h') diff --git a/src/direction.h b/src/direction.h index 0fe3e5a..14ea0a5 100644 --- a/src/direction.h +++ b/src/direction.h @@ -3,6 +3,9 @@ #include #include +#include + +using coord = std::tuple; enum class Direction { up, @@ -19,4 +22,13 @@ inline Direction directionFromString(std::string_view str) { 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 */ -- cgit 1.4.1