Conclusion and Recommendations

In conclusion, the process of creating games was enjoyable. “Memory” required some clever thinking to resolve the images issue. The rest of the coding of “Memory” wasn’t very difficult. The “Under seven, over seven” was an easy coding process without much vector manipulation. However, it was never resolved how to end the game for “Under seven, over seven”. Some recommendations would be to start the coding process with pseudocoding. This helps provide a representation of what tasks you must solve while coding. Also, thoroughly test the code. Do some complicated tests to see whether the program can handle them.

Discussion (for all games)

Memory-

The first step towards creating memory was to pseudocode the entire game. During the process of pseudocode, it was decided that the game would contain 24 cards (12 pairs) and would rely on three main vectors. One for the randomized images(memorycards2), the second for the images placed in the same way as the first vector(memorycards3), and the third vector which would contain the images of flipped cards(flippedCards). The third vector would be modified to store the image in vector2 only when a certain condition was met. It was also decided that the vector “BlueDeck” provided by the ENGR 1181 would be used. The first obstacle was how to relate the three vectors. As the images can’t be used as a condition for example=if(memorycards2(1)==memorycards2(3)) is not applicable. Thus, command” memorycards3(i) = BlueDeck(memorycards2(i))” was used to relate the images with the numbers in “memorycards2” as the value in “memorycards2” became the index value for” BlueDeck” which was stored in the same index value as “memorycards2”. The rest of the coding was finished with no problem. Next was testing, during the first test the code worked the way it was intended. It was then discovered that the first half of the vector “memorycards2” was in the same sequence as the second half for example= v[ 1 2 7 8 10 5 3 9 11 12 4 6 1 2 7 8 10 …]. This made the game predictable. The issue was resolved by re-randomizing “ShuffleDeck” and assigning the second half of the vector “memorycards2” with this re-randomized vector.

 

Under seven, over seven-

 

Like memory the first step was to pseudocode. The two main variables were “money” which was the amount the user started and “bet” which was the amount of money the user wanted to bet. the images used were provided by ENGR 1181. the coding for this game was a simple process. Thus, the code for this game was finished in 30-40 minutes. During the testing process the game was working perfectly it was realized there was one problem that was not resolved. This was ending the game. The way the game was organized was that the loop where most of the code was running until the variable “state” =1 the only time the value of state was changed was when “money” <=0. This was intended to break the loop and display the message. However, this never happened.

 

Reference-

“Memory Game: Drawing a Grid of Tiles.” Khan Academy, Khan Academy, www.khanacademy.org/computing/computer-programming/programming-games-visualizations/memory-game/a/grid-of-tiles.

 

Pseudocode (for all games)

Algorithm for Memory:

  1. Start
  2. Shuffle deck of 24 cards
  3. Lay out deck face down in row
  4. Pick card 1-24 for card 1 that is not flipped over, flip.
  5. Pick card 1-24 that is not card 1 and not flipped over, flip.
  6. If card 1 = card 2, leave face up. Display “awesome!”. If not, continue to step 7
  7. If card 1 =/= card 2, flip back over. Display “try again”
  8. If cards remain flipped over, return to step 4. If all cards are flipped over, continue.
  9. End

 

Algorithm for Under 7 over 7:

 

  1. Start
  2. Input starting amount of money
  3. Place bet. Bet must be less than or equal to money
  4. Guess if roll sum is under 7, over 7, or equal to 7.
  5. If guess = roll sum, add bet to money. If not, continue.
  6. If guess =/= roll sum, subtract bet from money.
  7. If money > 0, return to step 3
  8. If money = 0, continue.
  9. end

Over 7/Under 7 Code Description

List of variables:

money

bet

val

roll

functions:

randi() – creates a vector of length 2 with values ranging from 1 to 6

The variable “money” is used to store the amount the user wants to start with. “state” is used as a binary variable. the while loop runs until “state=1” if the value of “state” is changed the loop breaks. “bet” stores the amount the user wants to bet. If the bet is more than the money the user currently has or is less than 0 a message of “Invalid Input” is displayed to the screen. TheContinue command causes the loop to return to its starting position. The variable “val” contains the value after the user has been asked to enter 1,0 or 2 for over seven, under seven or equal to 7 respectively. “roll” is a vector that contains the value of the rolled dice. The values of the rolled dice are obtained from the command “Randi”. The two values inside “roll” are added and are reassigned to “roll”.

Next. The winning condition is check which is if the “roll”>7 and the user has entered 1 or if the “roll” <7 and the user has entered 0. When this happens “bet” is added to “money”. “Else if” is a statement which is used to only check if the first “If” statement is not met. The next condition which is checked is if the “roll” =7 and the user entered 2. when this happens the betting, amount is quadrupled(“bet*4”) and added to the “money”. Else the user’s guess is wrong and the “bet” is subtracted from “money”. The next condition checks whether the total money is <=0. If this condition is met the variable “state” is set to 0 to end the while loop. In the end “Game over” is displayed to the screen.

Memory Code Description

Memory:

List of variables:

Shuffledeck

memorycards2

n = 1;

count=1;

counter=12;

memorycards3

flippedCards

BlueDeck

row1

row2

 

Functions-

Imshow()- used to show the images in a vector

Randperm()- creates a random permutation of numbers from 1 to the input

The code begins with the creation of the vector “shuffledeck” which contains random numbers from 1 to 12 generated using the function “randperm()”. A vector called “memorycards2” is created with length 24 at this point it does not matter what values are in the vector. First half of “memorycards2” (cells from 1 to 12) is populated with values from “shuffledeck” using a for loop. Another random permutation of values between 1 and 12 is created and stored in “shuffledeck”. The other half of “memorycards2” (cells from 12 to 24) is populated with the new values in “shuffledeck” using a for loop.

Another vector is created called “memorycards3” to store the images in the same order as the values in “memorycards2”. The value stored in “memorycards2” is used as the index value for “BlueDeck”(contains the images of the cards). The value obtained from “BlueDeck” is stored in the same index as “memorycards2”. This process is completed through a for loop that runs to the 24. Next, the vector “flippedCards” is created with contains 24 images of the flipped card obtained from “BlueDeck”.

A variable is created called “counter” with the value 12. A while loop is created that runs until the value of counter is above 12. This is done so that the game runs until all the pairs are found. “row1” and “row2” are values that store the position of the card entered by the user. If the value of either “row1” or “row2” are out of range or their values are equal, a message of “invalid Input” is displayed to the screen. It is important to note that the “continue” command causes the loop to return to its starting position. Thus, it is a useful command in this situation. The values of “row1” and “row2” are then used as index values in “memorycards2” and used to check whether the values in those cells are equal. If these values are equal a message of “Awesome” is displayed to the screen and counter is decreased by 1.Continueis used again to return to the beginning of the code. If the none of the above conditions are met “Sorry try again” is displayed to the screen. The game runs to completion until “counter” =0.

 

 

Over 7/Under 7 User Manual

Under seven, over seven:

The game beings by asking the user to enter a starting amount.

Next, the user must enter an amount he/she is willing to bet.

Then the user is asked to enter 1,0 or 2 for over seven, under seven or equal to 7 respectively.

If the guess is wrong, the amount is subtracted from the total.

Images similar to the one above are shown to the screen for when the guess is right or equal to 7.

An image of the dice is also shown to the screen.

 

Memory User Manual

Memory:

The Game starts with a row of 24 cards all flipped down.

Next, it asks the user to input the position of the first and second card. If this condition is not met a message is displayed telling the user to try again.

If the condition is met a message is displayed on the screen expressing success.

When the message above is displayed another image pops up with the two cards flipped. The following is an image of three such occurrences.

The game runs until all the pairs have been found.

 

Introduction

This software documentation contains information regarding the game’s “Memory” and “over seven, under seven”. This software documentation provides a thorough description of the user manual and the code. It also contains pseudocode which will provide a visual representation of the thought process. Finally, there is a discussion for a deeper understanding of the development process and struggles that came during the programming phase. Finally, there are some recommendations for the development of these games.

Algorithms/Pseudocodes

Algorithms/Pseudocodes

Battleship (pseudocode)

clc

clear

 

%creates 10×10 matrix

grid100=[1:10 ; 11:20 ; 21:30 ; 31:40 ; 41:50 ; 51:60 ; 61:70 ; 71:80 ; 81:90 ; 91:100];

%creates an array from 1-100

guessArray=(1:100);

%sets pos (position) to a random number taken from guessArray

pos=randi(length(guessArray))

%guessFire is the cell in the matrix that gets shot based on the position

%randomly generated

guessFire=grid100(pos)

%removes the cell shot at from the random number in the array

guessArray(guessFire)=[];

 

Create a 10×10 matrix starting with 1 and increasing by 1 across the rows

 

 

Memory (algorithm)

  1. Start 
  2. Shuffle deck of 24 cards 
  3. Lay out deck face down in row 
  4. Pick card 1-24 for card 1 that is not flipped over, flip. 
  5. Pick card 1-24 that is not card 1 and not flipped over, flip. 
  6. If card 1 = card 2, leave face up. Display “awesome!”. If not, continue to step 7 
  7. If card 1 =/= card 2, flip back over. Display “try again” 
  8. If cards remain flipped over, return to step 4. If all cards are flipped over, continue. 
  9. End 

 

 

Under 7 Over 7 (algorithm)

  1. Start 
  2. Input starting amount of money 
  3. Place bet. Bet must be less than or equal to money 
  4. Guess if roll sum is under 7, over 7, or equal to 7.  
  5. If guess = roll sum, add bet to money. If not, continue. 
  6. If guess =/= roll sum, subtract bet from money. 
  7. If money > 0, return to step 3 
  8. If money = 0, continue. 
  9. end