2D Random Array Parsed to Chars

I am new to C++ and a self study student in my first class. I am creating a TicTacToe program and need to create 2 TICTACTOE boards one which is an ordered 2D array of chars, the second is a side by side randomized board. I am having problems creating a random board. The code works with 2 identical boards. I need to randomize the cells in the second board and parse them to chars as rand() is int. Essentially when you choose an X or O in one cell in one board it goes into a corresponding cell with the same index but not the same position on the second board thereby allowing 2 different ways of getting TICTACTOE. I am getting an error below, my code is below that. I have tried everything but cannot get a randomized bboard of chars. Thank you for any help you may offer.

----jGRASP exec: /Rick/MCC Programs/CIS 235 C++/TicTacToe2

----jGRASP wedge: process died on signal 8.
----jGRASP: operation complete.

#include <cstdlib>
#include <ctime>
#include <iostream>
#include <cmath>
#include <iomanip>


using namespace std;

void showgame();
void player();
bool gameover();


char player1, player2;
char user;
bool tie = false;
const int ROW = 3;
const int COL = 3;
int bboard[ROW][COL];


char aboard[3][3]= {{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'}};





int main()
{
// const int MIN = 1;
// const int MAX = 9;
//
unsigned seed = time(0);
srand(seed);

// char bboard[3][3]= char (rand() % {{1, 2, 3},
// {4, 5, 6},
// {7, 8, 9}});



for(int i=0; i<ROW; i++)
for(int j=0; j<COL; j++)
bboard[i][j] = (rand() % i*COL+j+1);



cout << "Tic Tac Toe\n";
do{
cout << " Player 1 is first select either X or O: ";
cin >> player1;
}while(player1 != 'X' && player1 != 'O');


if(player1 == 'X')
{
player2 = 'O';
user = 'X';
}
else if (player1 == 'O')
{
player2 = 'X';
user = 'O';
}


while(!gameover())

{
showgame();
player();
gameover();
}
if(user == 'X' && !tie)
{
showgame();
cout << "Tic Tac Toe: O Wins!\n";
}
else if(user == 'O' && !tie)
{
showgame();
cout << "Tic Tac Toe: X Wins!";
}
else
{
showgame();
cout << "Tie Game!";
}
}


void showgame()
{
cout<< " "<<" Player 1: "<<player1<<"\n";
cout<< " "<<" Player 2: "<<player2<<"\n";
cout<< " "<<"-----------------------"<<endl;

cout << " | | " " " " | | "<<endl;
cout << " "<<aboard[0][0] << " | " <<aboard[0][1] << " | " <<aboard[0][2] << " " <<bboard[0][0] << " | " <<bboard[0][1] << " | " <<bboard[0][2] <<endl;
cout << " | | " " " " | | "<<endl;
cout << "______ _________ ______" " " "______ _________ ______"<<endl;
cout << " | | " " " " | | "<< endl;
cout << " "<<aboard[1][0] << " | " <<aboard[1][1] << " | " <<aboard[1][2] << " " <<bboard[1][0] << " | " <<bboard[1][1] << " | " <<bboard[1][2]<<endl;
cout << " | | " " " " | | "<< endl;
cout << "______ _________ ______ " " " "______ _________ ______ "<< endl;
cout << " | | " " " " | | "<<endl;
cout << " "<<aboard[2][0] << " | " <<aboard[2][1] << " | " <<aboard[2][2] << " "<<bboard[2][0] << " | " <<bboard[2][1] << " | " <<bboard[2][2]<< endl;
cout << " | | " " " " | | "<<endl;
cout << " | | " " " " | | "<<endl;
}

void player()
{
int selection;
int row=0, column = 0;


if (user == 'X')
{
cout <<"X is up: ";
}
else if (user == 'O')
{
cout <<"O is up: ";
}

cin >> selection;

switch (selection)
{
case 1: row = 0; column = 0;
break;
case 2: row = 0; column = 1;
break;
case 3: row = 0; column = 2;
break;
case 4: row = 1; column = 0;
break;
case 5: row = 1; column = 1;
break;
case 6: row = 1; column = 2;
break;
case 7: row = 2; column = 0;
break;
case 8: row = 2; column = 1;
break;
case 9: row = 2; column = 2;
break;
default:
cout << "Number input is incorrect, input a number from 1-9! Try again.\n";
player();
}

if (user == 'X' && aboard[row][column] != 'X' && aboard[row][column] != 'O')
{
aboard[row][column] = 'X';
bboard[row][column] = 'X';
user='O';

}
else if (user == 'O' && aboard[row][column] != 'X' && aboard[row][column] != 'O')
{
aboard[row][column] = 'O';
bboard[row][column] = 'O';
user='X';

}
else
{
cout << "The space is already taken by the other player, choose an open space.\n";
player();
}
}

bool gameover()
{
for (int i = 0; i < 3; i++)
{
if ((((((((aboard[i][0] == aboard[i][1] && aboard[i][1] == aboard[i][2]) ||

(aboard[0][i] == aboard[1][i] && aboard[1][i] == aboard[2][i])||

(aboard[0][0] == aboard[1][1] && aboard[1][1] == aboard[2][2])||

(aboard[0][2] == aboard[1][1] && aboard[1][1] == aboard[2][0])||

(bboard[i][0] == bboard[i][1] && bboard[i][1] == bboard[i][2])||

(bboard[0][i] == bboard[1][i] && bboard[1][i] == bboard[2][i])||

(bboard[0][0] == bboard[1][1] && bboard[1][1] == bboard[2][2])||

(bboard[0][2] == bboard[1][1] && bboard[1][1] == bboard[2][0]))))))))
{
return true;
}


for (int x = 0; x < 3; x++)
{
for(int y = 0; y < 3; y++)
{
if ((aboard[x][y] != 'X' && aboard[x][y] != 'O') || (bboard[x][y] != 'X' && bboard[x][y] != 'O'))
{
return false;
}
}
tie = true;
return true;
return 0;
}
}
}


Topic archived. No new replies allowed.