allowing count selection

This commit is contained in:
noffie 2025-01-12 19:02:19 +01:00
parent ed93a280be
commit 1627abc431
3 changed files with 29 additions and 8 deletions

View file

@ -1,14 +1,29 @@
#include <stdio.h> #include <stdio.h>
#include "sortiva/sortiva.hpp" #include "sortiva/sortiva.hpp"
#include <string>
//#undef _DEBUG //#undef _DEBUG
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
uint8_t CountValues = 5;
for (int i = 0; i < argc; ++i)
{
std::string arg = argv[i];
if (arg == "-n")
{
if (i + 1 < argc)
{
arg = argv[++i];
CountValues = static_cast<uint8_t>(std::stoi(arg));
}
}
}
printf("Darling, I'm Home!\n"); printf("Darling, I'm Home!\n");
#ifdef _DEBUG #ifdef _DEBUG
try { try {
#endif #endif
Sortiva app; Sortiva app(CountValues);
app.run(); app.run();
#ifdef _DEBUG #ifdef _DEBUG
} }

View file

@ -9,8 +9,7 @@
#include <raylib.h> #include <raylib.h>
Sortiva::Sortiva() : m_Ticker(std::chrono::seconds(1)) void Sortiva::init() {
{
m_Sorter.set(m_List); m_Sorter.set(m_List);
m_Steps = std::make_unique<val_step_diag>(); m_Steps = std::make_unique<val_step_diag>();
@ -28,6 +27,13 @@ Sortiva::Sortiva() : m_Ticker(std::chrono::seconds(1))
MaximizeWindow(); MaximizeWindow();
} }
Sortiva::Sortiva(uint8_t count) : m_Ticker(std::chrono::seconds(1)) {
init();
count--;
m_CountValues = count % 7;
m_CountValues++;
}
Sortiva::~Sortiva() Sortiva::~Sortiva()
{ {
CloseWindow(); CloseWindow();
@ -60,10 +66,8 @@ void Sortiva::setup()
m_Steps->clear(); m_Steps->clear();
m_List.list.clear(); m_List.list.clear();
uint16_t count = 5;
for (uint8_t i = 1; i <= m_CountValues; ++i) // 1,2,3,4,5
for (int i = 1; i <= count; ++i) // 1,2,3,4,5
{ {
m_List.list.push_back(i); m_List.list.push_back(i);
m_Steps->emplace_back(); m_Steps->emplace_back();
@ -74,7 +78,7 @@ void Sortiva::setup()
std::ranges::shuffle(m_List.list, rng); // 2,3,1,5,4 std::ranges::shuffle(m_List.list, rng); // 2,3,1,5,4
for (int i = 1; i <= count; ++i) for (uint8_t i = 1; i <= m_CountValues; ++i)
{ {
m_Steps->at(m_List.at(i - 1) - 1).value = i; m_Steps->at(m_List.at(i - 1) - 1).value = i;
} }

View file

@ -52,7 +52,7 @@ public:
class Sortiva final class Sortiva final
{ {
public: public:
Sortiva(); Sortiva(uint8_t);
~Sortiva(); ~Sortiva();
void run(); void run();
@ -66,7 +66,9 @@ private:
void update(double); void update(double);
void setup(); void setup();
void init();
uint8_t m_CountValues;
bool m_SortingFinished = true; bool m_SortingFinished = true;
TickSystem m_Ticker; TickSystem m_Ticker;
Bubble_Sorter m_Sorter; Bubble_Sorter m_Sorter;