Mu Torere, the AI II

Step 12.
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.
The Constructor
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.
In case this is new, the standard headers for doing this are time.h, math.h, and stdlib.h.

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.
This point is one that is debatable. Just how much data is needed to determine the next move? Here the costs on system resources from multiple copies of the CGame object were balanced against the straight-forwardness of only one operation needed to list the possible moves.

The interface of getMove() allows the program to hide all the messy details of actually determing the next move.
int CMoveGenerator::getMove(void)
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.

No comments: