# Memory Game
#### Video Demo: https://youtu.be/VQEPIS-qccU
#### Description:

This is the README file for Memory Game. Memory game is based off of the card memory game that is usually done with cards that have pictures of objects on them where the player has to remember where each object is located and match it with the other object in the grid/pile of cards. Once the player finds all of the matches/pairs, the player wins. Instead of images for this game, letters were used. So the player has to pick letters in the grid and find their matches!

#### Gameplay:

- Firstly, the player chooses a difficulty level by selecting an option from the 4 options presented when the game starts.
- Once the player chooses a difficulty (or creates their own grid,) the game begins.
- The player is tasked with picking a row number and column number to reveal the respective blocks/cells and see what letter is in that position.
- The player keeps doing this until a match is found between two letters. Once the player finds all the matches, they win.

#### How The Game Works:

When the game is ran, the first function to be called is ***main()***. This function takes player input for the difficulty of the game or whether or not the player wants to play on a custom grid where they can choose the size of it. After the ***main()*** function takes the player input, it then checks the input and makes sure it is an integer and raises an error if its not. The input is checked for which difficulty the player chose ([1] is 4x3, [2] is 5x4, [3] is 6x6, [4] is a custom grid size). ***main()*** then calls ***game()*** with the respective row and column numbers that the player chose (either custom or pre-defined), ***game(*** rows, cols ***)***. If the player chose to create their own grid, the ***main()*** function calls ***custom()*** which takes the player input for the amount of rows and columns of their choosing. The result of rows * columns has to be equal to an even number because there has to be an equal number of pairs present in the grid for the player to win the game or else if the grid was not even, then there would be some letters in the grid that would not have a match, making the game impossible to win.

Now, the ***game()*** function. As mentioned earlier in this document, this function takes the parameters rows and cols to determine the size of the grid and start generating the letters to put in the grid. This grid generation happens in the ***create_grid()*** function. The ***game()*** function uses two helper functions, ***create_grid()*** and ***display_grid***. As their names suggest, the ***create_grid()*** function creates the grid using the parameters mentioned earlier (rows and cols). It also creates a hidden grid using block symbols, the same size as the grid with the letters. This hidden grid "covers" the other grid with the letters, essentially serving as a way to hide the letters underneath these blocks. The ***display_grid()*** function, on the other hand, helps display the current grid using a for loop and line indentation. The ***game()*** function keeps updating the grid whenever the player reveals a match or makes a mistake and it uses ***display_grid()*** to display the current status of the grid over the course of the current game.

The ***game()*** function has a while loop that keeps going until the player has found all the matches in the grid. The player keeps getting prompted for their input to choose a row number and column number to progress in the game. If there is no match between the two cells (letters) that the player revealed, a "try again" message is shown to the player and ```time.sleep(2)``` is used to pause the game/terminal a little bit so the player can remember the position of these letters and not make the same mistake again before the grid is updated once more and reset to its previous status/position. There are try and except statements implemented to catch invalid input from the player and the loop keeps going no matter what unless the player presses Ctrl+D on their keyboard to quit the program. After the player finds all of the matches, the ***game()*** function then displays the completed (fully revealed) grid, a congratulations message, and the total amount of matches the player has made in order to find all of the matches in the grid.

Most importantely, since the game takes place entirely inside the python terminal, ```os.system('clear')``` is used to clear the terminal so the player cannot see their previous attempts when revealing cells so the player cannot cheat their way through the game. Not only does this make the game look better, but it forces the player to remember the positions of certain letters in order to find their respective matches. This program only uses three libraries, ```os, random, & time```. The ```random``` library was used in the ***create_grid()*** function to randomly choose a letter from the alphabet and create matches for the grid. A list comprehension was used to do this action:
```letters = [random.choice(alphabet) for _ in range(rows * cols // 2)]```. After the letters are picked, they are shuffled using ```random.shuffle(letters)```.

Finally, the project.py file contains the code for the game and test_project.py contains tests for functions inside the project.py file. Thank you for taking the time to read this document. I hope it was beneficial.
