Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question order within a topic should be randomized, and then cycled #12

Open
HelmetRemover opened this issue Apr 27, 2016 · 1 comment

Comments

@HelmetRemover
Copy link
Contributor

No description provided.

eladg added a commit that referenced this issue May 3, 2016
Big WIP commit:
- New question now returns within a category
- Breaking API updates to adopt new model
- Games now have categories when created (stupid ugly JSON to string
patch)
- Fixed Question’s enum’s string to integer issue (DBs are not
migratable, please db:reset and seed for new change).
- Seed data now randomize categories for each question
@eladg
Copy link
Contributor

eladg commented May 3, 2016

A) Check if questions within the category and within the game are the same size (i.e. all questions have been asked on category)
A.1) If so, return a question within the game's question pool (still within the same category).
A.2) If no, randomize a unique question
A.3) Add new question to game's question pool
B) return the randomized question

or in Ruby:

  def new_question(category)

    # if no new question is available
    if Question.where(category: Question.categories[category]).count <= questions.where(category: Question.categories[category]).count
      question = questions.where(category: Question.categories[category]).sample
    else    
      question = loop do
        qq = Question::random_question(category)

        # prefer a unique question for our game
        break qq unless questions.include? qq
      end

      questions << question unless question.nil?
    end

    question
  end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants