Play Game Flashcards

(13 cards)

1
Q

what are the parameters called in playGame?

A

(List<int> Targets, List<int> NumbersAllowed, bool TrainingGame, int MaxTarget, int MaxNumber)</int></int>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

State the local variables inside PlayGame

A

Score: Tracks how many points the user has.

GameOver: Controls when to break from the game loop. Gains when hitting a target, loses 1 each turn.

UserInput: The raw expression the user types in each turn.

UserInputInRPN: The user’s expression converted to Reverse Polish Notation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Briefly explain the gameplay loop in playGame

A

Repeats until GameOver becomes true.

First calls DisplayState which in turn calls DisplayTargets, DisplayNumbersAllowed, and DisplayScore.

while (!GameOver) keeps running until a condition sets GameOver = true.
DisplayState(Targets, NumbersAllowed, Score);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How is the user input validated, in regards with the expression they type?

A

Reads the user’s typed math expression, like 2+3*8.

  • Uses CheckIfUserInputValid (a regex) to ensure it’s a valid format.

If valid, it calls ConvertToRPN to transform a standard expression with operator precedence into a form that’s easy to evaluate.

UserInput = Console.ReadLine();
Console.WriteLine();

if (CheckIfUserInputValid(UserInput))
UserInputInRPN = ConvertToRPN(UserInput);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Explain what this code does:

if
{
(CheckNumbersUsedAreAllInNumbersAllowed(NumbersAllowed, UserInputInRPN, MaxNumber))
{
if (CheckIfUserInputEvaluationIsATarget(Targets, UserInputInRPN, ref Score))
{
RemoveNumbersUsed(UserInput, MaxNumber, NumbersAllowed);
NumbersAllowed = FillNumbers(NumbersAllowed, TrainingGame, MaxNumber);
}
}

A

Ensures the user only used numbers that appear in NumbersAllowed.

If the evaluated result matches one or more targets, award points, remove the target(s) by setting them to -1, and remove the used numbers from NumbersAllowed.

Then refill the NumbersAllowed list if needed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How does the scoring system work , each time user enters an expression?

A

Each turn, the user loses 1 point for taking the turn, forcing them to solve targets efficiently rather than spamming random expressions.

Score–;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How does the game check whether the game ends while game loop is running?

A

If the first element in Targets is no longer -1, it means we have a “live” target in the front that the user hasn’t cleared in time, so the game ends.
if (Targets[0] != -1)
{
GameOver = true;
}

Otherwise, shift the queue of targets and generate a new one with UpdateTargets.
else
{
UpdateTargets(Targets, TrainingGame, MaxTarget);
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What happens in PLayGame when checking for game over conditions?

A

If the first target in the list is not -1, that means we have a “live” target at position 0 that the user hasn’t cleared, so the game ends.

Otherwise, we shift the queue with UpdateTargets, removing the front item and adding a new one.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the main functions of the PlayGame method:

A

user input,
validating,
evaluating,
scoring,
checking game-over conditions,
updating the board.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

what is target clear and how does it work?

A

Target Clear” is a game where you start with a queue of “targets,” each of which is an integer the user tries to “hit” by typing arithmetic expressions. The user also has a limited set of “numbers allowed” each turn.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

explain the game loop for target clear

A

The program checks if the expression is valid (regex check).

It converts that expression to Reverse Polish Notation (RPN) to handle operator precedence.

It evaluates the RPN expression to a single result.

If that result matches any of the “targets,” the user scores points, and those matching targets are marked cleared (represented by -1).

The numbers used to form that expression are removed from the “numbers allowed” and partially replenished.

If the leftmost (front) target is no longer marked as cleared (meaning it’s not -1), the game ends; otherwise, new targets come in from the “back” (like a conveyor belt).

Each turn costs you 1 point from your score, so you need to solve targets efficiently

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

explain how ref Position is used in CheckIfUserInputEvaluationIsATarget and why the ref is calculated in this way?

A

ref means that if this function modifies Score, those modifications are reflected back in the variable in the calling method. It’s like passing a direct reference, not just a copy of the integer.

This approach is chosen so we don’t need to return the score from the function. Instead, the function returns a bool for whether the user’s expression matched a target, and uses ref Score for the actual numeric effect.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

what are the conditions after the user hits the target?

A

Remove the numbers they used in the expression from NumbersAllowed.

Refill if the list now has fewer than 5 numbers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly