Connect Four on MATLAB is a variation of the classic Connect Four board, except it is on an electronic board. In the MATLAB program, the players simply drag and drop the chip into the desired slot location using the mouse with the added graphic function. This way, the players are not required to type in a column and row to drop the chip into the slot. With the drag and drop graphic feature, it reduces the chance of error. Regardless of if you drop the chip outside of the electronic board, the chip will fall into the closest column.
The 7 x 6 electronic board has seven hollow vertical slots and six rows. It’s a vertical board with 42 holes that fit chips presented in six rows and seven columns.
The goal of Connect Four is to connect four chips in a row horizontally, vertically, or diagonally on a 7 x 6 board before your opponent does. Based on where player one places their colored chips, the player two can stack their colored chips beside or above player one to stop them from connecting four in a row.
How to play:
Before the game begins, first open the MATLAB program and select the button under the editor tab that says “run.” Once you push this button, a 7 x 6 Connect Four graphic will appear on the screen. The program will ask for player 1 to type in their name and then player 2 to type in their name. Player 1 automatically has red chips and player 2 has the black chips. Player 1 will begin dragging and their mouse over the desired (row, column) and then player 2 will follow. This procedure should continue until a player matches four chips in a row horizontally, vertically, or diagonally. After a player wins, a “Congrats player _____, you won!” message will appear and it will ask if you would like to play again.