(P) Checkers¶
Goal: I will practice using vectors and Git. I will also learn to follow good programming style.
Instructions:
Retrieve the code template: templates/04/checkers
->
student/04/checkers
.
The code template provides you skeleton of the print method, but you shall complete it with the print of an element of the gameboard. Alternatively, you can write the print method by yourself.
Your task is to implement a checkers game for one player. The program receives a character for a game piece (the character to be printed) that will be used in filling the gameboard.
Important
Before starting to write code, read carefully the whole assignment. Note especially the points Implementing the program in parts (required commits), Special requirements, and Evaluation.
From the point Evaluation note especially that the program must first pass all automated test. Otherwise the work will not be evaluated by assistants, and no points will be given.
Note
This project can be done either in pairs or independently. If you do the project in pairs, choose ”Form a group” from the menu on the left to register your group. In addition, the submission box at the very end of the current page shows two choices: “Submit alone” / “Submit with…”. You should be careful when selecting the choice, because you cannot change it afterwards. Enter only the address of the Git repository owned by either of you (not both) in the submit box. The code files must contain (in comments) the personal data of both of you.
You can look for a group via Kooditorio’s Discord link (see Timetable & links).
Header comment and feedback language¶
The Evaluation point in this section requires a header comment in the code file. It means something like below:
/* Checkers (for one player)
*
* Desc:
* This program implements a checkers game for one player. The size of
* the gameboard is 8 x 8, and it will filled with empty spaces and
* game pieces (character given by the user).
* At first, the gameboard is filled with pieces, but there is an
* empty area of size 4 x 4 in the middle of the gameboard. The aim is to
* remove pieces such that only one of them is left. A piece can be moved
* diagonally over another piece, whereupon the piece that was skipped
* will be removed.
* On each round, the user is asked for two points (four coordinates):
* the piece to be moved and its target position. The program checks if
* if the move is possible.
* The program terminates when there is only one piece left or if the
* user gives a quitting command ('q' or 'Q'). In such case the program
* prints the number of moves made and that of pieces left.
*
* Program author ( Fill with your own info )
* Name: Teemu Teekkari
* Student number: 123456
* UserID: teekkart ( Necessary due to gitlab folder naming. )
* E-Mail: teemu.teekkari@tuni.fi
*
* Notes about the program and it's implementation (if any):
*
* */
Add above kind of comment at the very beginning of the file main.cpp
.
Also the code files must include your personal information, but
the description part is not necessary to repeat in every file, it is enough
to put it in the main program file.
You can write the above comment also in Finnish (see Finnish assignment), but write all comments in the same language. Remember to replace parts of the above text with your personal data.
If you are working in pairs, add personal data of both of you.
The template code has comments both in Finnish and English, you remove those not needed.
The feedback language will be chosen in the submission box (at the very end of this page). By default, the feedback language is Finnish, but you can change it, if you want to have the feedback, given by an assistant, in English. We will use the language you have given in the submission box of the final submission.
Checkers vs waterdrop game¶
The materials of this round include a description of waterdrop game that
uses a vector, the elements of which are vectors.
Further the elements of the inner vector are squares (Square
objects).
This project has a similar structure in a sense that also the gameboard
of checkers is a vector, the elements of which are vectors.
However, the elements of the inner vector are either characters or values
of enum
type, so they are simpler
than the squares in the waterdrop game, and thus, there is no need to
describe them as a class.
In the waterdrop game, each square has a pointer to the game board, since each square must know its adjacent squares. In the project, this is not needed, nor pointers at all.
Assignment¶
Your task is to implement such a version of checkers game that has only one player.
At first, the program asks for a character that will be used in filling the gameboard. After that the program prints the gameboard filled with that character:
Enter piece character: *
=======================
| | 1 2 3 4 5 6 7 8 |
-----------------------
| 1 | * * * * * * * * |
| 2 | * * * * * * * * |
| 3 | * * * * |
| 4 | * * * * |
| 5 | * * * * |
| 6 | * * * * |
| 7 | * * * * * * * * |
| 8 | * * * * * * * * |
=======================
Enter start point (x, y) and destination point (x, y), or q to quit:
After that the user can give two points with their x and y coordinates, i.e. four numbers (separated by empty spaces).
If coordinates give by the user are such that a piece can be moved from the start point to the destination point, the move will be made. Otherwise the program informs about an illegal input.
From the points given by the user, the following things are checked.
- The given points must consist of numbers.
- The given points must be inside the game board.
If either of the above requirement does not hold, the program prints:
Invalid start/destination point.
If the above requirements hold, the next conditions will be checked:
- The start point must have a piece.
- The destination point must empty.
- The start and destination points must be located in the same diagonal such that there is exactly one piece in the middle of them (so, the middle point must not be empty).
Otherwise, the program prints the error message:
Cannot move from start point to destination point.
More precise action of the program can be seen in the example execution:
Enter piece character: #
=======================
| | 1 2 3 4 5 6 7 8 |
-----------------------
| 1 | # # # # # # # # |
| 2 | # # # # # # # # |
| 3 | # # # # |
| 4 | # # # # |
| 5 | # # # # |
| 6 | # # # # |
| 7 | # # # # # # # # |
| 8 | # # # # # # # # |
=======================
Enter start point (x, y) and destination point (x, y), or q to quit: xx yy 1 2
Invalid start/destination point.
Enter start point (x, y) and destination point (x, y), or q to quit: x x y y 1 2
Invalid start/destination point.
Enter start point (x, y) and destination point (x, y), or q to quit: 0 1 2 3
Invalid start/destination point.
Enter start point (x, y) and destination point (x, y), or q to quit: 2 3 9 9
Invalid start/destination point.
Enter start point (x, y) and destination point (x, y), or q to quit: 1 8 4 5
Cannot move from start point to destination point.
Enter start point (x, y) and destination point (x, y), or q to quit: 3 6 1 8
Cannot move from start point to destination point.
Enter start point (x, y) and destination point (x, y), or q to quit: 1 6 3 6
Cannot move from start point to destination point.
Enter start point (x, y) and destination point (x, y), or q to quit: 1 8 3 6
=======================
| | 1 2 3 4 5 6 7 8 |
-----------------------
| 1 | # # # # # # # # |
| 2 | # # # # # # # # |
| 3 | # # # # |
| 4 | # # # # |
| 5 | # # # # |
| 6 | # # # # # |
| 7 | # # # # # # # |
| 8 | # # # # # # # |
=======================
Enter start point (x, y) and destination point (x, y), or q to quit: 1 5 3 3
=======================
| | 1 2 3 4 5 6 7 8 |
-----------------------
| 1 | # # # # # # # # |
| 2 | # # # # # # # # |
| 3 | # # # # # |
| 4 | # # # |
| 5 | # # # |
| 6 | # # # # # |
| 7 | # # # # # # # |
| 8 | # # # # # # # |
=======================
Enter start point (x, y) and destination point (x, y), or q to quit: q
2 move(s) made.
46 piece(s) left.
Implementing the program in parts¶
Use version control in your project such that there can be found at least five commits as follows:
- The program asks for a character for the game piece and prints the gameboard.
- The program reads points given by the user and checks their validity.
- The program can skip the game piece in the middle of the given points and remove it.
- In addition, you must have at least two more commits (before, between, or after the aforementioned ones).
You must also mention the steps described above clearly enough in the commit messages to enable course assistant to find them easily when evaluating your project. However, you can section above commits into several ones.
Tips for completing the assignment¶
- It is enough to use
vector
container from STL, but also other containers from STL are allowed.
- From the waterdrop game, you can learn how define a vector, the elements
of which are vectors (
square.
, line 12). Otherwise, the example is not so important.
Special requirements¶
You must use the class given in the template code (GameBoard
).
Consider which code naturally belong to this class and which code belong
to the main program module.
Which attributes the class could have?
And which methods?
Write methods concerning the gameboard in the aforementioned class, while code concerning user interface (e.g. reading input) suits in the main program module.
Evaluation¶
To end up to assistents’ evaluation, your work must first pass the automatic tests. Automatic tests do not accept a program producing warnings while compiling. If the automated tests give 0 points for your work, also your final points will be 0, and your work will not be evaluated by an assistant.
The assistant evaluates the latest Plussa submission that has passed the automated testing (= 1 p) before the deadline, according to the following criteria:
- The overall principle of the solution: 0-20 points:
- The learning goals of the exercise have been achieved.
- The program code has been split into logical, suitably long segments using functions, classes, and/or methods.
- If the program uses classes and objects, these have been implemented according to the basics of object-oriented programming (see previous material section: About programming style, especially at Object-oriented programming).
- The data structure does not include repetitive data nor unnecessary parts. The chosen data structures have been used in a reasonable way.
- The program code does not include unnecessary repetitions nor other unnecessary parts.
- The program code does not include unnecessary limitations or assumptions or other forced solutions.
- The implementations of the program structures are easy to understand.
- Global variables have not been used in the program code (global constants are OK).
- The program does not terminate with the
exit
function.
- Programming style: 0-20 points:
- Variables and functions are named clearly and appropriately. These items have named by using only one language, not e.g. Finnish and English mixed.
- Named constants have been used instead of magic numbers.
- The program code is neatly formatted.
- The length of program code lines do not exceed 80 characters.
- At the beginning of each file, there is a comment explaining the purpose of the file, the creator(s) of the project and other necessary information (see the point Header comment).
- At the beginning of each function/method there is a comment describing its working, return value and parameters. This comment is placed in the header file if such exists.
- There are comments in the code where necessary.
- Comments are related to the current version of the program, not to an older one.
- All comments have written in the same language (fi/en), but comments can be written in a language different from that used in naming variables and such.
- All the variables have been initialized.
- The compiler does not give warnings while compiling.
- Using the version control: 0-10 points:
- There are enough commits.
- The content of commit messages is clear and relevant.
Note about evaluation
Automated tests check if your program works, but assistants pay attention to your coding style and other evaluation criteria listed above. Therefore, it could be possible that a fully working program brings you only zero points, if the above criteria are not met.
Requirements concerning especially good programming style can be found from the earlier material section on the current round.
Note about submission versions
The version to be evaluated is the one that corresponds to your latest successful Plussa submission (within the deadline). A successful submission means such a submission that passed automated tests.
After the first successful submission, you most probably want to improve your coding style (e.g. add comments), assuming that the deadline is not too close.
Anyway, remember finally this: After the final Git push, submit your work also in Plussa.
A+ presents the exercise submission form here.