Sign in to follow this  

Naughts & Crosses AI (java)

This topic is 2546 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

TLDR: Good way of implementing AI for naughts and crosses
(TLDR = to long didn't read)

Hey, I am making a simple naughts and crosses game using Java and the swing toolkit but I'm having a problem with developing the AI.

I need for someone to suggest a better way of implementing it as how i am doing it now just isn't working.

You click on a box to move and a X appears in that box and a boolean value is set so we can tell that someones moved in that box. Then the AI function i made is called which generates a random number using the '.nextInt(9)' and assigns it to generatedINT variable.

It then runs through a long while statement which see's if a box is free E.G.

while((generatedINT == 1 && box1taken == true) || generatedInt == 2 && box2take..

So on through all the 9 available boxes if the generatedINT corresponding box is taken i made it generate a new number then i assume it runs the while loop an till it generates a number which can go in a free box, i then use a switch statement after this to deiced what box to put 'Y' in. But i run it click on a box X comes up and then like 3 Y's all at once and sometimes not even one Y :S

TLDR: Good way of implementing AI for naughts and crosses
(TLDR = to long didnt read)


FIXED: I wasent 'break;' ing out my switch statement, opps. Still let me know if theres a better way of implementing this

Share this post


Link to post
Share on other sites

This topic is 2546 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this