Well, I'm not going to go into arrays too much since thats a huge topic unto itself. But you have your tic tac toe grid set up in an array where grid[0] is the top left corner, grid[1] is the top spot, etc all the way to grid[8] being the bottom right corner. Then to print out your grid you would do:
Code:
for (int x=0; x<9; x++)
{
cout<<grid[x];
if ((x+1)%3==0)
cout<<endl;
}
Now to "rotate" the board. I put rotate in quotation marks because in reality you really aren't rotating anything. All you are doing is calling the index numbers of the grid array in a different order. If the grid is point up, then the top left corner is 0. If it is pointing to the right, then the top left corner is 6. Down its 3 and left its 8. So to keep track of the order of the all the numbers depending on which way the board is pointing I use the two-dimensional array and another integer which keeps track of which direction the board is currently facing. So put this into your compiler and watch it rotate:
Code:
char grid[9]={'X','0','0','0','X','X','0','X','0'};
int gridIndex[4][9]={{0,1,2,3,4,5,6,7,8},{6,3,0,7,4,1,8,5,2},{8,7,6,5,4,3,2,1,0},{2,5,8,1,4,7,0,3,6}};
int direction=0; // 0=up 1=right 2=down 3=left
for (direction=0; direction<4; direction++)
{
for (int x=0; x<9; x++)
{
cout<<grid[gridIndex[direction][x]];
if ((x+1)%3==0)
cout<<endl;
}
cout<<endl;
}