<commit_before>//!
//! Generate a super simple dungeon
//!

extern crate rand;
use self::rand::{thread_rng, Rng};

mod automata;
use self::automata::{Automaton, DrunkardsWalk};

mod builder;
use self::builder::{Buildable, Fussy, Simple};

pub mod map;
use self::map::{Grid, Tile, TileType};

use core::object::Entity;

mod dungeon_tests;

///
/// `Dungeon` struct to stitch together all builders and cellular automatons
///
#[derive(Default)]
pub struct Dungeon {
  pub width: usize,
  pub height: usize,
  pub grid: Grid<Tile>,
}

impl Dungeon {

  ///
  /// Make the dungeon
  ///
  pub fn build(&mut self) {

    // Apply simple builder first
    let mut grid = Simple::new(self.grid.clone()).build();

    let wall = Tile::new(
      "Wall",
      '#',
      (40, 40, 40),
      (33, 33, 33),
      TileType::Wall
    );

    let floor = Tile::new(
      "Floor",
      ' ',
      (255, 255, 255),
      (20, 20, 20),
      TileType::Floor
    );

    // Closure for generating drunkards walks
    let drunk = |chaos: f32, iter: u32, grid: &mut Grid<Tile> | -> Grid<Tile> {
      let d = DrunkardsWalk::new(chaos);
      d.generate(
        grid,
        None,
        None,
        Some(wall.clone()),
        floor.clone(),
        iter
      )
    };

    // Total randomness
    grid = drunk(1.0, 1000, &mut grid);

    // Semi random
    grid = drunk(0.5, 1000, &mut grid);

    // Mostly orderly
    grid = drunk(0.25, 1000, &mut grid);

    // Add Stairs
    //
    // So I know that get_valid_location() should be deprecated since we started adding stairs
    // but we're just gonna have to live with it for now
    //
    let spos1 = Dungeon::get_valid_location(&grid);
    grid[spos1.0][spos1.1] = Tile::new(
      "Down Stair",
      '>',
      (255, 255, 255),
      (0, 0, 0),
      TileType::DownStair
    );

    let spos2 = Dungeon::get_valid_location(&grid);
    grid[spos2.0][spos2.1] = Tile::new(
      "Up Stair",
      '<',
      (255, 255, 255),
      (0, 0, 0),
      TileType::UpStair
    );

    // Apply noise
    let mut f1 = Fussy::new(Dungeon::generate_grid(self.width, self.height, 0_u8), 1.2);
    let bin_grid1 = f1.build();

    for x in 0..self.width {
      for y in 0..self.height {
        if bin_grid1[x][y] == 1 {
          match grid[x][y].tiletype {
            TileType::Wall => {
               grid[x][y].set_fg((67, 57, 57));
               grid[x][y].set_bg((60, 50, 50));
            },
            _ => grid[x][y].set_bg((25, 20, 20))
          }
        }
      }
    }

    // Apply noise 2
    let mut f2 = Fussy::new(Dungeon::generate_grid(self.width, self.height, 0_u8), 1.2);
    let bin_grid2 = f2.build();

    for x in 0..self.width {
      for y in 0..self.height {
        if bin_grid2[x][y] == 1 {
          match grid[x][y].tiletype {
            TileType::Wall => {
               grid[x][y].set_fg((57, 57, 57));
               grid[x][y].set_bg((50, 50, 50));
            },
            _ => grid[x][y].set_bg((20, 20, 20))
          }
        }
      }
    }

    // Apply noise 3
    let mut f3 = Fussy::new(Dungeon::generate_grid(self.width, self.height, 0_u8), 1.4);
    let bin_grid3 = f3.build();

    for x in 0..self.width {
      for y in 0..self.height {
        if bin_grid3[x][y] == 1 {
          match grid[x][y].tiletype {
            TileType::Wall => {
              grid[x][y].set_fg((57, 57, 67));
              grid[x][y].set_bg((50, 50, 60));
            },
            _ => grid[x][y].set_bg((20, 20, 25))
          }
        }
      }
    }

    // Apply noise 4
    let mut f4 = Fussy::new(Dungeon::generate_grid(self.width, self.height, 0_u8), 1.4);
    let bin_grid4 = f4.build();

    for x in 0..self.width {
      for y in 0..self.height {
        if bin_grid4[x][y] == 1 {
          match grid[x][y].tiletype {
            TileType::Wall | TileType::DownStair | TileType::UpStair => {},
            _ => {
              grid[x][y].set_bg((128, 179, 255));
              grid[x][y].tiletype = TileType::Water;
            }
          }
        }
      }
    }

    self.grid = grid;

  }

  fn generate_grid<T : Clone>(w: usize, h: usize, init: T) -> Grid<T> {<commit_msg>changed default water tile color<commit_after>//!
//! Generate a super simple dungeon
//!

extern crate rand;
use self::rand::{thread_rng, Rng};

mod automata;
use self::automata::{Automaton, DrunkardsWalk};

mod builder;
use self::builder::{Buildable, Fussy, Simple};

pub mod map;
use self::map::{Grid, Tile, TileType};

use core::object::Entity;

mod dungeon_tests;

///
/// `Dungeon` struct to stitch together all builders and cellular automatons
///
#[derive(Default)]
pub struct Dungeon {
  pub width: usize,
  pub height: usize,
  pub grid: Grid<Tile>,
}

impl Dungeon {

  ///
  /// Make the dungeon
  ///
  pub fn build(&mut self) {

    // Apply simple builder first
    let mut grid = Simple::new(self.grid.clone()).build();

    let wall = Tile::new(
      "Wall",
      '#',
      (40, 40, 40),
      (33, 33, 33),
      TileType::Wall
    );

    let floor = Tile::new(
      "Floor",
      ' ',
      (255, 255, 255),
      (20, 20, 20),
      TileType::Floor
    );

    // Closure for generating drunkards walks
    let drunk = |chaos: f32, iter: u32, grid: &mut Grid<Tile> | -> Grid<Tile> {
      let d = DrunkardsWalk::new(chaos);
      d.generate(
        grid,
        None,
        None,
        Some(wall.clone()),
        floor.clone(),
        iter
      )
    };

    // Total randomness
    grid = drunk(1.0, 1000, &mut grid);

    // Semi random
    grid = drunk(0.5, 1000, &mut grid);

    // Mostly orderly
    grid = drunk(0.25, 1000, &mut grid);

    // Add Stairs
    //
    // So I know that get_valid_location() should be deprecated since we started adding stairs
    // but we're just gonna have to live with it for now
    //
    let spos1 = Dungeon::get_valid_location(&grid);
    grid[spos1.0][spos1.1] = Tile::new(
      "Down Stair",
      '>',
      (255, 255, 255),
      (0, 0, 0),
      TileType::DownStair
    );

    let spos2 = Dungeon::get_valid_location(&grid);
    grid[spos2.0][spos2.1] = Tile::new(
      "Up Stair",
      '<',
      (255, 255, 255),
      (0, 0, 0),
      TileType::UpStair
    );

    // Apply noise
    let mut f1 = Fussy::new(Dungeon::generate_grid(self.width, self.height, 0_u8), 1.2);
    let bin_grid1 = f1.build();

    for x in 0..self.width {
      for y in 0..self.height {
        if bin_grid1[x][y] == 1 {
          match grid[x][y].tiletype {
            TileType::Wall => {
               grid[x][y].set_fg((67, 57, 57));
               grid[x][y].set_bg((60, 50, 50));
            },
            _ => grid[x][y].set_bg((25, 20, 20))
          }
        }
      }
    }

    // Apply noise 2
    let mut f2 = Fussy::new(Dungeon::generate_grid(self.width, self.height, 0_u8), 1.2);
    let bin_grid2 = f2.build();

    for x in 0..self.width {
      for y in 0..self.height {
        if bin_grid2[x][y] == 1 {
          match grid[x][y].tiletype {
            TileType::Wall => {
               grid[x][y].set_fg((57, 57, 57));
               grid[x][y].set_bg((50, 50, 50));
            },
            _ => grid[x][y].set_bg((20, 20, 20))
          }
        }
      }
    }

    // Apply noise 3
    let mut f3 = Fussy::new(Dungeon::generate_grid(self.width, self.height, 0_u8), 1.4);
    let bin_grid3 = f3.build();

    for x in 0..self.width {
      for y in 0..self.height {
        if bin_grid3[x][y] == 1 {
          match grid[x][y].tiletype {
            TileType::Wall => {
              grid[x][y].set_fg((57, 57, 67));
              grid[x][y].set_bg((50, 50, 60));
            },
            _ => grid[x][y].set_bg((20, 20, 25))
          }
        }
      }
    }

    // Apply noise 4
    let mut f4 = Fussy::new(Dungeon::generate_grid(self.width, self.height, 0_u8), 1.4);
    let bin_grid4 = f4.build();

    for x in 0..self.width {
      for y in 0..self.height {
        if bin_grid4[x][y] == 1 {
          match grid[x][y].tiletype {
            TileType::Wall | TileType::DownStair | TileType::UpStair => {},
            _ => {
              grid[x][y].set_bg((57, 144, 255));
              grid[x][y].tiletype = TileType::Water;
            }
          }
        }
      }
    }

    self.grid = grid;

  }

  fn generate_grid<T : Clone>(w: usize, h: usize, init: T) -> Grid<T> {
{'fraction_non_alphanumeric': 0.16802297750119674, 'fraction_numerical': 0.04631402584968885, 'mean_word_length': 1.8415504930295818, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 35, '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': '2463858', 'n_tokens_mistral': 3298, 'n_tokens_neox': 2972, 'n_words': 702}