Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 26 additions & 14 deletions firmware/include/modes/SnakeMode.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,55 @@
#include "handlers/ClockHandler.h" // NOLINT(misc-include-cleaner)
#include "modules/ModeModule.h"

#include <array>
#include <bits/unique_ptr.h>
#include <deque>
#include <optional>

class SnakeMode final : public ModeModule
{
private:
struct Pixel
enum class Stage : uint8_t // NOLINT(performance-enum-size)
{
uint8_t x{0U}; // NOLINT(misc-non-private-member-variables-in-classes)
uint8_t y{0U}; // NOLINT(misc-non-private-member-variables-in-classes)
bool operator==(const Pixel &pixel) const { return x == pixel.x && y == pixel.y; }
bool operator!=(const Pixel &pixel) const { return x != pixel.x || y != pixel.y; }
bool operator<(const Pixel &pixel) const { return y < pixel.y || (y == pixel.y && x < pixel.x); }
READY,
MOVE,
DEATH,
REMOVE,
};

unsigned long lastMillis{0UL};

uint8_t blinkCount{0U};
uint8_t stage{0U};

Pixel target;
size_t head{0U};
size_t length{0U};
size_t target{0U};

std::deque<Pixel> snake{};
std::array<size_t, GRID_COLUMNS * GRID_ROWS> snake{};
std::array<bool, GRID_COLUMNS * GRID_ROWS> occupied{};

Comment thread
JanPetterMG marked this conversation as resolved.
std::unique_ptr<ClockHandler> clock{};

void idle();
[[nodiscard]] std::optional<Pixel> next() const;
void move();
Stage stage{Stage::READY};

void blink();
void clean();

void idle();
void move();
void setClock(bool _clock);
void setDead();
void setTarget();
void snakeReset(size_t start);
void snakeClear();
void transmit();

[[nodiscard]] bool snakePushBack(size_t pixel);

[[nodiscard]] size_t snakeAt(size_t index) const;
[[nodiscard]] size_t snakePopFront();

[[nodiscard]] std::optional<size_t> findStepAvailable() const;
[[nodiscard]] std::optional<size_t> findStepPath() const;

public:
static constexpr std::string_view name{"Snake"};

Expand Down
Loading