Project 3

For this project we will be playing Connect 4. Well not actually but close. We will be writing 2 classes that will allow us to play the game. For more information on Connect 4 check out this Wikipedia page.

Details

There are 2 main classes for this project. They are Board and Game. Full details can be found in the API. In general, the Game class is the smallest class and only has two strings and a board as private fields. It has a constructor and one other method, playGame. The playGame method is the method that will handle dropping the checkers, checking to see if the game has been won or if a draw has occurred.

The basic algorithm is as follows:

While the game isn't over
    determine whose turn it is
    determine what command was issued

The commands are described below in the Command section.

A player's turn is considered over, when they have successfully dropped a checker. Displaying the board, dropping a checker in a full column or dropping a checker in a row that is not on the board does not end their turn.

The Board class is the largest and most complex of the classes. It has methods to allow a checker to be dropped, to tell if there was a win or a draw. There are many ways to tell if there are 4 in a row and you can choose any method you like.

Only the public methods are required for the classes, except where noted below; the private methods, if any, are up to you.

Commands

There are two commands, one for dropping a checker and one for displaying the board.

Dropping a checker:

drop in <col>

-- this command will drop a checker into the column with the given column number. The column number should be between 1 and 7. The Game class will need to translate the column number to match the columns in the array, which are 0 to 6. Use the player's avatar as the checker. The avatar is most likely their first letter from their name, but doesn't have to be. So use the avatar as the checker.

display board

-- this command will print the board. It should be like this:

---------------
| | | | | | | |
---------------
| | | | | | | |
---------------
| | | | | | | |
---------------
| | | | | | | |
---------------
| | | | | | | |
---------------
| | | | | | | |
---------------

This is obviously for an empty board. When there are checkers in the board, you should display the avatar in the space for the checker. So if the avatar is one character, then the same size and shape is retained.

Or, if there are two players whose names are Dave and Kelly, and Dave has won, then the board would look like this:

---------------
| | | | | | | |
---------------
| | | | | | | |
---------------
| |D| | | | | |
---------------
| |K|K| | | | |
---------------
| |K|D|D|D|D| |
---------------
|D|K|D|K|K|D|K|
---------------

Input and Output

Input

Name: Dave
Avatar: D
drop in 1
display board
drop in 1
display board
drop in 1
display board
drop in 3
display board
drop in 4
display board
drop in 4
drop in 4
drop in 4

Output

When the game is over, display the board and then indicate who has won or if the game was a draw. Note: The output below is not from the input above:

---------------
| | | | | | | |
---------------
| | | | | | | |
---------------
| |D| | | | | |
---------------
| |K|K| | | | |
---------------
| |K|D|D|D|D| |
---------------
|D|K|D|K|K|D|K|
---------------
Game over:  Dave won

So when the game ends, you will output the words: Game over: and then if there was a winner, then output the name of the winner and the word won. If no one has won, then say this:

Game over: Draw game

Helpful Files

So, here is a file you can use for a main. This has two commented out lines. It uses an input file player2.txt as the input for player two. You can use this file, make your own, or use cin for both players. You can also make another input file for player 1 and use two files. How the input gets to the play game method is how the game will be played.

Hint List

  1. The win should be in a column where the win is on the bottom of the column.
  2. The win should be in a column where the win is one off the bottom of the column.
  3. The win should be in a column where the win is two off the bottom of the column.
  4. The win is in a row and the checkers are in rows 1-4.
  5. The win is in a row and the checkers are in rows 2-5.
  6. The win is in a row and the checkers are in rows 3-6.
  7. The win is in a row and the checkers are in rows 4-7.
  8. The win is in a diagonal starting in the top left corner and going down to the right.
  9. The win is in a diagonal starting in cell 0,1 going to down and to the right.
  10. The win is in a diagonal starting in cell 0,2 going down and to the right.
  11. The win is in a diagonal starting in cell 0,3 going down and to the right.
  12. The win is in a diagonal starting in cell 1,0 and going down to the right.
  13. The win is in a diagonal starting in cell 1,1 going to down and to the right.
  14. The win is in a diagonal starting in cell 1,2 going down and to the right.
  15. The win is in a diagonal starting in cell 1,3 going down and to the right.
  16. The win is in a diagonal starting in cell 0,4 and going down to the left.
  17. The win is in a diagonal starting in cell 0,5 going to down and to the left.
  18. The win is in a diagonal starting in cell 0,6 going down and to the left.
  19. The win is in a diagonal starting in cell 0,3 going down and to the left.
  20. The win is in a diagonal starting in cell 1,4 and going down to the left.
  21. The win is in a diagonal starting in cell 1,5 going to down and to the left.
  22. The win is in a diagonal starting in cell 1,6 going down and to the left.
  23. The win is in a diagonal starting in cell 1,3 going down and to the left.
  24. The win is in a diagonal starting in cell 2,0 and going down to the right.
  25. The win is in a diagonal starting in cell 2,1 going to down and to the right.
  26. The win is in a diagonal starting in cell 2,2 going down and to the right.
  27. The win is in a diagonal starting in cell 2,3 going down and to the right.
  28. The win is in a diagonal starting in cell 2,3 going down and to the left.
  29. The win is in a diagonal starting in cell 2,4 and going down to the left.
  30. The win is in a diagonal starting in cell 2,5 going to down and to the left.
  31. The win is in a diagonal starting in cell 2,6 going down and to the left.

Requirements

  1. You must implement the classes as listed in the API. The API is linked above and in the side menu in Scholar.
  2. Your board must be a 2 dimensional array of Checkers of 7 columns and 6 rows.
  3. The commenting requirements from before.
  4. Your classes will need a header at the top of the file.
  5. Your methods will need comments to indicate the use of the function.

Grading

Zip up your Game.h, Game.cpp, Board.h and Board.cpp and turn them in to Web-CAT.

Due

This is due on Wednesday April 2th Thursday April 3, by 11:55PM