diff --git a/src/core/a.out b/src/core/a.out deleted file mode 100755 index 7ac7b3c..0000000 Binary files a/src/core/a.out and /dev/null differ diff --git a/src/core/board2d.cpp b/src/core/board2d.cpp index 860846e..1d274d3 100644 --- a/src/core/board2d.cpp +++ b/src/core/board2d.cpp @@ -20,13 +20,13 @@ void Board2D::add_unit(const Coord c) if (!(space.capacity >= space.value)) throw InvalidMove {"Space is overloaded"}; space.value++; - _units[space.owner]++; - cout << "total: " << _units[space.owner] << endl; + units[space.owner]++; + cout << "total: " << units[space.owner] << endl; } auto Board2D::begin() const noexcept -> const_iterator { - return _spaces.cbegin(); + return spaces.cbegin(); } void Board2D::capture(const Coord c, const Player p) noexcept @@ -35,47 +35,47 @@ void Board2D::capture(const Coord c, const Player p) noexcept if (s.owner != p) { cout << "= P" << static_cast(p) << " captures " << s.coord.x << "," << s.coord.y << " : +" << s.value << endl; - _units[s.owner] -= s.value; - _units[p] += s.value; + units[s.owner] -= s.value; + units[p] += s.value; s.owner = p; } } auto Board2D::end() const noexcept -> const_iterator { - return _spaces.cend(); + return spaces.cend(); } -void Board2D::init(const size_type w, const size_type h) +void Board2D::init(const size_type w_, const size_type h_) { - _width = w; - _height = h; + w = w_; + h = h_; - _spaces.reserve(w * h); // NOLINT - for (size_type y = 0; y < h; y++) { - for (size_type x = 0; x < w; x++) { - _spaces.push_back(Coord {x, y}); - if (x == 0 || x == w - 1) { - if (y == 0 || y == h - 1) { - _spaces.back().capacity = 1; + spaces.reserve(w_ * h_); // NOLINT + for (size_type y = 0; y < h_; y++) { + for (size_type x = 0; x < w_; x++) { + spaces.push_back(Coord {x, y}); + if (x == 0 || x == w_ - 1) { + if (y == 0 || y == h_ - 1) { + spaces.back().capacity = 1; } else { - _spaces.back().capacity = 2; + spaces.back().capacity = 2; } } else { - if (y == 0 || y == h - 1) { - _spaces.back().capacity = 2; + if (y == 0 || y == h_ - 1) { + spaces.back().capacity = 2; } else { - _spaces.back().capacity = 3; + spaces.back().capacity = 3; } } } } - _units.emplace(Player::P1, 0); - _units.emplace(Player::P2, 0); + units.emplace(Player::P1, 0); + units.emplace(Player::P2, 0); } auto Board2D::is_overloaded(Coord c) const noexcept -> bool @@ -121,16 +121,16 @@ auto Board2D::neighbours(const Coord c) const noexcept -> vector vector nghbrs; if (c.x > 0) nghbrs.emplace_back(Coord {c.x - 1, c.y}); - if (c.x < _width - 1) nghbrs.emplace_back(Coord {c.x + 1, c.y}); + if (c.x < w - 1) nghbrs.emplace_back(Coord {c.x + 1, c.y}); if (c.y > 0) nghbrs.emplace_back(Coord {c.x, c.y - 1}); - if (c.y < _height - 1) nghbrs.emplace_back(Coord {c.x, c.y + 1}); + if (c.y < h - 1) nghbrs.emplace_back(Coord {c.x, c.y + 1}); return nghbrs; } auto Board2D::operator()(const Coord c) const noexcept -> const Board2D::Space& { - return _spaces.at(coord2idx(c)); + return spaces.at(coord2idx(c)); } void Board2D::remove_unit(const Coord c) @@ -139,20 +139,20 @@ void Board2D::remove_unit(const Coord c) const auto owner = s.owner; if (s.value > 1) { s.value--; - _units[owner]--; + units[owner]--; } else if (s.value == 1) { s.reset(); - _units[owner]--; + units[owner]--; } else throw logic_error("Space is empty"); cout << "- remove " << c.x << "," << c.y << " " - << "total: " << _units[owner] << endl; + << "total: " << units[owner] << endl; } auto Board2D::size() const noexcept -> pair { - return {_width, _height}; + return {w, h}; } auto Board2D::spread(const Coord src, const vector& targets, const Player p) @@ -188,7 +188,7 @@ auto Board2D::winner(const Board2D& b) noexcept -> Player { Player winner {Player::NONE}; - for (auto [key, value] : b._units) { + for (auto [key, value] : b.units) { if (value > 0) { if (winner == Player::NONE) winner = key; else return Player::NONE; @@ -200,15 +200,15 @@ auto Board2D::winner(const Board2D& b) noexcept -> Player auto Board2D::at(const Coord c) noexcept -> Space& { - return _spaces.at(coord2idx(c)); + return spaces.at(coord2idx(c)); } auto Board2D::at(const Coord c) const noexcept -> const Space& { - return _spaces.at(coord2idx(c)); + return spaces.at(coord2idx(c)); } auto Board2D::coord2idx(const Coord c) const noexcept -> size_type { - return c.y * _width + c.x; + return c.y * w + c.x; } diff --git a/src/core/board2d.hpp b/src/core/board2d.hpp index ed8f2b6..98abee1 100644 --- a/src/core/board2d.hpp +++ b/src/core/board2d.hpp @@ -51,16 +51,13 @@ namespace core Board2D() = default; Board2D(size_type, size_type); - void add_unit(Coord); [[nodiscard]] auto begin() const noexcept -> const_iterator; - void capture(Coord, Player) noexcept; [[nodiscard]] auto end() const noexcept -> const_iterator; void init(size_type, size_type); [[nodiscard]] auto is_overloaded(Coord) const noexcept -> bool; auto move(Coord, Player) -> Generator>; [[nodiscard]] auto neighbours(Coord) const noexcept -> std::vector; [[nodiscard]] auto operator()(Coord) const noexcept -> const Space&; - void remove_unit(Coord); [[nodiscard]] auto size() const noexcept -> std::pair; auto spread(Coord, const std::vector&, Player) -> Generator; [[nodiscard]] auto winner() const noexcept -> Player; @@ -68,14 +65,17 @@ namespace core [[nodiscard]] static auto winner(const Board2D&) noexcept -> Player; private: - size_type _height; - Spaces _spaces; - std::map _units; - size_type _width; + size_type h; + Spaces spaces; + std::map units; + size_type w; + void add_unit(Coord); [[nodiscard]] auto at(Coord) noexcept -> Space&; [[nodiscard]] auto at(Coord) const noexcept -> const Space&; + void capture(Coord, Player) noexcept; [[nodiscard]] auto coord2idx(Coord) const noexcept -> size_type; + void remove_unit(Coord); }; } diff --git a/src/core/generator.hpp.gch b/src/core/generator.hpp.gch deleted file mode 100644 index a50992a..0000000 Binary files a/src/core/generator.hpp.gch and /dev/null differ