Description
Your First C++ Program
You will write a C++ program that will play the game of Connect Four. The game of Connect Four is
played by two players (computer-user or user1-user2) on a two dimensional board (2D array) with
rectangular cells. Each cell is either computer, user, or empty. The game starts with the following
board for an 8×8 game
abcdefgh
……..
……..
……..
……..
……..
……..
……..
……..
where . represents the empty cells, X represents the computer(user1) cells and O represents the user
(user2) cells. The players take turns the play the game. For the above board, the user can pick any
letter to put the first piece. For example, if the user1 plays to letter C and user2 plays to letter B then
the board becomes
abcdefgh
……..
……..
……..
……..
……..
……..
……..
.XO…..
The game continues with the objective of “Connect four of your checkers in a row while preventing
your opponent from doing the same”. The rows can be diagonal, vertical or horizontal.
The following (attached GIF file) is a sample animation of the game.
For the detailed rules of the game see https://www.hasbro.com/common/instruct/ConnectFour.PDF
Your program will do the following
1. When your program starts, you will ask the user the board size, the board size can be 4×4,
6×6, 8×8, 10×10, …, 20×20. You should check the validity of the input.
2. Ask the user if this a two player game or user versus computer game
3. You will display the initial board
4. You ask the user to make a move, get the user move from the keyboard and draw the new
board. Use positions such as A,B,C, etc. If the move is not legal, then ask for another move.
5. The computer (or user2) makes a new move and draws the board again. You should print what
move the computer(user2) chose on the screen. The move should be legal.
6. The game continues until all the board is filled or one of the players wins.
7. The final result of the game should be printed on the screen showing who won and the
connected cells with small case o and x.
Notes:
Do not use any functions from the standard C library (like printf)
Your program should have only functions and no classes.
Do not forget to indent your code and provide comments.
Check the validity of the user input.
Test your programs very carefully at least with 10 different runs. For some runs, let the
computer win and for others the user should win. There should be cases for illegal moves
and your program should handle them appropriately.
You should submit your work to the moodle page.