Starting from:
$35

$29

Homework # 4 Solution

In this homework, you will modify your game of Hex program in C++ of HW3 using dynamic memory techniques and operator overloading. Here are the modifications and additions for your classes.
    • Make the inner class Cell a public inner class (not private).

    • You will keep the cells of Hex using dynamic memory techniques, so you are not allowed to use vectors as data members. In other words, this class will have Cell ** hexCells in its private section. Any other data members and function members needed will also be defined.

    • You will change your play functions. Your new class will have two functions named play that plays the game for a single step. First function does not take a parameter and it plays the computer and it returns the Cell where it made a change. The second function takes a Cell position and it plays the user.

    • Your new Hex class will have “undo” feature: when you call the operator-- on your Hex object, it will undo the last play. In other words, your Hex class should remember all the plays from the start of the game. You should implement both pre and post operator--

    • Overload stream insertion and extraction operators. Use these operators for both screen prints and file input output.

    • Write a function that returns a score for the user. The score will be higher if the board is better for the user. It is highest if the user wins and it is zero at the beginning of the game. You may choose to count the number of connected cells in the correct direction.
    • Overload operator== for comparing two Hex games like you did in HW3.

    • Modify or re-implement all the other functions of HW3

object oriented techniques. Your main class for this homework will be named Hex. This class will have a private inner class named Cell to represent a Hex cell. The class Cell will hold the position of the cell (A, B, C, etc) and the row number (1, 2, 3, etc). This class will also include all necessary setters/getters, constructors etc. Remember a cell can be empty, user (user1, user2) or computer, which will be represented by C++11 Enum types.

Write your main function to test your classes and all member functions. Make at least 5 objects of class Hex and play the games at the same time.

You will use all the object oriented techniques that we learned in the class including nullptr, explicit keywords.

Notes:
    • Do not use anything that we did not learn in the lectures.

    • Do not forget to indent your code and provide comments.
    • Check the validity of the user input.

    • Test your programs very carefully at least with 10 different runs. Submit at least two saved files with the HW.

    • You should submit your work to the moodle page.

More products