Sorry.....
It's set to 12/12 becuase i need to make sure the sequence created doesn't go "out of bounds"
Here is the wholfe thing if you want a look.
Oh and input has to be over 10 int's
Code:
#include <iostream>
#include <stdio.h>
#include <string>
#define RAND_MAX 3
#include <time.h>
#define PopSize 10
#define AAlgh 12
#define X 24
#define Y 24
using namespace std;
using std::string;
using std::cout;
using std::endl;
using std::cin;
void GetUserInput(string &Input)
{
cout << "Please enter Amino Acid Sequence \"H,P\": " << endl;
cin >> Input;
cin.get();
}
void GetSetupString(string theInput, int Output[10])
// To declare an Array as a reference from Main, syntax is differant then other
// references, ie: Type (&ArryName)[Size], try finding that in any tutorial :)
// Input is now changed into the correct alphabet {1,0} and stored in output
// edit, don't need to reference Arrys.
{
int index;
for (index = 0; index < 10; ++index)
{
switch (theInput[index])
{
case 'H':
Output[index] = 1;
break;
case 'P':
Output[index] = 0;
break;
default:
break;
}
cout << Output[index] ;
}
cout << endl;
cin.get();
}
void GetCreateGrid(int Grid[X][Y])
{
// Fill each element in arry
int index;
int j;
for (index = 0; index < X; index++)
{
for ( j = 0; j < Y; j++)
{
Grid[index][j] = 8;
cout << Grid[index][j] << " " ;
}
cout << endl;
}
cout << "Start Filling Grid" << endl;
}
void GetFillGrid(int Output[10], int Pop[PopSize][AAlgh], int Grid[X][Y] )
// Fill grid with an Individual and then store the sequence {Forward,Left,Right}
// as one of the population until whole population is created.
{
int x;
int y;
int rdm;
int index;
int j;
int i;
for (index = 0; index < PopSize; index++)
{
// clear whole grid again?
x = 12;
y = 12;
Grid[x][y] = Output[0]; // Place first element in [12][12] so it is
// impossible for it to go out of bounds
for ( j = 1; j < PopSize; j++)
{
rdm = rand()%3;
switch (rdm)
{
case 0: // Go Forward
{ if (Grid[++x][y] != 1 && Grid[x][y] != 0 )
{
Grid[x][y] = Output[j];
Pop[index][j] = 1;
cout << "Forward Picked" << endl;
}
else
{
Grid[--x][y];
j--;
cout << "Error" << endl;
}
}
break;
case 1: // Go Left
{ if (Grid[x][--y] != 1 && Grid[x][y] != 0 )
{
Grid[x][y] = Output[j];
Pop[index][j] = 2;
cout << "Left Picked" << endl;
}
else
{
Grid[x][++y];
j--;
cout << "Error" << endl;
}
}
break;
case 2: // Go Right
{ if (Grid[x][++y] != 1 && Grid[x][y] != 0 )
{
Grid[x][y] = Output[j];
Pop[index][j] = 3;
cout << "Right Picked" << endl;
}
else
{
Grid[x][--y];
j--;
cout << "Error" << endl;
}
}
break;
default:
break;
}
}
for (i = 0; i < X; i++)
{
for (j = 0; j < Y; j++)
{
cout << Grid[i][j] << " ";
}
cout << endl;
}
cout << endl;
// cout << "Grid Sequence: " << Pop[index][j] << endl;
for (i = 0; i < X; i++)
{
for ( j = 0; j < Y; j++)
{
Grid[i][j] = 8;
cout << Grid[i][j] << " " ;
}
cout << endl;
}
cout << "Grid Cleared" << endl;
cin.get();
}
}
int main ()
{
srand ( time(NULL) );
string Input;
int Output[10];
int Pop[PopSize][AAlgh];
int Grid[X][Y];
GetUserInput(Input);
GetSetupString(Input, Output);
GetCreateGrid(Grid);
GetFillGrid(Output, Pop, Grid);
cout << "all functions done" << endl;
cin.get();
}
I'am sure there are many newb mistakes and better ways to do what i've done, but i only started really getting into c++ like 5-7 days ago so bear with me thanks.
Regards Wolfe