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:
- Start
- Clear the board
- Player 1 chooses which column to place chip
- 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
- Check to see if board is full. If so, go to step 11. If not, go to step 6
- Player 2 chooses which column to place chip. Continue to step 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
- Check to see if board is full. If so, go to step 11. If not, go to step 3
- Player 1 wins. If players would like to play again, go to step 2. If not, go to step 12
- Player 2 wins. If players would like to play again, go to step 2. If not, go to step 12
- Draw. If players would like to play again, go to step 2. If not, go to step 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:
- Start
- Player enters how much money they would like to start with
- Player enters how much money they would like to wager
- Player guesses if the roll will be over, under, or exactly seven
- If the player guesses over or under and is correct then they win their wager, go to step 3. Else, go to step 7
- 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
- The player loses their wager
- Check to make sure the player has money left. If so, go to step 3. If not, go to step 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
- 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:
- Start
- Clear
- Instructions
- Create random permutation of (1-52)
- Split the random permutation in two decks
- A card from the computers deck is flipped up against the players card
- If the computers card is greater, then the computer gets the players card
- If the player’s card is greater, then the player gets the computers card
- If there is a draw go to step 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
- If there is still a draw, go to step 10
- Check to see if either deck is empty
- If deck is not empty, go to step 6
- If the players deck is empty, computer wins, go to step 16
- If the computer’s deck is empty, player wins, go to step 16
- End