Tic Tac Toe Problem. Need HELP!!!!
Code:
#include <iostream>
#include <time.h>
using namespace std;
void playerTurn(int *playerPickRow, int *playerPickCol);
void compTurn(int *compPickRow, int *compPickCol);
void playGame();
void playerWin(char *array, int value1, int value2);
int main()
{
cout << "Welcome to TicTacToe v.1" << endl;
cout << "Programmed by: Ryan Nielson\n\n" << endl;
playGame();
system("PAUSE");
return 0;
}
void playGame()
{
bool playerWin = true;
int playerPickCol, playerPickRow;
int compPickCol, compPickRow;
int i, j;
char array[3][3] = {{'.', '.', '.'},
{'.', '.', '.'},
{'.', '.', '.'}};
do {
playerTurn(&playerPickRow, &playerPickCol);
while (array[playerPickRow][playerPickCol] == 'O')
{
cout << "Do not place your piece on the opponents. Please try again." << endl;
playerTurn(&playerPickRow, &playerPickCol);
}
array[playerPickRow][playerPickCol] = 'X';
playerWin(array, 3, 3);
compTurn(&compPickRow, &compPickCol);
while ((array[compPickRow][compPickCol] == 'X') || (array[compPickRow][compPickCol] == 'O') )
{
compTurn(&compPickRow, &compPickCol);
}
array[compPickRow][compPickCol] = 'O';
cout << endl;
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
cout << array[i][j];
}
cout << endl;
}
cout << endl;
}while (playerWin != false);
}
void playerTurn(int *playerPickRow, int *playerPickCol)
{
cout << "Please pick a column: ";
cin >> *playerPickCol;
cout << "Please pick a Row: ";
cin >> *playerPickRow;
*playerPickRow -= 1;
*playerPickCol -= 1;
}
void compTurn(int *compPickRow, int *compPickCol)
{
// Get Dice Value
*compPickRow = (rand () % 3);
*compPickCol = (rand () % 3);
}
void playerWin(char *array, int value1, int value2)
{
if ((array[0][0] == 'X') && (array[0][1] == 'X') && (array[0][2] == 'X') )
{
cout << "X wins";
}
if ((array[1][0] == 'X') && (array[1][1] == 'X') && (array[1][2] == 'X') )
{
cout << "X wins";
}
if ((array[2][0] == 'X') && (array[2][1] == 'X') && (array[2][2] == 'X') )
{
cout << "X wins";
}
if ((array[0][0] == 'X') && (array[1][0] == 'X') && (array[2][0] == 'X') )
{
cout << "X wins";
}
if ((array[0][0] == 'X') && (array[1][1] == 'X') && (array[2][1] == 'X') )
{
cout << "X wins";
}
if ((array[0][2] == 'X') && (array[1][2] == 'X') && (array[2][2] == 'X') )
{
cout << "X wins";
}
}
Can anyone tell me whats wrong with it.
I know its in the playerWin function. I think im pointing to the array wrong.
Can anyone tell me?