75 lines
1.9 KiB
C++
75 lines
1.9 KiB
C++
#ifndef CORE_BOARD2D_HPP
|
|
#define CORE_BOARD2D_HPP
|
|
|
|
#include <array>
|
|
#include <stdexcept>
|
|
#include <vector>
|
|
|
|
#include "generator.hpp"
|
|
#include "player.hpp"
|
|
|
|
namespace core
|
|
{
|
|
class Board2D
|
|
{
|
|
public:
|
|
struct Space;
|
|
using Spaces = std::vector<Space>;
|
|
using size_type = Spaces::size_type;
|
|
|
|
struct Coord
|
|
{
|
|
size_type x;
|
|
size_type y;
|
|
|
|
Coord(size_t x_, size_t y_) : x {x_}, y {y_} {}
|
|
};
|
|
|
|
struct Space
|
|
{
|
|
int capacity {};
|
|
Coord coord;
|
|
Player owner {Player::NONE};
|
|
int value {0};
|
|
|
|
Space(Coord c) : coord {c} {}
|
|
|
|
inline void reset() noexcept
|
|
{
|
|
owner = Player::NONE;
|
|
value = 0;
|
|
}
|
|
};
|
|
|
|
struct InvalidMove : public std::logic_error
|
|
{
|
|
using std::logic_error::logic_error;
|
|
};
|
|
|
|
Board2D() = default;
|
|
Board2D(size_type, size_type);
|
|
|
|
void add_unit(Coord);
|
|
void capture(Coord, Player) noexcept;
|
|
void init(size_type, size_type);
|
|
auto move(Coord, Player) -> Generator<Board2D>;
|
|
[[nodiscard]] auto neighbours(Coord) const noexcept -> std::vector<Coord>;
|
|
[[nodiscard]] auto operator()(Coord) const noexcept -> const Space&;
|
|
[[nodiscard]] auto size() const noexcept -> std::array<size_type, 2>;
|
|
auto spread(Coord, const std::vector<Coord>&, Player) -> Generator<Board2D>;
|
|
|
|
[[nodiscard]] auto is_overloaded(Coord) const noexcept -> bool;
|
|
|
|
private:
|
|
size_type _height;
|
|
Spaces _spaces;
|
|
size_type _width;
|
|
|
|
[[nodiscard]] auto at(Coord) noexcept -> Space&;
|
|
[[nodiscard]] auto at(Coord) const noexcept -> const Space&;
|
|
[[nodiscard]] auto coord2idx(Coord) const noexcept -> size_type;
|
|
};
|
|
}
|
|
|
|
#endif
|