removed unused head count
This commit is contained in:
parent
e987438ab5
commit
3bc6efca18
@ -100,7 +100,6 @@ impl CanvasParts{
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct CanvasState {
|
pub struct CanvasState {
|
||||||
pub(crate) colors: i32,
|
|
||||||
pub(crate) iterations: u128,
|
pub(crate) iterations: u128,
|
||||||
//pub(crate) food_rate: u8,
|
//pub(crate) food_rate: u8,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -93,11 +93,11 @@ fn main() {
|
|||||||
|
|
||||||
// Create the canvas
|
// Create the canvas
|
||||||
let mut canvas: CanvasParts = create_canvas();
|
let mut canvas: CanvasParts = create_canvas();
|
||||||
let mut state = components::CanvasState {colors: 0, iterations: 0, }; //food_rate: 0
|
let mut state = components::CanvasState {iterations: 0, }; //food_rate: 0
|
||||||
draw_canvas(&canvas);
|
draw_canvas(&canvas);
|
||||||
loop {
|
loop {
|
||||||
part_handler::head_handle(&mut canvas, &mut state.colors);
|
part_handler::head_handle(&mut canvas);
|
||||||
part_handler::spawner_handle(&mut canvas, &mut state.colors);
|
part_handler::spawner_handle(&mut canvas);
|
||||||
part_handler::handle_killed(&mut canvas.alive);
|
part_handler::handle_killed(&mut canvas.alive);
|
||||||
part_handler::spawn_food(&mut canvas);
|
part_handler::spawn_food(&mut canvas);
|
||||||
|
|
||||||
|
|||||||
@ -1,11 +1,12 @@
|
|||||||
|
use std::thread;
|
||||||
|
use std::sync::mpsc;
|
||||||
use crossterm::style::Color;
|
use crossterm::style::Color;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use crate::HashMap;
|
use crate::HashMap;
|
||||||
|
|
||||||
use crate::components::{self, CanvasParts, Creature, Direction, Element, Part};
|
use crate::components::{self, CanvasParts, Creature, Direction, Element, Part};
|
||||||
const SIGHT_RADIUS: u16 = 5;
|
const SIGHT_RADIUS: u16 = 4;
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
pub static ref CHECK_DIRECTIONS: HashMap<(Direction, Direction), (Vec<Vec<Direction>>, Element)> = HashMap::from([
|
pub static ref CHECK_DIRECTIONS: HashMap<(Direction, Direction), (Vec<Vec<Direction>>, Element)> = HashMap::from([
|
||||||
@ -47,14 +48,14 @@ fn get_unused_color(creatures: &Vec<Creature>) -> Color {
|
|||||||
color
|
color
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn spawner_handle(canvas: &mut CanvasParts, heads: &i32) {
|
pub fn spawner_handle(canvas: &mut CanvasParts) {
|
||||||
let inactive_spawns: Vec<usize> = canvas.interactable.iter()
|
let inactive_spawns: Vec<usize> = canvas.interactable.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.filter(|(_, elem)| elem.element == Element::Spawn && canvas.alive.iter().filter(|creature| creature.spawner_at == elem.position).count() == 0)
|
.filter(|(_, elem)| elem.element == Element::Spawn && canvas.alive.iter().filter(|creature| creature.spawner_at == elem.position).count() == 0)
|
||||||
.map(|(index, _)| index)
|
.map(|(index, _)| index)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
if *heads < inactive_spawns.len() as i32{
|
if canvas.alive.len()< inactive_spawns.len() {
|
||||||
canvas.interactable[inactive_spawns[0]].color = Color::Rgb { r: 10, g: 255, b: 10 };
|
canvas.interactable[inactive_spawns[0]].color = Color::Rgb { r: 10, g: 255, b: 10 };
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,9 +129,8 @@ fn recursive_colision_check(color: &Color, parts_in_sight: &Vec<Part>, position:
|
|||||||
b.2.cmp(&a.2) compares the third element of b and a (in reverse order because we want the highest element first). */
|
b.2.cmp(&a.2) compares the third element of b and a (in reverse order because we want the highest element first). */
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn head_handle(canvas: &mut CanvasParts, head_count: &mut i32) {
|
pub fn head_handle(canvas: &mut CanvasParts) {
|
||||||
// Find all elements that head can see
|
// Find all elements that head can see
|
||||||
*head_count = canvas.alive.len() as i32;
|
|
||||||
let unified_canvas = canvas.clone();
|
let unified_canvas = canvas.clone();
|
||||||
for creature in canvas.alive.iter_mut() {
|
for creature in canvas.alive.iter_mut() {
|
||||||
let head = creature.parts.iter().filter(|elem| elem.element == Element::BodyPartHead).next();
|
let head = creature.parts.iter().filter(|elem| elem.element == Element::BodyPartHead).next();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user