View Full Version : Tic Tac Toe in Java
April 12, 2005, 02:55 PM
What would be a good data structure to use? Or can I simply view the board as a 2D array of square objects? In that case, what would the artificial intelligence of the computer player be like? I mean how would I make it act according to what's going on in the other squares?
I've thought of a design (both for the board and the AI), but would like a few suggestions before getting down to actual coding.
April 12, 2005, 03:00 PM
here's my plan: the board will be a two dimensional array of squares, and the computer will loop through the arrays to check for consecutive X's (assuming that the computer is playing with O's) and fill in the spot next to any two consecutive X's. if there's no threat, it'll do whatever it wants (either put in an O randomly or make two consecutive O's in a row). i will use a variable to randomly generate error's on the computer's part.
Edited on, April 12, 2005, 8:02 PM GMT, by AsifTheManRahman.
April 12, 2005, 04:06 PM
Just use a basic A-search method with a pruning algorithm....
April 12, 2005, 04:07 PM
April 12, 2005, 04:13 PM
April 12, 2005, 04:21 PM
pruning algorithm looks interesting. any source to a good read?
April 12, 2005, 04:28 PM
Nilsson, N., Principles of Artificial Intelligence, San Francisco: Morgan Kaufmann, 1980.
here's a brief intro on the web:
For tic-tac-toe you can actually afford to do exhaustive search
Edited on, April 12, 2005, 9:29 PM GMT, by Zunaid.
April 13, 2005, 08:55 AM
Nilsson all the way! :)
that was by far better than anything i got from google. thanks!
vBulletin® v3.8.7, Copyright ©2000-2016, vBulletin Solutions, Inc.