Archived

This topic is now archived and is closed to further replies.

VC++ AI (sorta)

This topic is 5586 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.


Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites