more stuff

This commit is contained in:
Asuro
2025-02-24 05:29:24 +01:00
parent 369b994755
commit d3dcec1458
6 changed files with 156 additions and 6 deletions

View File

@@ -1,3 +1,4 @@
#include "Log.h"
#include "Puzzle.h"
#include <cassert>
@@ -9,10 +10,36 @@ namespace
{0, 1},
{1, 0},
};
}
Puzzle::StaticPuzzleData* StaticDataInstance = nullptr;
} // namespace
namespace Puzzle
{
void StaticPuzzleData::Setup()
{
if (StaticDataInstance == nullptr)
{
StaticDataInstance = this;
Log("Setting up static puzzle data");
}
else
{
Log("Static puzzle data already set up");
}
}
StaticPuzzleData& StaticPuzzleData::Get()
{
assert(StaticDataInstance != nullptr);
return *StaticDataInstance;
}
const StaticPuzzleCard& StaticPuzzleData::GetCard(StaticPuzzleCardHandle H) const
{
assert(H.IsValid());
return Cards[H.Idx];
}
bool PuzzleNode::HasElement(PuzzleElementType search) const
{
for (int32_t i = 0; i < Config::MaxElementsPerTile; ++i)
@@ -37,11 +64,29 @@ namespace Puzzle
return MaxAvailableCount - UsedCount;
}
const PuzzleNode& PuzzleData::GetNodeAt(PuzPos pos) const
{
assert(pos.X < Config::MaxPuzzleSizeCards && pos.Y < Config::MaxPuzzleSizeCards && pos.X >= 0 && pos.Y >= 0);
return PlacedNodes[pos.Y * Config::MaxPuzzleSizeCards + pos.X];
}
PuzzleElementType PuzzleData::GetElementAt(ElemPos pos) const
{
assert(pos.ElemIdx < Config::MaxElementsPerTile);
const PuzzleNode& node = GetNodeAt(pos.Position);
return node.PlacedTypes[pos.ElemIdx];
}
bool PuzzleSolver::IsPuzzleSolved(const PuzzleData& puzzle)
{
bool IsSolved = true;
for (uint32_t i = 0; i < puzzle.GoalPositionCount; ++i)
{
if (!IsExitSatisfied(puzzle, puzzle.GoalPositions[i]))
{
IsSolved = false;
break;
}
}
return IsSolved;
}