DWK~~Thx so much

Have reduced the code replaced by yours haha.. I am so stupid ~ ~

Anyway can you give me a little bit more hint how to place the 1's??

thanks thanks

Printable View

- 03-30-2008peacealida
DWK~~Thx so much

Have reduced the code replaced by yours haha.. I am so stupid ~ ~

Anyway can you give me a little bit more hint how to place the 1's??

thanks thanks - 03-30-2008peacealida
still getting error and i am not sure is this correct as well

Code:`int run;`

char filename[16];

FILE *filep;

char *nodep;

int row, col, next_row, next_col, heading, steps, pellets;

enum {NORTH, EAST, SOUTH, WEST};

////create map 32 X 32 with all zeros////

char matrix[MATRIX_SIZE][MATRIX_SIZE];

char matrix_data[MATRIX_SIZE][MATRIX_SIZE] = {{0}};

////created the map with zeros////

///////////////////////////now fill 1's into the field/////////////////////////

/////////////////////////////////////////////////////////////////////////

///////////test/////////

int main() {

int x;

int c;

srand(()%1024);

for(x=0; x<100; x++) {

int n = 100 + rand() % 300;

printf("%d\n", 1);

for (c = 0; c < 300; c++) matrix_data[rand()%MATRIX_SIZE][rand()%MATRIX_SIZE] = 1;

}

}

/////////////////////////

char trace_matrix[MATRIX_SIZE][MATRIX_SIZE];

void output_program(struct prog *progp)

{

char *codep = progp->code;

char token;

while (token = *codep++)

fputs(token_table[token].name, stdout);

putchar('\n');

}

void print_matrix(void)

{ int i, j; char symbs[] = " OX";

for (i=0; i < MATRIX_SIZE; i++)

{ for (j=0; j < MATRIX_SIZE; j++)

putchar(symbs[trace_matrix[i][j]]);

putchar('\n');

}

}

- 04-01-2008peacealida
Hi the code is working now.

Code:

////create array map 32 X 32 (1024 steps) with all zeros and trace map////

int matrix[MATRIX_SIZE][MATRIX_SIZE];

int matrix_data[MATRIX_SIZE][MATRIX_SIZE] = {{0}};

int trace_matrix[MATRIX_SIZE][MATRIX_SIZE];

///////////////////////////////////////////char to int//////////////

void output_program(struct prog *progp)

{

char *codep = progp->code;

int token;

while (token = *codep++)

fputs(token_table[token].name, stdout);

putchar('\n');

}

int main()

{

int i; time_t start;

seed = time(NULL);

time(&start);

Now the program produce a random map. But how can i ensure food do not overlap??

In addition, is it able to create 1 random map and 2 maps to allow user to choose? and how can I implement it?

thanks - 04-01-2008tabstop
Watch carefully; there may be a test afterwards:

Code:`for (c = 0; c < 300; c++) {`

int x = rand()%MATRIX_SIZE;

int y = rand()%MATRIX_SIZE; //our x- and y-coordinates

matrix_data[x][y]++; // add 1 to our randomly chosen spot

if (matrix_data[x][y] > 1) { // oops! too much!

matrix_data[x][y] = 1; //reset food

c--; //take away from the count of food

}

}

- 04-01-2008peacealida
I cant belive you ability so fast......

It runs perfet!!!!

You know the array I have creted... can you hint me why it kept error pleasE??

Code:

int matrix[MATRIX_SIZE][MATRIX_SIZE];

int matrix_data[4][MATRIX_SIZE][MATRIX_SIZE];

{

cout <<"Ender Maze wanted:";

cin >> x;

cout <<"Maze Choosen is: " << x << endl <<endl;

matrix_data[0][MATRIX_SIZE][MATRIX_SIZE] = {{0}};

matrix_data[1][MATRIX_SIZE][MATRIX_SIZE]= {{1}};

// //--------------------------------------------------------------//

// //--------------------------------------------------------------//

return matrix_data[0];

}

int trace_matrix[MATRIX_SIZE][MATRIX_SIZE];

in the main

Code:`int main()`

{

int n;

for (n=0; n<4; n++);

//result += matrix_data[n];

printf("%d\n", matrix_data[n]);

//std::cout<< matrix_data <<std::enl;

//cout << result

return 0;

wt statement i need to read the array and put it back?

Thanks for you Great Help X 10000000000 - 04-01-2008tabstop
You can only use an array initializer when you declare it, so this line:

Code:`matrix_data[0][MATRIX_SIZE][MATRIX_SIZE] = {{0}};`

To initialize a matrix, you need to run a double for-loop. So, for instance, to initialize matrix_data[0], we would run a for-loop on row, and inside that a for-loop on col, and inside*that*we would set matrix_data[0][row][col].

Alternatively, you could do one big initializer as so:

Code:`matrix_data[4][MATRIX_SIZE][MATRIX_SIZE] = {`

{{0}}, //this is matrix_data[0], the random one

{{0,1,1,0,1,1,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0}, //this is first row of [1]

{ ...stuff ...}, //the second row of [1]

{ et cetera },

{ and so on}} //end of [1]

{{more numbers}, //first row of [2]

.

.

.

- 04-01-2008peacealida
These are what I have mdify:

Code:`#include <iostream.h>`

#include <fstream.h>

#include <iomanip.h>

////create array map 32 X 32 (1024 steps) with all zeros and trace map////

int matrix[MATRIX_SIZE][MATRIX_SIZE];

int matrix_data[2][MATRIX_SIZE][MATRIX_SIZE];

{

cout <<"Ender Maze wanted, 0,1,2,3:\n";

cout <<" 0- Random Maze\n";

cout <<" 1- Set Maze (1)\n";

cout <<" 2- Exit\n";

cin >> x;

cout <<"Maze Choosen is: " << x << endl <<endl;

matrix_data[0][MATRIX_SIZE][MATRIX_SIZE] = {{0}};

matrix_data[1][MATRIX_SIZE][MATRIX_SIZE] =

{ {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},

{0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},

{0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0},

{0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0},

{0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0},

{0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0},

{0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0},

{0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0},

{0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0},

{0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0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,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0},

{0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0},

{0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0},

{0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0},

{0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0},

{0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},

{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}

};

return matrix_data[0];

}

int trace_matrix[MATRIX_SIZE][MATRIX_SIZE];

///////////////////////////////////////////char to int//////////////

void output_program(struct prog *progp)

{

char *codep = progp->code;

int token;

while (token = *codep++)

fputs(token_table[token].name, stdout);

putchar('\n');

}

void print_matrix(void)

{ int i, j; char symbs[] = " OX";

for (i=0; i < MATRIX_SIZE; i++)

{ for (j=0; j < MATRIX_SIZE; j++)

putchar(symbs[trace_matrix[i][j]]);

putchar('\n');

}

}

But where do i use the double- for loop?? and what should i include in the main?

What i am currently in the main isn't very usefulllll

Code:`int main()`

{

int n;

for (n=0; n<4; n++);

//result += matrix_data[n];

printf("%d\n", matrix_data[n]);

std::cout<< matrix_data <<std::enl;

//cout << result

return 0;

---------------------------[thanks for the Help]-------------------------------- - 04-01-2008matspCode:
`matrix_data[1][MATRIX_SIZE][MATRIX_SIZE] =`

{ {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},

{0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},

{0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0},

{0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0},

....

};

Code:`int matrix_data[2][MATRIX_SIZE][MATRIX_SIZE];`

--

Mats - 04-01-2008tabstop
- 04-01-2008peacealida
Hi Mats I am sorry can you explain further what do i need to change??

you mean i have to change from:

matrix_data[1][MATRIX_SIZE][MATRIX_SIZE] =

{ {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,1},

{0,1,.....

[/code]

to

Code:

int matrix[MATRIX_SIZE][MATRIX_SIZE];

int matrix_data[2][MATRIX_SIZE][MATRIX_SIZE];

cout <<"Ender Maze wanted, 0,1,2,3:\n";

cout <<" 0- Random Maze\n";

cout <<" 1- Set Maze (1)\n";

cout <<" 2- Exit\n";

cin >> x;

cout <<"Maze Choosen is: " << x << endl <<endl;

matrix_data[0][MATRIX_SIZE][MATRIX_SIZE] = {{0}};

matrix_data[1][MATRIX_SIZE][MATRIX_SIZE] =

{ {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},

{0,1,0,0,0,0

or sth else???? Cheers

[code] - 04-01-2008peacealida
tapstop ic

So i should put the pre-define matrix inside the

int main()? - 04-01-2008matsp
I mean "something else".

You have variable declaration (int matrix_data[...][...][...];), and then you attempt to assign this variable using an initializer list somewhere else. That is not valid code.

Simple example:

Code:`// Valid code:`

int arr[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };

// Not valid code

int arr[10];

arr = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };

Mats - 04-01-2008peacealida
This is the problem; coz i am try to store differetn 32 X 32 matrix.

therefore in my array have 2 maps.

I can't not just put 1 number.

So how can i resolve this???

or like this?

Code:

int matrix_data[2][MATRIX_SIZE][MATRIX_SIZE]; = { {{0}}, {{1,1,1,1,1,0,0,0,0,0,0,},{1,1,1,0,0,0,0,1,1,0}};}

---------------------------[thanks for the Help]-------------------------------- - 04-01-2008tabstop
- 04-01-2008tabstop