#Weird patterns in Dungeon Generation (Java)

14 messages · Page 1 of 1 (latest)

devout maple
#

Hey everyone, I’m running into a strange issue with my dungeon generator.

I’m using a central java.util.Random object with a fixed seed, which I pass down to my logic classes (RoomLogic, PathLogic, etc.). Theoretically, it should be fine, but I keep getting repetitive, "unnatural" patterns in the layout that I can't explain.

The Setup: Standard Random object passed via a Config class.

The Issue: The distribution feels "off" almost like there's a bias in how rooms are placed.

My questions:

Is java.util.Random known for** poor distribution** in 2D/3D grid generation?

Should I switch to something like a Mersenne Twister or XorShift?

Or is this more likely a "Modulo Bias" / logic error in how I map coordinates?

Has anyone dealt with "non-random" looking randomness before? Any advice on how to debug this would be huge. Thanks!

    public boolean roomPlacement(ZoneConfig zoneConfig) {

        //---PLATZIERUNGS-VERSUCHE---//
        for (int i = 0; i < maxTries; i++) {
            
            //---ZONE ROTIEREN---//
            Zone rotatedZone = zoneConfig.getZone().get(Direction.getRandomDirection(random));

            ZoneSize size = rotatedZone.getZoneSize();

            //---GRID GRENZEN BERECHNEN---//
            int minX = 0 - size.getxMin();
            int maxX = g.xSize - 1 - size.getxMax();

            int minY = 0 - size.getyMin();
            int maxY = g.ySize - 1 - size.getyMax();

            int minZ = 0 - size.getzMin();
            int maxZ = g.zSize - 1 - size.getzMax();

            //---ZUFÄLLIGE POSITION---//

            int x = random.nextInt(maxX - minX + 1) + minX;
            int y = random.nextInt(maxY - minY + 1) + minY;
            int z = random.nextInt(maxZ - minZ + 1) + minZ;

            //---FÜR TOP ODER BOTTOM LAYER ROOMS---//
            if (zoneConfig.getLayer() == Layer.BOTTOM) {
                z = size.getzMin()*-1;

                for (int j = 0; j < size.getDiameterZ(); j++) {
                    if(g.getFillRatioOnZ(j) > targetFillRatio) {
                        return false;
                    }
                }
            }else if(zoneConfig.getLayer() == Layer.TOP) {
                z = g.zSize - size.getzMax() - 1;

                for (int j = g.zSize; j > size.getDiameterZ(); j--) {
                    if(g.getFillRatioOnZ(j-1) > targetFillRatio) {
                        return false;
                    }
                }
            }

            //---PLATZIERUNG PRÜFEN---//
            if (g.canPlace(rotatedZone, x, y, z)) {
                g.addRoom(rotatedZone, x, y, z);
                Log.info("Placed Room after [" + i + "] tries.");
                return true;
            }
        }

        //---KEINE PLATZIERUNG MÖGLICH---//
        Log.warning("Couldnt Place Room after [" + maxTries + "] tries.");
        return false;
    }
pallid fieldBOT
#

This post has been reserved for your question.

Hey @devout maple! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 720 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

devout maple
#

this happens in every generation at least once, can happen with any room, its very strange behaviour

#

it doenst matter how many different seeds or randoms i use, its always the same strange patterns

dry holly
#

Instead of random.nextInt(max - min + 1) + min you can just call random.nextInt(min, max + 1).

#

But I cannot see what should be off about those placements.

native anchor
#

One thing you could test is using SecureRandom which should have higher entropy

#

Also when you get into the conditional zoneConfig.getLayer() == Layer.BOTTOM, did you intentionally use *-1 (i.e. changing the sign) in z = size.getzMin()*-1?

devout maple
#

Yeah the *-1 is on purpose

devout maple
pallid fieldBOT
# devout maple thanks yeah i will change that

If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.

devout maple
native anchor
#

I am not entirely sure what the roomPlacement method is supposed to do