kyranstar / Hunt-The-Wumpus

6 stars 0 forks source link

Add randomly-generated cave #18

Closed WasabiFan closed 9 years ago

WasabiFan commented 9 years ago

We already have some basic code to create the whole cave. Now we just need to make it limit the corrections to 0<n<4 connections. There is a method to verify this in the map class.

kyranstar commented 9 years ago

Do you mean the CaveUtils.CheckIfValid method? Does that work?

WasabiFan commented 9 years ago

Do you mean the CaveUtils.CheckIfValid method?

Yup

Does that work?

Yes, although it is currently commented out here so that it doesn't throw exceptions while testing. I recommend that you test your algorithm by calling the check method yourself and then uncomment that line that I referenced when you think that you have it working.

kyranstar commented 9 years ago

@WasabiFan Do you have any idea how I can check if a Room already exists? For example, if I have this:

0
1 2
x 3

and I wanted to check if there was a room below 1, how could I do that? I was thinking I could check all of the rooms for their position and check if any were equal to (1.x, 1.y - 1.height), but that seems hacky. An easier way would be to check if any of x's neighbors are connecting to x, but then I need to figure out which rooms are x's neighbors. Any ideas?

WasabiFan commented 9 years ago

What contextual information do you have? If you already have the connections, it should be pretty easy (1.AdjacentRooms[Direction.South]), but I doubt that that's what you are trying to do. Are you assuming that you have a grid (say, 5x5) and you want to figure out what ID is below 1? Like what the MapGenerator.GetIDAtDirection method does, but in a more elegant way?

kyranstar commented 9 years ago

Sort of. I figured it out, but thanks! I basically just store the rooms in an array whenever I add them and just check whether they exist in the array when I'm adding a new one.

WasabiFan commented 9 years ago

@kyranstar Can you make it add random gold too?