Given all the de-allocation problems with CMoveGenerator as a Singleton, I decided to toss it over and just use a pointer within the Computer's move function (see update in last step.)
So there are only three functions that need to be constructed at this time, in addition to the constructor (which preps the RNG.) The public functions are the getMove(void) returning the CBoard location the Computer moves to and setGame(const CGame* data). The private function, randomMove(const COwner::Player& tag), just grabs an availible move at random. The decision tree part for the AI will be added later. This is enough to start play testing the program.
The only thing really unusual about the comstructor is that it requires an integer. This will be for the AI part.
|CMoveGenerator::CMoveGenerator(const int& aiL)|
|Enforce limits on the chosen AI level.|
If debugging, seed Random Number Generator with specific value.
Otherwise, use the value returned from time() as the seed.
Updating the CMoveGenerator instance with the current game is straight forward.
|void CMoveGenerator::setGame(const CGame* aGame)|
That aGame is valid.
|Set private CGame variable to COPY aGame.|
The interface of getMove() allows the program to hide all the messy details of actually determing the next move.
|Call the private move generator for the Computer's move.|
That the returned move is valid.
The only move generator right now is purely random (as much as a ccomputer can get anyway.)
|int CMoveGenerator::randomMove(const COwner::Player& tag)|
|Allocate memory to store the possible moves.|
Get the possible moves based on the store data.
Perform reality checks on data. (Not much to this one. The only biggie is the possiblity that this function is called when there are no moves left.)
Get a random possible move. I used a while loop (with an emergency limiter) to extract a non-CBoard::OFF_BOARD value.
Clean-up and return the move.