i have a program that generates a grid of 20x20 using a 2d array, it then populates it by randomly generating 2 numbers as co-ordinates, and then filling it with either an 'x' or an 'o' it has a maximum of 5 x's and 100 o's.
What i need it to do now, and the bit i'm stuck on is how to get it to randomly choose a square and move the contents up, down, left or right
#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
using namespace std;
int main()
{
time_t now;
time(&now);
srand(now);
rand();
int nextStep;
int direction;
char lifeBoard[20][20];
//Creates the initial grid
for(int col=0; col<19; col++)
{
for(int row=0; row<19; row++)
{
lifeBoard[row][col]='.';
cout<<lifeBoard[row][col];
}
cout<<endl;
}
//Populates the grid with x's
for(int i=0;i<5;i++)
{
lifeBoard[rand()%19][rand()%19] = 'x';
}
//Populates the grid with o's
for(int i=0;i<100;i++)
{
lifeBoard[rand()%19][rand()%19] = 'o';
}
//Re-Draws the grid with the new charaters
for(int col=0; col<19; col++)
{
for(int row=0; row<19; row++)
{
cout<<lifeBoard[row][col];
}
cout<<endl;
}
direction = rand()%3;
//Moves the item up
if(direction=0)
{
lifeBoard[rand()%19][rand()%19]=row-1;
}
//Moves the item down
if(direction=1)
{
lifeBoard[rand()%19][rand()%19]=row+1;
}
system("Pause");
return 0;
}
thats what i got so far...
I am grateful of any help i get