### rand() in attempted roguelike?

I've been trying to create a roguelike, and I was trying to create randomly generated rooms like in Rogue. I'm seperating my map array into sections and giving it a 50% chance of spawning a room, but right now it doesn't do anything but spawn solid rock. What am I doing wrong?

 ``123456789101112131415161718192021222324252627282930313233343536373839`` ``````int MapSizeX = 100; int MapSizeY = 100; char map[100][100] = {}; char wall = 178; int ViewDistance = 10; int x = 25; int y = 25; int Groom = 1; int RoomArea = 10; void Init() { map[MapSizeY][MapSizeX]; for(int a = 0; a < MapSizeY; a++) { for(int b = 0; b < MapSizeX; b++) { map[b][a] = wall; } } for(int c = 0; c < MapSizeX; c = c + RoomArea) { for(int d = 0; d < MapSizeY; d = d + RoomArea) { int Groom = (rand() % 2) + 1; if(Groom == 2) { for(int a = 0; a < RoomArea; a++) { for(int b = 0; b < RoomArea; b++) { map[a][b] = ' '; } } } } } }``````
Looks fine to me. Have you tried setting a breakpoint and stepping through that part?
The problem is your innermost loop:

 ``1234`` ``````for(int b = 0; b < RoomArea; b++) { map[a][b] = ' '; }``````

You are only ever setting the upper-left (or maybe lower-left) corner of the map. You want to do this:

 ``1234`` ``````for(int b = 0; b < RoomArea; b++) { map[a + c][b + d] = ' '; }``````

You just haven't seen the carved area because you are initializing x and y to 25 with a view distance of 10.
Oh, I get it! Thanks!
Topic archived. No new replies allowed.