CPE 101
Multi-dimensional arrays lab

Memory Quiz is a card game in which all of the cards are laid face down on a surface and two cards are flipped face up over each turn. The object of the game is to turn over pairs of matching cards. In the computer solitaire version, a grid of integers is used instead of cards.

At each turn the player chooses two cards and turns them face up. If they are the same then that player wins the pair and plays again. If they are not the same they are turned face down again. The game ends when the last pair has been turned up.  The object is to find all the pairs in the fewest number of turns.

The basic strategy is that over the course of the game, it becomes known where certain cards are located, and so upon turning up one card players with good memory will be able to remember where they have already seen its pair.

The instructor is providing a function that will create a random board for the game. Here is randomgrid.h.

/* Fill a grid of dimension size with random integers
* in the range 1 to (size * size ) / 2
* Each number appears twice.
* Precondition: 1 <= size < 256
*/
void getRandomGrid(int grid[256][256], /* output - random grid */ int size); /* input - grid dimension */

The object file is available on Unix1: ~graderjd/Public/randomgrid.o
A test program is available:  ~graderjd/Public/randomgridtest.exe
The instructor's solution can be run with this command on Unix1: ~graderjd/Public/memoryquiz.exe

While you are developing your implementation you might prefer to initialize a two-dimensional array to specific numbers to make it easy for you to guess.

The solution will be designed during lecture as a class exercise.  Your solution must follow the design created during lecture.

You may assume the user will enter valid input data.  A move is entered as the coordinates of two cells, with a lower case letter indicating the row and a digit indicating the column.

Allow the user to forfeit and quit the game by entering "zzzz".

Study the sample execution below where the user's input is shown in bold face.
Name your source file memoryquiz.c and submit it via handin to Lab11.

Bonus Problem

Write a boolean function checkRandomGrid that accepts a two dimensional array as an input parameter and the size (an integer). The function returns true if the grid meets the requirements for a board in the memory quiz game. That is, it contains each integer from 1 to size*2 two times.


Welcome to Memory Quiz. 
Enter desired grid size (4,6,or 8): 4
1 2 3 4
a ** ** ** **
b ** ** ** **
c ** ** ** **
d ** ** ** **
Turn: 1 Move? a1b1
3 -- -- --
1 -- -- --
-- -- -- --
-- -- -- --

1 2 3 4
a ** ** ** **
b ** ** ** **
c ** ** ** **
d ** ** ** **
Turn: 2 Move? a2b2
-- 5 -- --
-- 8 -- --
-- -- -- --
-- -- -- --

1 2 3 4
a ** ** ** **
b ** ** ** **
c ** ** ** **
d ** ** ** **
Turn: 3 Move? a3b3
-- -- 8 --
-- -- 1 --
-- -- -- --
-- -- -- --

1 2 3 4
a ** ** ** **
b ** ** ** **
c ** ** ** **
d ** ** ** **
Turn: 4 Move? a3b2
-- -- 8 --
-- 8 -- --
-- -- -- --
-- -- -- --

1 2 3 4
a ** ** 8 **
b ** 8 ** **
c ** ** ** **
d ** ** ** **
Turn: 5 Move? b1b3
-- -- -- --
1 -- 1 --
-- -- -- --
-- -- -- --

1 2 3 4
a ** ** 8 **
b 1 8 1 **
c ** ** ** **
d ** ** ** **
Turn: 6 Move? a4b4
-- -- -- 2
-- -- -- 4
-- -- -- --
-- -- -- --

1 2 3 4
a ** ** 8 **
b 1 8 1 **
c ** ** ** **
d ** ** ** **
Turn: 7 Move? c1d1
-- -- -- --
-- -- -- --
3 -- -- --
6 -- -- --

1 2 3 4
a ** ** 8 **
b 1 8 1 **
c ** ** ** **
d ** ** ** **
Turn: 8 Move? a1c3
3 -- -- --
-- -- -- --
-- -- 7 --
-- -- -- --

1 2 3 4
a ** ** 8 **
b 1 8 1 **
c ** ** ** **
d ** ** ** **
Turn: 9 Move? a1c1
3 -- -- --
-- -- -- --
3 -- -- --
-- -- -- --

1 2 3 4
a 3 ** 8 **
b 1 8 1 **
c 3 ** ** **
d ** ** ** **
Turn: 10 Move? c2d2
-- -- -- --
-- -- -- --
-- 7 -- --
-- 6 -- --

1 2 3 4
a 3 ** 8 **
b 1 8 1 **
c 3 ** ** **
d ** ** ** **
Turn: 11 Move? c2c3
-- -- -- --
-- -- -- --
-- 7 7 --
-- -- -- --

1 2 3 4
a 3 ** 8 **
b 1 8 1 **
c 3 7 7 **
d ** ** ** **
Turn: 12 Move? d1d2
-- -- -- --
-- -- -- --
-- -- -- --
6 6 -- --

1 2 3 4
a 3 ** 8 **
b 1 8 1 **
c 3 7 7 **
d 6 6 ** **
Turn: 13 Move? d3d4
-- -- -- --
-- -- -- --
-- -- -- --
-- -- 4 2

1 2 3 4
a 3 ** 8 **
b 1 8 1 **
c 3 7 7 **
d 6 6 ** **
Turn: 14 Move? d3c4
-- -- -- --
-- -- -- --
-- -- -- 5
-- -- 4 --

1 2 3 4
a 3 ** 8 **
b 1 8 1 **
c 3 7 7 **
d 6 6 ** **
Turn: 15 Move? d3b4
-- -- -- --
-- -- -- 4
-- -- -- --
-- -- 4 --

1 2 3 4
a 3 ** 8 **
b 1 8 1 4
c 3 7 7 **
d 6 6 4 **
Turn: 16 Move? a2d4
-- 5 -- --
-- -- -- --
-- -- -- --
-- -- -- 2

1 2 3 4
a 3 ** 8 **
b 1 8 1 4
c 3 7 7 **
d 6 6 4 **
Turn: 17 Move? a2a4
-- 5 -- 2
-- -- -- --
-- -- -- --
-- -- -- --

1 2 3 4
a 3 ** 8 **
b 1 8 1 4
c 3 7 7 **
d 6 6 4 **
Turn: 18 Move? a4d4
-- -- -- 2
-- -- -- --
-- -- -- --
-- -- -- 2

1 2 3 4
a 3 ** 8 2
b 1 8 1 4
c 3 7 7 **
d 6 6 4 2
Turn: 19 Move? a2c4
-- 5 -- --
-- -- -- --
-- -- -- 5
-- -- -- --

1 2 3 4
a 3 5 8 2
b 1 8 1 4
c 3 7 7 5
d 6 6 4 2
You won in 19 turns.