Connect-Four program is created using while loop and for loop with the help of other functions; example.m and simpleGameEngine.m. Variables used in this program are given below:
- graphic : This holds the object ‘ConnectFour.png’ which display the 6 x 7 board.
- ‘empty‘ variable is used for empty vector which is denoted by number 1 in the matrix, ‘red‘ is for red piece denoted by number 2 and ‘black‘ variable is for black piece denoted by number 3.
- player1: ask for the player 1 name.
- player2: ask for the player 2 name.
- row: holds the row vector
- col: holds the column vector.
- board: The board(matrix) is created using this variable.
- result: It is used to create a condition (result==true) for while loop. The loop works until the given condition is true.
- column: Holds the number of column, player 1 wants to drop the red piece on.
- column2: Holds the number of column, player 2 wants to drop the black piece on.
- test: Holds the number ‘2’ assigned to red piece.
- test2: holds the number ‘3’ assigned to black piece.
- c: Holds the range of column for which ‘for loop‘ will run.
- r: Holds the range of row for which for loop will run.
- gameover: Holds the object ‘gameover.jpg’ which will be displayed once either of the players win.
- Connect Four begins by asking the players to enter the column number where they want to drop their piece in 6 x 7 board. The players drop the piece alternatively.
- If the players enter any other number which is not in the 1 to 7 range , the program will keep asking for another input until the players enter the number between 1 to 7.
- Once the player drops the piece, the program will check if their is any winning condition (horizontal, vertical or diagonals).
- If any of these condition is present, the program will display who the winner is and if not, the program will ask for another player input and repeat the step 2 and 3.
- It will repeat the step 1 to 4 until the board is full. If nobody wins and board is full, the program will displays error.
- In order to play the game again, the player will need to hit run.
Over Under program is created using and input function, rand operator, and an if-elseif-else statement.
1. The input function asks the player to pick Over 5, Under 5, or Equal to 5.
2. The rand operator generates a random number one through ten.
3. The if-elseif -else statement issues and fprintf statement which lets the player know if they were correct or incorrect.