removed unused head count

This commit is contained in:
someone 2024-03-06 19:17:01 +01:00
parent e987438ab5
commit 3bc6efca18
3 changed files with 9 additions and 10 deletions

View File

@ -100,7 +100,6 @@ impl CanvasParts{
}
pub struct CanvasState {
pub(crate) colors: i32,
pub(crate) iterations: u128,
//pub(crate) food_rate: u8,
}

View File

@ -93,11 +93,11 @@ fn main() {
// Create the 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);
loop {
part_handler::head_handle(&mut canvas, &mut state.colors);
part_handler::spawner_handle(&mut canvas, &mut state.colors);
part_handler::head_handle(&mut canvas);
part_handler::spawner_handle(&mut canvas);
part_handler::handle_killed(&mut canvas.alive);
part_handler::spawn_food(&mut canvas);

View File

@ -1,11 +1,12 @@
use std::thread;
use std::sync::mpsc;
use crossterm::style::Color;
use lazy_static::lazy_static;
use rand::Rng;
use crate::HashMap;
use crate::components::{self, CanvasParts, Creature, Direction, Element, Part};
const SIGHT_RADIUS: u16 = 5;
const SIGHT_RADIUS: u16 = 4;
lazy_static! {
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
}
pub fn spawner_handle(canvas: &mut CanvasParts, heads: &i32) {
pub fn spawner_handle(canvas: &mut CanvasParts) {
let inactive_spawns: Vec<usize> = canvas.interactable.iter()
.enumerate()
.filter(|(_, elem)| elem.element == Element::Spawn && canvas.alive.iter().filter(|creature| creature.spawner_at == elem.position).count() == 0)
.map(|(index, _)| index)
.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 };
}
@ -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). */
}
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
*head_count = canvas.alive.len() as i32;
let unified_canvas = canvas.clone();
for creature in canvas.alive.iter_mut() {
let head = creature.parts.iter().filter(|elem| elem.element == Element::BodyPartHead).next();