tic-tac-toe

Discussion in 'Mac Programming' started by chris200x9, Dec 22, 2007.

  1. chris200x9 macrumors 6502a

    Joined:
    Jun 3, 2006
    #1
    Hi I'm writing a tic tac toe game and I am wondering how to go about making an AI, here is my code:

    Code:
    
    #include <iostream>
    using namespace std;
    int main()
    {
    int firstTurnRow;
    int firstTurnColumn;
    int secondTurnRow;
    int secondTurnColumn;
    int thirdTurnRow;
    int thirdTurnColumn;
    const int ROWS = 3;
    const int COLUMNS = 3;
    char board[ROWS][COLUMNS] = { {' ',' ',' '},
    							  {' ', ' ',' '},
    							  {' ',' ',' '} };
    						
    cout << "Here's the tic-tac-toe board:" << endl;
    for (int i = 0; i < ROWS; ++i)
    {
    	for (int j = 0; j < COLUMNS; ++j)
    	cout << board[i][j];
    	cout << endl;
    }
    cout << endl;
    
    cout << "enter the row you want to move into" << endl;
    cin >> firstTurnRow;
    
    cout << "enter column you want to move into" << endl;
    cin >> firstTurnColumn;
    
    board[firstTurnRow - 1][firstTurnColumn - 1] =  'X';
    
    
    cout << "Now the tic tac toe board is:" << endl;
    
    for (int i = 0; i < ROWS; ++i)
    {
    	for (int j = 0; j < COLUMNS; ++j)
    	cout << board[i][j];
    	cout << endl;
    }
    
    cout << endl;
    
    cout << "enter the row you want to move into" << endl;
    cin >> secondTurnRow;
    
    cout << "enter column you want to move into" << endl;
    cin >> secondTurnColumn;
    
    board[secondTurnRow - 1][secondTurnColumn - 1] =  'X';
    
    
    
    	cout << "Now the tic tac toe board is:" << endl;
    
    for (int i = 0; i < ROWS; ++i)
    {
    	for (int j = 0; j < COLUMNS; ++j)
    	cout << board[i][j];
    	cout << endl;
    }
    
    cout << endl;
    
    cout << "enter the row you want to move into" << endl;
    cin >> thirdTurnRow;
    
    cout << "enter column you want to move into" << endl;
    cin >> thirdTurnColumn;
    
    board[thirdTurnRow - 1][thirdTurnColumn - 1] =  'X';
    
    
    cout << "Now the tic tac toe board is:" << endl;
    
    for (int i = 0; i < ROWS; ++i)
    {
    	for (int j = 0; j < COLUMNS; ++j)
    	cout << board[i][j];
    	cout << endl;
    }
    
    cout << endl;
    
    	
    	
    	return 0;
    }
    
    

    any help would be greatly appreciated :)
     
  2. chris200x9 thread starter macrumors 6502a

    Joined:
    Jun 3, 2006

Share This Page