CMSC 201 |
Project 1 - Due 11/24This homework must be submitted by 5pm on the due date to get any credit. Connect FourWe will be programming an interface to simulate a connect four game. Those unfamiliar with connect four should look here for more details. The entire game will be text based, with players taking turns entering moves. Your connect four program should first prompt the user for a number of rows, then a number of columns. If either of these values is less than five, the program should continue to ask the user for a row or column value until the user enters a number five or greater. If the user enters something that isn't a number, the program should continue to prompt them until they enter a number. Once a number of rows and number of columns has been successfully been entered, you should continue to prompt each player for a move in turn until a player has won or drawn. Once the game has ended, you should display the winner and present an option to play again by typing y, or to quit by typing n. Your output should look EXACTLY as follows:Welcome to Connect Four! Please enter a number of rows: 6 Please enter a number of columns: 1 Please enter a valid choice: Tacocat Please enter a valid choice: 5 _____ _____ _____ _____ _____ _____ Player 1's turn: Please enter a move: 1 _____ _____ _____ _____ _____ x____ Player 2's turn: Please enter a move: 2 _____ _____ _____ _____ _____ xo___ Player 1's turn: Please enter a move: 1 _____ _____ _____ _____ x____ xo___ Player 2's turn: Please enter a move: -1 Please enter a valid choice: 2 _____ _____ _____ _____ xo___ xo___ Player 1's turn: Please enter a move: 1 _____ _____ _____ x____ xo___ xo___ Player 2's turn: Please enter a move: 2 _____ _____ _____ xo___ xo___ xo___ Player 1's turn: Please enter a move: 1 _____ _____ x____ xo___ xo___ xo___ Player 1 wins! Would you like to play again (y/n): y Please enter a number of rows: 6 Please enter a number of columns: 5 From here, the output should continue as it was before. For a draw, it should print "The game is a draw!". Should the player enter an "n" at the end, the program may simply terminate. If a player tries to move in a row that is already full, the program should prompt them to "Please enter a valid choice: ". What you needThe first step is not to panic! We are going to break what is an intimidating program down into something simple. For this project, you should represent the board as a 2D array of 0s, 1s, and -1s (where a 0 is a blank space, 1 is player 1's move, and a -1 is player 2's move). You will also need a way of keeping track of whose turn it is. Here is a list of methods you should have:
You are also allowed to reuse any functions from previous homeworks if they work! SubmittingWhen you've finished your homework, use the submit command to submit the file. You must be logged into your account and you must be in the same directory as the file you're trying to submit. At the Linux prompt, type submit cs201 PROJ1 proj1.pyAfter entering the submit command shown above, you should get a confirmation that submit worked correctly: Submitting proj1.py...OKIf not, check your spelling and that you have included each of the required parts and try again. You can check your submission by entering: submitls cs201 PROJ1You should see the name of the file that you just submitted, in this case proj1.py |
Adapted from UMBC CSHC's webpage design |