Skip to content

Conversation

chanderlud
Copy link

I worked with @JosephPotapenko on this assignment.

For extra credit, we implemented an AI trivia question generator that uses the OpenAI API to generate more questions once the preset ones run out. In order to use this feature, the OPENAI_API_KEY environmental variable must be set to a valid API key.

@Copilot Copilot AI review requested due to automatic review settings September 30, 2025 04:04
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds AI-generated trivia questions to the Princess Bride trivia game using OpenAI's API. After completing the preset questions, the game continues with dynamically generated questions until the user types 'exit'.

  • Integrated OpenAI API to generate additional Princess Bride trivia questions
  • Added continuous gameplay loop with exit condition
  • Fixed integer division bug in percentage calculation

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
Program.cs Added OpenAI integration, continuous gameplay loop, and fixed percentage calculation
PrincessBrideTrivia.csproj Added OpenAI package dependency
ProgramTests.cs Added basic tests for AI question generation functionality

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

{
var apiKey = Environment.GetEnvironmentVariable("OPENAI_API_KEY");
Question q = await TriviaGenerator.GeneratePrincessBrideQuestionAsync(apiKey);
Assert.HasCount(4, q.Answers);
Copy link
Preview

Copilot AI Sep 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assert.HasCount is not a valid MSTest assertion method. Use Assert.AreEqual(4, q.Answers.Length) instead.

Suggested change
Assert.HasCount(4, q.Answers);
Assert.AreEqual(4, q.Answers.Length);

Copilot uses AI. Check for mistakes.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may have been the standard previously, but with the MSTests that were provided which are more current than the old standards, this is no longer the case, and .HasCount is actually correct.

Copy link

@PigPig-SDK PigPig-SDK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super cool extra credit. Though I cannot say how well the AI semantics play (I cannot be bothered getting an API key). I'm confident the try,catch,async and awaits will be functional.

}

public static bool AskQuestion(Question question)
public static (bool, bool) AskQuestion(Question question)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could replace the tuple with [flag] enum for better code clarity.
EX:
[Flags] public enum SorryImBadAtNames: byte { None = 0, AnswerdCorrectly = 1, QuitProgram = 2, };
Then you can use the objectEnum.HasFlag(FLAG); to figure out the response. More info at link:
https://learn.microsoft.com/en-us/dotnet/api/system.enum.hasflag?view=net-9.0

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementing enum would be a lot messier and a less concise. However, dealing with both the correct answers and quitting the program in one function is a good suggestion and will be implemented.

Copy link

@BillMillerCoding BillMillerCoding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assignment Details
Pull Request title includes "Assignment 1" in the title ✔
Partner has also made a commit ✔
Pull Request targets Assignment 1 branch ✔
Issue 1: Application no longer crashes ✔
Issue 2: Unit test properly passes ✔
Extra Credit
Come up with a new feature for the application

Issue 3: Add a new feature request implemented ✔
Issue 3: Feature request unit tested ✔
Very impressive in my opinion! The AI feature is super cool and you guys definitely have some know how! great work

string answer2 = lines[lineIndex + 2];
string answer3 = lines[lineIndex + 3];
Question question = new() { Text = lines[lineIndex], Answers = new string[3], CorrectAnswerIndex = lines[lineIndex + 4] };
question.Answers[0] = lines[lineIndex + 1];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like how in this section you condensed the code and made it more streamlined. However, I personally prefer the readability of the previous version. Since I don't see this contradicting any guidelines this is purely a stylistic opinion.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd personally chose to stick with the streamlined code because it’s cleaner and easier to maintain. It does the same thing as before but with less repetition, which reduces the chance of errors if future maintenance was to become a concern.

if (string.IsNullOrWhiteSpace(apiKey))
throw new ArgumentException("API key is required.", nameof(apiKey));

if (choices is < 3 or > 6)
Copy link

@BillMillerCoding BillMillerCoding Oct 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very much grasping for straws here cause your code is so spot on! perhaps you should avoid making the bounds magic numbers and instead having the answer bounds be variables or consts. This would add versatility if the program ever was to be updated with more options

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback! In this case, I chose to leave the bounds as-is since the program is intentionally simple and unlikely to change. Introducing constants or variables here wouldn’t add much value for this particular use case, but I appreciate the suggestion.

Copy link

@steeley21 steeley21 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assignment Details

Pull Request title includes "Assignment 1" in the title ✔
Partner has also made a commit ✔
Pull Request targets Assignment 1 branch ✔
Issue 1: Application no longer crashes ✔
Issue 2: Unit test properly passes ✔

Extra Credit

Come up with a new feature for the application
    Issue 3: Add a new feature request implemented ✔
    Issue 3: Feature request unit tested ✔

Cool feature update!

JosephPotapenko and others added 6 commits October 1, 2025 21:34
…e Assert.HasCount(...) instead of Assert.AreEqual(..., collection.Length).
…n the same method in order to have more readable code.
… of the program. I changed it to the very beginning so as to be more user friendly. I also fixed the grades to display properly- whether you quit early, or if you finish everything correctly.
Copy link

github-actions bot commented Oct 2, 2025

Summary

Summary
Generated on: 10/02/2025 - 20:58:43
Coverage date: 10/02/2025 - 20:58:40
Parser: MultiReport (2x Cobertura)
Assemblies: 1
Classes: 3
Files: 3
Line coverage: 22.1% (37 of 167)
Covered lines: 37
Uncovered lines: 130
Coverable lines: 167
Total lines: 249
Branch coverage: 6% (4 of 66)
Covered branches: 4
Total branches: 66
Method coverage: Feature is only available for sponsors
Tag: 42_18205469505

Coverage

PrincessBrideTrivia - 22.1%
Name Line Branch
PrincessBrideTrivia 22.1% 6%
PrincessBrideTrivia.Program 33.6% 13.3%
PrincessBrideTrivia.Question 100%
PrincessBrideTrivia.TriviaGenerator 0% 0%

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

Successfully merging this pull request may close these issues.

5 participants