VC++ AI (sorta)
Hello, I am making a TicTacToe game in VC++ with dialog boxes and buttons, I am currently working on the single player AI, i have a function that determines which button the user picked and tries to block him from getting a line, but i am stuck when it comes to making it pick boxes that aren''t already picked!, I have gotten it to not pick them but then it just loses its turn and the user gets to put 2 x''s in a row, this problem happens alot when almost all the boxes are picked and there is only afew left, can anyone tell me how to make it pick from the boxes that are left??
here is one of the functions i have written (please note that this onl took me like 5 min''s so there is probubly going to be a better way to do this)
---------------------\/-CODE-\/---------------------------------
if(playerx == 1 && x != 1)
{
comp = (rand() % 3);
if(comp == 0 && eight != 1)
{ CWnd* pWnd = GetDlgItem(IDC_BUTTON88);
pWnd->SetWindowText("O");
player = 1;
eight = 1;
playery = 2;
}
if(comp == 1 && six != 1)
{ CWnd* pWnd = GetDlgItem(IDC_BUTTON66);
pWnd->SetWindowText("O");
player = 1;
six = 1;
playerc = 2;
}
if(comp == 2 && five != 1)
{ CWnd* pWnd = GetDlgIte(IDC_BUTTON55);
pWnd->SetWindowText("O");
player = 1;
five = 1;
playerb = 2;
}
x = 1;
}
----------------/\-CODE-/\--------------------------------------
Could someone please tell me how to not make it pick a button if its already been picked??
P.S. all the functions are the same basically........
Thank you
I didnt really look at your code, but you should try and save the positions of the left over boxes in an array
==========CODE================
int *iLeftOverBoxes = new int[iAmountOfLeftOverBoxes];
/* Fill the iLeftOverBoxes array with the index''s(?!?) of the left over boxes */
int iBoxToUse = iLeftOverBoxes[rand()%iAmountOfLeftOverBoxes];
==============================
Or something like that anyway.
==========CODE================
int *iLeftOverBoxes = new int[iAmountOfLeftOverBoxes];
/* Fill the iLeftOverBoxes array with the index''s(?!?) of the left over boxes */
int iBoxToUse = iLeftOverBoxes[rand()%iAmountOfLeftOverBoxes];
==============================
Or something like that anyway.
This is a reletively simple problem, and your code, uncommented as it is, is too hard to fallow for an outsider. NOTE that you will spend 5 mins coding and 15-20 mins debugging, instead of 10 mins coding and 5 mins debugging.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement