Write a program that allows two players to play the game of Newton, as illustrated in this video.
Our board will be 8 pieces high by 5 pieces wide, and play will alternate between X and O. On each move type in either the column number into which you want to drop a piece, or the letter 'r' to rotate a column, followed by the column number. The interface will look like this:
Author: Dale Reed Class: CS 141, Spring 2018 Lab: Mon 5am Program: #3, Newton Game Xcode on a Mac Welcome to the game of Newton, where you try to be the first to get 5 in a row either vertically, horizontally or diagonally. Two players alternate making moves. On each turn you may enter the column number where your piece will be placed, where that piece is inserted from the top and slides down as far as it can go in that column. You may also enter 'r' to rotate a piece out of the bottom of a column to be dropped back in at the top of that column. Enter 'x' to exit. 1 2 3 4 5 --- --- --- --- --- . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . --- --- --- --- --- 1 2 3 4 5 1. Enter column number to place X or 'r' to rotate: 3 1 2 3 4 5 --- --- --- --- --- . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . X . . --- --- --- --- --- 1 2 3 4 5 2. Enter column number to place O or 'r' to rotate: 6 *** Invalid input. Please retry... 2. Enter column number to place O or 'r' to rotate: 2 1 2 3 4 5 --- --- --- --- --- . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . O X . . --- --- --- --- --- 1 2 3 4 5 3. Enter column number to place X or 'r' to rotate: 2 1 2 3 4 5 --- --- --- --- --- . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . X . . . . O X . . --- --- --- --- --- 1 2 3 4 5 4. Enter column number to place O or 'r' to rotate: R 2 1 2 3 4 5 --- --- --- --- --- . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . O . . . . X X . . --- --- --- --- --- 1 2 3 4 5 5. Enter column number to place X or 'r' to rotate: r2 1 2 3 4 5 --- --- --- --- --- . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . X . . . . O X . . --- --- --- --- --- 1 2 3 4 5 6. Enter column number to place O or 'r' to rotate: 2 ... [skipping showing all the intervening moves ...] 1 2 3 4 5 --- --- --- --- --- . X . . . . O . . . . X . . . . O . . . . X . . . . O . . . . X . . . . O X . . --- --- --- --- --- 1 2 3 4 5 12. Enter column number to place O or 'r' to rotate: 2 *** Sorry, that column is already full. Please choose another. 12. Enter column number to place O or 'r' to rotate: 1 1 2 3 4 5 --- --- --- --- --- . X . . . . O . . . . X . . . . O . . . . X . . . . O . . . . X . . . O O X . . --- --- --- --- --- 1 2 3 4 5 13. Enter column number to place X or 'r' to rotate: 3 1 2 3 4 5 --- --- --- --- --- . X . . . . O . . . . X . . . . O . . . . X . . . . O . . . . X X . . O O X . . --- --- --- --- --- 1 2 3 4 5 14. Enter column number to place O or 'r' to rotate: 3 ...
Input can be upper or lower-case for 'r' and 'x'
On each move you can either place a piece, or rotate a column.
Input validation should be done. If there is input that is not 'r', 'x', or a valid column number, then an error message must be shown and the user should be prompted to retry the move. Likewise if a column is full and an attempt is made to move into that column, then an error message must be shown and the user should be prompted to retry the move.
Checking for a win should be done in this order:
All rows, starting from the top
All columns, starting from the left
Upper-left to lower-right diagonals, starting from the upper-left corner
Lower-left to upper-right diagonals, starting from the middle on the left side.
If a move results in a win for both players at once, the winning configuration that is found first (using the sequence described in the check-for-win step) is the winner.
Up to 10 points of extra credit will be given if you implement a "smart" computer opponent that does three-move-lookahead. One approach (but not the only one) you could take is a lookahead strategy. When it is the computer's move it should look at and store all possible 10 moves. For each of those 10 it should subsequently look at the following 10 moves, and for each of those likewise the next 10 moves, for a total of 1,110 moves. Figure out which one of those is the best. Your extra credit program should only allow for user input for the 'X' moves. The computer will make the 'O' moves on its own.
You may not submit a program into both the regular submission as well as the extra credit submission. If you do, you will not be eligible for any extra credit points. Submit your extra credit program using the same naming conventions shown below, into the Blackboard assignment Program 3 Extra Credit.
Inside your program itself you must include the following grading rubric, just below your header documentation, as shown below. We will use this when grading your program as a place to annotate and list any deductions taken off within each category. Note that this is in your code but is within a comment block so should not appear on the screen when you run your program.
/* ------------------------------------------------ reedProg3.cpp Program #3: Newton game to get 5 in a row. Players alternate placing a piece or rotating a column.
Class: CS 141 Author: Dale Reed Lab: Tues 5am System: C++ Mac Xcode Grading Rubric: 50 Execution points 2 Displays header info and instructions on screen when run 5 Move number and character-to-move update correctly 3 Handles upper and lower-case user input, spaces between inputs, and 'X' to exit 5 Does error checking of user input for valid input and space in column 10 Handles 'R' to rotate a column 10 Correctly places pieces on board 15 Detects a win of 5 in a row, and gives the corresponding ending message
45 Programming Style (Given only if program runs substantially correctly) 5 Program naming convention is followed 10 Meaningful identifier names 10 Comments: Has header and this rubric. Has comments on each block of code 10 Appropriate data and control structures 10 Code Layout: Appropriate indentation and blank lines ------------------------------------------------ */
Note that the last 5 points for credit on this program will come from your peer review. Instructions on what to do for this will be posted in Piazza after the program deadline.
The name of the program you will turn in should be your netid followed by Prog3 and the .cpp file extension. In other words, if your netid is reed then your program would be called reedProg3.cpp
Blackboard considers program source code as a threat and sometimes replaces random parts of it. To avoid this you must also zip up the code you turn in. To zip a file right-click on the single .cpp file to be turned in (e.g. reedProg3.cpp) and select "Send To" and then select the "compress" menu option. On a Mac simply right-click and then select the "compress" option. The resulting file (for instance) will then be called reedProg3.zip
Only turn in this single file, turning it in on Blackboard into the assignment Program 3: Newton
Failing to follow these naming conventions or failing to turn in a zip file will result in a 5 point deduction. (Note that I am not requesting some compression, but specifically zip compression). You may turn in multiple versions, but only the latest version will be graded.