ELET 2300
Assignment 4
Submit your program through Blackboard – No late submissions!
Make sure that you upload the right file (usually: main.cpp) !!!
In this assignment, you will implement a simplified game of Dara in C++ for two (human) players.
1. First be sure to understand how the game works. A summary of the game rules can be found at
the end of this document. You can also find extra information at Wikipedia:
https:
en.wikipedia.org/wiki/Dara_(game) and YouTube (https:
youtu.be/4pEY9MUYibU).
2. The original game starts with the players taking turns to place 12 pieces each on a 5x6 square
oard (i.e., the "drop" phase). To simplify the verification of your program, the program will
ead the initial board setup from a file instead of asking the players to enter the locations of the
initial pieces. An example of the file contents is:
.XOXOX
.XOOXX
O.XOOX
O.XO.O
XOX.XO
where "X", "O" represent the tokens of player 1 and 2 respectively. The dot (.) represents an
empty cell.
In your program the board will be represented as a char a
ay. Do not use strings. Implement the
file reading and board initialization in a C++ function named "readBoard".
3. Your program must verify whether this initial configuration is a valid one, i.e., make sure that
each player has exactly 12 pieces on the board without any 3-piece or more horizontal/vertical
ow (see the game rules).
4. Implement the function "displayBoard", which as the name implies, will show the cu
ent state
of the game on the screen.
5. Write a C++ loop in main( ) to implement the "move phase" of the game. The loop will:
A. Ask player 1 for the location of the piece that she wants to move and the movement
direction ('u',' d', 'r', 'l' for up, down right, left). If the piece at the requested location
elongs to the player AND the target cell is free, then execute the move. Otherwise, print
an e
or and ask the user to enter a different location/move direction.
B. In the original game, a valid move cannot form a column
ow of 4 equal pieces or more
and cannot put the latest piece back to its previous location. These two rules are optional
for this assignment, but you can implement them extra credit.
C. After a valid move, check whether a 3-same piece horizonal or vertical row was formed.
If so, ask the user for the location, i.e., the row number, column number, of the piece she
wants to capture. Verify that the location contains an opponent's piece and that is not
empty. If so, remove that piece (make that cell empty). If not, ask again the user for a
valid location.
D. After each capture, check whether the game has ended (i.e., opponent has no more
pieces on the board). If so, print a message announcing so.
E. Once the game has ended, ask whether they want to play again. If so, restart the game by
e-reading the initial board from the file (step 2 above). If not, terminate the program.
Design the main loop in modular form using additional C++ functions. For example, you can
implement a "gameover" function that checks whether all opponent's pieces has been captured
and then make call to that function from main( ).
Notes:
• You must use only the C++ instructions that we have covered so far in class.
• The program that you turn in must be your original and individual work. While you are allowed to
discuss the program assignments in general terms with others, you are not allowed to share details of
the actual solution(s) or program code with anybody except the instructor.
• Turning in a copy of someone else's program, even a copy with extensive changes made to it, or
eceiving any unauthorized assistance is a very serious offense in this course.
• An automated plagiarism checker may scan programs at any time during the semester.
• Only submit your source code (.cpp). This must be done on or before the due date through Blackboard.
No late submissions. Blackboard will automatically close the submission page right after the deadline.
• Your program must include comments explaining your steps and must be properly formatted (see
Program_Style_Guidelines.pdf in Blackboard).
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
∗ ELET 2300
∗ Programming Assignment
∗
* Compiler type (if other then Visual C++)
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗/
*Courtesy of the Mind Research Institute