<commit_before>package net.bytten.metazelda;

import java.util.ArrayList;
import java.util.List;

public class LennasDungeonGenerator extends DungeonGenerator {

    // Red key, Green key, Blue key, Equipment (Spring)
    private int numKeys = 4;
    // Aim for 20 rooms +/- 25%
    private int targetRoomCount = 20;
    
    public LennasDungeonGenerator(long seed) {
        super(seed);
    }
    
    private float computeSpaceChoiceProbFactor(Room room, Coords xy) {
        int x = Math.abs(xy.x),
            y = Math.abs(xy.y);
        if (x < Math.abs(room.coords.x)) x = 0;
        if (y < Math.abs(room.coords.y)) y = 0;
        int dist = Math.max(x, y);
        return 1.0f / (2*dist + 1.0f);
    }

    @Override
    protected Integer chooseAdjacentSpace(Room room) {
        // Choose a random direction, but bias it so that we stay near 0,0
        float dirs[] = new float[Direction.NUM_DIRS];
        float sum = 0.0f;
        boolean atLeastOne = false;
        for (int d = 0; d < dirs.length; ++d) {
            Coords xy = room.coords.nextInDirection(d);
            if (newRoomAllowedInSpace(xy)) {
                float val = computeSpaceChoiceProbFactor(room, xy);
                dirs[d] = val;
                sum += val;
                atLeastOne = true;
            } else {
                dirs[d] = 0.0f;
            }
        }
        if (!atLeastOne) return null;
        for (int d = 0; d < dirs.length; ++d) {
            dirs[d] /= sum;
        }
        float p = getRandom().nextFloat();
        float x = 0.0f;
        int d = 0;
        while (d < dirs.length) {
            x += dirs[d];
            if (x > p) {
                return d;
            }
            ++d;
        }
        return null;
    }

    @Override
    protected boolean chooseCreateNewItem() {
        // choose probabilities to aim towards a specific number of keys
        return getRandom().nextFloat() <
            1.0f - (float)dungeon.itemCount() / (float)getNumKeys();
    }
    
    @Override
    protected boolean chooseCreatePaddingRoom(int depth) {
        // choose probabilities to aim towards a specific number of rooms
        return depth < 3 && getRandom().nextFloat() <
            1.0f - (float)dungeon.roomCount() / (float)getTargetRoomCount();
    }

    @Override
    protected Room chooseExistingRoom() {
        List<Room> rooms = dungeon.computeBoundaryRooms();
        List<Room> filtered = new ArrayList<Room>(rooms.size());
        for (Room room: rooms) {
            if (room.coords.y < 0)
                filtered.add(room);
        }
        if (filtered.size() == 0)
            filtered.add(dungeon.get(0,0));
        return filtered.get(getRandom().nextInt(filtered.size()));
    }

    @Override
    protected boolean chooseLinkNeighborOneWay(Room room, Room neighbor) {
        return !room.isGoal() && !neighbor.isGoal() &&
                super.chooseLinkNeighborOneWay(room, neighbor);
    }

    @Override
    protected Symbol choosePlacedItem() {
        return super.choosePlacedItem();
    }

    @Override
    protected boolean chooseReuseItem() {
        return super.chooseReuseItem();
    }
    
    public boolean desirable() {
        return dungeon != null &&
            dungeon.itemCount() == getNumKeys() &&
            dungeon.roomCount() >= getTargetRoomCount() * 0.75 &&
            dungeon.roomCount() <= getTargetRoomCount() * 1.25;
    }

    @Override
    public Dungeon generate() {
        while (!desirable()) {
            if (dungeon != null) {
                System.out.println("Discarding undesirable design and trying again");
            }
            super.generate();
        }
        return dungeon;
    }<commit_msg>LennasDungeonGenerator: Disable generation of one-way links between rooms because Lenna's Inception doesn't have a mechanism for this yet.<commit_after>package net.bytten.metazelda;

import java.util.ArrayList;
import java.util.List;

public class LennasDungeonGenerator extends DungeonGenerator {

    // Red key, Green key, Blue key, Equipment (Spring)
    private int numKeys = 4;
    // Aim for 20 rooms +/- 25%
    private int targetRoomCount = 20;
    
    public LennasDungeonGenerator(long seed) {
        super(seed);
    }
    
    private float computeSpaceChoiceProbFactor(Room room, Coords xy) {
        int x = Math.abs(xy.x),
            y = Math.abs(xy.y);
        if (x < Math.abs(room.coords.x)) x = 0;
        if (y < Math.abs(room.coords.y)) y = 0;
        int dist = Math.max(x, y);
        return 1.0f / (2*dist + 1.0f);
    }

    @Override
    protected Integer chooseAdjacentSpace(Room room) {
        // Choose a random direction, but bias it so that we stay near 0,0
        float dirs[] = new float[Direction.NUM_DIRS];
        float sum = 0.0f;
        boolean atLeastOne = false;
        for (int d = 0; d < dirs.length; ++d) {
            Coords xy = room.coords.nextInDirection(d);
            if (newRoomAllowedInSpace(xy)) {
                float val = computeSpaceChoiceProbFactor(room, xy);
                dirs[d] = val;
                sum += val;
                atLeastOne = true;
            } else {
                dirs[d] = 0.0f;
            }
        }
        if (!atLeastOne) return null;
        for (int d = 0; d < dirs.length; ++d) {
            dirs[d] /= sum;
        }
        float p = getRandom().nextFloat();
        float x = 0.0f;
        int d = 0;
        while (d < dirs.length) {
            x += dirs[d];
            if (x > p) {
                return d;
            }
            ++d;
        }
        return null;
    }

    @Override
    protected boolean chooseCreateNewItem() {
        // choose probabilities to aim towards a specific number of keys
        return getRandom().nextFloat() <
            1.0f - (float)dungeon.itemCount() / (float)getNumKeys();
    }
    
    @Override
    protected boolean chooseCreatePaddingRoom(int depth) {
        // choose probabilities to aim towards a specific number of rooms
        return depth < 3 && getRandom().nextFloat() <
            1.0f - (float)dungeon.roomCount() / (float)getTargetRoomCount();
    }

    @Override
    protected Room chooseExistingRoom() {
        List<Room> rooms = dungeon.computeBoundaryRooms();
        List<Room> filtered = new ArrayList<Room>(rooms.size());
        for (Room room: rooms) {
            if (room.coords.y < 0)
                filtered.add(room);
        }
        if (filtered.size() == 0)
            filtered.add(dungeon.get(0,0));
        return filtered.get(getRandom().nextInt(filtered.size()));
    }

    @Override
    protected boolean chooseLinkNeighborOneWay(Room room, Room neighbor) {
        // TODO disabled because Lenna's Inception does not have a mechanism for
        // this yet.
        return false;
    }

    @Override
    protected Symbol choosePlacedItem() {
        return super.choosePlacedItem();
    }

    @Override
    protected boolean chooseReuseItem() {
        return super.chooseReuseItem();
    }
    
    public boolean desirable() {
        return dungeon != null &&
            dungeon.itemCount() == getNumKeys() &&
            dungeon.roomCount() >= getTargetRoomCount() * 0.75 &&
            dungeon.roomCount() <= getTargetRoomCount() * 1.25;
    }

    @Override
    public Dungeon generate() {
        while (!desirable()) {
            if (dungeon != null) {
                System.out.println("Discarding undesirable design and trying again");
            }
            super.generate();
        }
        return dungeon;
    }
{'fraction_non_alphanumeric': 0.1143046357615894, 'fraction_numerical': 0.010596026490066225, 'mean_word_length': 1.8537414965986394, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2886431', 'n_tokens_mistral': 2319, 'n_tokens_neox': 2198, 'n_words': 577}