diff --git a/cpp/src/board.hpp b/cpp/src/board.hpp index 0936109..6d7fc60 100644 --- a/cpp/src/board.hpp +++ b/cpp/src/board.hpp @@ -4,18 +4,6 @@ #include -struct Coords { - int x, y; - - int8_t to_index() const { - return this->y * 8 + this->x; - } - - static Coords from_index(int idx) { - return {idx % 8, idx / 8}; - } -}; - struct Board { private: int8_t get_king_of(int8_t colour) const; diff --git a/cpp/src/coords.hpp b/cpp/src/coords.hpp new file mode 100644 index 0000000..51a6f6c --- /dev/null +++ b/cpp/src/coords.hpp @@ -0,0 +1,19 @@ +#pragma once + +#include + +struct Coords { + int x, y; + + int8_t to_index() const { + return this->y * 8 + this->x; + } + + static Coords from_index(int idx) { + return {idx % 8, idx / 8}; + } + + bool is_within_bounds() const { + return this->to_index() < 64; + } +}; diff --git a/cpp/src/pieces/pawn.cpp b/cpp/src/pieces/pawn.cpp index 044715e..bb5f3d7 100644 --- a/cpp/src/pieces/pawn.cpp +++ b/cpp/src/pieces/pawn.cpp @@ -1,4 +1,5 @@ #include "../board.hpp" +#include "../coords.hpp" #include "../move.hpp" #include "piece.hpp" diff --git a/cpp/src/pieces/piece.cpp b/cpp/src/pieces/piece.cpp index b849c1d..99cd572 100644 --- a/cpp/src/pieces/piece.cpp +++ b/cpp/src/pieces/piece.cpp @@ -1,6 +1,7 @@ #include "piece.hpp" #include "../board.hpp" +#include "../coords.hpp" std::vector keep_only_blocking(const std::vector candidates, const Board& board) {