!!!Please help me with my tic-tac-toe game!!!
Im new to the forums
Iv made a visual basic Tic-Tac-Toe game, initially i wanted just for it to be a 2 player human game.. But iv decided i want to be able to play against a AI computer player, it does not have to be smart but it has to have some form of intelligence..
Here is the zip file with all the neccasary vb project/form files..
http://www.caldicot-pc-helpdesk.co.uk/Tic.zip
Basically what i need help with, is i want some way of selecting a 1 player game, i then want to be able to code is so that when the player chooses a square, it will run through the array and find all the enabled cmdbuttons, randomise and select a random cmdbutton and place a 0 or a X depending on what the computer player is..
Any help would be great..
Re: !!!Please help me with my tic-tac-toe game!!!
Re: !!!Please help me with my tic-tac-toe game!!!
Got anything abit simpler?
Re: !!!Please help me with my tic-tac-toe game!!!
His example may seem complex at first, but really the bit that conserns you is relativly straight foward.
What he's doing, in easy mode, is to randomly pic a position (by choosing a random number), then if it's already taken then choose another one... When he finds a free space, he goes there.
VB Code:
Do
'Randomize the numbers that Rnd() generates (only need to do this once)
Randomize
'Generate a random number from 0 to 8
RndNum = Int(Rnd() * 9) + 0
'If this space is free then exit this loop
Loop Until Picture1(RndNum).Picture = 0
Re: !!!Please help me with my tic-tac-toe game!!!
so how would i apply this to an array of 0-8 cmdbuttons (when the cmdbutton is clicked by player1, computer randomises and picks a cmdbutton, if it has a caption of X or 0 then move to the next one, if the caption of the cmdbutton = "" then place a mark)
Re: !!!Please help me with my tic-tac-toe game!!!
Something like this i guess:
VB Code:
Do
'Randomize the numbers that Rnd() generates (only need to do this once)
Randomize
'Generate a random number from 0 to 8
RndNum = Int(Rnd() * 9) + 0
'If this space is free then exit this loop
Loop Until cmdbuttons(RndNum).text = ""
cmdbuttons(RndNum).text = "X" 'assuming computer is Xs