D. Final Algorithm, Flowchart, or Pseudocode

The final algorithm used to program Connect Four can be seen below:

Givens:

  • Player will be playing against another player
  • Player 1 will always use red chips, Player 2 will always use black
  • Player 1 will always have the first turn, with alternating turns following
  • 4 consecutive chips of the same color win the game, whether they be diagonal, horizontal, or vertical
  • Chips can only be placed in open slots
  • Chips will fall into lowest available slot in a column
  • Game will be played until someone wins, or until winning is unachievable

Assumptions:

  • Players can type in a keyboard
  • There will be two players playing
  • Players will handle who is Player 1 and who is Player 2
  • Player 1 and Player 2 play on the same computer

Algorithm:

  1. Start
  2. Clear the board
  3. Player 1 chooses which column to place chip
  4. Check to see if four consecutive chips of similar color are present on the board. If so, go to step 9. If not, go to step 5
  5. Check to see if board is full. If so, go to step 11. If not, go to step 6
  6. Player 2 chooses which column to place chip. Continue to step 7
  7. Check to see if four consecutive chips of similar color are present on the board. If so, go to step 10. If not, go to step 8
  8. Check to see if board is full. If so, go to step 11. If not, go to step 3
  9. Player 1 wins. If players would like to play again, go to step 2. If not, go to step 12
  10. Player 2 wins. If players would like to play again, go to step 2. If not, go to step 12
  11. Draw. If players would like to play again, go to step 2. If not, go to step 12
  12. End

 

The final algorithm used to program Over/Under Seven can be seen below:

Givens:

  • You can not wager more money than you have
  • You must wager more than 0 dollars
  • Enter your “Over”, “Under”, or “Exactly” response capitalized with single quotes
  • If you wish to quit the game, press CTRL+C

Assumptions:

  • Player has money to start with
  • Player reads and follows all rules
  • Player knows how to dock the dice figure

Algorithm:

  1. Start
  2. Player enters how much money they would like to start with
  3. Player enters how much money they would like to wager
  4. Player guesses if the roll will be over, under, or exactly seven
  5. If the player guesses over or under and is correct then they win their wager, go to step 3. Else, go to step 7
  6. If the player guesses exactly seven and is correct then they win 4 times their wager, go to step 3. Else, go to step 7
  7. The player loses their wager
  8. Check to make sure the player has money left. If so, go to step 3. If not, go to step 9
  9. If the player wants to play again then they can press the space bar, go to step 2. If not, go to step 10
  10. End

 

The final algorithm used to program War can be seen below:

Givens:

  • The player will be playing against the computer
  • Player understands how to play the card game war
  • Will only be played with a full deck of cards
  • There are no jokers in the deck
  • Aces are the highest value card

Assumptions:

  • The player will be typing on a keyboard
  • Player’s card will be the bottom card displayed on the screen while the computer’s card is on top

Algorithm:

  1. Start
  2. Clear
  3. Instructions
  4. Create random permutation of (1-52)
  5. Split the random permutation in two decks
  6. A card from the computers deck is flipped up against the players card
  7. If the computers card is greater, then the computer gets the players card
  8. If the player’s card is greater, then the player gets the computers card
  9. If there is a draw go to step 10
  10. Three cards will be played down from each player’s deck, the next card will decide which player wins all of the cards currently in play
  11. If there is still a draw, go to step 10
  12. Check to see if either deck is empty
  13. If deck is not empty, go to step 6
  14. If the players deck is empty, computer wins, go to step 16
  15. If the computer’s deck is empty, player wins, go to step 16
  16. End