0% found this document useful (0 votes)
52 views3 pages

Memory Match Game Algorithm

The document outlines the algorithm for a Memory Match Game, detailing steps for game initialization, main game loop, and user interactions. It includes specific choices for matching cards, displaying the board, giving up, or exiting the game, along with point calculations for correct and incorrect matches. Sample scenarios illustrate how the game operates, including point adjustments and board displays.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views3 pages

Memory Match Game Algorithm

The document outlines the algorithm for a Memory Match Game, detailing steps for game initialization, main game loop, and user interactions. It includes specific choices for matching cards, displaying the board, giving up, or exiting the game, along with point calculations for correct and incorrect matches. Sample scenarios illustrate how the game operates, including point adjustments and board displays.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Memory Match Game Algorithm and Calculations

Algorithm (Step-by-step Recipe)

1. Game Initialization
1.1. Display program header with student info.​
1.2. Prompt the user to enter their name.​
1.3. Validate the name to ensure it only contains alphabet characters or spaces.​
1.4. Convert the name into title case (capitalize first letters of words).​
1.5. Initialize a 4x4 board (2D vector) to hold pairs of numbers 1 to 8.​
1.6. Shuffle the card values and assign them randomly to the board.​
1.7. Initialize a corresponding 4x4 boolean matrix to track matched card positions.​
1.8. Set initial points to 50.

2. Main Game Loop


Repeat the following until the player chooses to Give Up or Exit:
2.1. Display menu:
●​ 1. Match
●​ 2. Display
●​ 3. Give Up
●​ 4. Exit​

2.2. Prompt the player for their choice.

3. If Choice is 1: Match Cards


3.1. Display the board, showing matched cards and hiding unmatched ones with *.​
3.2. Prompt the user to enter two sets of coordinates: (r1, c1) and (r2, c2).​
3.3. Validate the coordinates:
●​ Ensure they are within range (0–3).
●​ Ensure they are not already matched.
●​ Ensure the two coordinates are different.​

3.4. Reveal both cards.


3.5. If values match:
●​ Mark both positions as matched.
●​ Display a match message
●​ Increase points by 5.​

3.6. If values don't match:


●​ Show both selected cards temporarily.
●​ Display a mismatch message.
●​ Decrease points by 1.​

3.7. Show updated points.

4. If Choice is 2: Display Board (Hint)


4.1. Check if the player has at least 10 points.
4.2. If yes:
●​ Display the current state of the board (matched cards shown).
●​ Deduct 10 points.
4.3. If no:
●​ Display updated points.
●​ Inform the player they do not have enough points.​

5. If Choice is 3: Give Up
5.1. Display the full board with all card values.​
5.2. Prompt user if they want to restart the game:
●​ If yes: Reset points and reinitialize the board.
●​ If no: Display final score and exit.​

6. If Choice is 4: Exit Game


6.1. Display final score.​
6.2. Exit the program.

Sample Hand Calculations / Test Simulation

Initial Points: 50
Let’s say this is the shuffled board (hidden to the player):
[2, 5, 1, 7]
[3, 4, 8, 6]
[6, 7, 2, 3]
[1, 5, 4, 8]

Scenario 1: Correct Match


User selects (0,0) and (2,2) → values are both 2.
●​ Match → +5 points → Total: 55
●​ Both positions marked as matched.​
Scenario 2: Wrong Match
User selects (0,1) and (0,2) → values are 5 and 1.
●​ No match → -1 point → Total: 54
●​ Both positions remain unmatched.

Scenario 3: Use Display Option


User uses Display option.
●​ Deduct 10 points → Total: 44
●​ Board shows currently matched cards only.

Scenario 4: Give Up
User chooses "Give Up".
●​ Show full board.
●​ User selects "No" to restart.
●​ Game ends. Final score displayed: 44​

You might also like