Khishin 0 Newbie Poster

I have just started using C++ after a year or two of a BASIC language, and I wanted to do something that required some logic, but not a lot of different commands. I decided to do a tic tac toe playing program where your opponent was the program.

The way this is supposed to work is that the program goes through loops and put down pieces until the game ends, and keeping track of wins, losses, and draws in all of those possibilities, and find the best move based on the count. My question comes as pieces are put down, and after the sim-game has ended inside the counting cycle. I'm almost sure that if the spaces are not reset to empty before the next time it is used, it will interefere with the simulations. I was wondering when an where to reset the spaces.

My time on the computer is almost up for a while so I will post the start of my code and return tomorrow.

//simple AI for tic tac toe.

//load headers and namespace
#include <iostream>
#include <conio.h>
#include <windows.h>

using namespace std;

//begin main function
int main()
{

int pos [9] ;
int turn ;
turn=9 ;
int space [9] ;
int wins [9] ;
int move [9] ;

/*

space positions

1 2 3
4 5 6
7 8 9

Winning possibilities
1 2 3
- - -
- - -

- - -
4 5 6
- - -

- - -
- - -
7 8 9

1 - -
4 - -
7 - -

- 2 -
- 5 -
- 8 -

- - 3
- - 6
- - 9

1 - -
- 5 -
- - 9

- - 3
- 5 -
7 - -


*/

//first turn
if (turn==9)
{
    //first turn, layer 1
    for (pos [1]=1; pos [1]<4; pos [1]++)
    {
        //reset all spaces to unocupied (0)
        pos [1]=0;
        pos [2]=0;
        pos [3]=0;
        pos [4]=0;
        pos [5]=0;
        pos [6]=0;
        pos [7]=0;
        pos [8]=0;
        pos [9]=0;
        //occupy chosen space with an AI piece (1)
        if (pos [1]==1) {space [1]=1;}
        if (pos [1]==1) {space [2]=1;}
        if (pos [1]==1) {space [5]=1;}
        //first turn, layer 2
        for (pos [2]=1; pos [2]<10; pos [2]++)
        {
            //check to see if chosen space is unoccupied or not
            if (space [pos [2]]=0)
            {
                //occupy space with human piece (2)
                space [pos [2]]=2;
                //first turn, layer 3
                for (pos [3]=1; pos [3]<10; pos [3]++)
                {

Thank you for whatever help I get and I am sorry for not being able to answer any questions today.

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.