PDA

View Full Version : Tic Tac Toe in Java


AsifTheManRahman
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.

thanks!:)

AsifTheManRahman
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.

Zunaid
April 12, 2005, 04:06 PM
Just use a basic A-search method with a pruning algorithm....

Arnab
April 12, 2005, 04:07 PM
show off

AsifTheManRahman
April 12, 2005, 04:13 PM
hahaha

AsifTheManRahman
April 12, 2005, 04:21 PM
pruning algorithm looks interesting. any source to a good read?

Zunaid
April 12, 2005, 04:28 PM
Classic:

Nilsson, N., Principles of Artificial Intelligence, San Francisco: Morgan Kaufmann, 1980.

here's a brief intro on the web:

http://students.cs.byu.edu/~cs670ta/Lectures/Minimax.html

For tic-tac-toe you can actually afford to do exhaustive search

Edited on, April 12, 2005, 9:29 PM GMT, by Zunaid.

AsifTheManRahman
April 13, 2005, 08:55 AM
Nilsson all the way! :)

that was by far better than anything i got from google. thanks!