puzzle setup
This commit is contained in:
120
src/game/Puzzle.h
Normal file
120
src/game/Puzzle.h
Normal file
@@ -0,0 +1,120 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
|
||||
namespace Puzzle
|
||||
{
|
||||
struct Config
|
||||
{
|
||||
static constexpr uint32_t CardSize = 2;
|
||||
static constexpr uint32_t NodesPerCard = CardSize * CardSize;
|
||||
static constexpr uint32_t MaxElementsPerTile = 4;
|
||||
static constexpr uint32_t MaxPuzzleSizeCards = 16;
|
||||
static constexpr uint32_t MaxCardsInPuzzle = MaxPuzzleSizeCards * MaxPuzzleSizeCards;
|
||||
static constexpr uint32_t MaxPuzzleSizeTiles = 16 * CardSize;
|
||||
static constexpr uint32_t MaxTilesInPuzzle = MaxPuzzleSizeTiles * MaxPuzzleSizeTiles;
|
||||
static constexpr uint32_t MaxAvailableStacks = 16;
|
||||
static constexpr uint32_t MaxGoalPositions = 16;
|
||||
};
|
||||
|
||||
struct PuzPos
|
||||
{
|
||||
int8_t X = 0;
|
||||
int8_t Y = 0;
|
||||
|
||||
PuzPos& operator+=(const PuzPos& rhs)
|
||||
{
|
||||
X += rhs.X;
|
||||
Y += rhs.Y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
friend PuzPos operator+(PuzPos lhs, const PuzPos& rhs)
|
||||
{
|
||||
lhs += rhs;
|
||||
return lhs;
|
||||
}
|
||||
};
|
||||
|
||||
struct ElemPos
|
||||
{
|
||||
PuzPos Position;
|
||||
uint8_t ElemIdx = 0;
|
||||
};
|
||||
|
||||
enum class PuzzleElementType : uint8_t
|
||||
{
|
||||
None,
|
||||
WaterIn,
|
||||
WaterGoal,
|
||||
WaterChannel,
|
||||
ElectricIn,
|
||||
ElectricGoal,
|
||||
Blocked,
|
||||
Bridge,
|
||||
};
|
||||
|
||||
struct PuzzleNode
|
||||
{
|
||||
PuzzleElementType PlacedTypes[Config::MaxElementsPerTile]{PuzzleElementType::None};
|
||||
|
||||
bool HasElement(PuzzleElementType search) const;
|
||||
bool IsEmpty() const;
|
||||
};
|
||||
|
||||
struct StaticPuzzleCard
|
||||
{
|
||||
PuzzleNode Nodes[Config::NodesPerCard];
|
||||
};
|
||||
|
||||
struct StaticPuzzleCardHandle
|
||||
{
|
||||
uint16_t Idx = UINT16_MAX;
|
||||
};
|
||||
|
||||
struct PlacedPuzzleCard
|
||||
{
|
||||
StaticPuzzleCardHandle RefCard;
|
||||
PuzPos Position;
|
||||
uint8_t Rotation = 0;
|
||||
bool IsLocked = false;
|
||||
};
|
||||
|
||||
struct PuzzleCardStack
|
||||
{
|
||||
StaticPuzzleCardHandle RefCard;
|
||||
uint8_t MaxAvailableCount = 0;
|
||||
uint8_t UsedCount = 0;
|
||||
|
||||
uint8_t GetRemainingCount();
|
||||
};
|
||||
|
||||
struct PuzzleData
|
||||
{
|
||||
uint32_t AvailableCardCount = 0;
|
||||
PuzzleCardStack AvailableCards[Config::MaxAvailableStacks];
|
||||
uint32_t PlacedCardCount = 0;
|
||||
PlacedPuzzleCard PlacedCards[Config::MaxCardsInPuzzle];
|
||||
|
||||
// Indexed by board position
|
||||
PuzzleNode PlacedNodes[Config::MaxTilesInPuzzle];
|
||||
|
||||
uint32_t GoalPositionCount = 0;
|
||||
ElemPos GoalPositions[Config::MaxGoalPositions];
|
||||
|
||||
const PuzzleNode& GetNodeAt(PuzPos pos) const;
|
||||
PuzzleElementType GetElementAt(ElemPos pos) const;
|
||||
};
|
||||
|
||||
struct PuzzleSolver
|
||||
{
|
||||
bool IsPuzzleSolved(const PuzzleData& puzzle);
|
||||
bool IsExitSatisfied(const PuzzleData& puzzle, ElemPos pos);
|
||||
|
||||
// This assumes flowFrom is already verified to be connected.
|
||||
bool IsValidGoalConnection(const PuzzleData& puzzle,
|
||||
PuzPos flowFrom,
|
||||
PuzPos flowTo,
|
||||
PuzzleElementType goalType);
|
||||
bool IsValidSource(PuzzleElementType sourceType, PuzzleElementType goalType);
|
||||
};
|
||||
} // namespace Puzzle
|
||||
Reference in New Issue
Block a user