Computer Programming

Ask questions about projects relating to: computer science or pure mathematics (such as probability, statistics, geometry, etc...).

Moderators: kgudger, bfinio, Moderators

Locked
Spencer
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

Post 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.
davidkallman
Former Expert
Posts: 675
Joined: Thu Feb 03, 2005 3:38 pm

Re: Computer Programming

Post by davidkallman »

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.
Cheers!

Dave
Spencer
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

Post 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.
davidkallman
Former Expert
Posts: 675
Joined: Thu Feb 03, 2005 3:38 pm

Re: Computer Programming

Post by davidkallman »

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
Cheers!

Dave
Locked

Return to “Grades 9-12: Math and Computer Science”