D. Final Algorithm, Flowchart, or Pseudocode

Battleship flowchart:

Played on an 10×20 board

  1. Displays a 10×20 board where the left side is the user’s and the right is the AIs
  2. Click to place ships into the grid
    1. Make sure it is an available place
    2. Make sure that it is a place on the grid and not just on the figure
    3. Make sure that it does not go off the figure
  3. Add all five ships into the grid
  4. AI automatically gets a random ship placement on the board
  5. Player clicks positions on board to check for enemy battleships
    1. Make sure it is on the figure and is a spot that could be selected
    2. Checks whether the position is a hit or miss and indicates it in that position
  6. AI generates 2 random integers between 1 and 10 and determines if that spot has part of the user’s battleship.
    1. Stores AI past moves to make sure
  7. When all battleships are destroyed on one side of the board (AI or User), the game ends

Black Jack Algorithm:

1. Initialize Deck array of card indices (randomperm(52)) and load CardDeck.
2. Initialize reference array for points of each card index.
4. Draw two cards for player
5. Dealer draws two cards but only one is printed and revealed.
6. Player can either “hit” “stand” or call for a “new hand”
7. If “hit” is chosen player adds draw card function to their array of cards
8. if the hand value exceeds 21 then the player “loses”
9. If “stand” is chose dealer will try to beat player.
10. Go back to step 6 until every player is in state of “stand”
11. Dealer reveals second card. If hand value is less than 17 he draws card and adds to his array of deck indices.
12. If player is closer to 21 then player wins, but if the dealer is closer then they lose. If both dealer and player have equal hand, then they draw.
13. After each game, the hand will automatically reset.