Page 1 of 1
Computer Programming
Posted: Sat Dec 06, 2008 12:13 pm
by Spencer
I'm doing a project on programming a computer to play Tic-Tac-Toe. Here's the link to the guide for my project-
https://www.sciencebuddies.org/science- ... ?from=Home. The project is due 12/16/08, so I need to get it soon. I've already started my experiment but I'm stuck on the
experimental procedure at the bottom of the page. I don't know how to program the computer to make a move so I need someone to help me with that or give me an example. Also here's the link to the site I'm using to program it-
http://www.w3schools.com/js/js_howto.asp. If you press the
Write HTML with Javascript it will get you to where I'm programing. Reply soon.
Re: Computer Programming
Posted: Sun Dec 07, 2008 11:18 pm
by deleted-2574
Hi Spencer,
I'm not really that familiar with javascript (lots of other languages). so I'll take a guess.
To make a move, it looks the program needs to include:
document.getElementById('a_b').value = "X";
to put an "X" on square with coordinates (a,b)
Similarly, one would include the code:
document.getElementById('a_b').value = "Y";
to put an "X" on square with coordinates (a,b)
I hope this is what you were looking for. If not, please let us know. Thanks.
Re: Computer Programming
Posted: Mon Dec 08, 2008 6:17 pm
by Spencer
I'm not sure you got what I meant. I mean I don't know how to make the computer make a move, as if I'm playing against the computer, I don't know how to make the computer move to a spot on the board. In other words, make the computer move to a spot itself.
Re: Computer Programming
Posted: Mon Dec 08, 2008 7:11 pm
by deleted-2574
Hi Spencer,
The computer does not move to a spot. When it's the computer's turn, the computer calculates the spot that the computer wants to select. The computer then sets the value of the square to either "X" or "Y" using the equation above. The computer then redisplays the board, calculates win/loss/draw and, if there are still empty spaces and the game has not reached a win/loss/draw conclusion, asks the human for the human's next move.
The logic for the above are explained in the text following Making a JavaScript Tic-Tac-Toe Board" in
https://www.sciencebuddies.org/science- ... ?from=Home