Maes
I like big butts!
Posts: 12395
Registered: 0706 
Weird sequence of actions you do there.
code:
//feltöltés
for(j=0;j<25;j++){
for(i=0;i<25;i++){
field[i][j]='.';
}
printf("\n");
}
So first every item in the field is a '.', OK.
code:
//kijárat lehelyezése. nem nagy cucc
x = rand() % 23 +1;
y = rand() % 23 +1;
if(field[x][y] != 'X'){
field[x][y] = 'X';
}
You check for ONE random point in the field if it's not equal to 'X'...which it won't, of course, so essentially you mark one random point as the 'X'. You can skip the if checking, I think.
code:
//random elemek behelyezése, random elszórással
for(i=0;i<100;i++){
x = rand() % 23 +1;
y = rand() % 23 +1;
if(field[x][y] != '?'){
field[x][y] = '?';
}else{
i= i1;
}
}
OK, so if I understood you're trying to place 100 unique random '?' marks here, repeating if necessary. Not the most clean way to do it, but it works.
code:
for(k=0;k<4;k++){
x = rand() % 23 +1;
y = rand() % 23 +1;
// itten gyün 3 ciklus ami ellenőrzi hogy vane 5x5ös távolságon belül hasonló elem
// ha nincs, kirajzolja az elemet, ha van, visszalép amíg nem talál olyat ahol nincs
for (j=y2;j<y+2;j++){
for (i=x2;i<x+2;i++){
if (field[i][j] == 'O'){
st1 = true;
}
if (field[i][j] == ''){
st2 = true;
}
if (field[i][j] == ''){
st3 = true;
}
}
}
if(st1 == false && st2 == false && st3 == false && x<25 && y<25 && x>0 && y>0){
field[x][y] = 'O';
field[x1][y] = '';
field[x+1][y] = '';
field[x][y1] = '';
field[x][y+1] = '';
}else{
k= k1;
}
}
If I understood correctly, you're trying to place 4 door/portallike elements like this:
code:

O

on your grid. You place an element centered on [x][y] iff there are no '', '' or 'O' within a Moore distance of 2 from [x][y] (the iterator you designed is a radius2 Moore/Tchebychev iterator), otherwise you try again.
The first obvious problem I see here is that the st1,st2,st3 variables are not reset to some default value at the beginning of a loop, so if at some point they are all set to true there's no way to set them back to false.
Second, the iterator might go out of bounds (1+ rand()%23 results in values of x,y:[1,23], and if you subtract 2 from x or y it might go out of bounds.
Third, since you said that "sometimes" it doesn't draw the grid, it would be useful to specify exactly WHICH portions are not drawn. All of them? Just the "portals"? What values of x,y and/or rand() cause this? Also, modifying the loop variable "k" is a bad idea: it might go negative SEVERAL times, and in the end either place more than 4 "portals" on the grid, or even underflow under extreme circumstances.
There are also easier ways to check if a "portal" is already placed: just check if a grid cell has an 'O', and/or decide beforehand where you want your portals placed (come up with 4 pairs of coordinates) and make sure than each pair has a Moore distance of >=2 or more than the others.
Also, I don't get this bit:
code:
void write(char tomb[25][25]){
int row,col; //row = sorok; col = oszlopok
for(col=0;col<20;col++){
for(row=0;row<20;row++){
printf("%c ",tomb[row][col]);
}
printf("\n");
}
}
Why do you only write the first 20x20 cells of the grid, if previously you computed a 25x25 one? It's not like you used a part of them as a safety border, either, though you seem to constrain certain x,y calculations to a [1,23] range, as noticed before. Perhaps you meant to use a 22*22 grid? In that case you must map a [1...23]range to [0...22] range in write()
Last edited by Maes on 041513 at 12:39
