Computer Programming
Moderators: kgudger, bfinio, Moderators
-
- Posts: 2
- Joined: Sat Dec 06, 2008 11:36 am
- Occupation: Student
- Project Question: Computer Programming
- Project Due Date: 12/16/08
- Project Status: I am conducting my experiment
Computer Programming
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.
-
- Former Expert
- Posts: 675
- Joined: Thu Feb 03, 2005 3:38 pm
Re: Computer Programming
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.
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.
Cheers!
Dave
Dave
-
- Posts: 2
- Joined: Sat Dec 06, 2008 11:36 am
- Occupation: Student
- Project Question: Computer Programming
- Project Due Date: 12/16/08
- Project Status: I am conducting my experiment
Re: Computer Programming
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.
-
- Former Expert
- Posts: 675
- Joined: Thu Feb 03, 2005 3:38 pm
Re: Computer Programming
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
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
Cheers!
Dave
Dave