brandonshawfhl / Quiz-Maker

0 stars 0 forks source link

Get rid of the List<List<string>> ? #27

Closed mayisa87 closed 8 months ago

mayisa87 commented 9 months ago

[10:34, 23.1.2024] Isabella Mayer: So I added some issues. What I still don't get completely is, your List<List> for your answer shuffeling...

So as far as I understand, what you want to achieve is, to shuffle all of your quiz data, so first of all your QuizCards in general, and then within the QuizCards, shuffle your answers. [10:36, 23.1.2024] Isabella Mayer: So for me it would make more sense, to first shuffle the QuizCards as you already do, and return the new shuffled list 👍🏻

And then use and change this list. 1.) So iterate through your QuizCards. 2.) For each QuizCards get the List of answers 3.) Make a temporary List where you store for this single QuizCard your shuffled answers. 4.) Instead of storing it into a List<List> you just overwrite the incorrectAnswer list in your QuizCard object [10:37, 23.1.2024] Isabella Mayer: What is the difference?

Instead of having a list of quiz cards and a list of answers separately, you will only have the list of QuizCards So you can then access the answers, shuffeled, via the QuizCard always, which makes it a bit more neat

brandonshawfhl commented 9 months ago

That was the way I originally had it set up, but Michael found it redundant. No matter what you still have to keep track of the correct answer, so it ends up getting stored twice in the object. He didn't like that so I changed it to the way that I'm doing it now which I also got a thumbs up from Florian on as well.

incredibleLeitman commented 9 months ago

Hey @brandonshawfhl I think there might be some confusion because of the long time and that the issue persists over several issues and chats :/

The initial feedback to not store the answers twice in each object was requested by me right and seems now to be fixed 👍

However, now you have a list of QuizCards and additionally a List of all answer lists:

List<QuizCard> currentQuiz = Logic.ShuffleQuizCards(madeQuiz);
List<List<string>> answerList = Logic.ShuffleAnswers(currentQuiz);

Here you also hold the actual answer data twice: once in each QuizCard object (where they are not shuffled) and again in the List<List> after shuffling.

What @mayisa87 meant was, that you could get rid of this second list when instead of holding all answers in a separate list you override the data in each quizcard instead.

So instead of having public static List<List<string>> ShuffleAnswers(List<QuizCard> currentQuiz) this function could take only one QuizCard object, create a temporary list that contains the shuffled answers and then just override the existing list like

public static void ShuffleAnswers(QuizCard quizCard)
{
  List<string> shuffledAnswers = new List<string>();
  // fill shuffledAnswers with all wrong answer options randomly

  quizCard.incorrectAnswers = shuffledAnswers;
}

The problem with this approach is, that this only allows you to shuffle the incorrect answers because your datastructure does not have a field for all answers. :/

To mitigate this, you could either create a function that returns a list of all answer (similar to what you do currently but for only one QuizCard not for the whole quiz so you just have a List and not a List<List>) or just shuffle all answers for the user when displaying them to the console.

It is pretty hard to explain through issues and chat and results in very long textblocks so I would advice to join one of the upcoming live calls to guide you through this :D