Jump to content
  • Advertisement
Sign in to follow this  
willselway

Naughts & Crosses AI (java)

This topic is 2757 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
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!