You haven't provided a whole lot of information, but you do not need pointers. The Ant class should know its own position.
Other things should refer to the current ant to know where the ant is.
What the ant
does need to know is its terrain. That is, it should have access to the gameboard. Do this with a reference. Your main should look something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
int main()
{
int rows = ask_user( "How many rows will your gameboard have? ", 100, 10000 );
int cols = ask_user( "How many columns will your gameboard have? ", 100, 10000 );
Gameboard gameboard( rows, cols );
int row = ask_user( "What row will your ant start at? ", 1, rows ) - 1;
int col = ask_user( "What column will your ant start at? ", 1, cols ) - 1;
Ant ant( gameboard, row, col );
int steps = ask_user( "How many steps should the ant take? ", 1, std::numeric_limits<int>::max() );
...
}
|
Notice how I created a function to help ask the user for a value in a given range.
1 2 3 4 5 6
|
int ask_user( const std::string& prompt, int min, int max )
{
...
// if something goes wrong, either fix the error [such as returning (max-min)/2+min]
// or print a message and exit().
}
|
You can even fix your prompts to give a default value, such as:
|
int rows = ask_user( "How many rows will your gameboard have (default:500)? ", 100, 500, 10000 );
|
You can make this part of the input work however you want.
Your Ant class looks fine as-is: just add a reference to the gameboard as a private or protected member, and design your constructor appropriately.
I do not know how you are supposed to report the results of the computation. If you have an easy way to display to an image or to a window that would be nice. You can even do a display loop for each step of the ant so that the user can watch the patterns emerge. (Though I suspect this is not likely part of your assignment.)
You can easily create a text file with the results as well. When the ant finishes, just dump the gameboard to a file, using any two highly contrasting characters, such as
and
#
. That way you (and your professor) can load it up in a plain-text (fixed-font) editor and see the highway.
After that it is just using a loop to tell the ant to make each successive step.
Unless your assignment forbids it, terminating at a wall is not very friendly. Your options are:
• terminate (easy and boring)
• wrap around the gameboard (most interesting, IMHO)
• create a new rule to turn the ant away from the wall
• expand the gameboard (hard)
Hope this helps.