2006-05-09

Mu Torere, setting the AI

Step 16.
The dialog for the custom AI 'Level-of-Effort' is fairly simple. All the special functionality works on a dialog box that contains a horizontal scrollbar, a couple of static texts to mark the high and low end of the scrollbar, an edit box and the 'OK' and 'Cancel' buttons. The only functions that need to be explained are the InitDialog(), the OnHScroll() and the OnEnChangeEdit1() (or what ever the edit box is id'ed in your program) functions.
Using MS's IDE one should associate a variable with the edit box.

Oh yes, there are a few named constants to specify the AI levels for the program. As long as 0 is used for the Off end of the scale and around 95 for High, it really does not matter what value is used for the Low and Middle of the scale (example, 25 and 66 respectively). Remember that the program uses the randomMove() function whenever the random value (mod 100) is GREATER than the AI level choosen.

On dialog initialization;
BOOL CAILevel::OnInitDialog()
Get a CEdit pointer the the dialog's Edit box.
Get a CScrollbar pointer to the dialog's horizontal scrollbar.

Get the text associated with the edit box. (Part of the Data Exchange process.)
Re-format the text as integer. (Use _tstoi() for the UNICODE enabled programs.)

Set the lower and upper limits of the scrollbar to 0 and 100 resp.
Set the scrollbar position to the integer value retrieved from the edit box. (As this is an initialization, the scrollbar will not need redrawing.)


On changes of the edit box;
void CAILevel::OnEnChangeEdit1()
Get a CEdit pointer the the dialog's Edit box.
Get a CScrollbar pointer to the dialog's horizontal scrollbar.

Get the text associated with the edit box. (Part of the Data Exchange process.)
Re-format the text as integer. (Use _tstoi() for the UNICODE enabled programs.)

Set the scrollbar position to the integer value retrieved from the edit box.


to reflect the changes of the scrollbar in the edit bxo (and the variable that is retrievable);
void CAILevel::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
Get the lowest limit, the highest limit and the current position of the scrollbar.

Given how the scrollbar position is changing (given by nSBCode),change the scrollbar position as appropriate.

Get the CEdit pointer the edit box.
Set the edit box's text to the value of the scrollbar's current position.

No comments: