From 36bcdd1518ba4580091d4130c81f9eb09f1e480d Mon Sep 17 00:00:00 2001 From: dani Date: Thu, 6 Jul 2023 14:06:27 +0000 Subject: [PATCH] implemented Distribution for Direction --- src/hexmap.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/hexmap.rs b/src/hexmap.rs index 8477128..cc386df 100644 --- a/src/hexmap.rs +++ b/src/hexmap.rs @@ -1,4 +1,6 @@ use crate::{Image, Tileset, Vec2}; +use rand::prelude::Distribution; +use rand::Rng; use std::rc::Rc; //odd-q vertical layout https://www.redblobgames.com/grids/hexagons @@ -125,3 +127,16 @@ impl HexMap { (coord.x + coord.y * self.size.x) as usize } } + +impl Distribution for Direction { + fn sample(&self, rng: &mut R) -> Direction { + match rng.gen_range(0..6) { + 0 => Direction::North, + 1 => Direction::NorthEast, + 2 => Direction::SouthEast, + 3 => Direction::South, + 4 => Direction::SouthWest, + _ => Direction::NorthWest, + } + } +}