Relationship between position (x, y) and game board grid width x height. Also, isn't there an out-of-bounds bug in one of the tests?
The convention used in the game is the standard matrix convention:
- In position (x, y), x indexes the rows, so also the height.
- In position (x, y), y indexes the columns, so also the width.
- Positions are always defined as (row, col), so (x, y).
- A somewhat looser convention is to define a matrix (game board grid) as width by height (w x h).
The code which you might consider buggy but which shows how these conventions interact is the following:
Game g(4, 5);
pass = g.addSimple(0, 0);
pass = pass && g.addStrategic(1, 1);
pass = pass && g.addFood(0, 2);
pass = pass && g.addFood(2, 1);
pass = pass && g.addAdvantage(2, 2);
pass = pass && g.addSimple(4, 3);
Notice the static constants
const unsigned Game::MIN_WIDTH = 3;
and
const unsigned Game::MIN_HEIGHT = 3;
The exception was defined to be called in the Game constructor.
"terminate called after throwing an instance of 'std::regex_error'" "throw_regex_error(regex_constants::error_brack);"
You are using GCC with version less than 4.9.0, in which full support for C++11 <regex> was added. C++11 compiler support is required for this course. Consider upgrading. If you are on Ubuntu/Mint, here is a helpful link.
Advantage::getCapacity()
As stated elsewhere in the requirements, you are supposed to return the present capacity multiplied by the static constant
const double Advantage::ADVANTAGE_MULT_FACTOR = 2.0;
How do I implement Piece::operator*()? What do I do in Piece::interact()? How do I use Piece::finish()?
Study, run, and understand the code in this section of Bruce Eckel's Thinking in C++. The code was analyzed in class twice and is referenced from the PA5 requirements. In short, the virtual function mechanism implements single (late) dispatch, which means that when a virtual method is called, the mechanism dereferences a function pointer from the calling object's virtual table, thus executing the correct version of the function. Since Piece::operator*() (aka "interaction operator") implements an interaction of two objects, one calling and one a right-hand side argument) (e.g. in a * b, a is the calling object and b is the argument), there are two objects with unknown runtime (dynamic) type. Therefore, single dispatch is not enough as it will only help determine the runtime type of one of the objects. Double dispatch is needed, instead. This is implemented by adding an overloaded pure virtual interact() function. The overridden operator*() only calls the interact() function on the right-hand side object with its own this pointer as an argument. This is the second virtual function dispatch. The interact() functions, implemented by each of the derived types that need to participate in an interaction, actually implement the functionality of the interaction, including terminating objects that have been consumed (as with Resource) or defeated (as with Agent). The finish() function is provided to achieve the termination of Agent objects, and should be called from the interact() functions.