<commit_before>use rand::Rng;
use num::Integer;
use calx::{V2};
use geomorph;
use geomorph::{Chunk};
use terrain::TerrainType;

pub fn gen_herringbone<R: Rng>(
    rng: &mut R, spec: &::AreaSpec, set_terrain: |V2<int>, TerrainType|) {
    let chunkref = geomorph::get_cache();
    let chunkbor = chunkref.borrow();
    let chunks = chunkbor.iter().filter(
        |c| c.spec.biome == spec.biome && c.spec.depth <= spec.depth)
        .collect::<Vec<&Chunk>>();

    let edge = chunks.iter().filter(|c| !c.exit && c.connected)
        .map(|&c| c).collect::<Vec<&Chunk>>();
    let inner = chunks.iter().filter(|c| !c.exit)
        .map(|&c| c).collect::<Vec<&Chunk>>();
    let exit = chunks.iter().filter(|c| c.exit)
        .map(|&c| c).collect::<Vec<&Chunk>>();

    assert!(!exit.is_empty(), "No exit chunks found");
    assert!(inner.len() + exit.len() == chunks.len());

    let exit_x = rng.gen_range(-1, 0);
    let exit_y = rng.gen_range(-1, 0);

    for cy in range(-2i, 2) {
        for cx in range(-2i, 2) {
            let on_edge = cy == -2 || cx == -2 || cy == 1 || cx == 1;

            let chunk = rng.choose(
                if (cx, cy) == (exit_x, exit_y) { exit.as_slice() }
                else if on_edge { edge.as_slice() }
                else { inner.as_slice() }).unwrap();

            for (&(x, y), &terrain) in chunk.cells.iter() {<commit_msg>Can spawn exit chunk anywhere on map<commit_after>use rand::Rng;
use num::Integer;
use calx::{V2};
use geomorph;
use geomorph::{Chunk};
use terrain::TerrainType;

pub fn gen_herringbone<R: Rng>(
    rng: &mut R, spec: &::AreaSpec, set_terrain: |V2<int>, TerrainType|) {
    let chunkref = geomorph::get_cache();
    let chunkbor = chunkref.borrow();
    let chunks = chunkbor.iter().filter(
        |c| c.spec.biome == spec.biome && c.spec.depth <= spec.depth)
        .collect::<Vec<&Chunk>>();

    let edge = chunks.iter().filter(|c| !c.exit && c.connected)
        .map(|&c| c).collect::<Vec<&Chunk>>();
    let inner = chunks.iter().filter(|c| !c.exit)
        .map(|&c| c).collect::<Vec<&Chunk>>();
    let exit = chunks.iter().filter(|c| c.exit)
        .map(|&c| c).collect::<Vec<&Chunk>>();

    assert!(!exit.is_empty(), "No exit chunks found");
    assert!(inner.len() + exit.len() == chunks.len());

    let exit_x = rng.gen_range(-2, 2);
    let exit_y = rng.gen_range(-2, 2);

    for cy in range(-2i, 2) {
        for cx in range(-2i, 2) {
            let on_edge = cy == -2 || cx == -2 || cy == 1 || cx == 1;

            let chunk = rng.choose(
                if (cx, cy) == (exit_x, exit_y) { exit.as_slice() }
                else if on_edge { edge.as_slice() }
                else { inner.as_slice() }).unwrap();

            for (&(x, y), &terrain) in chunk.cells.iter() {
{'fraction_non_alphanumeric': 0.2059992771955186, 'fraction_numerical': 0.010119262739428984, 'mean_word_length': 2.6088657105606257, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 23, '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': '7108143', 'n_tokens_mistral': 1025, 'n_tokens_neox': 998, 'n_words': 238}