Homework # 1
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 88 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
- When your program starts, you will ask the user the board size, the board size can be 44, 66, 88, 1010, , 2020. You should check the validity of the input.
- Ask the user if this a two player game or user versus computer game
- You will display the initial board
- 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.
- 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.
- The game continues until all the board is filled or one of the players wins.
- 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.
Reviews
There are no reviews yet.