1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use super::{RandomPerm, Sampler};
use vek::*;

const UNIT_CHOICES: [(Vec2<i32>, Vec2<i32>); 8] = [
    (Vec2 { x: 1, y: 0 }, Vec2 { x: 0, y: 1 }),
    (Vec2 { x: 1, y: 0 }, Vec2 { x: 0, y: -1 }),
    (Vec2 { x: -1, y: 0 }, Vec2 { x: 0, y: 1 }),
    (Vec2 { x: -1, y: 0 }, Vec2 { x: 0, y: -1 }),
    (Vec2 { x: 0, y: 1 }, Vec2 { x: 1, y: 0 }),
    (Vec2 { x: 0, y: 1 }, Vec2 { x: -1, y: 0 }),
    (Vec2 { x: 0, y: -1 }, Vec2 { x: 1, y: 0 }),
    (Vec2 { x: 0, y: -1 }, Vec2 { x: -1, y: 0 }),
];

pub struct UnitChooser {
    perm: RandomPerm,
}

impl UnitChooser {
    pub const fn new(seed: u32) -> Self {
        Self {
            perm: RandomPerm::new(seed),
        }
    }
}

impl Sampler<'static> for UnitChooser {
    type Index = u32;
    type Sample = (Vec2<i32>, Vec2<i32>);

    fn get(&self, perm: Self::Index) -> Self::Sample {
        UNIT_CHOICES[self.perm.get(perm) as usize % UNIT_CHOICES.len()]
    }
}