Program Description for Developers

This page contains a list of all assumptions made in the program.   Below that are lists containing all of the functions and variables used.  Additionally, there is a section that details the suggestions we received during beta testing and how we incorporated these ideas.   At the bottom of this page there are links for the pseudocode and flowchart.

Assumptions

  1. It was assumed that the user can read English.  This is essential to operating the game as the instructions are displayed in English words printed to the screen when ‘Display Rules’ is selected on the main menu.
  2. It was assumed the user is not blind and can adequately observe the Proteus screen in order to read it and follow simple directions.
  3. It was assumed the user knows the difference between ‘left’ and ‘right’.
  4. It was assumed that the user has at least one functioning hand.  This is necessary to tap the touch screen and play the game.
  5. It was assumed the user can follow simple directions such as ‘tap the left side of the screen’.
  6. It was assumed the user has basic reasoning skills, and can determine whether an Ace card is more valuable as a 1 or an 11 in their given situation.
  7. It was assumed that the player will always stay after 4 cards are drawn.  No functions are included to allow for a 5th card to be generated and displayed.  After the 4th card is displayed and processed, the loop including card generation for the player is exited and the program proceeds to the dealer’s turn.
  8. It was assumed that the dealer will stay after a value greater than 17 is accumulated.  Regardless of how many cards he holds, the dealer will continue to draw additional cards until his combined total exceeds 17.
  9. It was assumed that Blackjack is being played with an unlimited number of cards and each card is replaced in the deck after its use.  The implications of this mean that any card can be drawn at any time.  For example, 2 Jack’s of Spades could be drawn one after the other.  This also means the user cannot count cards.
  10. It was assumed that all cards have an equal chance of being drawn from a deck at any given time.

Variables

x: used in the formatting of screen display.  Represents the x coordinate on the proteus screen.

y: used in the formatting of screen display.  Represents the y coordinate on the proteus screen.

z: This variable determines how long the game will continue.  The entire game is held within a while loop inside the play function.  The loop continues as long as z is equal to 0.  z is initially set to 0 so that the game plays until the user decides to quit.  When the user selects ‘quit’ on the main menu, the value of z is changed to 1, ending the game by exiting the loop.

player_wins: This variable represents the number of wins the player has accumulated.  This statistic is recorded over multiple games and can be viewed when ‘display stats’ is selected on the main menu.

dealer_wins: This variable represents the number of wins the dealer has accumulated.  This statistic is recorded over multiple games and can be viewed when ‘display stats’ is selected on the main menu.

number_ties: This variable represents the number of ties.  This statistic is recorded over multiple games and can be viewed when ‘display stats’ is selected on the main menu.

number_games: This variable represents the number of games played since the last statistic reset.  This statistic is recorded over multiple games and can be viewed when ‘display stats’ is selected on the main menu.

player_card_total: This variable tallies the total combined value of all the cards the player currently holds.  It is updated after each new card is drawn and then compared to the deal_total to determine who wins the game.

deal_total: This variable tallies the total combined value of all the cards the dealer currently holds.  It is updated after each new card is drawn and then compared to the player_card_total to determine who wins the game.

card1, card2, card3, card4:  These variables represent the first, second, third, and fourth cards drawn respectively.  Each card is given a random number 2-14 using the function newcard.  There is a unique newcard function for each card 1-4.  After being assigned a value, each card passes through the function drawcard to assign a value to it based on its number.  There is a unique drawcard function for each card 1-4.  The card variables are used locally in both the player and dealer functions.

Winner: This variable is holds a value -1, 0, or 1 that dictates who wins the game.  The value is assigned to winner by the function who_win.  The value assigned to winner is dependent on who has the greater card total, the dealer or the player (assuming neither busted).  If the player has a greater total (player wins) winner is assigned the value 1.  If the player and dealer totals are equal, winner is assigned a value of 0.  If the dealer’s total is greater than the player’s (dealer wins), winner is assigned the value of -1.  After being assigned a value, winner is passed through a switch case structure that displays the proper message to the screen and updates the statistics accordingly.

real_card1, real_card2, real_card3, real_card4: These variables represent the actual point values each generated card 1-4 holds.  For example, a queen card is represented by the number 12.  However, the actual value of a queen is 10.  real_card represents this actual value.  This actual value is assigned to each card using the function drawcard or d_drawcard depending on if it’s the player or dealer’s cards.  

bust_value: This variable is assigned a value 0 or 1 by the function check_bust and represents whether or not the player or dealer busted.  If bust_value is assigned a value of 1, it means the player or dealer did not bust.  If bust_value is assigned a value of 0 it means the player or dealer busted.  bust_value is passed through if statements to carry out the appropriate actions depending on whether there is a bust or not.

stuff:  This variable is used to update the game statistics to reflect the outcome of the game.  It is used within the menu() function and is called once per game.  If the player won, stuff will be assigned a value of 0.  if the dealer won, stuff will be assigned a value of 1.  If the game was a tie, stuff will  be assigned a value of -1.  After being assigned a value to reflect the game outcome, stuff is passed through a switch case to update the statistics for player_wins, dealer_wins, number_ties, and number_games accordingly.

junk: This variable is used to hold a value 0 or 1 within the play() function.  The function will continue to loop and generate and display new cards for the player until they bust or choose to stay.  Junk is initially set to 0 and the actions will loop while it is equal to 0.  When the player either busts or chooses to stay, junk is given the value of 1 which exits the loop, indicating the program is proceeding to either the dealer’s turn or the main menu.

num:  This variable is given a randomly assigned value 0 or 1.  it is used locally within each color_card() function (there are 8 color_card() functions).  The randomly assigned number dictates whether the card will be Scarlet or Gray.  Num is passed through a switch case to determine which color to assign to the card.  If num is equal to 0, it will become Scarlet.  If num is equal to 1,  it will become Gray.

num2: This variable is given a randomly assigned value 0 or 1.  it is used locally within each color_card() function (there are 8 color_card() functions).  The randomly assigned number dictates what symbol the card will get..  Num2 is passed through a switch case within the switch case used for num to determine which symbol to assign to the card.  If num2 is equal to 0 and Scarlet, it will become Diamonds.  If num2 is equal to 0 and Scarlet,  it will become Hearts.  If num2 is equal to 0 and Gray, it will become Clubs.  If num2 is equal to 1 and Gray, it will become Spades.

 

Functions

void menu():  This function displays the main menu with options to play, display rules, display credits, display stats. Clear stats, and quit.  Each option is shown on the screen and the user is prompted to touch the option they wish to select.  The function then determines where the user touches based on the x and y coordinates.  The function will then carry out the appropriate actions based on what the user selects.  The menu() function will continue to loop as long as the variable z is equal to 1.  When the user selects ‘quit’, z will change to 0 and the while loop will be exited, ending the program.  This function is called once, takes no inputs, and returns no outputs.  

int play(): This function represents the ‘play game’ option on the main menu.  It is called if the user selects ‘play game’ on the main menu.  Within the function, 2 cards are dealt to the player using the newcard() and drawcard() functions (see below).  After receiving 2 cards, the player is prompted to touch one side of the screen or the other to indicate whether they want to ‘hit’ or ‘stay’.  If they choose to ‘hit’, the neward() and drawcard() functions are called again for the third card.  This can happen 1 more time for the fourth card, but it is assumed the player will stay after 4 cards.  The player’s combined card total is totaled after each new card is drawn and the function check_bust is used to routinely check if the player has exceeded 21.  After the player stays, the function continues on to the dealer’s turn.  The dealer’s turn is carried out within the function dealer().  At the end of play(), the variable winner is passed through a switch case to determine the proper message to display based on who won the game.

int newcard(): This function has 8 forms.  There is one form for each card 1-4 for the player, and one form for each card 1-4 for the dealer.  This function generates a random number 2-14 and assigns it to the variable card1.  This value is returned as an int.  The number generated represents a randomly generated card.  Numbers 1-10 correspond to cards 1-10.  The numbers 11, 12, 13, and 14 represent a Jack, Queen, King, and Ace respectively.  This function is called once per game and takes no inputs.

int drawcard(int card): This function has 8 forms.  There is one form for each card 1-4 for the player, and one form for each card 1-4 for the dealer.  This function takes the number of a card  assigned by the function newcard() and assigns a point value to the card.  This is accomplished using if statements.  If the card’s number is 2-10, its value is the same as its number.  If the card’s number is 11, 12, or 13 its value is 10.  If the card’s number is 14 (Ace) it is assigned a value of either 1 or 11.  This value of a 14 is determined by the user.  If a 14 is generated, the user is prompted to touch one side of the screen for a 1 or the other side for an 11.  Drawcard() reads this response and assigns the appropriate value to the card.  it then calls the color_card() function to display the card’s graphics and symbols.  Drawcard() returns the value of the card which is assigned to the variable real_card.

void color_card(): This function is called within drawcard().  It has 8 forms, one for each player card 1-4, and 1 for each dealer card 1-4.  The card is first assigned a random number either 0 or 1.  This value is stored to the variable num.  Num is then passed through a switch case.  If num is 0, the card is displayed as red.  If num is 1, the card is displayed as gray.  Then, within each case (0 and 1) a second randomly generated number, num2 with a value of  0 or 1 is passed through a switch case.   A scarlet card with a 0 for num2 is given the symbol diamond.  A scarlet card with a 1 for num2 is given the heart symbol.  A gray card with a 0 for num2 is given the clubs symbol.  A gray card with a 1 for num2 is given the spades symbol.  color_card() then displays the card’s symbol on the card on the screen.

int check_bust(int player_card_total): This function is called after each new card is dealt to the player.  It takes the player’s card total as an input and uses if statements to determine if this value is greater than 21.  The function then returns a value 0 or 1 and assigns it to the variable bust_value.  If the player’s card total is greater than 21 the value of 0 is returned.  If the player’s total is not greater than 21, the value of 1 is returned.  

int dealer(): This function carries out the actions for the dealer’s turn.  It is called at most once per game after the player selects ‘stay’.  If the player busts, this function is not called.  Dealer() generates 2 cards for the dealer and assigns them values using the functions newcard() and drawcard().  The dealer’s card total is recorded with the variable deal_total.  After the first 2 cards are generated, a third card is generated only if the dealer’s total is less than or equal to 17.  If the dealer’s total is greater than 17, they will ‘stay’.  If the dealer’s total is still less than or equal to 17 after a third card, a fourth card will be generated and dealt.  It is assumed that the dealer will ‘stay’ after 4 cards.  If the dealer’s total exceeds 21 after any card is dealt, the appropriate message is printed to the screen indicating the dealer busted.

int who_win(int player_card_total, int deal_total):  This function is called at most once per game, and only if neither the player or dealer busts.  It takes the player and dealer card totals as inputs and uses if statements to determine which total is greater, or if they are equal.  The function then returns an integer value -1, 0, or 1 to the variable winner.  If the player’s total is greater, a 1 is returned.  If the totals are equal, a 0 is returned.  If the dealer’s total is greater, a -1 is returned.

void display_rules(): This function is called if the user selects ‘display rules’ on the main menu.  This function prints the rules of the game to the screen and then sleeps to allow time for the user to read them.  This function takes in no inputs and returns no output.

void dispay_credits(): This function is called if the user selects ‘display credits’ on the main menu.  This functions displays the credits to the screen and then sleeps to allow the user to read the credits.  This function takes no inputs and returns no output.

void clear_stats(): This function is called if the user selects ‘clear stats’ on the main menu.  If called, this function resets the variables player_wins, dealer_wins, number_games, and number_ties to 0.  This function takes to inputs and returns no output.

 

Beta Testing Suggestions

One major suggestion offered to us during bveta testing was to fix the code so that the player can choose to ‘hit’.  We encountered an error just before beta testing that prevented the player from selecting ‘hit’.  This error was resolved later by switching the if statements in the play() function to an if and else if statement.

Another suggestion we received was to improve the statistics tracking.  During beta testing, the statistics were not being recorded correctly.  This error was never fully resolved, but we developed a method to allow the statistics to be properly recorded.  In order for the statistics to be saved, the player must play the game and then select ‘display stats’ before playing the game again.  Furthermore, it is necessary for the player to continue to select ‘display stats’ after each game played.

<PSEUDOCODE>

<FLOWCHART>