From dcfaa5d1eb527ab8d6bfcc14aab6c7a4ad92e185 Mon Sep 17 00:00:00 2001 From: Nicolas Mailloux Date: Mon, 16 Dec 2024 15:19:12 -0500 Subject: [PATCH] FlashExam: new 'brain brute-force' mode --- src/apps/flashexam.cpp | 50 ++++++++++++++- src/apps/flashexam.h | 4 ++ src/apps/flashexam.ui | 138 +++++++++++++++++++++++++++++------------ 3 files changed, 148 insertions(+), 44 deletions(-) diff --git a/src/apps/flashexam.cpp b/src/apps/flashexam.cpp index 9475706..7a5e064 100644 --- a/src/apps/flashexam.cpp +++ b/src/apps/flashexam.cpp @@ -34,6 +34,7 @@ flashExam::flashExam(QWidget *parent) ui->saveCardsNotKnownToFileCheckBox->setDisabled(true); ui->randomizeCheckBox->click(); ui->randomizeCheckBox->setDisabled(true); + ui->brainBruteForceCardsThresholdSpinBox->setDisabled(true); graphicsScene = new QGraphicsScene(this); setupCardsList(); @@ -69,6 +70,7 @@ void flashExam::on_startBtn_clicked() listName = ui->listWidget->currentItem()->text(); QString cardsList = "/mnt/onboard/onboard/.flashexam/" + listName; QString answersList = "/mnt/onboard/onboard/.flashexam/" + listName + ".answers"; + brainBruteForceCardsThreshold = ui->brainBruteForceCardsThresholdSpinBox->value(); if(QFile::exists(answersList)) { log("Setting up cards list '" + listName + "'", className); initCardsList(cardsList, answersList); @@ -87,6 +89,7 @@ void flashExam::initCardsList(QString cardsList, QString answersList) { randomize = ui->randomizeCheckBox->isChecked(); nonRedundantRandomization = ui->nonRedundantRandomizationCheckBox->isChecked(); saveCardsNotKnownToFile = ui->saveCardsNotKnownToFileCheckBox->isChecked(); + brainBruteForceMode = ui->brainBruteForceCheckBox->isChecked(); cardsAlreadyShown.clear(); cardsNotKnown.clear(); ui->nonRedundantRandomizationCheckBox->setChecked(false); @@ -140,13 +143,32 @@ void flashExam::displayCard(bool existingCardNumber) { ui->cardNumberLabel->setText(QString::number(cardsAlreadyShownNumber / cardsTotalFloat * 100, 'f', 1) + "% done, " + QString::number(cardsNotKnownNumber / cardsTotalFloat * 100, 'f', 1) + "% forgotten"); } else { - ui->cardNumberLabel->hide(); + if(!brainBruteForceLock) { + ui->cardNumberLabel->hide(); + } } if(!existingCardNumber) { if(randomize) { + if(brainBruteForceLock && cardsNotKnown.isEmpty()) { + brainBruteForceLock = false; + ui->cardNumberLabel->hide(); + ui->cardNumberLabel->setText(""); + } + if(brainBruteForceMode && cardsNotKnown.count() >= brainBruteForceCardsThreshold) { + brainBruteForceLock = true; + ui->cardNumberLabel->setText("Brain brute-force mode"); + ui->cardNumberLabel->show(); + } while(true) { - currentCardNumber = QRandomGenerator::global()->bounded(cardsTotal - 1); + if(brainBruteForceLock) { + currentCardNumber = cardsNotKnown.at(cardsNotKnown.count() - 1); + cardsNotKnown.removeLast(); + log("Brain brute-force mode: displaying card " + QString::number(currentCardNumber), className); + } + else { + currentCardNumber = QRandomGenerator::global()->bounded(cardsTotal - 1); + } if(nonRedundantRandomization) { if(!cardsAlreadyShown.contains(currentCardNumber)) { cardsAlreadyShown.append(currentCardNumber); @@ -218,9 +240,11 @@ void flashExam::on_randomizeCheckBox_toggled(bool checked) { if(checked) { ui->nonRedundantRandomizationCheckBox->setDisabled(false); + ui->brainBruteForceCheckBox->setDisabled(false); } else { ui->nonRedundantRandomizationCheckBox->setDisabled(true); + ui->brainBruteForceCheckBox->setDisabled(true); } } @@ -234,7 +258,9 @@ void flashExam::on_didNotKnowBtn_clicked() void flashExam::on_nonRedundantRandomizationCheckBox_toggled(bool checked) { if(checked) { - ui->saveCardsNotKnownToFileCheckBox->setDisabled(false); + if(!ui->brainBruteForceCheckBox->isChecked()) { + ui->saveCardsNotKnownToFileCheckBox->setDisabled(false); + } } else { ui->saveCardsNotKnownToFileCheckBox->setDisabled(true); @@ -242,3 +268,21 @@ void flashExam::on_nonRedundantRandomizationCheckBox_toggled(bool checked) } } + +void flashExam::on_brainBruteForceCheckBox_toggled(bool checked) +{ + if(checked) { + if(ui->nonRedundantRandomizationCheckBox->isChecked()) { + ui->saveCardsNotKnownToFileCheckBox->setDisabled(true); + ui->saveCardsNotKnownToFileCheckBox->setChecked(false); + } + ui->brainBruteForceCardsThresholdSpinBox->setDisabled(false); + } + else { + if(ui->nonRedundantRandomizationCheckBox->isChecked()) { + ui->saveCardsNotKnownToFileCheckBox->setDisabled(false); + } + ui->brainBruteForceCardsThresholdSpinBox->setDisabled(true); + } +} + diff --git a/src/apps/flashexam.h b/src/apps/flashexam.h index 059c9b6..d63d1fb 100644 --- a/src/apps/flashexam.h +++ b/src/apps/flashexam.h @@ -25,6 +25,9 @@ private: bool randomize; bool nonRedundantRandomization; bool saveCardsNotKnownToFile; + bool brainBruteForceMode; + bool brainBruteForceLock = false; + int brainBruteForceCardsThreshold; QList cardsAlreadyShown; QList cardsNotKnown; bool answerShown = false; @@ -47,6 +50,7 @@ private slots: void on_randomizeCheckBox_toggled(bool checked); void on_didNotKnowBtn_clicked(); void on_nonRedundantRandomizationCheckBox_toggled(bool checked); + void on_brainBruteForceCheckBox_toggled(bool checked); }; #endif // FLASHEXAM_H diff --git a/src/apps/flashexam.ui b/src/apps/flashexam.ui index 2fd2227..8637006 100644 --- a/src/apps/flashexam.ui +++ b/src/apps/flashexam.ui @@ -35,6 +35,31 @@ + + + + QFrame::Shadow::Plain + + + 2 + + + Qt::Orientation::Horizontal + + + + + + + + U001 + + + + Non-redundant randomized mode + + + @@ -102,7 +127,10 @@ - + + + + QFrame::Shadow::Plain @@ -112,28 +140,27 @@ - - - - QFrame::Shadow::Plain - - - 2 - - - Qt::Orientation::Horizontal - - - - - + + U001 - Non-redundant randomized mode + Save forgotten cards list to file + + + + + + + + true + + + + Start @@ -150,31 +177,60 @@ - - - - true - + + + 0 - - Start - - - - - - - - - - - U001 - - - - Save forgotten cards list to file - - + + + + 10 + + + + + + + + 0 + 0 + + + + + U001 + + + + Brain brute-force mode + + + + + + + + U001 + + + + Every + + + + + + + + U001 + + + + forgotten cards + + + +