For Project
COP-3223H
Table of Contents
1. Overview
In this project, you will implement the eight queens game, where users can place queens on a chess board.
2. Repository setup
Log into eustis:
ssh NID@eustis.eecs.ucf.edu
Go to your local repository: Be sure you have already completed the git exercise before attempting this project.
cd ~/cop3223spring26/assignments
Create and enter a directory for the for project:
mkdir for cd for
You only need to mkdir once to create the directory.
Make sure you are in the right directory
pwd
You should see
/home/net/NID/cop3223spring26/assignments/for
3. Create the eight queens program
Make sure you are in the right directory
pwd
You should see
/home/net/NID/cop3223spring26/assignments/for
3.1. Initial board
Start with an 8x8 board, with each space containing the character '.'. Be sure to clear the terminal screen.
........ ........ ........ ........ ........ ........ ........ ........
Each line is a row.
3.2. Inputs
Read the row number, then the column number from the user (you can use two scanf calls). Rows and columns are both 1 to 8 inclusive. After inputting the two numbers, place an uppercase 'Q' at the corresponding position on the board and redraw it. For instance, if the user puts 1 then 8, the board will look like this:
.......Q ........ ........ ........ ........ ........ ........ ........
Notice that the row is the first line.
Continue inputting a row and column. E.g., if the user then inputs 7 and 3, the board will then be
.......Q ........ ........ ........ ........ ........ ..Q..... ........
Be sure to clear the terminal screen between each redraw.
See the tic tac toe game for hints at drawing boards and reading inputs.
3.3. Error checking
Only place a 'Q' when it is a valid position on the board. Firstly, the row and column inputs should each be between 1 and 8, inclusive, corresponding to the position of the board. If the user provides a row and/or column that is out of bounds, do not modify the board and redraw and request inputs again.
3.4. Enforcing queen movement
Additionally, enforce only placement of queens at positions where they cannot attack each other. The queen can attack any piece in the same column, row, or diagonal. For instance, if there is already a queen at row, col (1, 1), then do not place a queen if the user inputs a queen to the same row (1, 2), same column (5, 1), or same diagonal (4, 4), for any such position. If a user does request placement to the same row, column, or diagonal as an existing queen, then ignore the input by not modifying the board. Redraw and request inputs again instead.
3.5. Exit condition
Continue requesting, checking, and placing queens (when possible) until the user inputs 0 for the row and 0 for the column. Then stop redrawing the board and requesting inputs from the user, allowing the program to terminate.
3.6. Example game
Initial board:
........ ........ ........ ........ ........ ........ ........ ........
User inputs row 1 and column 1
1 1
Q....... ........ ........ ........ ........ ........ ........ ........
User inputs row 2 and column 3
2 3
Q....... ..Q..... ........ ........ ........ ........ ........ ........
User inputs row 4 and column 4. This position can be attacked by the queen already in position (1, 1), so there is no change to the board, which is redrawn, and the user can continue inputting a position:
Q....... ..Q..... ........ ........ ........ ........ ........ ........
User inputs row 3 and column 5
3 5
Q....... ..Q..... ....Q... ........ ........ ........ ........ ........
User inputs row 0 and column 10. This position is out of bounds, so no change is made to the board, which is redrawn, and the user can continue to input values.
Q....... ..Q..... ....Q... ........ ........ ........ ........ ........
User inputs row 0 and column 0
0 0
The program ends.
3.7. Output format
Put no characters into the output expect characters to the clear the terminal and print the board. Do not prompt the user with any text with printf. Just use scanf to read the row and column. See the above example game for an illustration of the output.
3.8. Program name
The program must be called for.c and must be in the for directory, i.e., the full path should be
~/cop3223spring26/assignments/for/for.c
Compile and run the program whenever you make changes using
cd ~/cop3223spring26/assignments/for/ gcc -o for for.c ./for
Be sure there is no other output besides the required output as the grading will be automatic. If you would like to have debugging output, use fprintf(stderr, "...", ...); instead of printf.
4. Submitting your program via git
This assumes you have already setup your repository and that you are still in your hello directory in your repository.
4.1. Add and commit the file
Enter
git add for.c git commit for.c
Write an appropriate commit message. Remember that you will need to save (Ctrl-x Ctrl-s) then quit (Ctrl-x Ctrl-c) the emacs editor that pops up. If you are having trouble, be sure that you have completed the git project first.
Do not commit the backup file for.c~ nor the for program. Use a .gitignore file to exclude those from the repository, so they won't show up when you type git status.
Then to synchronize the changes to the remote git repository on the grading server:
git push
5. Self-check
5.1. Remove the previous self-check
If you have already run the self-check, you can remove it like this
rm -rf ~/tmp/assignments_selfcheck
Double-check the path carefully to avoid deleting the wrong directory.
5.2. Make a fresh clone of your project
git clone gitolite3@eustis3.eecs.ucf.edu:cop3223/$USER/assignments ~/tmp/assignments_selfcheck
You should see something like
Cloning into '/home/net/NID/tmp/assignments_selfcheck'... Welcome to eustis.eecs.ucf.edu. Please use your NID and NID password to log in. See http://t.cs.ucf.edu/help/eustis for additional instructions. remote: Enumerating objects: 16, done. remote: Counting objects: 100% (16/16), done. remote: Compressing objects: 100% (12/12), done. remote: Total 16 (delta 1), reused 0 (delta 0), pack-reused 0 Receiving objects: 100% (16/16), done. Resolving deltas: 100% (1/1), done.
If you see
fatal: destination path '/home/net/NID/tmp/assignments_selfcheck already exists and is not an empty directory.
5.3. Enter the fresh clone's directory
cd ~/tmp/assignments_selfcheck/for
5.4. Make sure for runs correctly
cd for gcc -o for for.c ./for
6. Grading schema
| Criterion | Points |
|---|---|
| for.c exists and compiles | 1 |
| The program runs correctly, prorated by successful test cases | 3 |
| TOTAL | 4 |