HW 1 : ConnectFour
DUE: FRIDAY, FEBUARY 23rd, 2007, 11:59PM
Write an interactive Text Based ConnectFour Game.
ConnectFour (also called Four in a Row) is a game with columns of slots, where players alternate placing pieces in the column. The piece falls to the bottom of the chosen slot. Once 4 of a player's pieces are in a row, either vertically, horizontally, or diagonally, then that player wins.
Use a 2-Dimensional Array to Model the Connect Four Board.
Game Play
Two Players alternate inputing the name of the column (listed as a letter 'A' through 'G'). Note that the names of the players are "Player X" and "Player O" with their pieces represented as character's 'X' and 'O' respectfully on the game board.
Here is how the game play will go, make the input and outputs behave EXACTLY as follows (remember, the line starting with a '%' is the UNIX prompt and is not to be printed out by your program):
% connectfour Welcome to Connect Four 1) New Game 2) Help 3) Quit >> 1 | . | . | . | . | . | . | . | | . | . | . | . | . | . | . | | . | . | . | . | . | . | . | | . | . | . | . | . | . | . | | . | . | . | . | . | . | . | | . | . | . | . | . | . | . | +---+---+---+---+---+---+---+ A B C D E F G Player O Move? A | . | . | . | . | . | . | . | | . | . | . | . | . | . | . | | . | . | . | . | . | . | . | | . | . | . | . | . | . | . | | . | . | . | . | . | . | . | | O | . | . | . | . | . | . | +---+---+---+---+---+---+---+ A B C D E F G Player X Move? D | . | . | . | . | . | . | . | | . | . | . | . | . | . | . | | . | . | . | . | . | . | . | | . | . | . | . | . | . | . | | . | . | . | . | . | . | . | | O | . | . | X | . | . | . | +---+---+---+---+---+---+---+ A B C D E F G Player O Move? A | . | . | . | . | . | . | . | | . | . | . | . | . | . | . | | . | . | . | . | . | . | . | | . | . | . | . | . | . | . | | O | . | . | . | . | . | . | | O | . | . | X | . | . | . | +---+---+---+---+---+---+---+ A B C D E F G Player X Move? D | . | . | . | . | . | . | . | | . | . | . | . | . | . | . | | . | . | . | . | . | . | . | | . | . | . | . | . | . | . | | O | . | . | X | . | . | . | | O | . | . | X | . | . | . | +---+---+---+---+---+---+---+ A B C D E F G Player O Move? B | . | . | . | . | . | . | . | | . | . | . | . | . | . | . | | . | . | . | . | . | . | . | | . | . | . | . | . | . | . | | O | . | . | X | . | . | . | | O | O | . | X | . | . | . | +---+---+---+---+---+---+---+ A B C D E F G Player X Move? D | . | . | . | . | . | . | . | | . | . | . | . | . | . | . | | . | . | . | . | . | . | . | | . | . | . | X | . | . | . | | O | . | . | X | . | . | . | | O | O | . | X | . | . | . | +---+---+---+---+---+---+---+ A B C D E F G Player O Move? C | . | . | . | . | . | . | . | | . | . | . | . | . | . | . | | . | . | . | . | . | . | . | | . | . | . | X | . | . | . | | O | . | . | X | . | . | . | | O | O | O | X | . | . | . | +---+---+---+---+---+---+---+ A B C D E F G Player X Move? D | . | . | . | . | . | . | . | | . | . | . | . | . | . | . | | . | . | . | X | . | . | . | | . | . | . | X | . | . | . | | O | . | . | X | . | . | . | | O | O | O | X | . | . | . | +---+---+---+---+---+---+---+ A B C D E F G Player X wins! Welcome to Connect Four 1) New Game 2) Help 3) Quit >> 3 %
Help
Notice in the Game menu, option 2 is "Help". Print out concise but helpful instructions on how to play the game.
Quit
Notice in the Game menu, option 3 is "Quit". Exit gracefully from the main() of your program. Points
Verification
After every Player's move your program must check if anybody has won the game. One approach to this is to check the entire board for 4 in the row. However, this is very inefficient. Can you think of a more efficient algorithm for verifying if someone has won the game? (i.e. What assumptions can you make about how the board changes between every move?)
Base Homework Credit
Total number of Points for this assignment is 6 Points, for program correctness, appropriate coding style (as discussed in class), and explicit documentation.
Challenges
To help encourage you to complete the base program ahead of time, here are some extra challenges which will award you extra points which will help buffer your Homework Grade. This Challenges might require research beyond the scope of class, and in no way should you begin on a Challegen until after you have you Basic Program complete.
You must turn in each Challenge Feature as a seperate versions of your program.
For example, you have already turned in the Basic Connect Four program. Make a copy of that program and add the code for the Animation Challenge. You will turn in the Animation Challenge code as a seperate file.
Connect N (1 Point)
Allow for the number of pieces in the row be adjustable, along with the size of the board. Research how to pass parameters from the command line. In other words, your ConnectN game would start like this:
% connectN <num-in-a-row> <rows> <columns>
% connectN 4 6 7
This describes the default Connect 4 game with 6 rows and 7 columns.
% connectN 5 9 12
This describes a Connect 5 game with 9 rows and 12 columns.
Animation (1 Point)
Can you animate the piece dropping down into it's slot? You will have to research drawing and refreshing the UNIX screen.
Computer Player (1-2 Point)
Add an option to the Game Menu to play against a Computer Player. (The second Point is if your Computer Player can beat me at a game.)
Last Updated 2-8-2007