Trivia Quiz

From UBC Wiki

What is the problem?

We will make a trivia quiz system in Prolog that mimics those often presented at "trivia night" events. There will be a set of questions organized in a table. Each column consists of questions in the same or different categories, and each row consists of questions with specific difficulties. Each row is assigned a score value, and if a team answers the question on that row correctly, they will gain that amount of score. Usually, the questions with higher scores are designed to be harder to answer. Participating teams take turns choosing an unanswered question from the table; the question will only be revealed after it has been chosen. Then, the team has to provide a correct answer in order to gain the score for that question. After all questions have been answered, the highest scoring team wins.

Our program will facilitate the revealing of questions and checking the correctness of the answers given by the players.

What is the something extra?

We plan to add a score tracking feature so each team's total score so far can be retrieved and displayed.

If time permits, we would also like to try to generate the questions from a given knowledge base dynamically so that each time the trivia board is played, the questions will be different.

What did you learn from it?

In our trivia quiz, we can see the strengths of Prolog when dealing with tasks that involve complex logical relationships. Prolog’s declarative nature allows programmers to describe what the program should accomplish rather than how to do it, which is particularly suitable for problems that are governed by logic and rules.

Moreover, the game showcases Prolog's capabilities in pattern matching and recursion. These features make Prolog especially well-suited for managing data structures and implementing algorithms that perform complex operations on data. For instance, the sorting and display of trivia questions in the game rely heavily on these techniques.

State management in Prolog is achieved by dynamically adding and removing facts (such as the answered status of questions in our game), demonstrating how logic programming can effectively handle state within a declarative paradigm. This is different from the traditional functional programming approach of using immutable data structures to manage state, but it is equally powerful.

Work division

Shenglong: Generated the game table based on the questions, added basic rules and logic of the game.

William: Created the questions and the random generation of questions on initialization. Also added handling for edge cases.

Sophie(Yufei): Added the give-up actions, including actual give-up, try again, and providing hints. Also added the create team name section, and changing accordingly during the play game section.

Links to code etc.

https://github.com/legendword/trivia-quiz