What are the Odds? Pseudocode:
| Step | Description | MATLAB |
| 1 | Answer whether you want to hear the rules
|
Input(commands) |
| 2 | The program creates a random number
|
Variable=randi(number) |
| 3 | The program runs this number through a while loop and ifelse statements to pick a random dare from the selection.
|
While loop running the random number through a series of ifelse statements |
| 4 | Computer prompts you to enter the bounds for the odds
|
Variable=input(bounds) |
| 5 | The computer prompts you to enter a number within the bounding range
|
Variable=input(number) |
| 6 | The program compares the numbers and displays whether you have to do the dare
|
Another series of ifelse loops with fprintf statements |
| 7 | This continues until the user prompts a quit
|
The program stops running |
| 8 | The program ends |
ends |
Over Under Seven Pseudocode:
| Step | Description | MATLAB |
| 1 | Answer whether you want to hear the rules
|
input(commands) |
| 2 | Computer loads the dice program
|
load Dice; |
| 3 | Computer prompts you to make a bet
|
bet=input(‘amount(0 to quit)’) |
| 4 | The program will use a while loop to test the validity of the bet
|
While loop containing several other forms of loops |
| 5 | The program prompts high low or sevens
|
Variable=input(commands) |
| 6 | The program uses an if else loop to run the dice program and display the results
|
The ifelse loop compares the roll from the Dice program and determines a win or loss |
| 7 | This continues until the end command is given
|
Loop prompts another input from the user. |
| 8 | After quitting a message is displayed
|
Thanks for playing! |
Rock Paper Scissors Pseudocode:
| Step | Description | MATLAB |
| 1 | Input an option as rock paper or scissors
|
x = input(…) |
| 2 | Computer generates a random number and assigns it to a variable
|
y = randint from 1-3 |
| 3 | Compare x and y inputs to see if rock paper or scissors wins |
if x = rock and y = scissors: x wins if x = scissors and y = rock: y wins… etc
|
| 4 | Display statement declaring the winner
|
fprintf statement |
| 5 | Keep score by accumulating points based on if the user or computer wins
|
if x = rock and y = scissors: x wins x score + 1
|
| 6 | The option is given to play again or quit.
|
While loop prompts user to enter 0 to quit or 1 to keep playing0
|
| 7 | After quitting a message is displayed
|
Thanks for playing! |
Connect 4 Pseudocode:
| Step | Description | MATLAB |
| 1 | Load graphics onto the program
|
“load Connect” |
| 2 | Set initializers; including accumulators equal to 0, and vector to account for the number of rows in the game board
|
Chips connected = 0 Red chips entered = 0 Black chips entered = 0 x = [6 6 6 6 6 6 6] |
| 3 | Display the board
|
imshow command |
| 4 | Statement prompting the user to enter the column to place a chip
|
Input statement |
| 5 | Subtract 1 from the column row vector (x)
|
ex. user puts chip in column 1 x = [5 6 6 6 6 6 6] |
| 6 | Outer while loop continues to loop turns between player 1 and player 2
|
“while” …………. |
| Checking the game board to decide a winner | ||
| 7 | Checking rows:
A series of while statements combined with an accumulator that will accumulate to 4 if successive chips of the same color are detected and break the while loop to declare a winner
|
amount counted = 0 – for every successive chip that is counted, the matrix position will move one to the right matrix(x(column1) +/- k, colulmn1)
|
| 8 | Checking columns:
Same process as rows, except matrix position moves up and down to check for successive chips
|
amount counted = 0 matrix(x(column1), column +/- k) |
| 9 | Checking diagonals:
Same process as rows and columns combined, moves matrix position up and to the right, up and to the left, down and to the right, down and to the left
|
amount counted = 0 matrix(x(colulmn1) +/- k, column1 +/- k) |
| 11 | If amount counted = 4, the while loop breaks and player 1 or 2 is declared the winner! | fprintf “You won!” |