so i have this tic tac toe assignment in c++ and i need some help doing the moves part for both the computer and the player....i already got the board down with arrays and the specs for the functions needed are listed below...some help would be greatly appricaited and i dont need the WHOLE thing just how to start it off...thanks!

the board looks like this:

123
456
789

basically the player picks a number and an X is placed in the number and then the computer automatically makes another move, etc.
/**
* Displays the current game board.
*
* @param board The game board.
* @param size The number of elements in the game board.
*/
void displayBoard(const char board[], int size);

/**
* Prompts for a move and makes the move if valid.
* Otherwise, posts an error message and asks the
* user to enter a correct move.
*
* @param board The game board.
* @param prompt Message to display to the user.
* @param player Name of the player ('X' or 'O').
* @return The play made or -1 if the player exits the game.
*/
int move(char board[], int size, string prompt, char player);

/**
* Checks to see if the game has a winner.
*
* @param board The game board.
* @return true if a winner was found, otherwise false.
*/
bool checkWinner(const char board[]);

Member Avatar for iamthwee

>doing moves for the player.

Give them an option to enter a digit from 1-9 which will corresponds to an element on the grid. You also have to check that the position they choose isn't already occupied.

>doing moves for the computer.

This is a little bit more tricky. You will have to devise simple, yet non-trivial form of AI.

Your first task however, is to get all your basic functions working.

[IMG]http://img476.imageshack.us/img476/5171/cut20ln.png[/IMG]
Piworld ™
[Tis simple as Pie]

You can take advantage of the fact that you can rearrange a 3x3 grid so that all horz/vert/diag lines create a sum of 15

2  9  4
  7  5  3
  6  1  8

This gives you a much firmer ground to perform mathematical checks on lines, for both the human player and the AI

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.