Computer Science homework help.
Objective: The main objective of this assignment is checking the students’ ability to work with ADTs. In this week’s assignment, you will be writing the interface of an ADT in order to conform to the requirements of a larger application.
Description: You have been tasked with implementing a program that can read chess games from a file and detect whether the initial moves (opening) matches any of the stored openings (also read from a file). Note that the program does not compile successfully as it is missing ADT definitions which you will implement.
For example, the position in Figure 1, which corresponds to the first 5 moves, is called the “Italian Game”.
You must utilize 2 ADTs (Opening, Game) for the tasks described in next section.
Opening must have the following attributes:
- String Name
- String moves: The actual moves (i.e. e4, e5, f4 or e4, e5, Nf3, Bb5) Note that some slots in the array can be empty if there are fewer than six moves in an opening
- String Official number of times opening has been played in tournaments (the string datatype is used as the values can be larger than the int data type allows)
- Double Percentage of White’s victory in this opening
- Double Percentage of Draw in this opening
- Double Percentage of Black’s victory in this opening
Game must have the following attributes:
- Char outcome – specifies the outcome of the game (B for Black winning, D for draw, W for white winning.
- int numMoves – specifies the number of moves in the game
- String array Moves
You have been provided with skeleton code for the tasks below. The functions are:
GetString: To retrieve a filename from the user
GetNumOpenings: return number of openings from file
Menu: function that based on user input, either prints openings, detects an opening given a game file, or exits.
- Create the two ADTs. You must include accessor functions, mutator functions, constructors. Depending on your implementation you might also need a user-defined destructor.
- Then implement the function ReadOpenings, which must read a list of openings from the file “openings.txt” and store them in an array of type Opening.
Implement the function PrintOpenings. The expected output is illustrated in Figure 2.
The format of the file can be seen in Figure 3.
Note: You can read more about the notation used to represent a move at
You must successfully load the contents of a game file to the Game ADT’s member variables.
You have two options:
- Create a member function of the Game ADT to read the moves of a game, and then store them in the ADTs corresponding array
- Load the game’s moves to the ADT’s array, by utilizing the constructor. To do so, you can pass the file’s name as a parameter to a user-defined constructor.
Implement the function DetectOpening. This function must prompt for a game’s filename to be inserted, so that a game’s moves are available. Then the game’s moves must be compared against the known openings. If an opening is detected, you must print it to the screen along with the win percentages (white win, draw, black win) in the following manner: