1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use {
    super::{Creature, Generation},
    std::cmp::Ordering::Equal,
};
impl Generation {
    //TODO panic if all values are zero
    pub fn sort(&self) -> Vec<Creature> {
        let mut x = self.clone().unwrap();
        x.sort_by(|a, b| a.score.partial_cmp(&b.score).unwrap_or(Equal));
        x
        // Code once used to check the sort. The sort worked and was valid
        // let mut value = -0.1;
        // for (index, gene) in self.genes.iter().enumerate() {
        //     if value <= self.genes[index].score {
        //         value = self.genes[index].score;
        //     } else {
        //         panic!("Not sorted");
        //     }
        // }
    }
}